how to post xmldata to an https:// wsdl via php - php

Good Evening All,
I am been fighting an uphill battle try to post xml data to an https web service. I am new to PHP so I am trying to learn as I go. I have been able to post the xml data to the web services via soapUI but I cannot recreate to process thru PHP. If anyone who a PHP SOAP guru could explain to me what I am doing wrong that would be a great help. Below is the code snippet I am trying to post to the web service.
<?php
$user = "xxxxxx";
$password = "xxxxx";
$url = "https://esws.energystar.gov/DataServices/servlet/webservices?ver=1.1&wsdlxml";
$post_string = <<<EOT
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:roof="http://www.energystar.gov/schema/Roof_Products_2_x/" xmlns:core="http://www.energystar.gov/schema/core/">
<soapenv:Header/>
<soapenv:Body>
<roof:Roof_Products_submission>
<core:core_submission>
<core:Authentication_UserName>xxxxx</core:Authentication_UserName>
<core:Authentication_Password>xxxxxxx</core:Authentication_Password>
<core:Certification_Body_EPA_Issued_Organization_Id>xxxxxxx</core:Certification_Body_EPA_Issued_Organization_Id>
<core:Is_Test_Submission>Yes</core:Is_Test_Submission>
</core:core_submission>
<!--1 or more repetitions:-->
<roof:Roof_Products>
<core:core_product_data>
<core:ENERGY_STAR_Manufacturing_Partner>QPX Active Partner</core:ENERGY_STAR_Manufacturing_Partner>
<core:ENERGY_STAR_Manufacturing_Partner_s_EPA_issued_Organization_ID>xxxxxxxxx</core:ENERGY_STAR_Manufacturing_Partner_s_EPA_issued_Organization_ID>
<core:Partner_Contact_Name_For_This_Model>xxxxxxx</core:Partner_Contact_Name_For_This_Model>
<core:Type_of_Transaction>Initial Certification</core:Type_of_Transaction>
<core:Reason_for_Transaction>Initial Certification: Model Meets ENERGY STAR Requirements</core:Reason_for_Transaction>
<core:Date_of_Transaction_Type>2010-12-31</core:Date_of_Transaction_Type>
<core:ENERGY_STAR_Model_Identifier>TestID2929</core:ENERGY_STAR_Model_Identifier>
<core:Certification_ID>TestCertID123</core:Certification_ID>
<core:Family_ID>TestFamID123</core:Family_ID>
<core:Model_Name>Model_Name1234</core:Model_Name>
<core:Model_Number>Model_Number33453</core:Model_Number>
<core:Brand_Name>Brand_Name1</core:Brand_Name>
<core:Tested_Model_Name>Tested_Model_Name1</core:Tested_Model_Name>
<core:Tested_Model_Number>Tested_Model_Number1</core:Tested_Model_Number>
<!--Zero or more repetitions:-->
<core:Additional_Models_Represented_by_Family_Series_or_DOE_Basic>
<core:Additional_Model_Name>test</core:Additional_Model_Name>
<core:Additional_Model_Number>12345</core:Additional_Model_Number>
<core:Additional_Identifying_Information>non</core:Additional_Identifying_Information>
</core:Additional_Models_Represented_by_Family_Series_or_DOE_Basic>
<core:Is_the_Partner_Listed_the_Original_Equipment_Manufacturer_OEM>Yes</core:Is_the_Partner_Listed_the_Original_Equipment_Manufacturer_OEM>
<core:If_the_Partner_is_Not_the_Original_Equipment_Manufacturer_Who_is>?</core:If_the_Partner_is_Not_the_Original_Equipment_Manufacturer_Who_is>
<core:Currently_Available_on_Market>Yes</core:Currently_Available_on_Market>
<core:Date_Available_On_Market>2010-12-31</core:Date_Available_On_Market>
<core:Date_Tested>2010-12-31</core:Date_Tested>
<core:Date_CB_Notified_Partner_of_Model_Qualification>2010-12-31</core:Date_CB_Notified_Partner_of_Model_Qualification>
<core:Certification_Body_Contact_Name_for_This_Model>QPX Certification Body 1</core:Certification_Body_Contact_Name_for_This_Model>
<!--Zero or more repetitions:-->
<core:Laboratory>
<core:Laboratory_EPA_issued_Organization_ID>xxxxxxxxx</core:Laboratory_EPA_issued_Organization_ID>
<core:Laboratory_Contact_for_This_Model>QPX Laboratory Test</core:Laboratory_Contact_for_This_Model>
</core:Laboratory>
<!--1 to 8 repetitions:-->
<core:To_What_Major_Markets_is_This_Model_Sold>United States</core:To_What_Major_Markets_is_This_Model_Sold>
<core:Notes>notes on the product</core:Notes>
</core:core_product_data>
<roof:ENERGY_STAR_Specification_Version>2.2</roof:ENERGY_STAR_Specification_Version>
<roof:Product_Type>Single-Ply</roof:Product_Type>
<roof:Measured_Initial_Solar_Reflectance>0.25</roof:Measured_Initial_Solar_Reflectance>
<roof:Reported_Initial_Solar_Reflectance>0.26</roof:Reported_Initial_Solar_Reflectance>
<roof:Initial_Solar_Reflectance_Test_Method>ASTM E903-96</roof:Initial_Solar_Reflectance_Test_Method>
<roof:Measured_Solar_Reflectance_After_Three_Years>0.15</roof:Measured_Solar_Reflectance_After_Three_Years>
<roof:Reported_Reflectance_After_Three_Years>0.16</roof:Reported_Reflectance_After_Three_Years>
<roof:Solar_Reflectance_After_Three_Years_Test_Method>ASTM C1549-09</roof:Solar_Reflectance_After_Three_Years_Test_Method>
<roof:Measured_Initial_Emissivity>0.01</roof:Measured_Initial_Emissivity>
<roof:Reported_Initial_Emissivity>0.02</roof:Reported_Initial_Emissivity>
<roof:Initial_Emissivity_Test_Method_Used>ASTM E408-71(1996) e1</roof:Initial_Emissivity_Test_Method_Used>
<roof:Low_Slope>Yes</roof:Low_Slope>
<roof:Steep_Slope>Yes</roof:Steep_Slope>
<roof:Roof_Cleaned_Prior_to_Third_Year_Test>No</roof:Roof_Cleaned_Prior_to_Third_Year_Test>
<roof:Warranty_Period>abcdefg</roof:Warranty_Period>
</roof:Roof_Products>
</roof:Roof_Products_submission>
</soapenv:Body>
</soapenv:Envelope>
EOT;
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));
curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
?>
Any and all help would be greatly appreciated.

