maguohua hace 8 años
padre
commit
32b3ed2a64
Se han modificado 4 ficheros con 44 adiciones y 4 borrados
  1. 1 2
      controller/v1/cities.js
  2. 39 0
      controller/v1/search.js
  3. 1 1
      prototype/baseComponent.js
  4. 3 1
      routes/v1.js

+ 1 - 2
controller/v1/cities.js

@@ -1,7 +1,6 @@
 'use strict';
 
 import Cities from '../../models/v1/cities';
-import http from 'http';
 import pinyin from "pinyin";  
 import BaseComponent from '../../prototype/baseComponent'
 
@@ -67,7 +66,7 @@ class CityHandle extends BaseComponent{
 	 		调用新浪接口,获取ip地址信息
 	 		 */
 			const url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php';
-			let res = await this.fetch('GET', url , {format: 'js', ip,}, 'TEXT');
+			let res = await this.fetch(url , {format: 'js', ip,}, 'GET', 'TEXT');
 			const cityInfo = JSON.parse(res.split('=')[1].toString().replace(';', ''));
 			/*
 			汉字转换成拼音

+ 39 - 0
controller/v1/search.js

@@ -0,0 +1,39 @@
+'use strict';
+
+import BaseComponent from '../../prototype/baseComponent';
+import Cities from '../../models/v1/cities';
+
+class SearchPlace extends BaseComponent{
+	constructor(){
+		super()
+	}
+	async search(req, res, next){
+		const {type, city_id, keyword} = req.query;
+		if (!type || isNaN(city_id) || !keyword) {
+			res.send({
+				name: 'ERROR_QUERY_TYPE',
+				message: '参数错误',
+			})
+			return
+		}
+		try{
+			const cityInfo = await Cities.getCityById(city_id);
+			const aaa = await this.fetch('http://restapi.amap.com/v3/place/text?key=e1467cff48d3359df43012aa8c3a252b&keywords=北京大学&types=141201&city=北京&children=1&offset=20&page=1&extensions=all')
+			// const resList = await this.fetch(http://restapi.amap.com/v3/place/text', {
+			// 	key: 'e1467cff48d3359df43012aa8c3a252b',
+			// 	keywords: keyword,
+			// 	types: 141201,
+			// 	city: cityInfo.name,
+			// 	children: 1,
+			// 	offset: 10,
+			// 	page: 1,
+			// 	extensions: 'all',
+			// })
+			res.send(aaa);
+		}catch(err){
+			res.send(err);
+		}
+	}
+}
+
+export default new SearchPlace();

+ 1 - 1
prototype/baseComponent.js

@@ -4,7 +4,7 @@ export default class BaseComponent {
 	constructor(){
 
 	}
-	async fetch(type = 'GET', url = '', data = {}, resType = 'JSON'){
+	async fetch(url = '', data = {}, type = 'GET', resType = 'JSON'){
 		type = type.toUpperCase();
 		resType = resType.toUpperCase();
 		if (type == 'GET') {

+ 3 - 1
routes/v1.js

@@ -1,10 +1,12 @@
 'use strict';
 
 import express from 'express';
-import CityHandle from '../controller/v1/cities'
+import CityHandle from '../controller/v1/cities';
+import SearchPlace from '../controller/v1/search'
 const router = express.Router();
 
 router.get('/cities', CityHandle.getCity);
 router.get('/cities/:id', CityHandle.getCityById);
+router.get('/pois', SearchPlace.search)
 
 export default router