thinkphp中集成nusoap说明详解
开始对接联通的Cisco Jasper系统,需要用到SOAP API信息,这里只是获取联通Jasper系统提供的数据信息,而不提供信息,所以本文只是thinkphp3.2集成SOAP获取相应信息而已,并不提供数据信息。
NuSOAP中最常用到的类是soap_server和soapclient, 其中soap_server用于创建 Webservice服务,类soapclient则用于调用Webservice .这两个类的定义都在lib/nusoap.php中,因此我们在创建 或调用Webservice接口程序时均需要引用该文件
首先下载nusoap,可以在http://sourceforge.net/projects/nusoap/files/下载得到,然后放到thinkphp系统文件夹下:ThinkPHP\Library\Vendor\NuSoap;
然后就可以引用和使用了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php /** * 联通 接口信息 */ namespace Home\Controller; use Think\Controller; class YingController extends Controller { private $APIKEY,$APIPATH,$APIUSER,$APIPASS,$iccid; public function __construct() { parent::__construct(); Vendor('NuSoap.nusoap'); $this->APIKEY='324b'; $this->APIPATH='https://api.10646.cn'; $this->APIUSER = ''; $this->APIPASS = '.'; $this->iccid = '89860....'; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
public function test(){ $JASPER_URI = 'http://api.jasperwireless.com/ws/schema'; $env = 'apitest'; # Apitest URL. See "Get WSDL Files" in the API documentation for Production URL. $wsdlUrl = 'http://'.$env.'.jasperwireless.com/ws/schema/Echo.wsdl'; $licenseKey = '<INSERT LICENSE KEY HERE>'; $service = new \nusoap_client($wsdlUrl, true /** wsdl **/); $msg = '<EchoRequest xmlns="'.$JASPER_URI.'">'. '<messageId></messageId>'. '<version></version>'. '<licenseKey>'.$licenseKey.'</licenseKey>'. '<value>Hello World</value>'. '</EchoRequest>'; $result = $service->call('Echo', $msg); if ($service->fault) { echo 'faultcode: ' . $service->faultcode . "\n"; echo 'faultstring: ' . $service->faultstring . "\n"; echo 'faultDetail: ' . $service->faultdetail . "\n"; echo 'response: ' . $service->response; exit(0); } echo 'Request: ' . $service->request . "\n"; echo 'Response: ' . $service->response . "\n"; echo 'Call result: ' . $result['value'] . "\n"; } |
很简单的就集成在了一起,至于thinkphp5的暂时没有研究,只针对thinkphp3.2,老系统了不想升级折腾了;最后说个题外话,上次我说过电信物联网启用身份鉴权的事情,现在终于实施了,再次查询号码信息需要提供公司设定的密码才能查询信息!