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

时间:2016-03-02 06:07:50

标签: php web-services soap header request

我是SOAP新手。我想以下列格式发出肥皂请求。有没有人会帮我这样做。如果你能做到,请帮助我。

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

1 个答案:

答案 0 :(得分:0)

我有一个使用nusoap库的类似工作解决方案。 适应问题看起来像这样。

  $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);

信封标签将由nusoap模板自动生成。如果没有得到xmlns:v2 =“ http://www.huawei.com.cn/schema/common/v2_1”,并且 xmlns:loc =“ envelope”标签属性中的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>';