diff --git a/code/VideoAccess-VCMP/api/.vscode/launch.json b/code/VideoAccess-VCMP/api/.vscode/launch.json index 1507984..18a127d 100644 --- a/code/VideoAccess-VCMP/api/.vscode/launch.json +++ b/code/VideoAccess-VCMP/api/.vscode/launch.json @@ -18,7 +18,9 @@ "-g postgres://postgres:123@10.8.30.32:5432/video_access", "--redisHost 127.0.0.1", "--redisPort 6379", - "--axyApiUrl http://127.0.0.1:4100" + "--axyApiUrl http://127.0.0.1:4100", + "--godUrl https://restapi.amap.com/v3", + "--godKey 21c2d970e1646bb9a795900dd00093ce" ] }, { diff --git a/code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js b/code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js index 4d5edcb..5ab6678 100644 --- a/code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js +++ b/code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js @@ -2,64 +2,65 @@ const request = require('superagent') class paasRequest { - constructor(root) { - this.root = root; - } + constructor(root, { query = {} } = {}) { + this.root = root; + this.query = query + } - #buildUrl = (url) => { - return `${this.root}/${url}`; - } + #buildUrl = (url) => { + return `${this.root}/${url}`; + } - #resultHandler = (resolve, reject) => { - return (err, res) => { - if (err) { - reject(err); - } else { - resolve(res.body); - } - }; - } + #resultHandler = (resolve, reject) => { + return (err, res) => { + if (err) { + reject(err); + } else { + resolve(res.body); + } + }; + } - get = (url, { query = {}, header = {} } = {}) => { - return new Promise((resolve, reject) => { - request.get(this.#buildUrl(url)).set(header).query(query).end(this.#resultHandler(resolve, reject)); - }) - } + get = (url, { query = {}, header = {} } = {}) => { + return new Promise((resolve, reject) => { + request.get(this.#buildUrl(url)).set(header).query(Object.assign(query, this.query)).end(this.#resultHandler(resolve, reject)); + }) + } - post = (url, { data = {}, query = {}, header = {} } = {}) => { - return new Promise((resolve, reject) => { - request.post(this.#buildUrl(url)).set(header).query(query).send(data).end(this.#resultHandler(resolve, reject)); - }) - } + post = (url, { data = {}, query = {}, header = {} } = {}) => { + return new Promise((resolve, reject) => { + request.post(this.#buildUrl(url)).set(header).query(Object.assign(query, this.query)).send(data).end(this.#resultHandler(resolve, reject)); + }) + } - put = (url, { data = {}, header = {}, query = {}, } = {}) => { - return new Promise((resolve, reject) => { - request.put(this.#buildUrl(url)).set(header).query(query).send(data).end(this.#resultHandler(resolve, reject)); - }) - } + put = (url, { data = {}, header = {}, query = {}, } = {}) => { + return new Promise((resolve, reject) => { + request.put(this.#buildUrl(url)).set(header).query(Object.assign(query, this.query)).send(data).end(this.#resultHandler(resolve, reject)); + }) + } - delete = (url, { header = {} } = {}) => { - return new Promise((resolve, reject) => { - request.delete(this.#buildUrl(url)).set(header).end(this.#resultHandler(resolve, reject)); - }) - } + delete = (url, { header = {}, query = {} } = {}) => { + return new Promise((resolve, reject) => { + request.delete(this.#buildUrl(url)).set(header).query(Object.assign(query, this.query)).end(this.#resultHandler(resolve, reject)); + }) + } } function factory (app, opts) { - if (opts.pssaRequest) { - try { - for (let r of opts.pssaRequest) { - if (r.name && r.root) { - app.fs[r.name] = new paasRequest(r.root) - } else { - throw 'opts.pssaRequest 参数错误!' - } + if (opts.pssaRequest) { + try { + for (let r of opts.pssaRequest) { + if (r.name && r.root) { + app.fs[r.name] = new paasRequest(r.root, { ...(r.params || {}) }) + } else { + throw 'opts.pssaRequest 参数错误!' } - } catch (error) { - console.error(error) - process.exit(-1); - } - } + } + } catch (error) { + console.error(error) + process.exit(-1); + } + } } module.exports = factory; diff --git a/code/VideoAccess-VCMP/api/config.js b/code/VideoAccess-VCMP/api/config.js index 44b64ea..149666d 100644 --- a/code/VideoAccess-VCMP/api/config.js +++ b/code/VideoAccess-VCMP/api/config.js @@ -15,6 +15,8 @@ args.option('redisHost', 'redisHost'); args.option('redisPort', 'redisPort'); args.option('redisPswd', 'redisPassword'); args.option('axyApiUrl', 'axyApiUrl'); // 安心云 api +args.option('godUrl', '高德地图API请求地址'); +args.option('godKey', '高德地图API key'); const flags = args.parse(process.argv); @@ -26,8 +28,10 @@ const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redis const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码 const AXY_API_URL = process.env.AXY_API_URL || flags.axyApiUrl; +const GOD_URL = process.env.GOD_URL || flags.godUrl || 'https://restapi.amap.com/v3'; +const GOD_KEY = process.env.GOD_KEY || flags.godKey; -if (!IOT_VIDEO_ACCESS_DB || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT) { +if (!IOT_VIDEO_ACCESS_DB || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT || !GOD_KEY) { console.log('缺少启动参数,异常退出'); args.showHelp(); process.exit(-1); @@ -59,7 +63,15 @@ const product = { pssaRequest: [{ // name 会作为一个 request 出现在 ctx.app.fs name: 'axyRequest', root: AXY_API_URL - }] + }, { + name: 'godRequest', + root: GOD_URL, + params: { + query: { + key: GOD_KEY + } + } + },] } } ],