2016-07-05 12 views
2

SOAP APIを実装しようとしています。しかし、私は与えられたURLにリクエストを送る方法を知りません。XMLをSOAPリクエストで送信し、証明書を添付するPHP

私はそのAPIをサポートしていません。命令としては数行しかありません。

以前はSOAPを使用していませんでしたが、証明書を使用してXMLとしてリクエストを作成して送信する方法を理解するのに役立つことがあります。 (ともSoapClient:(PHP & XML - How to generate a soap request in PHP from this XML?をこちらから)ここで

は私がCURLを試してみました、私は.crt延長

を持つファイルを持ってこれに伴い

Test API Link 
https://202.82.66.148:8443/ptms4541/ws/CksServices 

Worksite:BST-API 
Account:BST-API01 

Response to connect (Have to set header of the following) 

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
<soap:Header>  
<tns:RequestSOAPHeader xmlns:tns="https://202.82.66.148:8443/ptms4541/ws/CksServices">  
<tns:account xmlns="https://202.82.66.148:8443/ptms4541/ws/CksServices">BST-API01</tns:account>  
<tns:timestamp xmlns="https://202.82.66.148:8443/ptms4541/ws/CksServices">201606211538</tns:timestamp>  
<tns:pwd xmlns="https://202.82.66.148:8443/ptms4541/ws/CksServices">***********</tns:pwd>  
<tns:worksite xmlns="https://202.82.66.148:8443/ptms4541/ws/CksServices">BST-API</tns:worksite>  
<tns:discount_id xmlns="https://202.82.66.148:8443/ptms4541/ws/CksServices"/></tns:RequestSOAPHeader>  
</soap:Header>  
<soap:Body>  
<ns2:getShippingLine xmlns:ns2="http://ws.service.gen.cks.com/"/> </soap:Body>  
</soap:Envelope> 

Certificates to installed attached in Email 

getShippingLine()  

APIを使用する命令でありますこれを実装するために必要なフォーマットでリクエストを作成する方法を理解できませんでした:Sending XML input to WSDL using SoapClient)。

実際には、どのようにリクエストを送信するのか、そのリクエストでどのような方法で送信する必要があるのか​​を理解できません。

ご理解ください。

おかげ

答えて

0

PHPのSOAPライブラリーは、WSE-PHP奪うリチャード・ライブラリーは、このような場合のためにとてもよくやっただけでなく、証明書と秘密鍵の主張をサポートしていません、私は久しぶりにこのソリューションを来ている:

function Curl_Soap_Request($request, $url) 
{ 
    /** 
    * @param request is your xml for soap request 
    * @param url is location of soap where your request with hit 
    */ 

    $keyFile = getcwd() . "\\privatekey.pem"; // 
    $caFile = getcwd() . "\\certificate.pem"; // 
    $certPass = "test123"; 
    // xml post structure 

    $xml_post_string = $request; // data from the form, e.g. some ID number 

    $headers = array(
     "Content-type: application/soap+xml; charset=\"utf-8\"", 
     "Accept: text/xml", 
     "Cache-Control: no-cache", 
     "Pragma: no-cache", 
     // "SOAPAction: '/Imp1/ApplicantEligibilityService", 
     "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, false); 
    //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    // The --key option - If your key file has a password, you will need to set 
    // this with CURLOPT_SSLKEYPASSWD 
    // curl_setopt($ch, CURLOPT_SSLKEY, $keyFile); 
    curl_setopt($ch, CURLOPT_SSLKEY, $keyFile); 

    // The --cacert option 
    curl_setopt($ch, CURLOPT_SSLCERT, $caFile); 

    // The --cert option 
    //curl_setopt($ch, CURLOPT_SSLCERT, $certFile); 
    curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $certPass); 
    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, 180); 
    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); 
    return $response; 

} 
+0

このリンクをたどってこれを解決することもできます:http://zrashwani.com/wcf-ssl-service-with-php/#.V8Ato6KN2tY –

関連する問題