From a641d1f8efe34f298dae41a60590a8c338d34c89 Mon Sep 17 00:00:00 2001 From: liyi Date: Tue, 10 Jun 2025 17:47:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=91?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=80=9F=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constant.js | 2 + star-cloud/configureNetwork.js | 142 +++++++++++++++++++++++++++++++++ uni/storage.js | 9 +++ web/storage.js | 9 +++ 4 files changed, 162 insertions(+) create mode 100644 star-cloud/configureNetwork.js diff --git a/constant.js b/constant.js index 700e5f7..4aadaf7 100644 --- a/constant.js +++ b/constant.js @@ -110,6 +110,8 @@ export const eventKeys = { registerPalmVeinConfirm: 'registerPalmVeinConfirm', // 注册遥控确认 registerRemoteConfirm: 'registerRemoteConfirm', + // 搜索wifi列表结果 + searchWiFiResult: 'searchWiFiResult', } diff --git a/star-cloud/configureNetwork.js b/star-cloud/configureNetwork.js new file mode 100644 index 0000000..f645d3b --- /dev/null +++ b/star-cloud/configureNetwork.js @@ -0,0 +1,142 @@ +import { + _convertToMilliseconds, + checkRequiredFields, + convertWeekdaysToNumber, createPackageEnd, md5Encrypt, + parseTimeToList, + timestampToArray +} from "../format.js"; +import {cmdIds, Result, subCmdIds} from "../constant.js"; +import { + checkRepeatCardName, + checkRepeatFaceName, + checkRepeatFingerprintName, + checkRepeatPalmVeinName, + checkRepeatRemoteName +} from "../api.js"; +import {searchAndConnectDevice, writeBLECharacteristicValue} from "../uni/basic.js"; +import {sm4} from "sm-crypto"; + +/** + * 开始搜索wifi + * @returns {Promise} + */ +export async function startSearchWiFi(params) { + const uid = this.accountInfo.uid.toString() + // 设置执行账号 + const result = await this.login(uid) + if (result.code !== Result.Success.code) { + return result + } + // 确认设备连接正常 + if (!params.connected) { + const searchResult = await searchAndConnectDevice(this.lockInfo.bluetooth.bluetoothDeviceName) + if (searchResult.code !== Result.Success.code) { + return searchResult + } + this.updateLockInfo(searchResult.data) + } + + // 检查是否已添加为用户 + const checkResult = await this.checkLockUser() + if (!checkResult) { + return { + code: -1 + } + } + + const length = 2 + 1 + 1 + 40 + 20 + 2 + 2 + 1 + 1 + 1 + 4 + 1 + 1 + 4 + 4 + 4 + 4 + 1 + 16 + const headArray = this.createPackageHeader(3, length) + const contentArray = new Uint8Array(length) + + contentArray[0] = cmdIds.expandCmd / 256 + contentArray[1] = cmdIds.expandCmd % 256 + // 子命令 + if (type === 'card') { + contentArray[2] = subCmdIds.registerCard + } else if (type === 'fingerprint') { + contentArray[2] = subCmdIds.registerFingerprint + } else if (type === 'face') { + contentArray[2] = subCmdIds.registerFace + } else if (type === 'remote') { + contentArray[2] = subCmdIds.registerRemote + } else if (type === 'palmVein') { + contentArray[2] = subCmdIds.registerPalmVein + } + contentArray[3] = length - 3 + + for (let i = 0; i < keyId.length; i++) { + contentArray[i + 4] = keyId.charCodeAt(i) + } + + for (let i = 0; i < uid.length; i++) { + contentArray[i + 44] = uid.charCodeAt(i) + } + + // 子命令 + if (type === 'card') { + contentArray[64] = (params.cardNumber || 0) / 256 + contentArray[65] = (params.cardNumber || 0) % 256 + } else if (type === 'fingerprint') { + contentArray[64] = (params.fingerprintNumber || 0) / 256 + contentArray[65] = (params.fingerprintNumber || 0) % 256 + } else if (type === 'face') { + contentArray[64] = (params.faceNumber || 0) / 256 + contentArray[65] = (params.faceNumber || 0) % 256 + } else if (type === 'remote') { + contentArray[64] = (params.remoteNumber || 0) / 256 + contentArray[65] = (params.remoteNumber || 0) % 256 + } else if (type === 'palmVein') { + contentArray[64] = (params.palmVeinNumber || 0) / 256 + contentArray[65] = (params.palmVeinNumber || 0) % 256 + } + + contentArray[66] = (userCountLimit || 0xffff) / 256 + contentArray[67] = (userCountLimit || 0xffff) % 256 + contentArray[68] = operate + contentArray[69] = isAdmin || 0 + contentArray[70] = isForce || 0 + + contentArray.set(this.lockInfo.token || new Uint8Array([0, 0, 0, 0]), 71) + + contentArray[75] = isRound + contentArray[76] = convertWeekdaysToNumber(weekDay) + + contentArray.set(timestampToArray(startDate), 77) + contentArray.set(timestampToArray(endDate), 81) + + if (isRound) { + contentArray.set(parseTimeToList(startTime), 85) + contentArray.set(parseTimeToList(endTime), 89) + } else { + contentArray.set(new Uint8Array([0, 0, 0, 0]), 85) + contentArray.set(new Uint8Array([0, 0, 0, 0]), 89) + } + + contentArray[93] = 16 + + const md5Array = md5Encrypt( + keyId + uid, + this.lockInfo.token || new Uint8Array([0, 0, 0, 0]), + this.lockInfo.bluetooth.signKey + ) + + contentArray.set(md5Array, 94) + + console.log('加密前:', Array.from(contentArray)) + const cebArray = sm4.encrypt(contentArray, this.lockInfo.bluetooth.privateKey, { + mode: 'ecb', + output: 'array' + }) + + const packageArray = createPackageEnd(headArray, cebArray) + + const writeResult = await writeBLECharacteristicValue(this.lockInfo.deviceId, + this.lockInfo.serviceId, + this.lockInfo.writeCharacteristicId, + packageArray) + if (writeResult.code !== Result.Success.code) { + return writeResult + } + return this.getWriteResult(this.registerExtendedProducts, params) +} + diff --git a/uni/storage.js b/uni/storage.js index 837f6fd..0d2c825 100644 --- a/uni/storage.js +++ b/uni/storage.js @@ -78,4 +78,13 @@ export function emitRegisterPalmVeinConfirmEventUni(resultData) { */ export function emitRegisterRemoteConfirmEventUni(resultData) { uni.$emit(eventKeys.registerRemoteConfirm, resultData) +} + +/** + * 触发搜索wifi结果事件 + * @param resultData 事件响应数据 + * @returns {*} + */ +export function emitSearchWiFiResultEventUni(resultData) { + uni.$emit(eventKeys.searchWiFiResult, resultData) } \ No newline at end of file diff --git a/web/storage.js b/web/storage.js index 9d253ba..e108ff4 100644 --- a/web/storage.js +++ b/web/storage.js @@ -79,4 +79,13 @@ export function emitRegisterPalmVeinConfirmEventWeb(resultData) { */ export function emitRegisterRemoteConfirmEventWeb(resultData) { // TODO 待实现web端触发事件 +} + +/** + * 触发搜索wifi结果事件 + * @param resultData 事件响应数据 + * @returns {*} + */ +export function emitSearchWiFiResultEventWeb(resultData) { + // TODO 触发搜索wifi结果事件 } \ No newline at end of file