I'm not sure, if this is correct, but it should be something along these lines:
$namespace = 'https://esws.energystar.gov';
$auth = new ChannelAdvisorAuth($user, $password);
$header = new SoapHeader($namespace, 'APICredentials', $auth, false);
$soap = new SoapClient($url);
$soap->__setSoapHeaders($header);
$soap->DataServices_Server($post_string);
I hope this will point you in the right direction :)

Related

PHP xml SOAP and laravel

I have been trying to figure out how to make a soap request using php/laravel. But from all the research on internet since two days now the only things that I can find are old rusty php codes to make soap requests non of them even worked:
Here is a snipped that I am trying to make it work so I have a general view of those soap requests but I only get errors not able to make a soapclient:
<?php
$aHTTP['http']['header'] = "User-Agent: PHP-SOAP/5.5.11\r\n";
$aHTTP['http']['header'].= "username: XXXXXXXXXXX\r\n"."password: XXXXX\r\n";
$context = stream_context_create($aHTTP);
$client=new SoapClient("http://www.thomas-bayer.com/axis2/services/BLZService?wsdl",array('trace' => 1,"stream_context" => $context));
$result = $client::__getFunctions();
var_dump($result);
since it looks super hard to me to find any info about the soap with php any idea ?
This is a sample of a soap request I currently make to a payment provider via php using curl statements. Basically map the xml request you want to make in a string. The string will be sent in the curl post fields and the response returned.
$soapdata="<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:tns='tns:ns'>
<soapenv:Header>
<tns:CheckOutHeader>
<MERCHANT_ID>$merchantid</MERCHANT_ID>
<PASSWORD>$password</PASSWORD>
<TIMESTAMP>$timestamp</TIMESTAMP>
</tns:CheckOutHeader>
</soapenv:Header>
<soapenv:Body>
<tns:processCheckOutRequest>
<MERCHANT_TRANSACTION_ID>$merchanttransactionid</MERCHANT_TRANSACTION_ID>
<REFERENCE_ID>$referenceid</REFERENCE_ID>
<AMOUNT>$amount</AMOUNT>
<MSISDN>$mobileno</MSISDN>
<!--Optional:-->
<ENC_PARAMS></ENC_PARAMS>
<CALL_BACK_URL>$callbackurl</CALL_BACK_URL>
<CALL_BACK_METHOD>$callbackmethod</CALL_BACK_METHOD>
<TIMESTAMP>$timestamp</TIMESTAMP>
</tns:processCheckOutRequest>
</soapenv:Body>
</soapenv:Envelope>";
//End Soap data
//We call the server for the first time
//end calling function
function makesoaprequest($url, $soapdata)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Authorization: Basic'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$soapdata");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Begin SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//End SSL
$response = curl_exec($ch);
return $response;
curl_close($ch);
}

