简体   繁体   English

使用 PHP 中的标头发送 SOAP 请求

[英]Send SOAP request with headers in PHP

I am new to SOAP.我是 SOAP 新手。 I want to make a soap request in the following format.我想以以下格式发出肥皂请求。 Is there anyone who will help me doing this.有没有人会帮我做这件事。 Please help me if you can do it.如果你能做到,请帮助我。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:v2="http://www.huawei.com.cn/schema/common/v2_1"
    xmlns:loc="http://www.csapi.org/schema/parlayx/sms/notification_manager/v2_3/local
    ">
    <soapenv:Header>
        <RequestSOAPHeader xmlns="http://www.huawei.com.cn/schema/common/v2_1">
            <spId>000201</spId>
            <spPassword>e6434ef249df55c7a21a0b45758a39bb</spPassword>
            <serviceId>35000001000001</serviceId>
            <timeStamp>20100731064245</timeStamp>
        </RequestSOAPHeader>
    </soapenv:Header>
    <soapenv:Body>
        <loc:startSmsNotification>
        <loc:reference>
        <endpoint>http://10.138.38.139:9080/notify</endpoint>
        <interfaceName>notifySmsReception</interfaceName>
        <correlator>00001</correlator>
        </loc:reference>
    <loc:smsServiceActivationNumber>1234501</loc:smsServiceActivationNumber>
    <loc:criteria>demand</loc:criteria>
    </loc:startSmsNotification>
    </soapenv:Body>
    </soapenv:Envelope>

I have a similar working solution using nusoap library.我有一个使用 nusoap 库的类似工作解决方案。 Adapting to the question looks like this.适应这个问题看起来像这样。

  $header = '<RequestSOAPHeader xmlns="http://www.huawei.com.cn/schema/common/v2_1">
        <spId>000201</spId>
        <spPassword>e6434ef249df55c7a21a0b45758a39bb</spPassword>
        <serviceId>35000001000001</serviceId>
        <timeStamp>20100731064245</timeStamp>
    </RequestSOAPHeader>';

    $body = '<loc:startSmsNotification>
    <loc:reference>
    <endpoint>http://10.138.38.139:9080/notify</endpoint>
    <interfaceName>notifySmsReception</interfaceName>
    <correlator>00001</correlator>
    </loc:reference>
<loc:smsServiceActivationNumber>1234501</loc:smsServiceActivationNumber>
<loc:criteria>demand</loc:criteria>
</loc:startSmsNotification>';

    $client = new nusoap_client($this->xipay_wsdl, true);

    $client->soap_defencoding = 'UTF-8'; 
    $client->setUseCurl(true);
    $client->useHTTPPersistentConnection();

    //Set any CURL option you need
    $client->setCurlOption(CURLOPT_URL, '');
    //etc

    $client->setHeaders($header);

    //Call the function you need
    $result = $client->call('SoapOp', $body);

The envelope tags will be generated automatically by nusoap template.信封标签将由 nusoap 模板自动生成。 If you do not get xmlns:v2="http://www.huawei.com.cn/schema/common/v2_1" and xmlns:loc="http://www.csapi.org/schema/parlayx/sms/notification_manager/v2_3/local in the envelope tag attributes you should place it directly into the headers or body tag like this.如果没有得到 xmlns:v2="http://www.huawei.com.cn/schema/common/v2_1" 和 xmlns:loc="http://www.csapi.org/schema/parlayx/sms/ Notification_manager/v2_3/local 在信封标签属性中,您应该像这样将其直接放入标头或正文标签中。

   $body = '<loc:startSmsNotification 
   xmlns:loc="http://www.csapi.org/schema/parlayx/sms/notification_manager/v2_3/local>
    <loc:reference>
    <endpoint>http://10.138.38.139:9080/notify</endpoint>
    <interfaceName>notifySmsReception</interfaceName>
    <correlator>00001</correlator>
    </loc:reference>
<loc:smsServiceActivationNumber>1234501</loc:smsServiceActivationNumber>
<loc:criteria>demand</loc:criteria>
</loc:startSmsNotification>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM