读取
<?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&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;