Posting a SOAP request with php

I'm at a slight loss, havent touched a soap script in forever and looking around stackoverflow and google just confuses the matter more. PHP.net examples seem outdated as well.
The SOAP Request is supposed to POST to a non-WSDL url.
https://some.soapurl.com/provided
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:cam="http://kamp.gw.com/kamp">
<soapenv:Header/>
<soapenv:Body>
<cam:setRolesUpdatedRequest>
<cam:orgCode>username</cam:orgCode>
<cam:password>password</cam:password>
<cam:emails>
<cam:email>abc#dom.com</cam:email>
<cam:email>def#dom.com</cam:email>
<cam:email>ghi#dom.com</cam:email>
</cam:emails>
<cam:updateAllUsers>false</cam:updateAllUsers>
</cam:setRolesUpdatedRequest>
</soapenv:Body>
</soapenv:Envelope>
Just running this snippet returns a 200 OK header, which is good.
try {
$client = new SoapClient("https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated");
}
catch(Exception $e)
{
$e->getMessage();
}
The Response i'm looking to get is supposed to look like
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:returnStatus xmlns:ns1="http://kamp.gw.com/kamp">
<ns1:type>S</ns1:type>
<ns1:desc>Successful</ns1:desc>
</ns1:returnStatus>
</soapenv:Body>
</soapenv:Envelope>
EDIT:
I attempted a curl version to post the xml string directly.
$post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cam="http://kamp.gw.com/kamp">
<soapenv:Header/>
<soapenv:Body>
<cam:setRolesUpdatedRequest>
<cam:orgCode>username</cam:orgCode>
<cam:password>password</cam:password>
<cam:emails>
<cam:email>abc#dom.com</cam:email>
<cam:email>def#dom.com</cam:email>
<cam:email>ghi#dom.com</cam:email>
</cam:emails>
<cam:updateAllUsers>false</cam:updateAllUsers>
</cam:setRolesUpdatedRequest>
</soapenv:Body>
</soapenv:Envelope>';
$user = "username";
$password = "password";
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($xml),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 100000);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 100000);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers); //array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) )
curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
var_dump($result);
echo "<br /><br />";
var_dump($err);
But unfortunately the result is
bool(false)
string(74) "Failed connect to abc.kamp.group.com:443; Connection timed out"
And i'm not certain if that's my fault or the web service's fault. Even though i get connection timed out, the header returned is still 200 Ok.
First check that the SOAP service url and access credentials are working. Use SoapUI or a similar tool to make a request independent of your PHP SoapClient code.
Also check if there are any IP address restrictions in place when making calls and, if so, create / ask for an exception for the IP address you are making requests from.
If everything checks, use php.net SoapClient examples to make simple calls and build your script logic.
<?php
$client = new SoapClient('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl');
var_dump($client->__getFunctions());
?>
Forgot i was behind a proxy, once i pointed curl to the proxy server everything worked out just fine.

Invoking API with SOAP using SoapClient - can't find method

