我正在尝试创建一个PHP脚本,该脚本会使用SOAP和xml向商家发送潜在客户,但我遇到此错误:
致命错误:未捕获的SoapFault异常:[WSDL] SOAP-ERROR:解析WSDL:无法从“https://tst.webservices.outsurance.co.za/SecureHost/Lead/LeadPostService.svc?wsdl”加载:无法加载外部实体“https://tst.webservices.outsurance.co.za/SecureHost/Lead/LeadPostService.svc?wsdl”
似乎我无法连接到安全的Web服务。他们说我应该包括一个证书,所以我把它包括在内但我仍然得到同样的错误。我搜索了一些解决方案,其中大多数建议启用,openssl,fopen等,但所有这些解决方案都已在我的服务器上启用。这是我的代码:
function sendRequest($url, $params)
{
$request = curl_init($url); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_POSTFIELDS, $params); // use HTTP POST to send form data
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
$response = curl_exec($request); // execute curl post and store results in $post_response
curl_close ($request); // close curl object
return $response;
}
// Get Variables sent from websites
$uname = $_GET['un'];
$usname = $_GET['ul'];
$uphone = $_GET['up'];
$uemail = $_GET['ue'];
$testlive = $_GET['test'];
$aff_id = $_GET['af'];
$unique_id = $_GET['uid'];
$script = $_GET['script'];
// Convert URL and Name split
$rurl = 'http://'.$_GET['rurl'];
// Split Name if no surname entered
if (strlen($usname) > 0) {
$firstname = $uname;
$lastname = $usname; // I have a first and lastname
} else {
list($firstname, $lastname) = explode(" ",$uname,2); // I only entered my firstname
}
// Determine phone number format
$phoneformat = strpos($uphone,'-');
if($phoneformat === false) {
// string - NOT found in haystack
$phonesubmit = $uphone;
} else {
$phone1 = substr($uphone,0,3);
$phone2 = substr($uphone,4,3);
$phone3 = substr($uphone,8,4);
$phonesubmit = $phone1.$phone2.$phone3;
}
// Determine Live or Test
$testlive = strtolower($testlive);
switch ($testlive) {
case "test":
$debug = true; //Set this to 'false' to redirect users
$outurl = 'https://tst.webservices.outsurance.co.za/SecureHost/Lead/LeadPostService.svc?wsdl'; // Set to TEST environment
break;
case "live":
$debug = false;
$outurl = 'https://webservices.outsurance.co.za/SecureHost/Lead/LeadPostService.svc?wsdl'; // Set to LIVE environment
break;
}
// Set Variables
if($debug) echo("<pre>\n");
if($debug) echo("Form data complete\n");
if($debug) echo("Creating XML document\n");
$cert = "certificate.cer";
$client = new SoapClient($outurl, array('local_cert'=>file_get_contents($cert)));
$xml = new stdClass();
$xml->mode = 'LIVE';
$xml->title = '';
$xml->firstname = $firstname;
$xml->lastname = $lastname;
$xml->id = $unique_id;
$xml->homecode = '';
$xml->hometel = '';
$xml->workcode = '';
$xml->worktel = '';
$xml->mobile = $phonesubmit;
$xml->homecode = '';
$xml->email = $uemail;
$xml->comment = $script;
$xml->source = 'UPSTART';
$xml->notes = '';
$xml->language = 'E';
$xml->product = 'P';
$result = $client->SubmitAffiliateLead($xml);
print_r($result);