详细解读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类文件
<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> </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>
以上就是PHP链接WEB SERVICE类的相关使用方法。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
