webservice示例

读取

<?php
$soap = <<<EOF //模板数据格式
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:acc="http://siebel.com/sales/account/">
   <soapenv:Header/>
   <soapenv:Body>
      <acc:QueryAccount>
         <crm_code>{$code}</crm_code>
      </acc:QueryAccount>
   </soapenv:Body>
</soapenv:Envelope>
EOF;
        $opt = array(
            'http'=>array(
                'method'=>"POST",
                'header'=>"Content-Type: application/json\r\n" .
                    "Cookie: ".$_COOKIE."\r\n",
                'content' =>json_encode($arr)
            )
        );
    //请求
     $opt = array(
         'http'=>array(
             'method'=>"POST",
             'header'=>"Content-Type: text/xml",
             'content' => $soap
         )
     );
     $context = stream_context_create($opt);
     $url = 'http://172.16.26.152:8088/eai_anon_chs/start.swe?SWEExtSource=AnonWebService&amp;SweExtCmd=Execute';
     $str = file_get_contents($url,false,$context);
//获取XML-$str
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SOAP-ENV:Body>
        <rpc:QueryAccountResponse xmlns:rpc="http://siebel.com/sales/account/">
            <biz_scope></biz_scope>
            <country_bn>China</country_bn>
            <crm_code>XXX</crm_code>
            <email>123@.com</email>
            <first_name>wangs</first_name>
            <mobile>XX</mobile>
            <name>WWW</name>
            <status>1</status>
        </rpc:QueryAccountResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
//获取数据为空格式
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body><rpc:QueryAccountResponse xmlns:rpc="http://siebel.com/sales/account/"><biz_scope></biz_scope><country_bn></country_bn><crm_code></crm_code><email></email><first_name></first_name><mobile></mobile><name></name><status>1</status></rpc:QueryAccountResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Cache-Control: no-cache, must-revalidate, max-age=0
    [2] => Pragma: no-cache
    [3] => Content-Length: 521
    [4] => Content-Type: text/xml;charset=UTF-8
    [5] => Server: Microsoft-IIS/7.5
    [6] => _charset: UTF-8
    [7] => X-Powered-By: ASP.NET
    [8] => Date: Tue, 02 Jan 2018 14:00:39 GMT
    [9] => Connection: close
)
//解析xml
$sxe = new SimpleXMLElement($str);
$soapenv = $sxe->registerXPathNamespace('c', 'http://siebel.com/sales/account/');
$result = $sxe->xpath('//c:InsertAccount');
$arr= json_decode(json_encode($result[0]),true);
//截取解析XMl
$need = strstr($str,'<biz_scope>');
$need = strstr($need,'</rpc:QueryAccountResponse>',true);
$xml = '<root>'.$need.'</root>';
$xmlObj = simplexml_load_string($xml);
$arr = json_decode(json_encode($xmlObj),true);
//结果
Array
(
    [biz_scope] =>XXX
    [country_bn] => 中国
    [crm_code] => GDQ20171226
    [email] => 123@.com
    [first_name] => wangs
    [mobile] => XX
    [name] => www
    [status] => 1
)

添加

<?php
$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:acc="http://siebel.com/sales/account/">
<soapenv:Header/>
<soapenv:Body>
  <acc:InsertAccount>
     <name>{$datajson[\'name\']}</name>
     <mobile>{$datajson[\'official_phone\']}</mobile>
     <country_bn>{$datajson[\'country_name\']}</country_bn>
     <email>{$datajson[\'official_email\']}</email>
     <biz_scope></biz_scope>
     <crm_code>{$datajson[\'buyer_code\']}</crm_code>
     <first_name>{$datajson[\'first_name\']}</first_name>
  </acc:InsertAccount>
</soapenv:Body>
</soapenv:Envelope>';
//获取结果
$str = <<<EOF
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body><rpc:InsertAccountResponse xmlns:rpc="http://siebel.com/sales/account/"><errorMsg></errorMsg><status>0</status></rpc:InsertAccountResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Cache-Control: no-cache, must-revalidate, max-age=0
    [2] => Pragma: no-cache
    [3] => Content-Length: 405
    [4] => Content-Type: text/xml;charset=UTF-8
    [5] => Server: Microsoft-IIS/7.5
    [6] => _charset: UTF-8
    [7] => X-Powered-By: ASP.NET
    [8] => Date: Wed, 03 Jan 2018 03:10:45 GMT
    [9] => Connection: close
)
EOF;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值