Пример #1
0
 /**
  * 使用sina接口
  */
 public static function getArea($ip = null)
 {
     //ip为空时使用请求ip
     if (empty($ip)) {
         $ip = CRequest::getIp();
     }
     $api = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=';
     $requestUrl = $api . $ip;
     //发送http请求
     $content = CResponse::sendHttpRequest($requestUrl);
     //请求错误
     if ($content['info']['http_code'] != 200) {
         return '';
     }
     $content = json_decode($content['content'], true);
     $result = (isset($content['province']) ? $content['province'] : '') . ' ' . (isset($content['city']) ? $content['city'] : '');
     return $result;
 }