PHP link WEB SERVICE class code example:
- //Communication class starts
- class webserv
-
{
- //webservice address parameters
-
var $webadd = array(
-
"publ" => "client.asmx?wsdl",
-
"client" => "Client.asmx?wsdl",
-
"bann" => "");
- //Call webservice
-
function soap($class,$function ,$par = array()){
- //Link
- web service
-
$client = new SoapClient($this->webadd[$class]);
-
$require = $client- >$function($par);
- //Call information debug
- if (is_soap_fault($require)) {
- echo "Remote interface".$function." call failed!";
- exit();
- }
- //Get the return value
-
$function_result = $function."Result";
-
$str = $require-> $function_result;
- //Parse XML
-
$row = @simplexml_load_string($str);
- //If XML parsing cannot be used, return directly
-
if ($row == false) {
- if (is_string($str)){
-
return $str; = (get_object_vars($str));
- $
-
str = $require['string ']; return $str;
- } }
- //Convert the result to an array
- $
row_arr-
=
- get_object_vars
- ($row); print_r($row_arr);exit(); $row_return = $row_arr['Table'];
- //Judge whether it is Multiple feedback records
- if (is_array($row_arr['Table'])) { foreach ($row_return as $
key-
=
-
>
-
$vlaues){ $rows[$key] = get_object_vars($vlaues); } } else {
- $rows[0] = get_object_vars($row_arr['Table']);
- }
- //Communication record
- //$this-
- >
- soap_log($class,$function,$par,$rows);
- return $rows; } //Interface communication record
- function soap_log($class, $function, $in, $out){
- $
log-
=
- date
- ("Y-m-d H:i:s "); $log .= " "
- .$class."->".$function." input:"; $input = ""
- ; if ($in != array()) { foreach ($in as $ key =
-
>
-
$vlaue){ $input .= $key."=".$vlaue; }
- $log .= $input." output:".var_export($rows)." n";
- }
- }
- }
The above is the communication class content. The usage is very simple
include PHP link WEB SERVICE class file
<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>
Copy after login
The above is the relevant usage method of PHP linking WEB SERVICE class.
http://www.bkjia.com/PHPjc/445913.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445913.htmlTechArticlePHP link WEB SERVICE class code example: //Communication class starts classwebserv { //webservice address parameter var$ webadd = array (publ= client.asmx?wsdl, client= Client.asmx?wsdl, bann= ); //Adjust...