From c63783c17abe2ef15861002387249614d30261ee Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 1 Aug 2023 21:07:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=99=BA=E8=B0=83=E7=B3=BB=E7=BB=9F=E9=89=B4?= =?UTF-8?q?=E6=9D=83+=E8=8E=B7=E5=8F=96=E8=BD=A6=E8=BE=86=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/data/index.js | 4 +-- api/app/lib/controllers/overview/operation.js | 28 +++++++++++++++++++ api/app/lib/routes/overview/index.js | 3 ++ api/config.js | 7 +++++ api/utils/zhidiaoSystem.js | 27 ++++++++++++++++++ 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 api/utils/zhidiaoSystem.js diff --git a/api/app/lib/controllers/data/index.js b/api/app/lib/controllers/data/index.js index e2e8135f..fdac7f6f 100644 --- a/api/app/lib/controllers/data/index.js +++ b/api/app/lib/controllers/data/index.js @@ -4,7 +4,7 @@ const xlsxDownload = require('../../../../utils/xlsxDownload.js'); const moment = require('moment'); const request = require('superagent'); -async function dataExport(ctx) { +async function dataExport (ctx) { try { let tableAttributesCopy = {} const models = ctx.fs.dc.models; @@ -146,7 +146,7 @@ async function dataExport(ctx) { } } -async function godTrans(ctx) { +async function godTrans (ctx) { try { const models = ctx.fs.dc.models; const { userId } = ctx.fs.api diff --git a/api/app/lib/controllers/overview/operation.js b/api/app/lib/controllers/overview/operation.js index 4fde47db..47a47205 100644 --- a/api/app/lib/controllers/overview/operation.js +++ b/api/app/lib/controllers/overview/operation.js @@ -1,4 +1,5 @@ 'use strict'; +const zhidiaoSystem = require('../../../../utils/zhidiaoSystem.js'); async function busCarLevelList (ctx) { try { @@ -127,8 +128,35 @@ async function vehicleStatistic (ctx) { } } +async function busRunRealTime (ctx) { + try { + const { models } = ctx.fs.dc; + const { app } = ctx + + const busCarRes = await models.BusCar.findAll({ + attributes: ['id', 'vehicleLicensePlateNumber',], + }) + + const Authorization = zhidiaoSystem.createAuthorization() + const busRunRes = await app.fs.zhidiaoRequest.get(`getBusRunList`, { + header: { + Authorization: Authorization + } + }) + + ctx.status = 200; + ctx.body = (busRunRes || []).filter(b => busCarRes.some(bc => bc.vehicleLicensePlateNumber == b.busNoChar)) + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} module.exports = { busCarLevelList, vehicleStatistic, + busRunRealTime, }; \ No newline at end of file diff --git a/api/app/lib/routes/overview/index.js b/api/app/lib/routes/overview/index.js index 1d37acaf..9bd23c45 100644 --- a/api/app/lib/routes/overview/index.js +++ b/api/app/lib/routes/overview/index.js @@ -23,4 +23,7 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/transportation/statistic'] = { content: '获取运政统计', visible: false }; router.get('/transportation/statistic', operation.vehicleStatistic); + + app.fs.api.logAttr['GET/bus/run_realtime'] = { content: '获取公交实时运行信息', visible: false }; + router.get('/bus/run_realtime', operation.busRunRealTime); } \ No newline at end of file diff --git a/api/config.js b/api/config.js index 13265b27..bf4f6e63 100644 --- a/api/config.js +++ b/api/config.js @@ -34,6 +34,8 @@ const YINGSHI_KEY = process.env.YINGSHI_KEY || flags.yingshiKey; const YINGSHI_SECRET = process.env.YINGSHI_SECRET || flags.yingshiSecret; // 萤石服务的地址 const YINGSHI_URL = process.env.YINGSHI_URL || flags.yingshiUrl || 'https://open.ys7.com/api'; +// 智调系统基础数据接口 +const ZHIDIAO_URL = process.env.ZHIDIAO_URL || flags.zhidiaoUrl || 'http://61.131.207.68:31005'; if ( !FS_UNIAPP_DB || @@ -74,6 +76,11 @@ const product = { name: 'yingshiRequest', root: YINGSHI_URL, params: {} + }, + { + name: 'zhidiaoRequest', + root: ZHIDIAO_URL, + params: {} } ] } diff --git a/api/utils/zhidiaoSystem.js b/api/utils/zhidiaoSystem.js new file mode 100644 index 00000000..39317c8b --- /dev/null +++ b/api/utils/zhidiaoSystem.js @@ -0,0 +1,27 @@ +'use strict'; +const CryptoJS = require('crypto-js'); +const hmacSHA512 = require('crypto-js/hmac-sha512'); +const Base64 = require('crypto-js/enc-base64'); +const moment = require('moment'); + +const createAuthorization = () => { + let appid = 10009 + let appkey = '12b1b4724b9643b89a40858000f1cd7e' + + let timestamp = moment().valueOf() + let sb = `appid=${appid}×tamp=${timestamp}` + + let digest = CryptoJS.HmacSHA1(sb, appkey) + + // digest = Base64.stringify(hmacSHA512(sb, appkey)) + + digest = Base64.stringify(digest) + + return `HmacSHA appid:${timestamp}:${digest}` + return `HmacSHA ${appid}:${timestamp}:${digest}` +} + + +module.exports = { + createAuthorization +} \ No newline at end of file