簡體   English   中英

在Soap請求中發送XML並附加證書PHP

[英]Send XML in soap request and attach certificate PHP

我正在嘗試實現SOAP API。 但是我沒有得到如何將請求發送到給定的URL。

我對該API沒有任何支持,僅以幾行作為指令。

我以前沒有使用過SOAP,請幫助一下以了解如何使用證書創建和發送XML請求。

這是使用API​​的說明

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() 

與此一起,我有一個擴展名為.crt的文件

我已經嘗試過CURL (從這里開始: PHP&XML-如何XML中生成PHP中的soap請求? )和SoapClient (不了解如何以所需格式創建請求: 使用SoapClientXML輸入發送到WSDL )來實現這可是沒有運氣。

實際上,我無法理解如何發送請求以及需要以哪種方式發送該請求中的內容。

請幫助我理解這一點。

謝謝

PHP SOAP庫不支持證書和私鑰斷言,並且wse-php rob richard庫在這種情況下做得很好,我必須在很長一段時間后才能采用以下解決方案:

 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;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM