From 930541d5d675b152b74541311769c7e47c4fe621 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Fri, 27 Aug 2021 13:27:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=8D=A2ip=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/config/util.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/back/config/util.ts b/back/config/util.ts index eaa94062..28b652fd 100644 --- a/back/config/util.ts +++ b/back/config/util.ts @@ -159,14 +159,16 @@ export async function getNetIp(req: any) { const baiduApi = got.get( `https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=${ip}&co=&resource_id=6006&t=1555898284898&ie=utf8&oe=utf8&format=json&tn=baidu`, ); - const ipApi = got.get(`http://ip-api.com/json/${ip}?lang=zh-CN`); - const [{ data }, { country, regionName, city }] = await ( + const ipApi = got.get( + `https://whois.pconline.com.cn/ipJson.jsp?ip=${ip}&json=true`, + ); + const [{ data }, { addr, region, city }] = await ( await Promise.all([baiduApi, ipApi]) ).map((x) => JSON.parse(x.body)); if (data[0] && data[0].location) { return { address: data[0].location, ip }; - } else if (country && regionName) { - return { address: `${country} ${regionName} ${city}`, ip }; + } else if (city && region) { + return { address: `${addr}`, ip }; } else { return { address: `获取失败`, ip }; }