前言
简单封装一下万维易源归属地查询接口,因为官方文档已经写的很好了。
代码
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 
 | const showapiSdk = require('showapi-sdk');
 module.exports = api = {
 getLocalInfoByShow: async function (ip, appId, secret) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 showapiSdk.setting({
 url: "http://route.showapi.com/20-1",
 appId: appId,
 secret: secret,
 timeout: 5000,
 options: {
 testParam: 'test'
 }
 });
 
 const request = showapiSdk.request();
 request.appendText('ip', ip);
 return new Promise((resolve, reject) => {
 request.post(function (data) {
 if (data.showapi_res_error) return reject(data.showapi_res_error);
 const ipinfo = data.showapi_res_body;
 resolve ({
 ip_country: ipinfo.country,
 ip_region: ipinfo.region,
 ip_city: ipinfo.city,
 ip_isp: ipinfo.isp
 })
 });
 });
 }
 };
 
 
 |