PHP連結WEB SERVICE類別程式碼實例:
- //通訊類別開始
- class webserv
- class webserv
-
//webservice 位址參數 -
var $webaddarray(
"publ" =-
"client.asmx?wsdl",
"client" =-
🎜> "Client.asmx?wsdl", "bann" =
>-
""); //呼叫webservice ftion
- function 🎜>
par-
= array()){ 🎜> >//連結 web service
- $
- $
- > = new SoapClient($this->>>
webadd[$class]); $requirerequire 🎜>>-
$function($par);
- //調用資訊🎜>
- //調用資訊🎜> if (is_soap_fault($require)) { echo "遠端介面".$function."呼叫失敗!";
- exit();
- }
- }
-
/🎜> $function_result
-
= $function."Result"; = $ $str = $require->>
-
>
-
>> function_result; //解析XML
- $
-
$ = @simplexml_load_string( $str ); //若無法用XML解析直接回傳
- ifo>
row-
== false) {
- if (is_string($str)){
- >return $str; } else { $
-
require = (get_object_vars($str)); $
-
str> ];
- return $str;
- }
- }
- } //結果轉換為數組 $row_arr
- =
- get_object_vars($row); print_r($row_arr);exit(); $
- row_return
- = $row_arr['Table'];
-
/嗎判斷回饋記錄 if (is_array($row_arr['Table'])) { foreach (> foreach ($row_foreach 🎜>key =
-
>
- >
$rows[$key] = get_object_vars($vlaues); -
} -
$rows[0] = get_object_vars($row_arr['Table']); -
} -
} -
} //通訊記錄 //$this-
- >
- >
-
- return $rows;
- } //介面通訊記錄 function soap_log($class, $function, $in, $out){ log
-
= datedate("Y-m-d"): $log .=
- " ".$class."->".$function." input:";
- $
input-
= """" if ($in != array()) {
- foreach ($in as =
> $vlaue){ -
$vlaue){ >$input .
- = $key."=".$vlaue; } 🎜> } 🎜> 🎜> $log .= $input." output:".var_export($rows)."n"; > }
- }
- }
<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ? </span></span></li><li><span>include "./webserv.class.php"; </span></li><li class="alt"><span>$</span><span class="attribute">webserv</span><span> = </span><span class="attribute-value">new</span><span> webserv; </span></li><li><span>//这里是调用方法给传递的参数 </span></li><li class="alt"><span>$</span><span class="attribute">a</span><span> = </span><span class="attribute-value">array</span><span>("aa"=</span><span class="tag">></span><span>"aaaa"); </span></span></li>
<li>
<span>print_r($webser-</span><span class="tag">></span><span>soap("function_name",$a)); </span>
</li>
<li class="alt">
<span class="tag">?></span><span> </span>
</li>
</ol>
登入後複製
>類的內容。用法很簡單include 一下PHP連結WEB SERVICE類別檔案
以上就是PHP連結WEB SERVICE類別的相關使用方法。
http://www.bkjia.com/PHPjc/445913.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445913.htmlTechArticlePHP連結WEB SERVICE類別程式碼實例: //通訊類別開始classwebserv { //webservice位址參數var$ webadd = array ( publ= client.asmx?wsdl, client= Client.asmx?wsdl, bann= ); //調...