123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace baidu;
- /*
- 百度WebAPI接口插件
- */
- class Api
- {
- protected $AK="";
- public function __construct()
- {
- //执行父类的构造方法
- $this->AK = sysconfig('baidu.map_ak');
- }
- // IP地址转位置
- public function ip_to_address($ip)
- {
- $url = "http://api.map.baidu.com/location/ip?ak=".$this->AK."&ip=".$ip."&coor=bd09ll";
- $result=json_decode(file_get_contents($url),true);
- if(isset($result['status']) && 0==$result['status']){
- return $result['content'];
- }else{
- Wlog('BaiduAPI','ACTION:'.__FUNCTION__);
- Wlog('BaiduAPI','REQUEST:'.$ip);
- Wlog('BaiduAPI',$result['message']);
- return false;
- }
- }
- // 根据行政区域编码获取天气
- public function getWeather($areacode)
- {
- if(!empty($areacode)){
- $url = "https://api.map.baidu.com/weather/v1/?district_id=$areacode&data_type=now&ak=".$this->AK;
- $result = json_decode(file_get_contents($url),true);
- if(isset($result['status']) && 0==$result['status']){
- return $result['result']['now'];
- }else{
- Wlog('BaiduAPI','ACTION:'.__FUNCTION__);
- Wlog('BaiduAPI','REQUEST:'.$areacode);
- Wlog('BaiduAPI',$result['message']);
- return false;
- }
- }else{
- return false;
- }
- }
- }
- ?>
|