美好的一天,
我遇到问题我的代码是肥皂客户端,用来检查用户在我的网站购买一套电视时是否拥有有效的电视许可证,
该程序在本地主机上正常运行且没有错误,并返回结果。当移动到实时服务器时,它会出现以下错误:
错误!“SOAP-ERROR:解析WSDL:无法加载 'https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc?wsdl' :无法加载外部实体 \ “HTTPS:?//secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc WSDL \” \ n“个
我的代码:
<?php
$wdsl = "https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc?wsdl";
$opts = array(
'http' => array(
'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);
$soapClientOptions = array(
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE
);
//Generate GUID
function getGUID()
{
if (function_exists('com_create_guid')) {
return com_create_guid();
} else {
mt_srand((double) microtime() * 10000);
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45); // "-"
$uuid = chr(123) // "{"
. substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12) . chr(125); // "}"
return trim($uuid, '{}');
}
}
$quid = getGUID();
$licencetype = isset($_POST['licencetype']) ? $_POST['licencetype'] : NULL;
switch ($licencetype) {
case 'domestic':
$holder_id = isset($_POST['holder_id']) ? $_POST['holder_id'] : NULL;
try {
$client = new SoapClient($wdsl, $soapClientOptions);
$client->__setLocation('https://secure4.tvlic.co.za/AccountEnquiryService_1.0/AccountEnquiryService.svc');
$arrParams = array(
'request' => array(
'Header' => array(
'Rquid' => $quid,
'ApiKey' => '2c261e98-90ca-4f7d-90a0-1f5e91ebf416'
),
'AccountIdentifier' => $holder_id,
'AccountIdentifierType' => 'SaidNumber'
)
);
$account = $client->GetAccount($arrParams);
echo json_encode($account);
}
catch (\Exception $e) {
echo "Error!";
echo json_encode($e->getMessage());
echo 'Last response: ' . $client->__getLastResponse();
}
break;
case 'business':
$tvlicencenumber = isset($_POST['tvlicence']) ? $_POST['tvlicence'] : NULL;
try {
$client = new SoapClient($wdsl, $soapClientOptions);
$client->__setLocation('https://secure4.tvlic.co.za/AccountEnquiryService_1.0/AccountEnquiryService.svc');
$arrParams = array(
'request' => array(
'Header' => array(
'Rquid' => $quid,
'ApiKey' => '5957237e-101c-4ff2-8fdc-4bd6c9393a1d'
),
'AccountIdentifier' => $tvlicencenumber,
'AccountIdentifierType' => 'AccountNumber'
)
);
$account = $client->GetAccount($arrParams);
echo json_encode($account);
}
catch (\Exception $e) {
echo "Error!";
echo json_encode($e->getMessage());
echo 'Last response: ' . $client->__getLastResponse();
}
break;
case 'dealer':
$tvlicencenumber = isset($_POST['tvlicence']) ? $_POST['tvlicence'] : NULL;
try {
$client = new SoapClient($wdsl, $soapClientOptions);
$client->__setLocation('https://secure4.tvlic.co.za/AccountEnquiryService_1.0/AccountEnquiryService.svc');
$arrParams = array(
'request' => array(
'Header' => array(
'Rquid' => $quid,
'ApiKey' => '5957237e-101c-4ff2-8fdc-4bd6c9393a1d'
),
'AccountIdentifier' => $tvlicencenumber,
'AccountIdentifierType' => 'AccountNumber'
)
);
$account = $client->GetAccount($arrParams);
echo json_encode($account);
}
catch (\Exception $e) {
echo "Error!";
echo json_encode($e->getMessage());
echo 'Last response: ' . $client->__getLastResponse();
}
break;
default:
echo json_encode('Please select licence type');
}
?>
Xampp使用:
php 5.6
直播服务器
PHP / 5.6.33-0 + deb8u1
请帮助解决此错误
答案 0 :(得分:0)
您确定https://secure4.tvlic.co.za/AccountEnquiryService_1.0/AccountEnquiryService.svc
是SOAP客户端的正确位置吗?当我在浏览器中打开它时,它显示错误 - 此服务的元数据发布当前已禁用。即使这是因为我没有初始化SOAP客户端以打开它,您似乎仍然混合测试和实时API,从你的WSDL判断(BTW你命名为wsdl变量$ wdsl,我猜错了,但你一直使用它,这应该不是问题)和SOAP地址。
比较
↓ SOAP address (not working, even with ?wsdl appended)
https://secure4.tvlic.co.za/AccountEnquiryService_1.0/AccountEnquiryService.svc
https://secure4.tvlic.co.za/AccountEnquiryService_Test_1.0/AccountEnquiryService.svc?wsdl
↑ WSDL address (working)