当前位置:   article > 正文

php如何调用webservice,如何用php调用webservice

php edi web services

一、利用php的soap扩展

( extension=php_openssl.dll         extension=php_soap.dll          php.ini 这2项要开通 )

利用http://webservice.webxml.com.cn/提供的获取ip地址的webservices

$client = new SoapClient("http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl");

echo '

';

print_r($client->__getFunctions ()) ;// 获取webservice提供的函数

echo '

';

$myip =  $out->getGeoIPContextResult->string;

echo '

';

print_r($myip);

echo '

';

$param = array('theIpAddress'=>'192.168.1.1');//注意参数

$out = $client->getCountryCityByIp($param);

$arr = $out->getCountryCityByIpResult->string;

echo '

';

print_r($arr);

echo '

';

?>

输出的结果:

Array

(

[0] => getCountryCityByIpResponse getCountryCityByIp(getCountryCityByIp $parameters)

[1] => getGeoIPContextResponse getGeoIPContext(getGeoIPContext $parameters)

[2] => getVersionTimeResponse getVersionTime(getVersionTime $parameters)

[3] => getCountryCityByIpResponse getCountryCityByIp(getCountryCityByIp $parameters)

[4] => getGeoIPContextResponse getGeoIPContext(getGeoIPContext $parameters)

[5] => getVersionTimeResponse getVersionTime(getVersionTime $parameters)

[6] => ArrayOfString getCountryCityByIp(string $theIpAddress)

[7] => ArrayOfString getGeoIPContext()

[8] => string getVersionTime()

[9] => ArrayOfString getCountryCityByIp(string $theIpAddress)

[10] => ArrayOfString getGeoIPContext()

[11] => string getVersionTime()

)

Array

(

[0] => 211.103.248.103

[1] => 北京市昌平区 电信通

)

Array

(

[0] => 192.168.1.1

[1] => 局域网 对方和您在同一内部网

)

二、服务器不支持soap扩展的情况下,可引入网上开源的类库:

include("lib/nusoap.php");

$client = new SoapClient("http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl","wsdl");

$client->soap_defencoding = 'utf-8';

$client->decode_utf8 = false;

$client->xml_encoding = 'utf-8';

$out = $client->call('getGeoIPContext');

echo '

';

print_r($out) ;

echo '

';

$param = array('theIpAddress'=>'202.173.45.28');//注意参数

$out = $client->call('getCountryCityByIp',$param);

echo '

';

print_r($out) ;

echo '

';

?>

输出的结果:

Array

(

[getGeoIPContextResult] => Array

(

[string] => Array

(

[0] => 211.103.248.103

[1] => 北京市昌平区 电信通

)

)

)

Array

(

[getCountryCityByIpResult] => Array

(

[string] => Array

(

[0] => 95.173.45.28

[1] => 美国

)

)

)

{jcomments on}{jcomments off}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/65961
推荐阅读
  

闽ICP备14008679号