I'm trying to connect to an API that uses SOAP. It is working for me with php/curl, but what I'd really like to do is use SoapClient, which looks like it would produce much cleaner code.
This is the php that works:
$xml_post_string = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope
/" xmlns:v300="http://V300">
<soapenv:Header/>
<soapenv:Body>
<v300:GetNote soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<Request xsi:type="get:Request" xmlns:get="http://getNote.note.V300">
<Security xsi:type="req:Security" xmlns:req="http://request.base.V300">
<Password xsi:type="xsd:string">'.$soapPassword.'</Password>
<Username xsi:type="xsd:string">'.$soapUser.'</Username>
</Security>
<NoteID xsi:type="xsd:string">'.$soapNoteID.'</NoteID>
</Request>
</v300:GetNote>
</soapenv:Body>
</soapenv:Envelope>';
$headers = array(
"Content-type: application/soap+xml;charset=utf-8",
"Accept: text/xml",
"SOAPAction: https://webservices.aus.vin65.com/V300/NoteService.cfc?wsdl",
"Content-length: ".strlen($xml_post_string),
);
$url = $soapUrl;
$ch = curl_init();
echo("set curl\n");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE,false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
echo("about to execute\n");
// converting
$response = curl_exec($ch);
echo('Got '.strlen($response)." characters in response\n");
curl_close($ch);
echo("Response:\n".$response."\n");
And this is my attempt at a SoapClient version, informed by this helpful StackExchange user over here: How to make a PHP SOAP call using the SoapClient class
class Security{
function Security($Username,$Password){
$this->Username = $Username;
$this->Password=$Password;
}
}
class Request{
function Request($Security,$NoteID){
$this->Security = $Security;
$this->NoteID = $NoteID;
}
}
$client = new SoapClient($soapUrl);
$security = new Security($soapUser,$soapPassword);
$securityArray = array("Username"=>$soapUser,"Password"=>$soapPassword);
//$request = new Request($security,$soapNoteID);//gave error message "expects parameter 2 to be array"
//$request = array("Security"=>$security,"NoteID"=>$soapNoteID);//gave error message "No such operation 'GetNote'"
$request = array("Security"=>$securityArray,"NoteID"=>$soapNoteID);//gave error message "No such operation 'GetNote'"
echo("Showing Request:\n");
var_dump($request);
$response=null;
try{
$response = $client->__soapCall("GetNote",$request);
}catch(Exception $ex){
echo("Caught Exception: ".$ex->getMessage()."\n");
echo("Last Request was: ".$client->__getLastRequest()."\n");
echo("Last Request Headers: ".$client->__getLastRequestHeaders()."\n");
echo("Last Response was: ".$client->__getLastResponse()."\n");
echo("Last Response Headers: ".$client->__getLastResponseHeaders()."\n");
}
if($response){
var_dump($response);
}
As you can see, I've tried a couple of different ways to feed it the user/password/NoteID information, noting down which error message it gives me each time. Currently it's claiming that there's 'no such operation GetNote' - definintely not right, but I don't know what the underlying problem is.
Thanks in advance for any pointers.
When i do $client->__getFunctions(), the method GetNote method shows up and works
<?php
$client = new SoapClient('https://webservices.aus.vin65.com/V300/NoteService.cfc?wsdl');
/**
print_r($client->__getFunctions());
Array
(
[0] => Response SearchNotes(Request $Request)
[1] => Response AddUpdateNote(Request $Request)
[2] => Response GetNote(Request $Request)
)
*/
$result = $client->GetNote([
'Security' => [
'Password' => 'XXX',
'Username' => 'XXX'
],
'NoteID' => 'XXX'
]);
print_r($result);

Configuring soap api xml

I want to configure an api of soap with php, following the xml is used for the api, but its not responding, please help me to recover this problem
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fram="http://framework.zend.com">
<soapenv:Header/>
<soapenv:Body>
<fram:getCountries>
<securityInfo>
<userName>username</userName>
<password>password</password>
<agentCode>code</agentCode>
<lang>en</lang>
</securityInfo>
</fram:getCountries>
</soapenv:Body>
</soapenv:Envelope>
The below showing the php code I used to call xml. But I didnt get any response to my php code, but the xml is correct, I have asked to the provider they told me the xml is correct but my php code is not correct. I dont what I do to solve this problem :(
<?php
$soapUrl = "http://testapi.roombookpro.com/en/soap/index?wsdl"; // asmx URL of WSDL
$soapUser = "username"; // username
$soapPassword = "password"; // password
// xml post structure
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fram="http://framework.zend.com">
<soapenv:Header/>
<soapenv:Body>
<fram:getCountries>
<securityInfo>
<!-- You may enter the following 4 items in any order -->
<userName>username</userName>
<password>password</password>
<agentCode>agentcode</agentCode>
<lang>en</lang>
</securityInfo>
</fram:getCountries>
</soapenv:Body>
</soapenv:Envelope>'; // data from the form, e.g. some ID number
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache"
"SOAPAction: http://testapi.roombookpro.com/en/soap/index#getCountries",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$url = $soapUrl;
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response2);
var_dump($parser);
echo $parser;
// user $parser to get your data out of XML response and to display it.
?>
In your code,your request is pointing to wsdl link below,
http://testapi.roombookpro.com/en/soap/index?wsdl
and thats why you are not getting soap response rather you getting the definitions.
you should use the following soap url to get the soap response,
http://testapi.roombookpro.com/en/soap/index
EDIT:
and to get the XML response (as string):
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
to get as SimpleXMLElement Object :
$xml = simplexml_load_string($response);
foreach ($xml->xpath('//ns2:Soap_Model_SOAP_Location_Country') as $item)
{
print_r($item);
//to access individual elements
// echo $item->id ;
// echo $item ->code;
// echo $item->name;
// echo "\n";
}
which gives array of XML objects:
SimpleXMLElement Object
(
[id] => 252
[code] => ZW
[name] => Zimbabwe
)

