当前位置:Gxlcms > PHP教程 > 详细解读PHP链接WEBSERVICE类_PHP教程

详细解读PHP链接WEBSERVICE类_PHP教程

时间:2021-07-01 10:21:17 帮助过:26人阅读

PHP链接WEB SERVICE类代码实例:

  1. //通讯类开始
  2. class webserv
  3. {
  4. //webservice 地址参数
  5. var $webadd = array(
  6. "publ" => "client.asmx?wsdl",
  7. "client" => "Client.asmx?wsdl",
  8. "bann" => "");
  9. //调用webservice
  10. function soap($class,$function,$par = array()){
  11. //链接
  12. web service
  13. $client = new SoapClient($this->webadd[$class]);
  14. $require = $client->$function($par);
  15. //调用信息debug
  16. if (is_soap_fault($require)) {
  17. echo "远程接口".$function."调用失败!";
  18. exit();
  19. }
  20. //获取返回值
  21. $function_result = $function."Result";
  22. $str = $require->$function_result;
  23. //解析XML
  24. $row = @simplexml_load_string( $str );
  25. //如果不能用XML解析直接返回
  26. if ($row == false) {
  27. if (is_string($str)){
  28. return $str;
  29. } else {
  30. $require = (get_object_vars($str));
  31. $str = $require['string'];
  32. return $str;
  33. }
  34. }
  35. //结果转换为数组
  36. $row_arr = get_object_vars($row);
  37. print_r($row_arr);exit();
  38. $row_return = $row_arr['Table'];
  39. //判断是不是多反馈记录
  40. if (is_array($row_arr['Table'])) {
  41. foreach ($row_return as $key => $vlaues){
  42. $rows[$key] = get_object_vars($vlaues);
  43. }
  44. } else {
  45. $rows[0] = get_object_vars($row_arr['Table']);
  46. }
  47. //通讯记录
  48. //$this->soap_log($class,$function,$par,$rows);
  49. return $rows;
  50. }
  51. //接口通讯记录
  52. function soap_log($class, $function, $in, $out){
  53. $log = date("Y-m-d H:i:s");
  54. $log .= " ".$class."->".$function." input:";
  55. $input = "";
  56. if ($in != array()) {
  57. foreach ($in as $key => $vlaue){
  58. $input .= $key."=".$vlaue;
  59. }
  60. $log .= $input." output:".var_export($rows)."n";
  61. }
  62. }
  63. }


以上是通信类的内容。用法很简单

include 一下PHP链接WEB SERVICE类文件

  1. < ?
  2. include "./webserv.class.php";
  3. $webserv = new webserv;
  4. //这里是调用方法给传递的参数
  5. $a = array("aa"=>"aaaa");
  6. print_r($webser->soap("function_name",$a));
  7. ?>

以上就是PHP链接WEB SERVICE类的相关使用方法。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445913.htmlTechArticlePHP链接WEB SERVICE类代码实例: //通讯类开始 classwebserv { //webservice地址参数 var$ webadd = array ( publ= client.asmx?wsdl, client= Client.asmx?wsdl, bann= ); //调...

人气教程排行