Как получить значение от данного объекта ответа от Twinfield в Laravel/Lumen?

Это ответ, когда я вызываю метод входа из API Twinfield. Он дал идентификатор сеанса и пространство имен кластера, но проблема в том, как получить значение из него.

$customerApiConnector = new \PhpTwinfield\ApiConnectors\CustomerApiConnector($login);
print_r($customerApiConnector);die;

Выход:

  PhpTwinfield\ApiConnectors\CustomerApiConnector Object
    (
        [service:protected] => PhpTwinfield\Services\ProcessXmlService Object
            (
                [trace] => 1
                [compression] => 32
                [_stream_context] => Resource id #153
                [_soap_version] => 1
                [sdl] => Resource id #154
                [__default_headers] => Array
                    (
                        [0] => SoapHeader Object
                            (
                                [namespace] => http://www.twinfield.com/
                                [name] => Header
                                [data] => Array
                                    (
                                        [SessionID] => f7b4c213-1a01-4c7c-87cb-7de80b1583fe
                                    )

                                [mustUnderstand] => 
                            )

                    )

            )

    )

Это другой объект.

Array
(
    [1] => PhpTwinfield\CustomerAddress Object
        (
            [ID:PhpTwinfield\CustomerAddress:private] => 1
            [type:PhpTwinfield\CustomerAddress:private] => invoice
            [default:PhpTwinfield\CustomerAddress:private] => true
            [name:PhpTwinfield\CustomerAddress:private] => Anand
            [contact:PhpTwinfield\CustomerAddress:private] => 
            [country:PhpTwinfield\CustomerAddress:private] => IN
            [city:PhpTwinfield\CustomerAddress:private] => Indore
            [postcode:PhpTwinfield\CustomerAddress:private] => 452001
            [telephone:PhpTwinfield\CustomerAddress:private] => 
            [fax:PhpTwinfield\CustomerAddress:private] => 
            [email:PhpTwinfield\CustomerAddress:private] => anand@comfisoft.com
            [field1:PhpTwinfield\CustomerAddress:private] => 
            [field2:PhpTwinfield\CustomerAddress:private] => lig
            [field4:PhpTwinfield\CustomerAddress:private] => 
            [field5:PhpTwinfield\CustomerAddress:private] => 
            [field6:PhpTwinfield\CustomerAddress:private] => 
        )

)

1 ответ

Решение

Попробуйте это, это будет работать;)

function accessProtectedProperty($obj, $prop)
{
    $reflection = new \ReflectionClass($obj);
    $property = $reflection->getProperty($prop);
    $property->setAccessible(true);
    return json_decode($property->getValue($obj));
}
Другие вопросы по тегам