Browse Source

智调系统鉴权+获取车辆实时数据

dev
巴林闲侠 1 year ago
parent
commit
c63783c17a
  1. 4
      api/app/lib/controllers/data/index.js
  2. 28
      api/app/lib/controllers/overview/operation.js
  3. 3
      api/app/lib/routes/overview/index.js
  4. 7
      api/config.js
  5. 27
      api/utils/zhidiaoSystem.js

4
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

28
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,
};

3
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);
}

7
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: {}
}
]
}

27
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}&timestamp=${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
}
Loading…
Cancel
Save