&coor=bd09ll"; $ak = 'ao4JlMvJdqbGbz59nANYDGG0FzqusAmV'; function request_get($url = '', $param = array()) { if (empty($url) || empty($param)) { return false; } $getUrl = $url . "?" . http_build_query($param); $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($curl, CURLOPT_URL, $getUrl); curl_setopt($curl, CURLOPT_TIMEOUT, 1000); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HEADER, 0); $data = curl_exec($curl); if (!$data) { print("an error occured in function request_get(): " . curl_error($curl) . "\n"); } curl_close($curl); return $data; } $url = 'https://api.map.baidu.com/location/ip'; $param['ip'] = $ip; $param['coor'] = 'bd09ll'; $param['ak'] = $ak; $ipProvinceKey="ip_province_key_".$ip; if($_COOKIE['UIID']=='7f14c2d462c3d2826307cdf95b59410160b1f9f21da2595e92'){ } $ipProvince = ""; if(!empty($redis) && !$redis->get($ipProvinceKey)){ $ipProvince = $redis->get($ipProvinceKey); }; if(!$ipProvince && date("H")>8){ $res = request_get($url, $param); if($res){ $ipInfo = json_decode($res,true); if(!empty($ipInfo) && isset($ipInfo["content"]['address_detail']['province'])){ $ipProvince = $ipInfo["content"]['address_detail']['province']; if($redis){ $redis->set($ipProvinceKey,$ipProvince,100000); } } } } ?>
//百度统计 20220402 uicn