1

这是我从 twinfield API 调用登录方法时的响应。它给出了session idcluster namespace,但问题是如何从中获取值。

$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] => 
        )

)
4

1 回答 1

1

试试这个它会工作;)

function accessProtectedProperty($obj, $prop)
{
    $reflection = new \ReflectionClass($obj);
    $property = $reflection->getProperty($prop);
    $property->setAccessible(true);
    return json_decode($property->getValue($obj));
}
于 2017-12-28T11:50:14.893 回答