依靠Nusoap来调用webservice是很容易的,在http://www.webxml.com.cn的网站上有好多免费的webservice可以用的,下面来实现一个查询国内手机号码归属地的程序,
相关信息
Url
http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx
getDatabaseInfo
获得国内手机号码归属地数据库信息
输入参数:无;返回数据:一维字符串数组(省份 城市 记录数量)。
getMobileCodeInfo
获得国内手机号码归属地省份、地区和手机卡类型信息
输入参数:mobileCode = 字符串(手机号码,最少前7位数字),userID = 字符串(商业用户ID) 免费用户为空字符串;返回数据:字符串(手机号码:省份 城市 手机卡类型)。
http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx
getDatabaseInfo
获得国内手机号码归属地数据库信息
输入参数:无;返回数据:一维字符串数组(省份 城市 记录数量)。
getMobileCodeInfo
获得国内手机号码归属地省份、地区和手机卡类型信息
输入参数:mobileCode = 字符串(手机号码,最少前7位数字),userID = 字符串(商业用户ID) 免费用户为空字符串;返回数据:字符串(手机号码:省份 城市 手机卡类型)。
前台的html这里不写了,提交以后的程序代码如下:
- <?php
- require_once('lib/nusoap.php');
- $wsdl = 'http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL';
- $mobileCode = $_POST['mobileCode'];
- $userID = $_POST['userid']
- $client = new soapclient($wsdl,true);
- $client->soap_defencoding = 'utf-8'; //防止乱码
- $client->decode_utf8 = false;
- #$client->xml_encoding = 'utf-8';
- $err = $client->getError();
- $param = array('mobileCode' => $mobileCode,'userID' => $userID);
- $result = $client->call('getMobileCodeInfo', array('parameters' => $param), '', '', false, true,'document','encoded');
- if ($client->fault) {
- echo '<h2>Fault</h2><pre>';
- print_r($result);
- echo '</pre>';
- } else {
- $err = $client->getError();
- if ($err) {
- echo '<h2>Error</h2><pre>' . $err . '</pre>';
- }
- else
- {
- echo '<h2>Result</h2><pre>';
- echo print_r($result['getMobileCodeInfoResult']);
- echo '</pre>';
- }
- }
- ?>
代码是大体的思路,要注意的是编码的指定,要不乱码会很烦人。至此Nusoap的应用大体也差不多了,欢迎交流。在webxml的网站有好多免费的webservice可以使用,测试下。