增加腾讯地图地址查询的接口

This commit is contained in:
zhl 2021-04-21 12:45:10 +08:00
parent 83efbc2e5d
commit 94aff0ca6e
3 changed files with 45 additions and 2 deletions

View File

@ -0,0 +1,19 @@
import BaseController from '../../common/base.controller'
import { router } from '../../decorators/router'
import { queryArea } from '../../services/TencentMap'
import { ZError } from '../../common/ZError'
class MapController extends BaseController {
@router('post /area/query')
async fetchArea(req, res) {
let {keyword, region} = req.params
let data = await queryArea(keyword, region)
if (data.status != 0) {
throw new ZError(data.status, data.message)
}
return {
count: data.count,
records: data.data
}
}
}

View File

@ -45,13 +45,13 @@ class ShopClass extends FindOrCreate {
* @type {number}
*/
@prop()
public longitude: number
public lng: number
/**
*
* @type {number}
*/
@prop()
public latitude: number
public lat: number
/**
*
* @type {boolean}

View File

@ -0,0 +1,24 @@
import axios from 'axios'
import { md5 } from '../utils/security.util'
const key = 'LAHBZ-TXZYJ-CT7FQ-KIK5N-Z6PBV-QCFXN'
const signKey = 'lWmmEpmAul4u8q9gktxFmu5N36IslYyy'
export async function queryArea(keyword: string, region: string) {
let host = 'https://apis.map.qq.com'
let path = '/ws/place/v1/suggestion'
let signStr = `${path}?key=${key}&keyword=${keyword}&region=${region}${signKey}`
let sig = md5(signStr)
let data = {
key,
keyword,
region,
sig
}
let url = `${host}${path}`
return axios.get(url, {params: data})
.then(res => {
return res.data
})
}