webservice示例

读取


$soap = <<//模板数据格式
"http://schemas.xmlsoap.org/soap/envelope/" xmlns:acc="http://siebel.com/sales/account/">
   
   
      
         {$code}
      
   

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
"http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    
        "http://siebel.com/sales/account/">
            
            China
            XXX
            123@.com
            wangs
            XX
            WWW
            1
        
    

//获取数据为空格式
"http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">"http://siebel.com/sales/account/">1Array
(
    [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,'');
$need = strstr($need,'',true);
$xml = ''.$need.'';
$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
)

添加

$xml = '


  
     {$datajson[\'name\']}
     {$datajson[\'official_phone\']}
     {$datajson[\'country_name\']}
     {$datajson[\'official_email\']}
     
     {$datajson[\'buyer_code\']}
     {$datajson[\'first_name\']}
  

';
//获取结果
$str = <<<EOF
"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>:InsertAccountResponse xmlns:rpc="http://siebel.com/sales/account/"></errorMsg>0></rpc:InsertAccountResponse>SOAP-ENV:Body>: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;

你可能感兴趣的:(webservice,web,service,soap)