PHP SOAP API 设置/登录

问题描述 投票:0回答:2

到目前为止我只使用过 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

php web-services api soap
2个回答
0
投票

问题出在我的语法中:

改变了

$UserInfo = array(
...
'SessionID' => null,
...
));

$UserInfo = array(
...
'Session' => array('SessionId' => ''),
...
));

0
投票

你能为我提供 guid() 功能吗? 因为我正在使用相同的功能。

© www.soinside.com 2019 - 2024. All rights reserved.