我打电话给肥皂网服务。
$client = new nusoap_client('https://site/webservices/Customer.asmx?WSDL', 'wsdl');
$param = array('asWebSecurityKey' => $asWebSecurityKey,'asEmail' => $user,'asPassword' => $pass);
$result = $client->call('AuthenticateCustomer', array('parameters' => $param), '', '', false, true);
在我调用该服务后,我收到一个这样的数组,但不确定如何在php页面上使用它们有什么帮助吗?
Array
(
[AuthenticateCustomerResult] => 0
[aCustomerArray] => Array
(
[UDT_Cpower_CustomerInfo] => Array
(
[CustomerKey] => 57f8cb38-08e9-428a-8f7d-808941b92106
[Title] =>
[FirstName] => TestMe
[LastName] => TestMe
[FullName] => TestMe TestMe
[Company] =>
[Address_Street] => 45 Test Rd.
[Address_Street2] =>
[Address_City] => Toronto
[Address_ProvState] => HI
[Address_PostalZip] => h0h k0k
[Phone_Home] => (444) 686-2222
[Phone_Work] => (333) 686-2222
[Phone_Other] =>
[Email] => test@test.com
[Language] =>
)
)
)
我尝试了以下内容:
$CustomerKey = ($result['CustomerKey']);
$FullName = ($result['FullName']);
$Address_Street = ($result['Address_Street']);
$Address_ProvState = ($result['Address_ProvState']);
$Address_PostalZip = ($result['Address_PostalZip']);
$Phone_Home = ($result['Phone_Home']);
答案 0 :(得分:0)
这里有一个多维数组结构。有2个级别的嵌套。 AuthenticateCustomerResult
是标量值0
,但aCustomerArray
本身是一个数组,其中一个元素的键名为UDT_Cpower_CustomerInfo
。在那里你可以找到你想要的所有属性。
例如:
// Assuming $result is the outermost Array structure you posted above.
$CustomerKey = $result['aCustomerArray']['UDT_Cpoiwer_CustomerInfo']['CustomerKey'];
或者为了节省一些输入,请参考带有变量的子数组:
// Make $custinfo point directly to the nested array
$custinfo = $result['aCustomerArray']['UDT_Cpoiwer_CustomerInfo'];
// Then you can access those values from $custinfo
$CustomerKey = $custinfo['CustomerKey'];
$FullName = $custinfo['FullName'];
但实际上,我不打算为每个变量创建像$CustomerKey, $FullName
这样的变量。它为您的全局命名空间添加了许多不必要的变量。相反,我只是直接从上面创建的$custinfo
使用它们。由于这些值是相关的,因此通过将它们保存为数组来保持它们的关系具有良好的逻辑意义。
echo "The customer's key is {$custinfo['CustomerKey']} and name is {$custinfo['FullName']}.";