Commit 335087fa authored by 陈颖's avatar 陈颖

~

parent 3abd9456
Pipeline #47836 passed with stage
in 2 minutes 31 seconds
...@@ -185,34 +185,6 @@ module.exports = { ...@@ -185,34 +185,6 @@ module.exports = {
return gps; return gps;
}, },
async parseGps(gps) {
if (!gps || gps.indexOf(',') === -1) {
return '';
}
const gps_arr = gps.split(',');
if (Math.abs(gps_arr[0]) >= 90) {
gps_arr.reverse();
gps = gps_arr.join(',');
}
const data = {
ak: 'kpqBbfkKx9HvdhfAAEybyy0ATwaZgimI',
pois: 0,
output: 'json',
location: gps,
};
const { ctx } = this;
const resp = await ctx.curl('http://api.map.baidu.com/geocoder/v2/', { timeout: 3000, dataType: 'json', method: 'GET', data });
const ret = resp.data;
if (ret.status != 0) {
return {};
}
return ret;
},
async getGPS(address, city) { async getGPS(address, city) {
console.info(address); console.info(address);
const baidu_url = 'https://api.map.baidu.com/geocoder/v2/'; const baidu_url = 'https://api.map.baidu.com/geocoder/v2/';
...@@ -226,28 +198,45 @@ module.exports = { ...@@ -226,28 +198,45 @@ module.exports = {
}, },
// 根据IP地址来处理业务的展示与否 // 根据IP地址来处理业务的展示与否
async parseIp() { async parseIp(ip = '') {
const ip = this.getClientIP(); const { app } = this;
//
// ip = '122.224.130.226';
if (!ip) { if (!ip) {
return ''; ip = this.getClientIP();
}
const ip_city_key = `ip_city_${ip}`;
let ret = {};
ret = await app.memcache.get(ip_city_key);
if (ret && Object.keys(ret).length !== 0) {
return ret;
} }
const txmap = await this.getTaskIp(ip);
if (Object.keys(txmap).length !== 0) {
ret = txmap.info;
}
await app.memcache.set(ip_city_key, ret, 5);
return ret;
},
async getTaskIp(ip) {
const { ctx, app } = this;
const url = `${app.config.NODE_BASE_URL}/apply/task-ip`;
const data = { const data = {
ak: 'kpqBbfkKx9HvdhfAAEybyy0ATwaZgimI',
output: 'json',
ip, ip,
source: '腾讯地图app-server',
key: app.config.TencentIpKey,
}; };
const { ctx } = this; const ret = await ctx.curl(url, {
const resp = await ctx.curl('https://api.map.baidu.com/location/ip', { timeout: 3000, dataType: 'json', method: 'GET', data }); method: 'POST',
data,
dataType: 'json',
contentType: 'json',
});
const ret = resp.data; app.logger.info(JSON.stringify({ url, status: ret.status, res: ret.data }));
if (ret.status != 0) { if (ret.status !== 200) {
return {}; return {};
} }
return ret; return ret.data;
}, },
async check_submit_frequent(redis_key, expire = 5) { async check_submit_frequent(redis_key, expire = 5) {
......
...@@ -29,6 +29,7 @@ module.exports = appInfo => { ...@@ -29,6 +29,7 @@ module.exports = appInfo => {
jsonLimit: '10mb', jsonLimit: '10mb',
formLimit: '10mb', formLimit: '10mb',
}; };
// 腾讯地图 key
config.TencentIpKey = 'MSMBZ-LMTKZ-6STXT-ZUIE4-SOO7E-W4BO4';
return config; return config;
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment