加解密接口调试完成

This commit is contained in:
wuhan 2023-07-31 17:15:47 +08:00
parent 53337e72f2
commit 263180142a
5 changed files with 50 additions and 48 deletions

View File

@ -21,4 +21,5 @@ ipBoxUrl: 'https://103.39.222.134:65531'
secureIp: 'https://43.228.38.182:15443'
title: 'test'
secret: '1qaz@WSX'
zjgUrl: 'http://221.224.155.68:8000/epoint-smartcity-ssov2zs'
zjgUrl: 'http://221.224.155.68:8000/epoint-smartcity-ssov2zs'
keyAlias: 'SEMK_SUB'

View File

@ -1,4 +1,4 @@
import {Controller, Post, Body, Get} from '@nestjs/common';
import { Controller, Post, Body, Get } from '@nestjs/common';
import { ClientService } from './client.service';
@Controller()
@ -11,7 +11,7 @@ export class ClientController {
/**
*
*/
@Post('/api/v1/mop/queryNationalPlateAuth')
@Post('/api/v1/mop/szjt/queryNationalPlateAuth')
queryNationalPlateAuth() {
return this.clientService.queryNationalPlateAuth();
}
@ -19,7 +19,7 @@ export class ClientController {
/**
*
*/
@Post('/api/v1/mop/generateNationalPlateAuth')
@Post('/api/v1/mop/szjt/generateNationalPlateAuth')
generateNationalPlateAuth() {
return this.clientService.generateNationalPlateAuth();
}
@ -30,7 +30,7 @@ export class ClientController {
* @param res
* @param next
*/
@Post('/api/v1/mop/queryEntList')
@Post('/api/v1/mop/szjt/queryEntList')
queryEntList(@Body() { entName }) {
return this.clientService.queryEntList({ entName });
}
@ -42,17 +42,17 @@ export class ClientController {
* @param next
* @returns
*/
@Post('/api/v1/mop/generateEntAuth')
@Post('/api/v1/mop/szjt/generateEntAuth')
generateEntAuth(@Body() { entId }) {
return this.clientService.generateEntAuth({ entId });
}
@Post('/api/v1/mop/queryEntAuth')
queryEntAuth(@Body() {entId}) {
@Post('/api/v1/mop/szjt/queryEntAuth')
queryEntAuth(@Body() { entId }) {
return this.clientService.queryEntAuth(entId);
}
@Post('/api/v1/mop/queryMPInfo')
@Post('/api/v1/mop/szjt/queryMPInfo')
queryMPInfo(@Body() { id }) {
return this.clientService.queryMPInfos(id);
}
@ -61,8 +61,8 @@ export class ClientController {
*
* @param id
*/
@Post('/api/v1/mop/queryAppCode')
queryAppCode(@Body() {id}) {
@Post('/api/v1/mop/szjt/queryAppCode')
queryAppCode(@Body() { id }) {
return this.clientService.queryAppCode(id);
}
@ -72,7 +72,7 @@ export class ClientController {
* @param res
* @param next
*/
@Post('/api/v1/mop/setAppCode')
@Post('/api/v1/mop/szjt/setAppCode')
setAppCode(@Body() { id, code, secretKey }) {
return this.clientService.setAppCode({ id, code, secretKey });
}
@ -81,7 +81,7 @@ export class ClientController {
*
* @param id
*/
@Post('/api/v1/mop/queryAreaInfo')
@Post('/api/v1/mop/szjt/queryAreaInfo')
queryAreaInfo() {
return this.clientService.queryAreaInfo();
}
@ -90,13 +90,13 @@ export class ClientController {
*
* @param id
*/
@Post('/api/v1/mop/setAreaInfo')
setAreaInfo(@Body() {areaCode,areaName,mqttUrl}) {
return this.clientService.setAreaInfo(areaCode,areaName,mqttUrl);
@Post('/api/v1/mop/szjt/setAreaInfo')
setAreaInfo(@Body() { areaCode, areaName, mqttUrl }) {
return this.clientService.setAreaInfo(areaCode, areaName, mqttUrl);
}
@Post('/api/v1/mop/setMPInfo')
setMPInfo(@Body() { id,limitFlag,ssoAppKey,ssoAppSecret}) {
return this.clientService.setMPInfo(id,limitFlag,ssoAppKey,ssoAppSecret);
@Post('/api/v1/mop/szjt/setMPInfo')
setMPInfo(@Body() { id, limitFlag, ssoAppKey, ssoAppSecret }) {
return this.clientService.setMPInfo(id, limitFlag, ssoAppKey, ssoAppSecret);
}
}

View File

@ -113,14 +113,14 @@ export class ClientService {
}
}
async queryEntAuth(entId){
async queryEntAuth(entId) {
const queryEntAuth = await clientMapper.getQueryEntAuth(entId);
let data={
'clientId':queryEntAuth[0].clientId,
'clientSecret':queryEntAuth[0].clientSecret,
'encodingKey':queryEntAuth[0].encodingKey
}
return Base.success(data)
const data = {
clientId: queryEntAuth[0].clientId,
clientSecret: queryEntAuth[0].clientSecret,
encodingKey: queryEntAuth[0].encodingKey,
};
return Base.success(data);
}
/**
@ -177,8 +177,8 @@ export class ClientService {
* @param areaName
* @param mqttUrl
*/
async setAreaInfo(areaCode,areaName,mqttUrl) {
const data = await clientMapper.setAreaInfo(areaCode,areaName,mqttUrl);
async setAreaInfo(areaCode, areaName, mqttUrl) {
const data = await clientMapper.setAreaInfo(areaCode, areaName, mqttUrl);
if (!data) {
return Base.error('无数据');
}
@ -194,10 +194,10 @@ export class ClientService {
*/
async setMPInfo(id, limitFlag, ssoAppKey, ssoAppSecret) {
const data = await clientMapper.setMPInfo(
id,
limitFlag,
ssoAppKey,
ssoAppSecret
id,
limitFlag,
ssoAppKey,
ssoAppSecret,
);
if (!data) {
return Base.success();

View File

@ -9,6 +9,7 @@ import mqttService from './mqtt.service';
import { MpService } from '../mp/mp.service';
import global from '../utils/global';
import { SecureService } from '../secure/secure.service';
import hccMapper from 'src/hcc/hcc.mapper';
// 地方服务平台生成连接地址
// getConfig().options.clientId = `IOT_ASP_${stringRandom(16)}`
@ -165,30 +166,30 @@ client.subscribe(['1/req/#', '1/rsp/#']);
setInterval(async () => {
console.log(`${new Date()}查询家庭数据`);
const reqId = stringRandom(16);
// info = await mqttService.encrypt(seId, keyAlias, res);
const hccId = 'e6ca693e-a803-4ef4-91d6-e16131536937';
const hccInfo = await hccMapper.getInfoByHccId(
'e6ca693e-a803-4ef4-91d6-e16131536937',
);
let seId;
if (hccInfo.length) {
seId = hccInfo[0].se_id;
}
// 调用加密接口
const data = await new SecureService().encrypt({
seId: '',
keyAlias: '',
data: JSON.stringify({
const info = await mqttService.encrypt(
seId,
getConfig().keyAlias,
JSON.stringify({
cmd: '7',
reqId,
payload: { dataType: '01', mpId: '6433be833832fb000180193e' },
}),
});
if (!data) {
// 加密失败
console.log('mqtt加密失败');
return;
}
// const data = await mqttService.encrypt()
client.publish(`2/req/1234567890`, data, () => {
);
client.publish(`2/req/${hccId}`, JSON.stringify({ message: info }), () => {
// 记录reqid放入全局缓存
global.reqIdMap.set(reqId, null);
console.log('通知成功');
});
}, 20000);
}, 500);
export default client;

View File

@ -7,7 +7,7 @@ export default function (
): Promise<any[]> | Promise<any> {
return new Promise((resolve, reject) => {
// 新建一个连接池
console.log(getConfig().MYSQL_CONFIG);
// console.log(getConfig().MYSQL_CONFIG);
const pool = mysql.createPool(getConfig().MYSQL_CONFIG);