Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial PHP中调用WebService接口,谁给个详细代码呢?

PHP中调用WebService接口,谁给个详细代码呢?

Jun 23, 2016 pm 01:45 PM

有一个WebService接口,http://218.245.0.236:7880/sms?WSDL
请问如何在PHP中调用这个接口呢?谁给个详细代码呢?谢谢了!


回复讨论(解决方案)

你用的是nusoap扩展类还是用的自带的soap类呢

这个是nusoap扩展类的用法,你要先去下一个nusoap工具类

$soapClient = new nusoap_client("http://218.245.0.236:7880/sms?WSDL",true);$parameters=array(**,**,**);$outString = $soapClient->call("webserviceName", $parameters);//一般是这样调的//call方法里还可以配很多参数,你根据自己的需要来配,有问题的话,去下个抓包工具来看发送和接收到的包就行
Copy after login

我下载了一个nusoap-0.9.5.zip,用的里面lip里的nusoap.php。
我代码是这样写的

include('nusoap.php');// 创建一个soapclient对象,参数是server的WSDL $client = new soapclient('http://218.245.0.236:7880/sms?WSDL', 'wsdl');// 参数转为数组形式传递$aryPara = array('spID'=>'922017', 'Password'=>MD5('admin41501012'));// 调用远程函数$aryResult = $client->call('RetrieveAll',$aryPara);echo $aryResult;
Copy after login

我在网页上运行后他返回的是Array,这是什么意思呢?我得返回值应该是

RESULTCODE #@#BALANCE#@#
RDFLAG#@#MID#@#SPID#@#ACCESSCODE#@#MOBILE#@#STAT#@#DELIVERTIME#@# RDFLAG#@#MID#@#SPID#@#ACCESSCODE#@#MOBILE#@#MSGCONTENT#@#DELIVERTIME#@#
这种形式的!
还有我在网上看得例子上面有这个
$document=$client->document;
echo <<


$document


SoapDocument;
这又是什么意思呢?谢谢指教!

如果你调用成功了,返回的就是那个webservice执行后的结果呀

首先你要确认下,返回的是不是webservice返回的正确的结果集

编码也要设置下

        $soapClient->soap_defencoding = 'utf-8';        $soapClient->decode_utf8 = false;        $soapClient->xml_encoding = 'utf-8';
Copy after login

调用前加这段代码
可以解决乱码问题

他输出的是Array,我返回值的形式应该是1#@#0#@#这种形式的!
我在代码里加上

$document=$client->document;echo <<<SoapDocument<?xml version="1.0" encoding="GB2312"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd">   <SOAP-ENV:Body>   $document   </SOAP-ENV:Body></SOAP-ENV:Envelope>SoapDocument;	?>
Copy after login

这些后,就出现一个Array 3#@#-1#@#,这是什么意思呢?加上这段代码是什么意思呢?

我用的时候没有加这一串东西。
他这样写的意思应该是构造发送过去的包吧。你不用写这段代码啊
而且我发觉你用的soapclient方法,这个是PHP 5.0+自带的soap类中的方法,并不是你使用的nusoap扩展类。
如果你要使用soap类要修改php.int中的配置,然后重启服务器。
你就这样写

include('nusoap.php');// 创建一个soapclient对象,参数是server的WSDL $client = new nusoap_client('http://218.245.0.236:7880/sms?WSDL', true);// 解决编码(如果需要的话就加上)/*$soapClient->soap_defencoding = 'utf-8';$soapClient->decode_utf8 = false;$soapClient->xml_encoding = 'utf-8';*/// 参数转为数组形式传递$aryPara = array('spID'=>'922017', 'Password'=>MD5('admin41501012'));// 调用远程函数$aryResult = $client->call('RetrieveAll',$aryPara);echo $aryResult;
Copy after login

就这样调用 其它不用加

我把你的代码加上怎么提示我

$client = new nusoap_client('http://218.245.0.236:7880/sms?WSDL', true);
Copy after login

语法错误呢?
你是用什么软件编写的呢?我用的dreamerweaver,环境是warm

你搜一下你的nusoap.php 文件,client方法具体命名是什么,之前你写的soapclient,是soap类中的方法,如果nusoap类里面的也是叫这个名字可能会产生冲突的

顺便推荐你个PHP IDE 叫做PHPSTORM 非常好用

谢谢你的帮忙了!我现在使用代理方式调用可以出来值了,直接调用还是没出来。第一次接触PHP什么都不懂,郁闷!
还有,我使用代理方式调用的时候换必须有这段代码才可以

<?xml version=”1.0″ encoding=”GB2312″?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/” xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:SOAP-ENC=”http://schemas.xmlsoap.org/soap/encoding/” xmlns:si=”http://soapinterop.org/xsd“><SOAP-ENV:Body>$document</SOAP-ENV:Body></SOAP-ENV:Envelope>SoapDocument;?>
Copy after login

如果没有这段代码直接输出的话只能出现一个Array,郁闷。我在看下吧!

楼主能给一下具体代码吗?因为我php都没学过但现在在一周之内必须完成,时间急,求解救!麻烦您把包和php代码发到我邮箱:1006183252@qq.com   谢谢!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles