php 請求 webseviceapp遇到的坑。

首先php環境需要開啓

extension=php_soap.dll

然後看下確保phpinfo中soap是否已連接。

接下來就是最關鍵的代碼要怎麼寫了?廢話不多說直接上代碼。

    public function sendserve($phone='',$pwd='',$pphone=''){
        $xmldata='<?xml version="1.0" encoding="utf-8"?>
          <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
              <AddCloudUser xmlns="http://tempuri.org/">
                <phone>'.$phone.'</phone>
                <pwd>'.$pwd.'</pwd>
                <pphone>'.$pphone.'</pphone>
              </AddCloudUser>
            </soap:Body>
          </soap:Envelope>';
        header("text/xml; charset=utf-8"); 
        $wsdl = 'http://47.***.131.79:8000/WebServiceApp.asmx?wsdl';
        $client = new \SoapClient($wsdl);
        $result = $client->__doRequest($xmldata,$wsdl,'http://tempuri.org/AddCloudUser',1,0);
        $xml=simplexml_load_string($result);//xml格式化
        $res = $xml->children('http://schemas.xmlsoap.org/soap/envelope/')->children('http://tempuri.org/');
        $result=(self::object_array($res));
        if(isset($result['AddCloudUserResponse']['AddCloudUserResult']['string'])){
          return $result['AddCloudUserResponse']['AddCloudUserResult']['string'];
        } else{
          return -1;
        }
    }
   private  function object_array($array) {  
        if(is_object($array)) {  
            $array = (array)$array;  
         } if(is_array($array)) {  
             foreach($array as $key=>$value) {  
                 $array[$key] = self::object_array($value);  
                 }  
         }  
         return $array;  
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章