你的位置: 首页>> PHP, 技术天空 >> php 使用天气预报 webservice

php 使用天气预报 webservice

热度:



http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
感谢http://www.webxml.com.cn提供的免费数据接口,虽然24小时 只能使用50次,但是我只要缓存一下,没一小时查询一次就可以了。

调用方法

$wsdl = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl";//这是服务地址
$uri = 'http://WebXml.com.cn/';//命名空间经常会忘记。
//$client = new SoapClient($wsdl);
$client = new SoapClient ( $wsdl, array ('trace' => 1, 'uri' => $uri ) );
$parameters = array('theCityName'=>"54734");
//$parameters = array('theCityName'=>iconv("gbk","UTF-8","淄博"));
$out = $client->getWeatherbyCityName($parameters);
$arr = $out->getWeatherbyCityNameResult->string;
$result = array();
$result['province'] = $arr[0];
$result['city'] = $arr[1];
$result['lastupdate'] = $arr[4];
$result['today_temperature'] = $arr[5];
$result['today_weather'] = $arr[6];
$result['today_wind'] = $arr[7];
$result['today_pic1'] = $arr[8];
$result['today_pic2'] = $arr[9];
$result['today_description'] = $arr[10];
$result['exponent'] = $arr[11];
$result['tomorrow_temperature'] = $arr[12];
$result['tomorrow_weather'] = $arr[13];
$result['tomorrow_wind'] = $arr[14];
$result['tomorrow_pic1'] = $arr[15];
$result['tomorrow_pic2'] = $arr[16];
$result['dayaftertomorrow_temperature'] = $arr[17];
$result['dayaftertomorrow_weather'] = $arr[18];
$result['dayaftertomorrow_wind'] = $arr[19];
$result['dayaftertomorrow_pic1'] = $arr[20];
$result['dayaftertomorrow_pic2'] = $arr[21];
$result['cityintroduction'] = $arr[22];

foreach($result as $key=>$value){
if(strpos($value,'gif')){
print("$key :
");
}else{
print("$key : $value
");
}

}

Tags: ,

留个脚印

Copyright © 2010 高度PHP All rights reserved.
Designed by Modified by ifanqie. Powered by WordPress.