详细解读PHP链接WEB SERVICE类
PHP用途非常广泛,我们可以运用庞大的函数来帮助我们实现各种功能需求。下面我们就一起来看看有关PHP链接WEB SERVICE类的使用方法。
PHP链接WEB SERVICE类代码实例:
- //通讯类开始
- class webserv
- {
- //webservice 地址参数
- var $webadd = array(
- "publ" => "client.asmx?wsdl",
- "client" => "Client.asmx?wsdl",
- "bann" => "");
- //调用webservice
- function soap($class,$function,$par = array()){
- //链接
- web service
- $client = new SoapClient($this->webadd[$class]);
- $require = $client->$function($par);
- //调用信息debug
- if (is_soap_fault($require)) {
- echo "远程接口".$function."调用失败!";
- exit();
- }
- //获取返回值
- $function_result = $function."Result";
- $str = $require->$function_result;
- //解析XML
- $row = @simplexml_load_string( $str );
- //如果不能用XML解析直接返回
- if ($row == false) {
- if (is_string($str)){
- return $str;
- } else {
- $require = (get_object_vars($str));
- $str = $require['string'];
- 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 ($row_return as $key => $vlaues){
- $rows[$key] = get_object_vars($vlaues);
- }
- } else {
- $rows[0] = get_object_vars($row_arr['Table']);
- }
- //通讯记录
- //$this->soap_log($class,$function,$par,$rows);
- return $rows;
- }
- //接口通讯记录
- 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";
- }
- }
- }
以上是通信类的内容。用法很简单
include 一下PHP链接WEB SERVICE类文件
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20