Browse Source

高德服务

pull/3/head
yuan_yi 3 years ago
parent
commit
ddc013104d
  1. 4
      code/VideoAccess-VCMP/api/.vscode/launch.json
  2. 15
      code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js
  3. 16
      code/VideoAccess-VCMP/api/config.js

4
code/VideoAccess-VCMP/api/.vscode/launch.json

@ -18,7 +18,9 @@
"-g postgres://postgres:123@10.8.30.32:5432/video_access", "-g postgres://postgres:123@10.8.30.32:5432/video_access",
"--redisHost 127.0.0.1", "--redisHost 127.0.0.1",
"--redisPort 6379", "--redisPort 6379",
"--axyApiUrl http://127.0.0.1:4100" "--axyApiUrl http://127.0.0.1:4100",
"--godUrl https://restapi.amap.com/v3",
"--godKey 21c2d970e1646bb9a795900dd00093ce"
] ]
}, },
{ {

15
code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js

@ -2,8 +2,9 @@
const request = require('superagent') const request = require('superagent')
class paasRequest { class paasRequest {
constructor(root) { constructor(root, { query = {} } = {}) {
this.root = root; this.root = root;
this.query = query
} }
#buildUrl = (url) => { #buildUrl = (url) => {
@ -22,25 +23,25 @@ class paasRequest {
get = (url, { query = {}, header = {} } = {}) => { get = (url, { query = {}, header = {} } = {}) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
request.get(this.#buildUrl(url)).set(header).query(query).end(this.#resultHandler(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 = {} } = {}) => { post = (url, { data = {}, query = {}, header = {} } = {}) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
request.post(this.#buildUrl(url)).set(header).query(query).send(data).end(this.#resultHandler(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 = {}, } = {}) => { put = (url, { data = {}, header = {}, query = {}, } = {}) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
request.put(this.#buildUrl(url)).set(header).query(query).send(data).end(this.#resultHandler(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 = {} } = {}) => { delete = (url, { header = {}, query = {} } = {}) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
request.delete(this.#buildUrl(url)).set(header).end(this.#resultHandler(resolve, reject)); request.delete(this.#buildUrl(url)).set(header).query(Object.assign(query, this.query)).end(this.#resultHandler(resolve, reject));
}) })
} }
} }
@ -50,7 +51,7 @@ function factory (app, opts) {
try { try {
for (let r of opts.pssaRequest) { for (let r of opts.pssaRequest) {
if (r.name && r.root) { if (r.name && r.root) {
app.fs[r.name] = new paasRequest(r.root) app.fs[r.name] = new paasRequest(r.root, { ...(r.params || {}) })
} else { } else {
throw 'opts.pssaRequest 参数错误!' throw 'opts.pssaRequest 参数错误!'
} }

16
code/VideoAccess-VCMP/api/config.js

@ -15,6 +15,8 @@ args.option('redisHost', 'redisHost');
args.option('redisPort', 'redisPort'); args.option('redisPort', 'redisPort');
args.option('redisPswd', 'redisPassword'); args.option('redisPswd', 'redisPassword');
args.option('axyApiUrl', 'axyApiUrl'); // 安心云 api args.option('axyApiUrl', 'axyApiUrl'); // 安心云 api
args.option('godUrl', '高德地图API请求地址');
args.option('godKey', '高德地图API key');
const flags = args.parse(process.argv); 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 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 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('缺少启动参数,异常退出'); console.log('缺少启动参数,异常退出');
args.showHelp(); args.showHelp();
process.exit(-1); process.exit(-1);
@ -59,7 +63,15 @@ const product = {
pssaRequest: [{ // name 会作为一个 request 出现在 ctx.app.fs pssaRequest: [{ // name 会作为一个 request 出现在 ctx.app.fs
name: 'axyRequest', name: 'axyRequest',
root: AXY_API_URL root: AXY_API_URL
}] }, {
name: 'godRequest',
root: GOD_URL,
params: {
query: {
key: GOD_KEY
}
}
},]
} }
} }
], ],

Loading…
Cancel
Save