到目前为止,我只使用WEB API,我无法弄清楚SOAP究竟是如何工作的。PHP官方网站缺乏详细信息,几个例子对我没有多大帮助。我相信,如果我让 DoLogin 功能工作,我可以处理所有其他事情,但我错过了一些小东西,无法弄清楚到底是什么。这是我到目前为止的代码:
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
date_default_timezone_set('America/Denver');
$output = array();
$UserName = 'myusername';
$Password = 'mypassword';
$WSDL = 'https://onlineavl2api-us.navmanwireless.com/onlineavl/api/V1.9/service.asmx?WSDL';
$URL = 'https://onlineavl2api-us.navmanwireless.com/onlineavl/api/V1.9/service.asmx';
$client = new SoapClient($WSDL, array('trace' => 1, 'encoding' => 'UTF-8'));
$client->__setLocation($URL);
$GUID = getGUID(); // I have a separate function for creating GUID with PHP i can post if needed
$UserInfo = array(
'request' => array(
'SessionID' => null,
'UserCredential' => array(
'UserName' => $UserName,
'Password' => $Password,
'ApplicationID' => $GUID,
'ClientID' => $GUID,
'ClientVersion' => '1.2'
),
'IPAddress' => $_SERVER['SERVER_ADDR'],
'ClockVerificationUtc' => time()
));
try{
$SessionID = $client->DoLogin($UserInfo);
$AllFunctions = $client->__getFunctions();
$GetTypes = $client->__getTypes();
$LastRequest = $client->__getLastRequest();
$LastResponse = $client->__getLastResponse();
// $SessionID = $client->DoLogin($UserInfo);
}
catch(Exception $e) {
$output['errors'] = $e->getMessage();
}
$output['Types'] = $GetTypes;
$output['Functions'] = $AllFunctions;
$output['result'] = $result;
$output['LastRequest'] = $LastRequest;
$output['LastResponse'] = $LastResponse;
$output['SessionInfo'] = $SessionInfo;
print json_encode($output);
此代码的响应是以下错误:
Server was unable to process request. ---> A service call threw a security fault exception - Security.Fault: SessionIDNotFound ---> Security.Fault: SessionIDNotFound
以下是 DoLogin 函数已发布接口文档的链接:https://onlineavl2api-us.navmanwireless.com/onlineavl/api/V1.9/service.asmx?op=DoLogin
问题出在我的语法中:
改变
$UserInfo = array(
...
'SessionID' => null,
...
));
自
$UserInfo = array(
...
'Session' => array('SessionId' => ''),
...
));