This commit is contained in:
rainerosion 2021-10-01 23:30:19 +08:00
commit 42f1f4d020
2 changed files with 49 additions and 0 deletions

15
docker-compose.yaml Normal file
View File

@ -0,0 +1,15 @@
version: '3'
services:
phpweb:
container_name: php73-tipdw
image: phpstorm/php-73-apache-xdebug-27
ports:
- 8081:80
volumes:
- ./:/var/www/html
environment:
XDEBUG_CONFIG: remote_host=host.docker.internal
networks:
- php73-tipdw
networks:
php73-tipdw:

34
index.php Normal file
View File

@ -0,0 +1,34 @@
<?php
error_reporting(0);
date_default_timezone_set('PRC');
header('Access-Control-Allow-Origin: *');
header('Content-type: application/json');
// 应用API KEY
const API_KEY = "";
function curl_get($url){
$header = array(
'Accept: application/json',
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, 1);
curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($curl);
// 显示错误信息
if (curl_error($curl)) {
return "Error: " . curl_error($curl);
} else {
// 打印返回的内容
return ($data);
}
curl_close($curl);
}
$ip = isset($_GET["ip"])?$_GET["ip"]:'';
$url = sprintf("https://apis.map.qq.com/ws/location/v1/ip?ip=%s&key=%s", urlencode($ip), API_KEY);
echo curl_get($url);