PHP的SOAP工具包--nusoap

来源:互联网 发布:淘宝店招收藏店铺代码 编辑:程序博客网 时间:2024/05/22 17:22

什么是SOAP

SOAP:简单对象访问协议,简单对象访问协议(SOAP)是一种轻量的、简单的、基于 XML 的协议,它被设计成在 WEB 上交换结构化的和固化的信息。

NuSOAP 是一组功能强大的PHP类,使得使用和创建SOAP消息变得相当简单。NuSOAP由Dirtrich Ayala编写,可以无缝地与很多最流行的SOAP服务实现交互,它遵循LGPL发布。NuSOAP提供了很多令人印象深刻的特性,包括: 
简单 :NuSOAP的面向对象方法隐藏了SOAP消息组装、解析、提交和接收的有关细节,使用户集中于应用程序本身。
WSDL生成和导入 :NuSOAP可以生成一个对应于所发布Web服务的WSDL文档,并且能导入一个WSDL引用在NuSOAP客户端使用。
代理类 :NuSOAP可以生成的一个代理类,允许调用远程方法,如同调用本地方法一样。
HTTP代理 :出于多种原因(安全性和审计是其中两个原因),有些客户端被强制将请求委托给HTTP代理,由代理代表客户端执行请求。也就是说,需要所有SOAP请求都传递给此代理,而不是直接查询服务器。NuSOAP为指定代理服务器提供了基本支持。
SSL :如果可以通过PHP使用CURL扩展,NuSOAP还支持通过SSL的安全通信。

SOAP对PHP的版本要求

 soap要求PHP5.0以上版本,且php默认是不加载soap模块的。解决方法是在php.ini中的Dynamic Extensions里添加:extension=php_soap.dll,如果原来有这一条,只是被注释掉了,那么只要把前边的分号去掉就可以了。

注:nusoap可以兼容PHP4和PHP5。

SOAP相关基础知识 

1.wsdl(web服务标记语言)
WSDL(网络服务描述语言,Web Services Description Language)是一门基于 XML 的语言,用于描述 Web Services 以及如何对它们进行访问。
具体参考请访问下面网址 http://www.w3school.com.cn/wsdl/index.asp

2.soap 
SOAP 是一种简单的基于 XML 的协议,它使应用程序通过 HTTP 来交换信息。
具体参考请访问下面网址 http://www.w3school.com.cn/soap/index.asp

3.php扩展
具体参考请访问下面网址 http://php.net/manual/en/book.soap.php

NuSOAP的应用举例

天气预报接口调用:

view source
print?
01.$client newnusoap_client('http://www.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl''wsdl');
02.$client->soap_defencoding = 'utf-8';
03.$client->decode_utf8 = false;
04.$client->xml_encoding = 'utf-8';
05.$param array('theUserID'=>'''theCityCode'=>$city);
06.$result $client->call('getWeather'$param);
07.if(!$client->fault AND !$client->getError())
08.{
09.print_r($result);
10.}

常用WEB SERVICE

天气预报Web Service ,数据来源于中国气象局
Endpoint : http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl

IP地址来源搜索Web Service (是目前最完整的IP地址数据)
Endpoint : http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl

随机英文、数字和中文简体字Web Service
Endpoint : http://www.webxml.com.cn/WebServices/RandomFontsWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/RandomFontsWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/RandomFontsWebService.asmx?wsdl

中国邮政编码 <--> 地址信息双向查询/搜索Web Service
Endpoint : http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx?wsdl

验证码图片Web Service 支持中文、字母、数字 图像和多媒体
Endpoint : http://www.webxml.com.cn/WebServices/ValidateCodeWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/ValidateCodeWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/ValidateCodeWebService.asmx?wsdl

Email 电子邮件地址验证Web Service
Endpoint : http://www.webxml.com.cn/WebServices/ValidateEmailWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/ValidateEmailWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/ValidateEmailWebService.asmx?wsdl

中文简体字 <-->繁体字转换Web Service
Endpoint : http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/TraditionalSimplifiedWebService.asmx?wsdl

中文 <--> 英文双向翻译Web Service
Endpoint : http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx?wsdl

火车时刻表Web Service (第六次提速最新列车时刻表)
Endpoint : http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx?wsdl

中国股票行情数据Web Service (支持深圳和上海股市的基金、债券和股票)
Endpoint : http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl

即时外汇汇率数据Web Service
Endpoint : http://www.webxml.com.cn/WebServices/ExchangeRateWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/ExchangeRateWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/ExchangeRateWebService.asmx?wsdl

腾讯QQ在线状态Web Service
Endpoint : http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx
Disco : http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?disco
WSDL : http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl

中国电视节目预告 (电视节目表)Web Service
Endpoint : http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx
Disco : http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?disco
WSDL : http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?wsdl

外汇-人民币即时报价Web Service
Endpoint : http://www.webxml.com.cn/WebServices/ForexRmbRateWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/ForexRmbRateWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/ForexRmbRateWebService.asmx?wsdl

中国股票行情分时走势预览缩略图Web Service
Endpoint : http://www.webxml.com.cn/webservices/ChinaStockSmallImageWS.asmx
Disco : http://www.webxml.com.cn/webservices/ChinaStockSmallImageWS.asmx?disco
WSDL : http://www.webxml.com.cn/webservices/ChinaStockSmallImageWS.asmx?wsdl

国内飞机航班时刻表 Web Service
Endpoint : http://www.webxml.com.cn/webservices/DomesticAirline.asmx
Disco : http://www.webxml.com.cn/webservices/DomesticAirline.asmx?disco
WSDL : http://www.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl

中国开放式基金数据Web Service
Endpoint : http://www.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx
Disco : http://www.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/ChinaOpenFundWS.asmx?wsdl

股票行情数据 Web Service (支持香港、深圳、上海基金、债券和股票;支持多股票同时查询)
Endpoint : http://www.webxml.com.cn/WebServices/StockInfoWS.asmx
Disco : http://www.webxml.com.cn/WebServices/StockInfoWS.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/StockInfoWS.asmx?wsdl