|
@@ -3,11 +3,12 @@
|
|
|
import Cities from '../../models/v1/cities';
|
|
|
import http from 'http';
|
|
|
import pinyin from "pinyin";
|
|
|
-import fetch from 'node-fetch';
|
|
|
+import BaseComponent from '../../prototype/baseComponent'
|
|
|
|
|
|
|
|
|
-class CityHandle {
|
|
|
+class CityHandle extends BaseComponent{
|
|
|
constructor(){
|
|
|
+ super()
|
|
|
this.cityGuess = this.cityGuess.bind(this);
|
|
|
}
|
|
|
async cityGuess(req, res, next){
|
|
@@ -42,18 +43,12 @@ class CityHandle {
|
|
|
req.connection.socket.remoteAddress;
|
|
|
const ipArr = ip.split(':');
|
|
|
ip = ipArr[ipArr.length -1];
|
|
|
- // ip = '116.231.55.195';
|
|
|
+ ip = '116.231.55.195';
|
|
|
/*
|
|
|
调用新浪接口,获取ip地址信息
|
|
|
*/
|
|
|
- const url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=' + ip;
|
|
|
- let res;
|
|
|
- try{
|
|
|
- res = await fetch(url);
|
|
|
- res = await res.text();
|
|
|
- }catch(err){
|
|
|
- console.log(err)
|
|
|
- }
|
|
|
+ const url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php';
|
|
|
+ let res = await this.fetch('GET', url , {format: 'js', ip,}, 'TEXT');
|
|
|
const cityInfo = JSON.parse(res.split('=')[1].toString().replace(';', ''));
|
|
|
/*
|
|
|
汉字转换成拼音
|