Detailed interpretation of PHP link WEB SERVICE class_PHP tutorial

WBOY
Release: 2016-07-22 09:01:48
Original
866 people have browsed it

PHP link WEB SERVICE class code example:

  1. //Communication class starts
  2. class webserv
  3. {
  4. //webservice address parameters
  5. var $webadd = array(
  6. "publ" => "client.asmx?wsdl",
  7. "client" => "Client.asmx?wsdl",
  8. "bann" => "");
  9. //Call webservice
  10. function soap($class,$function ,$par = array()){
  11. //Link
  12. web service
  13. $client = new SoapClient($this->webadd[$class]);
  14. $require = $client- >$function($par);
  15. //Call information debug
  16. if (is_soap_fault($require)) {
  17. echo "Remote interface".$function." call failed!";
  18. exit();
  19. }
  20. //Get the return value
  21. $function_result = $function."Result";
  22. $str = $require-> $function_result;
  23. //Parse XML
  24. $row = @simplexml_load_string($str);
  25. //If XML parsing cannot be used, return directly
  26. if ($row == false) {
  27. if (is_string($str)){
  28. return $str; = (get_object_vars($str));
  29. $
  30. str = $require['string ']; return $str;
  31. } }
  32. //Convert the result to an array
  33. $
  34. row_arr
  35. =
  36. get_object_vars
  37. ($row); print_r($row_arr);exit(); $row_return = $row_arr['Table'];
  38. //Judge whether it is Multiple feedback records
  39. if (is_array($row_arr['Table'])) { foreach ($row_return as $
  40. key
  41. =
  42. >
  43. $vlaues){ $rows[$key] = get_object_vars($vlaues); } } else {
  44. $rows[0] = get_object_vars($row_arr['Table']);
  45. }
  46. //Communication record
  47. //$this-
  48. >
  49. soap_log($class,$function,$par,$rows);
  50. return $rows; } //Interface communication record
  51. function soap_log($class, $function, $in, $out){
  52. $
  53. log
  54. =
  55. date
  56. ("Y-m-d H:i:s "); $log .= " "
  57. .$class."->".$function." input:"; $input = ""
  58. ; if ($in != array()) { foreach ($in as $ key =
  59. >
  60. $vlaue){ $input .= $key."=".$vlaue; }
  61. $log .= $input." output:".var_export($rows)." n";
  62. }
  63. }
  64. }


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.


www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template