Parameter Missing in XML String

I am passing an xml string to https://insurance-api.pingtree.co.uk/api through curl but is getting parameter error in response (code 12 0) which can be also seen if you browse the above mentioned url.The parameter is defined in the xml i.e. the campaign code then why isn't the system recognizing it. here is my code below which i also got from the http://www.quinternet.com site.
<?php
/**
* Initialize the request xml string here.
* The string in the tag like '[int]' should be replaced with actual value.
* The string in the square brackets is the data type.
*/
$request_string =
'<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:pt_service">
<soapenv:Header />
<soapenv:Body>
<urn:submit
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<campaign_code>dllfYg0JBwQ</campaign_code>
<site_url>www.surelifecover.co.uk</site_url>
<client_ip>127.0.0.1</client_ip>
<policy_type>J</policy_type>
<cover_purpose>1</cover_purpose>
<cover_amount>50000</cover_amount>
<cover_term>1</cover_term>
<title>1</title>
<first_name>INTRODUCERTEST</first_name>
<last_name>wwww</last_name>
<dob >1995-04-05</dob >
<email>will#bitscube.com</email>
<home_phone>07111111111</home_phone>
<best_call_time>1</best_call_time>
<gender>F</gender>
<is_smoker>Y</is_smoker>
<title2>1</title2>
<first_name2>ww</first_name2>
<last_name2>wwww</last_name2>
<dob2>1991-02-03</dob2>
<email2>913661383#qq.com</email2>
<home_phone2>07111111112</home_phone2>
<best_call_time2>2</best_call_time2>
<gender2>M</gender2>
<is_smoker2>N</is_smoker2>
<terms_consent>Y</terms_consent>
<privacy_content>Y</privacy_consent>
<mode>LIVE</mode>
<keyword>life ins</keyword>
<match_type>1</match_type>
<network>ABC</network>
<device>mobile</device>
<ref>00</ref>
<v1>var1</v1>
<v2>var2</v2>
<v3>var3</v3>
<v4>var4</v4>
<v5>var5</v5>
<i1>1</i1>
<i2>2</i2>
<i3>3</i3>
<i4>4</i4>
<i5>5</i5>
</urn:submit>
</soapenv:Body>
</soapenv:Envelope>
</env:Envelope>';
echo htmlspecialchars($request_string);
echo '<br>';
/**
* The values of the following fields please refer
*to the reference field list spec*
//setup the request headers here, notice at the action string and SOAPAction string */
$request_headers = array('Content-Type: application/soap+xml;charset=utf-8;action="urn:pt_service#Webservice#submit"',
'SOAPAction: "urn:pt_service#Webservice#submit"',
'Content-length: '.strlen($request_string) );
//setup the service url here
$service_url = 'https://insurance-api.pingtree.co.uk/api';
//setup the user agent for the request
$user_agent = $_SERVER['HTTP_USER_AGENT'];
//initialize the curl here
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLINFO_HEADER_OUT, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST,TRUE );
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_POSTFIELDS,$request_string);
curl_setopt($ch, CURLOPT_HTTPHEADER,$request_headers);
//do the submit process here
$result= curl_exec ($ch);
$response_string = curl_exec($ch);
// Convert API feed to xml object
var_dump($response_string);
$xml = simplexml_load_string($response_string);
$name = $xml->response->status;
echo $name;
//-----------------------------------------------
//parsing the response string here
/*example response below. Please get detail
refer for the reponse in specs.
<?xml version="1.0" encoding="UTF8"?>
<response>
<result>20</result>
<status>1</status>
<commission>10.00</commission>
<reference>347</reference>
<message><![CDATA[Accepted]]></message>
<redirect_url>
http://insurance-api.pingtree.co.uk/redirect?p=bUzbir4VhB-BB-Z_gMxVSy8YT15gxUB9iJMBGxi_aOq5PQuDBf_JPqgvc2egv6orCj6TJkeR5g6tX1y0D7hZgbV6DdBAlzbccKmkFNG4-PgWmaNR9LQ57cUQg6jTOXuB
</redirect_url>
</response>
//-----------------------------------------------*/
curl_close($ch);
?>

Categories