php判断请求IP是不是北京、上海、广州、杭州的代码

高德地图 php 文章 2021-03-05 21:48 585 0 全屏看文

AI助手支持GPT4.0

function get_client_city(){
 	$ip=getip(); 
	
	if($ip){
		$response = HTTP::request("https://restapi.amap.com/v3/ip?ip=$ip&output=json&key=高德的开发者KEY", 'GET');
		//print_r($response);
		if ($response)
		{
			$response = json_decode($response);
			if($response->status=="1"){
				return $response->city;
			}
		}
	}
 }

image.png

到时候只需要判断返回的数据是 北京市、上海市、苏州市、广州市、杭州市就可以了。


-EOF-

AI助手支持GPT4.0