From e491cdb48129752324c4e3764f99bd9203c56dec Mon Sep 17 00:00:00 2001
From: lgq <1015864684@qq.com>
Date: 星期二, 31 三月 2026 09:48:44 +0800
Subject: [PATCH] 1.新增VF205门禁机代码
---
vf205_access/src/service/codeService.js | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 205 insertions(+), 0 deletions(-)
diff --git a/vf205_access/src/service/codeService.js b/vf205_access/src/service/codeService.js
new file mode 100644
index 0000000..10dfe20
--- /dev/null
+++ b/vf205_access/src/service/codeService.js
@@ -0,0 +1,205 @@
+/**
+ * 浜岀淮鐮�/鏉″舰鐮佸鐞嗘湇鍔℃ā鍧�
+ * 澶勭悊鍚勭被浜岀淮鐮�/鏉″舰鐮佺殑瑙f瀽鍜屽鐞嗭紝鍖呮嫭閰嶇疆鐮併�佷簯璇佹縺娲荤爜鍜岄�氳鐮�
+ */
+import common from '../../dxmodules/dxCommon.js';
+import log from '../../dxmodules/dxLogger.js'
+import qrRule from '../../dxmodules/dxQrRule.js'
+import std from '../../dxmodules/dxStd.js'
+import config from '../../dxmodules/dxConfig.js'
+import base64 from '../../dxmodules/dxBase64.js'
+import dxMap from '../../dxmodules/dxMap.js'
+import ota from "../../dxmodules/dxOta.js";
+import bus from "../../dxmodules/dxEventBus.js"
+import sqliteService from "./sqliteService.js";
+import driver from '../driver.js';
+import utils from '../common/utils/utils.js';
+import configConst from '../common/consts/configConst.js';
+import configService from './configService.js';
+import accessService from './accessService.js';
+import logger from '../../dxmodules/dxLogger.js';
+const codeService = {}
+
+/**
+ * 鎺ユ敹娑堟伅骞跺鐞�
+ * @param {ArrayBuffer} data - 鎺ユ敹鍒扮殑鍘熷鏁版嵁
+ */
+codeService.receiveMsg = function (data) {
+ log.info('[codeService] receiveMsg :' + JSON.stringify(data))
+ // 灏咥rrayBuffer杞崲涓哄崄鍏繘鍒跺瓧绗︿覆锛屽啀杞崲涓篣TF8瀛楃涓�
+ let str = common.utf8HexToStr(common.arrayBufferToHexString(data))
+ // 璋冪敤code鏂规硶澶勭悊瀛楃涓�
+ this.code(str)
+}
+
+/**
+ * 姣旇緝涓や釜瀛楃涓茬殑鍓峃涓瓧绗︽槸鍚︾浉绛�
+ * @param {string} str1 - 绗竴涓瓧绗︿覆
+ * @param {string} str2 - 绗簩涓瓧绗︿覆
+ * @param {number} N - 姣旇緝鐨勫瓧绗︽暟
+ * @returns {boolean} 鍓峃涓瓧绗︽槸鍚︾浉绛�
+ */
+function comparePrefix (str1, str2, N) {
+ let substring1 = str1.substring(0, N);
+ let substring2 = str2.substring(0, N);
+ return substring1 === substring2;
+}
+
+/**
+ * 澶勭悊浜岀淮鐮�/鏉″舰鐮佹暟鎹�
+ * @param {string} data - 浜岀淮鐮�/鏉″舰鐮佺殑鍘熷鏁版嵁
+ */
+codeService.code = function (data) {
+ log.info('[codeService] code :' + data)
+ // 鏍煎紡鍖栦簩缁寸爜鏁版嵁
+ data = qrRule.formatCode(data, sqliteService)
+
+ // 鍒ゆ柇浜岀淮鐮佺被鍨�
+ if (data.type == 'config' || comparePrefix(data.code, "___VF102_CONFIG_V1.1.0___", "___VF102_CONFIG_V1.1.0___".length)) {
+ // 閰嶇疆鐮佸鐞�
+ configCode(data.code)
+ } else if (comparePrefix(data.code, "___VBAR_ID_ACTIVE_V", "___VBAR_ID_ACTIVE_V".length)) {
+ // 浜戣瘉婵�娲荤爜澶勭悊
+ let activeResute = driver.eid.active(config.get("sys.sn"), config.get("sys.appVersion"), config.get("sys.mac"), data.code);
+ log.info("[codeService] code: activeResute " + activeResute)
+ if (activeResute === 0) {
+ log.info("[codeService] code: 浜戣瘉婵�娲绘垚鍔�")
+ driver.screen.upgrade({ title: "confirm.cloudCertActive", content: "confirm.cloudCertActiveSuccess" })
+ } else {
+ log.info("[codeService] code: 浜戣瘉婵�娲诲け璐�")
+ driver.screen.upgrade({ title: "confirm.cloudCertActive", content: "confirm.cloudCertActiveFail" })
+ }
+ } else {
+ // 閫氳鐮佸鐞�
+ log.info("瑙f瀽閫氳鐮侊細", JSON.stringify(data))
+ bus.fire("access", { data })
+ }
+}
+
+/**
+ * 閰嶇疆鐮佸鐞�
+ * @param {string} code - 閰嶇疆鐮佹暟鎹�
+ * @param {boolean} configType - 閰嶇疆绫诲瀷鏍囧織
+ */
+function configCode (code, configType) {
+ // 閰嶇疆鐮佹牎楠屾殏鏃舵敞閲�
+ // if (!checkConfigCode(code)) {
+ // log.error("閰嶇疆鐮佹牎楠屽け璐�")
+ // return
+ // }
+
+ // 瑙f瀽閰嶇疆鐮佷负JSON瀵硅薄
+ let json = utils.parseString(code)
+ if (Object.keys(json).length <= 0) {
+ try {
+ json = JSON.parse(code.slice(code.indexOf("{"), code.lastIndexOf("}") + 1))
+ } catch (error) {
+ log.error(error)
+ }
+ }
+ log.info("瑙f瀽閰嶇疆鐮侊細", JSON.stringify(json))
+
+ // 妯″紡鍒囨崲澶勭悊
+ if (!utils.isEmpty(json.w_model)) {
+ try {
+ common.setMode(json.w_model)
+ common.asyncReboot(1)
+ } catch (error) {
+ log.error(error, error.stack)
+ log.info('鍒囨崲澶辫触涓嶅仛浠讳綍澶勭悊');
+ }
+ return
+ }
+
+ let map = dxMap.get("UPDATE")
+ // 鎵爜鍗囩骇澶勭悊
+ if (json.update_flag === 1) {
+ if (!driver.net.getStatus()) {
+ driver.alsa.play(`/app/code/resource/${config.get("base.language") == "CN" ? "CN" : "EN"}/wav/network.wav`)
+ return
+ }
+ if (map.get("updateFlag")) {
+ return
+ }
+ map.put("updateFlag", true)
+ try {
+ driver.screen.upgrade({ title: "confirm.upgrade", content: "confirm.upgrading" })
+ ota.updateHttp(json.update_addr, json.update_md5, 300)
+ driver.screen.upgrade({ title: "confirm.upgrade", content: "confirm.upgradeSuccess" })
+ } catch (error) {
+ logger.info(error.message)
+ driver.screen.upgrade({ title: "confirm.upgrade", content: "confirm.upgradeFail" })
+ } finally {
+ map.del("updateFlag")
+ }
+ common.asyncReboot(3)
+ return
+ }
+
+ // 璁惧閰嶇疆澶勭悊
+ let configData = {}
+ for (let key in json) {
+ let transKey
+ if (configType == true) {
+ transKey = key
+ } else {
+ transKey = configConst.getValueByKey(key)
+ }
+ if (transKey == undefined) {
+ continue
+ }
+ let keys = transKey.split(".")
+ if (utils.isEmpty(configData[keys[0]])) {
+ configData[keys[0]] = {}
+ }
+ configData[keys[0]][keys[1]] = json[key]
+ }
+
+ let res = false
+ if (Object.keys(configData).length > 0) {
+ res = configService.configVerifyAndSave(configData)
+ }
+
+ if (typeof res != 'boolean') {
+ log.error(res)
+ return
+ }
+
+ if (res) {
+ log.info("閰嶇疆鎴愬姛")
+ } else {
+ log.error("閰嶇疆澶辫触")
+ }
+
+ // 閰嶇疆鍚庨噸鍚�
+ if (json.reboot === 1) {
+ driver.screen.warning({ msg: config.get("sysInfo.language") == 1 ? "Rebooting" : "閲嶅惎涓�", beep: false })
+ common.asyncReboot(1)
+ }
+}
+
+/**
+ * 鏍¢獙閰嶇疆鐮�
+ * @param {string} code - 閰嶇疆鐮佹暟鎹�
+ * @returns {boolean} 鏍¢獙鏄惁鎴愬姛
+ */
+function checkConfigCode (code) {
+ let password = config.get('sysInfo.com_passwd') || '1234567887654321'
+ let lastIndex = code.lastIndexOf("--");
+ if (lastIndex < 0) {
+ lastIndex = code.lastIndexOf("__");
+ }
+ let firstPart = code.substring(0, lastIndex);
+ let secondPart = code.substring(lastIndex + 2);
+ let res
+ try {
+ res = base64.fromHexString(common.arrayBufferToHexString(common.hmac(firstPart, password)))
+ } catch (error) {
+ log.error(error)
+ return false
+ }
+
+ return res == secondPart;
+}
+
+export default codeService
--
Gitblit v1.9.3