繁体   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