public function city($ip)
      {
          //每个ip的访问接口频率每分钟不能超过150次否者会被拉黑
          if ($ip != '127.0.0.1'&& $ip !='localhost') {
              $getip = file_get_contents("http://ip-api.com/php/" . $ip . '?lang=zh-CN');
                  $getarr = unserialize($getip);
                  if($getarr['status']=="success"){
                      //拼接country 国家 regionName 省  city 市
                      return $getarr['country'] . $getarr['regionName'] . $getarr['city'];
                  }else{
                      return '获取失败';
                  }
          } else {
              return '未知ip';
          }
      }
      
Last modification:December 23, 2020
如果觉得我的文章对你有用,请随意赞赏