伙计我有一个问题我过去几天一直在学习肥皂,我一直在尝试连接到在线商店的网络服务,以验证用户购买电视机之前的电视许可证。
我编写了以下代码来测试电视许可证公司提供的网络服务。
<?php
$wdsl = "https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc?wsdl";
$options = array(
'trace' => true,
'exceptions' => true,
'connection_timeout' => 1
);
try{
$client = new SoapClient($wdsl,$options);
$apiauth = array(
'Rquid' => '3600cd32-28b9-4a4f-a522-4326def4a9c2',
'ApiKey' => '5957237e-101c-4ff2-8fdc-4bd6c9393a1d',
'AccountIdentifier' => '9211186012088',
'AccountIdentifierType' => 'SaidNumber');
$header = new SoapHeader('http://tempuri.org/','Auth',$apiauth,true);
$client->__setSoapHeaders($header);
$account = $client->GetAccount();
var_dump($account);
echo "<pre>";
var_dump($client);
echo "</pre>";
}catch (Exception $e) {
echo "Error!";
echo $e->getMessage() . "<br>";
echo 'Last response: ' . $client->__getLastResponse();
}
?>
wdsl不需要客户端证书,上面的api密钥仅用于测试。
我总是遇到的问题
unable to connect to host
但是如果我写了一个无效的函数,我得到一个错误,该函数对于这个服务是无效的,当我使用__GetFunctions()时,我确实看到了服务中的函数,但是当我尝试使用其中一个函数时,我点击了没有连接到主机,人们可以帮助我连接到这项服务。
答案 0 :(得分:2)
希望这可以让你前进,我认为实时wsdl
无需拨打__setLocation()
即可正常工作
<?php
$wdsl = "https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc?wsdl";
$options = array(
'trace' => true,
'exceptions' => true,
'connection_timeout' => 1
);
try {
$client = new SoapClient($wdsl, $options);
// use https location - the host for http (http://jhb-tvlicweb2.sabc.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc) dosn't exist
$client->__setLocation('https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc');
// setup parameters
$arrParams = array(
'request' => array(
'Header' => array(
'Rquid' => '3600cd32-28b9-4a4f-a522-4326def4a9c2',
'ApiKey' => '5957237e-101c-4ff2-8fdc-4bd6c9393a1d'
),
'AccountIdentifier' => '9211186012088',
'AccountIdentifierType' => 'SaidNumber'
)
);
// request parameters passed in the body not the header
$account = $client->GetAccount($arrParams);
var_dump($account);
echo "<pre>";
var_dump($client);
echo "</pre>";
} catch (\Exception $e) {
echo "Error!";
echo $e->getMessage() . "<br>";
echo 'Last response: ' . $client->__getLastResponse();
}