Commit 60e83527 authored by 李纪文's avatar 李纪文

feat: 消息订阅增加mqtt账户信息设置

parent 84938fcb
Pipeline #92738 waiting for manual action with stages
...@@ -17,8 +17,8 @@ export const MESSAGE_TYPE = { ...@@ -17,8 +17,8 @@ export const MESSAGE_TYPE = {
export const NEW_MESSAGE = 'NEW_MESSAGE'; export const NEW_MESSAGE = 'NEW_MESSAGE';
export const USERNAME = 'mao2080'; export const USERNAME = 'admin';
export const PASSWORD = '123'; export const PASSWORD = 'public';
export const PLATFORM_LEVEL = '4'; export const PLATFORM_LEVEL = '4';
export const VIDEO_LEVEL = '5'; export const VIDEO_LEVEL = '5';
export const SYS_LEVEL = '6'; export const SYS_LEVEL = '6';
......
import logger from '@wisdom-utils/utils/lib/logger'; import logger from '@wisdom-utils/utils/lib/logger';
import _, { isEmpty, isString } from 'lodash'; import _, { isEmpty, isString } from 'lodash';
import MqttClient from 'mqtt-client'; import MqttClient from 'mqtt-client';
import CryptoJS from 'crypto-js';
import { isJSON } from '@wisdom-utils/components/lib/AppLayout/helpers/index'; import { isJSON } from '@wisdom-utils/components/lib/AppLayout/helpers/index';
import { api } from './api'; import { api } from './api';
import { replaceSpeak, generatedId } from './utils'; import { replaceSpeak, generatedId } from './utils';
...@@ -27,6 +28,25 @@ import { createMessageFromHis, createMessageFromReal } from './message'; ...@@ -27,6 +28,25 @@ import { createMessageFromHis, createMessageFromReal } from './message';
/* eslint-disable */ /* eslint-disable */
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const Logger = logger('mqtt'); const Logger = logger('mqtt');
// mqtt密码解密
export const getDecryptedValue = (encryptedText) => {
const AESKey = '1p2a3n4d5a6o7m8s9a10n1e2t3c4o5re'; //32位
const AES_IV = '1234567890000000'; //16位
const key = CryptoJS.enc.Utf8.parse(AESKey);
const iv = CryptoJS.enc.Utf8.parse(AES_IV);
// 解密
const decrypted = CryptoJS.AES.decrypt(
{ ciphertext: CryptoJS.enc.Hex.parse(encryptedText) },
key,
{ iv: iv },
);
// 转换为明文
const plaintext = decrypted.toString(CryptoJS.enc.Utf8);
return plaintext;
};
class Notifier { class Notifier {
constructor(userInfo, renderVideo, renderPlatform, renderSysPlatform, props) { constructor(userInfo, renderVideo, renderPlatform, renderSysPlatform, props) {
this.userInfo = userInfo; this.userInfo = userInfo;
...@@ -185,8 +205,8 @@ class Notifier { ...@@ -185,8 +205,8 @@ class Notifier {
const keepAlive = DEFAULT_KEEPLIVE; const keepAlive = DEFAULT_KEEPLIVE;
const cleanSession = true; const cleanSession = true;
const ssl = this._siteConfig.IsSSL; const ssl = this._siteConfig.IsSSL;
const userName = USERNAME; const userName = this._siteConfig?.mqtt_account || USERNAME;
const password = PASSWORD; const password = this._siteConfig?.mqtt_cyphers ? getDecryptedValue(this._siteConfig?.mqtt_cyphers) : PASSWORD;
const path = this._siteConfig.mqtt_path; const path = this._siteConfig.mqtt_path;
const siteCode = this._siteConfig.site_code ?? ''; const siteCode = this._siteConfig.site_code ?? '';
this.MQTTCount = 0; this.MQTTCount = 0;
...@@ -244,6 +264,8 @@ class Notifier { ...@@ -244,6 +264,8 @@ class Notifier {
mqttConfig.mqtt_mess.MessageLevel = self._siteConfig.MessageLevel = data.MessageLevel mqttConfig.mqtt_mess.MessageLevel = self._siteConfig.MessageLevel = data.MessageLevel
? data.MessageLevel ? data.MessageLevel
: DEFAULT_PARSE_LEVEL; : DEFAULT_PARSE_LEVEL;
mqttConfig.mqtt_account = self._siteConfig.mqtt_account = data?.EmqAccount || '';
mqttConfig.mqtt_cyphers = self._siteConfig.mqtt_cyphers = data?.EmqPassword || '';
if (data.NginxStart) { if (data.NginxStart) {
mqttConfig.NginxStart = self._siteConfig.NginxStart = data.NginxStart; mqttConfig.NginxStart = self._siteConfig.NginxStart = data.NginxStart;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment