详细解读PHP链接WEB SERVICE类

开发 后端
我们在这篇文章中通过一段代码范例来为大家详细解读有关PHP链接WEB SERVICE类的使用技巧,希望对大家有所帮助。

PHP用途非常广泛,我们可以运用庞大的函数来帮助我们实现各种功能需求。下面我们就一起来看看有关PHP链接WEB SERVICE类的使用方法。#t#

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. }  

 


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

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类的相关使用方法。

责任编辑:曹凯 来源: 网易博客
相关推荐

2009-12-07 15:34:18

PHP类的封装

2009-12-08 18:14:53

WCF Service

2009-12-01 19:28:16

PHP模板

2009-12-10 09:48:26

PHP获取远程图片

2009-12-01 17:25:16

PHP $_FILES

2009-12-08 10:00:36

PHP比较运算符

2009-12-08 16:48:25

PHP类phpExce

2009-12-02 16:31:54

PHP发送邮件

2009-12-11 15:35:50

PHP弹出对话框

2009-12-08 14:11:03

PHP时区修改

2009-12-11 14:39:41

PHP函数mysql_

2009-12-11 16:28:20

PHP统计图表类

2009-12-02 10:49:59

PHP解析XML元素结

2009-12-04 15:28:36

PHP JSON类库

2009-12-02 14:55:46

PHP抽象类abstr

2009-08-10 10:08:45

.NET调用PHP W

2009-08-11 13:07:26

C#类库中添加Web

2009-04-08 13:22:55

PHPXMLWeb Service

2009-12-08 17:48:28

Web Service

2009-08-20 15:38:50

C#建立Web Ser
点赞
收藏

51CTO技术栈公众号