我正在尝试使用WDSL客户端创建__soapCall。但是我得到了这个错误:
Fatal error: Uncaught SoapFault exception: [Client] Function
("GenerateBarcode") is not a valid method for this service in
/Applications/MAMP/htdocs/postnl/postnl.php:75
Stack trace:
#0 /Applications/MAMP/htdocs/postnl/postnl.php(75): SoapClient-
>__soapCall('GenerateBarcode', Array)
#1 /Applications/MAMP/htdocs/postnl/postnl.php(110): Postnl-
>GenerateBarcode('DEVC', 11223344)
#2 {main}
我正在尝试调用此API:
https://developer.postnl.nl/apis/barcode-webservice/documentation
实例化客户端:
private $client;
public function __construct(){
// CreateSoapClient and assign to class
$this->createClient('https://testservice.postnl.com/CIF_SB/BarcodeWebService/1_1/?wsdl');
//Create Soap security
$this->createSoapSecurity($this->username, $this->password);
//Setting headers to client
$this->setSoapHeaders($securityHeader);
}
private function createClient($url){
//Create Client
$this->client = new SoapClient($url,['trace' => true]);
}
private function createSoapSecurity($username,$password){
//Create security
$username = new SoapVar($username, XSD_STRING, null, null, 'Username', self::XMLNS);
$password = new SoapVar(sha1($password), XSD_STRING, null, null, 'Password', self::XMLNS);
$usernameToken = new SoapVar([$username, $password], SOAP_ENC_OBJECT, null, null, 'UsernameToken', self::XMLNS);
$security = new SoapVar([$usernameToken], SOAP_ENC_OBJECT, null, null, 'Security', self::XMLNS);
$this->securityHeader = $security;
}
private function setSoapHeaders($securityHeader) {
// Set soap headers to client
$this->client->__setSoapHeaders($SecurityHeader);
}
当我vardump $this->client->__getFunctions()
时:
它正确返回:
array(1) { [0]=> string(80) "GenerateBarcodeResponse GenerateBarcode(GenerateBarcodeMessage $GenerateBarcode)" }
电话:
public function GenerateBarcode($customerCode, $customerNumber){
$this->createMessage();
$this->createBarcode('3S');
return $this->client->__soapcall('GenerateBarcode', [
'MessageID' => $this->MessageID,
'MessageTimeStamp' => $this->MessageTimeStamp,
'CustomerCode' => $this->customerCode,
'CustomerNumber' => $this->customerNumber,
'Type' => $this->type,
'Serie' => $this->serie
]);
}
它返回错误..
检查了Pratheek Katal请求中的soap标题。这是我需要创建的示例标题。
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password>password (sha1 hash)</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
我用来尝试制作的PHP代码:
$ns = $this->XMLNS;
$headerbody = [
'wsse:UsernameToken' => [
'wsse:Username' => $this->username,
'wsse:Password' => sha1($this->password),
],
];
$header = new SOAPHeader($ns, 'wsse:Security', $headerbody);
// Set soap headers to client
$this->client->__setSoapHeaders($header);
仍然得到同样的错误......
感谢任何帮助...