master
elf 8 months ago
parent e2bbf02ee0
commit ec9cfd760a

@ -1,2 +1,58 @@
<?php
echo file_get_contents("https://www.ip138.com/iplookup.php?ip=120.32.100.138&action=2");
function getIpInfo() {
// 云市场分配的密钥Id
$secretId = 'AKID5tH3om0m0dPG4KMBLFLp03E4zrOF0a1qTCXh';
// 云市场分配的密钥Key
$secretKey = 'J06iJMIphW7P6j2KvOr9lMk3EuD9UkJ1ltVo2R3p';
$source = 'market';
// 签名
$datetime = gmdate('D, d M Y H:i:s T');
$signStr = sprintf("x-date: %s\nx-source: %s", $datetime, $source);
$sign = base64_encode(hash_hmac('sha1', $signStr, $secretKey, true));
$auth = sprintf('hmac id="%s", algorithm="hmac-sha1", headers="x-date x-source", signature="%s"', $secretId, $sign);
// 请求方法
$method = 'POST';
// 请求头
$headers = array(
'X-Source' => $source,
'X-Date' => $datetime,
'Authorization' => $auth,
);
// 查询参数
$queryParams = array (
);
// body参数POST方法下
$bodyParams = array (
'ip' => '',
);
// url参数拼接
$url = 'https://service-hnhpr5tw-1305308687.gz.apigw.tencentcs.com/release/ip/query';
if (count($queryParams) > 0) {
$url .= '?' . http_build_query($queryParams);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, array_map(function ($v, $k) {
return $k . ': ' . $v;
}, array_values($headers), array_keys($headers)));
if (in_array($method, array('POST', 'PUT', 'PATCH'), true)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($bodyParams));
}
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo "Error: " . curl_error($ch);
} else {
print_r($data);
}
curl_close($ch);
}

Loading…
Cancel
Save