feat:增加配网功能接口
This commit is contained in:
parent
a641d1f8ef
commit
bcb7a9cfa1
2
api.js
2
api.js
@ -126,7 +126,7 @@ export function deleteLockRequest(data) {
|
||||
})
|
||||
}
|
||||
|
||||
// 删除锁
|
||||
// 更新锁电量
|
||||
export function updateElectricQuantityRequest(data) {
|
||||
return request({
|
||||
url: '/v1/lock/updateElectricQuantity',
|
||||
|
||||
39
common.js
39
common.js
@ -3,7 +3,7 @@ import {
|
||||
arrayToTimestamp,
|
||||
convertWeekdaysToNumber,
|
||||
createPackageEnd,
|
||||
md5Encrypt,
|
||||
md5Encrypt, parseWifiList,
|
||||
removeTrailingZeros,
|
||||
timestampToArray,
|
||||
uint8ArrayToString
|
||||
@ -53,6 +53,7 @@ import {
|
||||
version
|
||||
} from './export'
|
||||
import log from './log'
|
||||
import {emitSearchWiFiResultEventUni} from "./uni/storage.js";
|
||||
|
||||
/**
|
||||
* 同步开门记录
|
||||
@ -573,6 +574,7 @@ export function getWriteResult(request, params) {
|
||||
return new Promise(resolve => {
|
||||
const getWriteResultTimer = setTimeout(() => {
|
||||
resolve(Result.Fail)
|
||||
console.log("超时失败")
|
||||
}, 20000)
|
||||
this.characteristicValueCallback = async data => {
|
||||
// code 6 token过期,重新获取
|
||||
@ -733,7 +735,6 @@ export function listenCharacteristicValue(res) {
|
||||
|
||||
// 解析特征值
|
||||
export async function parsingCharacteristicValue(binaryData) {
|
||||
|
||||
// 0x20 明文 0x22 SM4(事先约定密钥) 0x23 SM4(设备指定密钥)
|
||||
if (binaryData[7] === 0x20) {
|
||||
if (binaryData[12] * 256 + binaryData[13] === cmdIds.getPublicKey) {
|
||||
@ -746,7 +747,16 @@ export async function parsingCharacteristicValue(binaryData) {
|
||||
})
|
||||
}
|
||||
this.characteristicValueCallback(new Result(binaryData[14]))
|
||||
} else if (binaryData[12] * 256 + binaryData[13] === cmdIds.searchWiFi) {
|
||||
this.characteristicValueCallback(new Result(binaryData[14]))
|
||||
}
|
||||
// } else if (binaryData[12] * 256 + binaryData[13] === cmdIds.configureNetworkResult) {
|
||||
// console.log("收到明文数据configureNetworkResult", Array.from(binaryData))
|
||||
// this.characteristicValueCallback(new Result(binaryData[14]))
|
||||
// } else if (binaryData[12] * 256 + binaryData[13] === cmdIds.configureNetwork) {
|
||||
// console.log("收到明文数据configureNetwork", Array.from(binaryData))
|
||||
// this.characteristicValueCallback(new Result(binaryData[14]))
|
||||
// }
|
||||
} else if (binaryData[7] === 0x22) {
|
||||
// 截取入参
|
||||
const cebBinaryData = binaryData.slice(12, binaryData.length - 2)
|
||||
@ -759,7 +769,7 @@ export async function parsingCharacteristicValue(binaryData) {
|
||||
mode: 'ecb',
|
||||
output: 'array'
|
||||
})
|
||||
console.log('ecb解密后的数据', decrypted)
|
||||
console.log('SM4(事先约定密钥) ecb解密后的数据', decrypted)
|
||||
|
||||
if (decrypted[0] * 256 + decrypted[1] === cmdIds.getCommKey) {
|
||||
if (decrypted[2] === Result.Success.code) {
|
||||
@ -775,6 +785,9 @@ export async function parsingCharacteristicValue(binaryData) {
|
||||
console.log('signKey', Array.from(this.lockInfo.bluetooth.signKey))
|
||||
}
|
||||
this.characteristicValueCallback(new Result(decrypted[2]))
|
||||
} else if (decrypted[0] * 256 + decrypted[1] === cmdIds.configureNetworkResult) {
|
||||
console.log("SM4(事先约定密钥) ecb解密后的数据configureNetworkResult", Array.from(binaryData))
|
||||
this.characteristicValueCallback(new Result(binaryData[14]))
|
||||
}
|
||||
} else {
|
||||
const cebBinaryData = binaryData.slice(12, binaryData.length - 2)
|
||||
@ -783,7 +796,7 @@ export async function parsingCharacteristicValue(binaryData) {
|
||||
output: 'array',
|
||||
padding: 'none'
|
||||
})
|
||||
console.log('ecb解密后的数据', decrypted)
|
||||
console.log('SM4(设备指定密钥) ecb解密后的数据', decrypted)
|
||||
|
||||
const cmdId = decrypted[0] * 256 + decrypted[1]
|
||||
|
||||
@ -1091,7 +1104,6 @@ export async function parsingCharacteristicValue(binaryData) {
|
||||
// 增加返回一个指纹序号
|
||||
addResult.data.fingerprintNumber = decrypted[6] * 256 + decrypted[7];
|
||||
}
|
||||
console.log('registerFingerprintConfirm', decrypted)
|
||||
// 触发指纹确认事件
|
||||
emitRegisterFingerprintConfirmEvent(addResult)
|
||||
// 断开蓝牙连接
|
||||
@ -1430,6 +1442,23 @@ export async function parsingCharacteristicValue(binaryData) {
|
||||
this.characteristicValueCallback(new Result(decrypted[6]))
|
||||
}
|
||||
break
|
||||
case cmdIds.searchWiFiResult:
|
||||
if (decrypted[2] === Result.Success.code) {
|
||||
const wifiInfoList = parseWifiList(decrypted);
|
||||
emitSearchWiFiResultEventUni({
|
||||
code: wifiInfoList.status,
|
||||
numberOfSsid: wifiInfoList.numberOfSsid,
|
||||
wifiList: wifiInfoList.wifiList,
|
||||
})
|
||||
}
|
||||
break;
|
||||
case cmdIds.configureNetworkResult:
|
||||
if (decrypted[2] === Result.Success.code) {
|
||||
this.characteristicValueCallback(new Result(decrypted[2], null, "配网成功"))
|
||||
} else {
|
||||
this.characteristicValueCallback(new Result(decrypted[2], null, "配网失败"))
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.updateLockInfo({
|
||||
token: decrypted.slice(2, 6)
|
||||
|
||||
10
constant.js
10
constant.js
@ -18,14 +18,14 @@ export const cmdIds = {
|
||||
cleanUser: 0x300c,
|
||||
// 扩展命令
|
||||
expandCmd: 0x3030,
|
||||
// 获取Wi-Fi列表
|
||||
getWifiList: 0x30f6,
|
||||
// 获取Wi-Fi
|
||||
searchWiFi: 0x30F6,
|
||||
// Wi-Fi列表
|
||||
wifiList: 0x30f7,
|
||||
searchWiFiResult: 0x30F7,
|
||||
// 配网
|
||||
distributionNetwork: 0x30f4,
|
||||
configureNetwork: 0x30F4,
|
||||
// 配网结果
|
||||
distributionNetworkResult: 0x30f5
|
||||
configureNetworkResult: 0x30F5
|
||||
}
|
||||
|
||||
// 子命令ID
|
||||
|
||||
44
format.js
44
format.js
@ -26,6 +26,7 @@ export function timestampToArray(timestamp) {
|
||||
array[3] = timestamp & 0xff
|
||||
return array
|
||||
}
|
||||
|
||||
// 时分字符串转二进制
|
||||
export function parseTimeToList(timeString) {
|
||||
let timeList = [0, 0, 0, 0]
|
||||
@ -174,3 +175,46 @@ export function checkRequiredFields(params, requiredFields) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 转换解析wifi列表数据
|
||||
* @param data
|
||||
* @returns {{status: *, numberOfSsid: *, wifiList: *[]}}
|
||||
*/
|
||||
export function parseWifiList(data) {
|
||||
// data: Array or Uint8Array
|
||||
// 跳过前两位命令码
|
||||
const status = data[2];
|
||||
const numberOfSsid = data[3];
|
||||
const wifiList = [];
|
||||
let offset = 4;
|
||||
for (let i = 0; i < numberOfSsid; i++) {
|
||||
// 取32字节SSID
|
||||
const ssidBytes = data.slice(offset, offset + 32);
|
||||
// 用自定义函数转字符串并去除末尾0
|
||||
const ssid = _bytesToString(ssidBytes).trim();
|
||||
|
||||
offset += 32;
|
||||
// 取rssi
|
||||
let rssi = data[offset];
|
||||
// 通常rssi是无符号byte,需转为有符号
|
||||
if (rssi > 127) rssi = rssi - 256;
|
||||
offset += 1;
|
||||
// 过滤空名
|
||||
if (ssid) {
|
||||
wifiList.push({ssid, rssi});
|
||||
}
|
||||
}
|
||||
return {status, numberOfSsid, wifiList};
|
||||
}
|
||||
|
||||
function _bytesToString(bytes) {
|
||||
// 只适用于ASCII和UTF-8无多字节字符的场景
|
||||
let str = '';
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
if (bytes[i] === 0) break; // 截断0
|
||||
str += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@ -5,7 +5,11 @@ import ignore from 'ignore'
|
||||
import { uniVersion } from './env.js'
|
||||
|
||||
// 获取当前目录和构建目标目录
|
||||
const sourceDir = path.dirname(new URL(import.meta.url).pathname)
|
||||
const sourceDir = path.dirname(
|
||||
process.platform === 'win32'
|
||||
? new URL(import.meta.url).pathname.slice(1)
|
||||
: new URL(import.meta.url).pathname
|
||||
)
|
||||
const distDir = path.join(sourceDir, 'dist')
|
||||
const gitignorePath = path.join(sourceDir, '.gitignore')
|
||||
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "star-cloud-uni",
|
||||
"version": "1.0.10",
|
||||
"version": "1.0.14",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "star-cloud-uni",
|
||||
"version": "1.0.10",
|
||||
"version": "1.0.14",
|
||||
"dependencies": {
|
||||
"buffer": "^6.0.3",
|
||||
"crc": "^4.3.2",
|
||||
|
||||
@ -10,6 +10,7 @@ import * as elec from './star-cloud/elec.js'
|
||||
import * as coldWater from './star-cloud/coldWater.js'
|
||||
import * as hotWater from './star-cloud/hotWater.js'
|
||||
import * as generalExtend from './star-cloud/generalExtend.js'
|
||||
import * as configureNetwork from './star-cloud/configureNetwork.js'
|
||||
import { onBLECharacteristicValueChange } from './uni/basic'
|
||||
|
||||
/**
|
||||
@ -141,7 +142,7 @@ class StarCloud {
|
||||
* @param {Boolean} params.isReportLog 是否上报日志
|
||||
*/
|
||||
init(params) {
|
||||
Object.assign(StarCloud.prototype, device, lock, other, password, record, user, common, elec,coldWater, hotWater,generalExtend)
|
||||
Object.assign(StarCloud.prototype, device, lock, other, password, record, user, common, elec,coldWater, hotWater,generalExtend,configureNetwork)
|
||||
|
||||
const { clientId, clientSecret, env, platform, accounts,clientUrl } = params
|
||||
this.envVersion = 'release'
|
||||
|
||||
@ -1,20 +1,9 @@
|
||||
import {
|
||||
_convertToMilliseconds,
|
||||
checkRequiredFields,
|
||||
convertWeekdaysToNumber, createPackageEnd, md5Encrypt,
|
||||
parseTimeToList,
|
||||
timestampToArray
|
||||
createPackageEnd,
|
||||
} from "../format.js";
|
||||
import {cmdIds, Result, subCmdIds} from "../constant.js";
|
||||
import {
|
||||
checkRepeatCardName,
|
||||
checkRepeatFaceName,
|
||||
checkRepeatFingerprintName,
|
||||
checkRepeatPalmVeinName,
|
||||
checkRepeatRemoteName
|
||||
} from "../api.js";
|
||||
import {cmdIds, Result} from "../constant.js";
|
||||
import {searchAndConnectDevice, writeBLECharacteristicValue} from "../uni/basic.js";
|
||||
import {sm4} from "sm-crypto";
|
||||
|
||||
/**
|
||||
* 开始搜索wifi
|
||||
@ -23,7 +12,7 @@ import {sm4} from "sm-crypto";
|
||||
export async function startSearchWiFi(params) {
|
||||
const uid = this.accountInfo.uid.toString()
|
||||
// 设置执行账号
|
||||
const result = await this.login(uid)
|
||||
const result = await this.login(params.uid)
|
||||
if (result.code !== Result.Success.code) {
|
||||
return result
|
||||
}
|
||||
@ -38,97 +27,26 @@ export async function startSearchWiFi(params) {
|
||||
|
||||
// 检查是否已添加为用户
|
||||
const checkResult = await this.checkLockUser()
|
||||
if (!checkResult) {
|
||||
return {
|
||||
code: -1
|
||||
}
|
||||
if (checkResult.code !== Result.Success.code) {
|
||||
return checkResult
|
||||
}
|
||||
|
||||
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)
|
||||
// 判断锁是否支持wifi功能
|
||||
if (!this.lockInfo.lockFeature || this.lockInfo.lockFeature.wifi !== 1) {
|
||||
return new Result(Result.codes.Fail, null, '该锁不支持wifi配置');
|
||||
}
|
||||
|
||||
|
||||
const length = 2 + 20
|
||||
const headArray = this.createPackageHeader(0, 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)
|
||||
}
|
||||
|
||||
contentArray[0] = cmdIds.searchWiFi / 256
|
||||
contentArray[1] = cmdIds.searchWiFi % 256
|
||||
for (let i = 0; i < uid.length; i++) {
|
||||
contentArray[i + 44] = uid.charCodeAt(i)
|
||||
contentArray[i + 2] = i < uid.length ? uid.charCodeAt(i) : 0;
|
||||
}
|
||||
|
||||
// 子命令
|
||||
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 packageArray = createPackageEnd(headArray, contentArray)
|
||||
|
||||
const writeResult = await writeBLECharacteristicValue(this.lockInfo.deviceId,
|
||||
this.lockInfo.serviceId,
|
||||
@ -137,6 +55,115 @@ export async function startSearchWiFi(params) {
|
||||
if (writeResult.code !== Result.Success.code) {
|
||||
return writeResult
|
||||
}
|
||||
return this.getWriteResult(this.registerExtendedProducts, params)
|
||||
return this.getWriteResult(this.startSearchWiFi, params)
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接wifi
|
||||
* @param params
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
export async function connectWiFi(params) {
|
||||
const cardRequiredFields = ['ssid', 'password'];
|
||||
const missingField = checkRequiredFields(params, cardRequiredFields);
|
||||
if (missingField) {
|
||||
return new Result(Result.codes.NotMoreData, null, `参数信息不完整: ${missingField}`);
|
||||
}
|
||||
|
||||
let {
|
||||
ssid,
|
||||
password,
|
||||
configureJson = JSON.stringify({
|
||||
starcloudRpcPeerId: "6HnEcGnXMUcLQoE7rnC4aXMVJmojMnKAjqKHrt4TmN1U",
|
||||
starcloudReportPeerId: "G3ehYz8djE35CTE2LWn5xe2nD51UpjC4hWd3vqVmXViE",
|
||||
starcloudUrl: "http://cloud.skychip.top",
|
||||
userPeerId: "C2HjHNy9LsjxW2QEmceiNDTN6XSXFDUZ3fYsnBigVQXA",
|
||||
scdUrl: "http://scd.skychip.top:8710",
|
||||
starlockPeerId: "0b3bd6327daafe2da24fdd0cae76c71477f32e3ef8ab",
|
||||
clientId: "sBfWAwdMqVKIMBj4dPuRextHViC266aE",
|
||||
secretKey: "zNn1AluC6sTVAtA4dX",
|
||||
userPeerld: "zC2HjHNy9LsjxW2QEmceiNDTN6XSXFDUZ3fYsnBigVQX"
|
||||
})
|
||||
} = params
|
||||
|
||||
|
||||
const uid = this.accountInfo.uid.toString()
|
||||
// 设置执行账号
|
||||
const result = await this.login(params.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.code !== Result.Success.code) {
|
||||
return checkResult
|
||||
}
|
||||
|
||||
// 判断锁是否支持wifi功能
|
||||
if (!this.lockInfo.lockFeature || this.lockInfo.lockFeature.wifi !== 1) {
|
||||
return new Result(Result.codes.Fail, null, '该锁不支持wifi配置');
|
||||
}
|
||||
|
||||
// 处理 configureJson
|
||||
let configureJsonBytes = [];
|
||||
if (configureJson) {
|
||||
for (let i = 0; i < configureJson.length; i++) {
|
||||
const code = configureJson.charCodeAt(i);
|
||||
if (code < 0x80) {
|
||||
configureJsonBytes.push(code);
|
||||
} else if (code < 0x800) {
|
||||
configureJsonBytes.push(0xc0 | (code >> 6));
|
||||
configureJsonBytes.push(0x80 | (code & 0x3f));
|
||||
} else {
|
||||
configureJsonBytes.push(0xe0 | (code >> 12));
|
||||
configureJsonBytes.push(0x80 | ((code >> 6) & 0x3f));
|
||||
configureJsonBytes.push(0x80 | (code & 0x3f));
|
||||
}
|
||||
}
|
||||
}
|
||||
const configureJsonLength = configureJsonBytes.length;
|
||||
|
||||
// 计算总长度
|
||||
const length = 2 + 30 + 20 + 2 + configureJsonLength;
|
||||
const headArray = this.createPackageHeader(0, length);
|
||||
const contentArray = new Uint8Array(length);
|
||||
|
||||
contentArray[0] = cmdIds.configureNetwork / 256;
|
||||
contentArray[1] = cmdIds.configureNetwork % 256;
|
||||
// SSID: 30字节,补0
|
||||
for (let i = 0; i < 30; i++) {
|
||||
contentArray[i + 2] = i < ssid.length ? ssid.charCodeAt(i) : 0;
|
||||
}
|
||||
// Password: 20字节,补0
|
||||
for (let i = 0; i < 20; i++) {
|
||||
contentArray[i + 32] = i < password.length ? password.charCodeAt(i) : 0;
|
||||
}
|
||||
// configureJsonLength: 2字节(大端序)
|
||||
contentArray[52] = (configureJsonLength >> 8) & 0xff;
|
||||
contentArray[53] = configureJsonLength & 0xff;
|
||||
// configureJson内容
|
||||
for (let i = 0; i < configureJsonLength; i++) {
|
||||
contentArray[54 + i] = configureJsonBytes[i];
|
||||
}
|
||||
|
||||
console.log("配网命令:", Array.from(contentArray))
|
||||
const packageArray = createPackageEnd(headArray, contentArray)
|
||||
console.log("蓝牙包:", Array.from(packageArray))
|
||||
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.connectWiFi, params)
|
||||
}
|
||||
62
uni.md
62
uni.md
@ -675,6 +675,38 @@ refreshHotWaterInfo(params)
|
||||
**返回**
|
||||
无
|
||||
|
||||
# 监听事件
|
||||
|
||||
**监听相关事件**
|
||||
|
||||
| 事件名 | 描述 | 返回值示例 |
|
||||
|----------------------------|----------|-------------------------------------------------------|
|
||||
| registerCardConfirm | 卡片注册成功 | {cardNumber:1,cardId:1} |
|
||||
| registerFingerprintProcess | 指纹注册进度 | {status: 0,process: 0};**process总步数在上方统一`Result`中返回** |
|
||||
| registerFingerprintConfirm | 指纹注册成功 | {fingerprintNumber:1,fingerprintId:1} |
|
||||
| registerFaceProcess | 人脸注册进度 | {faceNumber:1,faceId:1} |
|
||||
| registerFaceConfirm | 人脸注册成功 | {faceNumber:1,faceId:1} |
|
||||
| registerPalmVeinConfirm | 掌静脉注册成功 | {palmVeinNumber:1,palmVeinId:1} |
|
||||
| registerRemoteConfirm | 遥控注册成功 | {remoteNumber:1,remoteId:1} |
|
||||
| searchWiFiResult | wifi搜索结果 | {status:0, numberOfSsid:7, wifiList:[Object]} |
|
||||
|
||||
**监听事件示例**
|
||||
|
||||
```js
|
||||
// uniapp 监听注册卡片完成事件
|
||||
uni.$on('registerCardConfirm', async data => {
|
||||
// TODO
|
||||
})
|
||||
// uniapp 监听注册指纹进度
|
||||
uni.$on('registerFingerprintProcess', async data => {
|
||||
// TODO
|
||||
})
|
||||
// uniapp 指纹注册成功
|
||||
uni.$on('registerFingerprintConfirm', async data => {
|
||||
// TODO
|
||||
})
|
||||
```
|
||||
|
||||
# 扩展功能操作(ic卡、指纹、人脸、遥控、掌静脉)
|
||||
|
||||
## 注册、修改、删除、 删除全部
|
||||
@ -736,36 +768,6 @@ registerExtendedProducts(params)
|
||||
>
|
||||
> 收到锁版提示后,将卡片放置读卡器
|
||||
|
||||
|
||||
**监听相关事件**
|
||||
|
||||
| 事件名 | 描述 | 返回值示例 |
|
||||
|----------------------------|---------|-------------------------------------------------------|
|
||||
| registerCardConfirm | 卡片注册成功 | {cardNumber:1,cardId:1} |
|
||||
| registerFingerprintProcess | 指纹注册进度 | {status: 0,process: 0};**process总步数在上方统一`Result`中返回** |
|
||||
| registerFingerprintConfirm | 指纹注册成功 | {fingerprintNumber:1,fingerprintId:1} |
|
||||
| registerFaceProcess | 人脸注册进度 | {faceNumber:1,faceId:1} |
|
||||
| registerFaceConfirm | 人脸注册成功 | {faceNumber:1,faceId:1} |
|
||||
| registerPalmVeinConfirm | 掌静脉注册成功 | {palmVeinNumber:1,palmVeinId:1} |
|
||||
| registerRemoteConfirm | 遥控注册成功 | {remoteNumber:1,remoteId:1} |
|
||||
|
||||
**监听事件示例**
|
||||
|
||||
```js
|
||||
// uniapp 监听注册卡片完成事件
|
||||
uni.$on('registerCardConfirm', async data => {
|
||||
// TODO
|
||||
})
|
||||
// uniapp 监听注册指纹进度
|
||||
uni.$on('registerFingerprintProcess', async data => {
|
||||
// TODO
|
||||
})
|
||||
// uniapp 指纹注册成功
|
||||
uni.$on('registerFingerprintConfirm', async data => {
|
||||
// TODO
|
||||
})
|
||||
```
|
||||
|
||||
## 取消操作
|
||||
|
||||
**调用方法**
|
||||
|
||||
@ -358,13 +358,15 @@ export function writeBLECharacteristicValue(deviceId, serviceId, characteristicI
|
||||
serviceId,
|
||||
characteristicId,
|
||||
value: writeData.buffer,
|
||||
success() {
|
||||
success(res) {
|
||||
successCount++
|
||||
if (successCount === count) {
|
||||
resolve(Result.Success)
|
||||
}
|
||||
console.log("writeBLECharacteristicValue res", res)
|
||||
},
|
||||
fail() {
|
||||
fail(err) {
|
||||
console.error("writeBLECharacteristicValue err", err)
|
||||
resolve(Result.Fail)
|
||||
}
|
||||
})
|
||||
|
||||
22
uni/index.js
22
uni/index.js
@ -1,5 +1,6 @@
|
||||
import starCloudInstance from '../star-cloud'
|
||||
import {Result, supportFunctionsFeatureBit} from '../constant'
|
||||
|
||||
export {Result}
|
||||
|
||||
/**
|
||||
@ -345,7 +346,6 @@ export const readSupportFunctionsSetting = async params => {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取Ic卡列表
|
||||
* @param params.lockId 锁id (必填)
|
||||
@ -414,3 +414,23 @@ export const remoteUnLock = async params => {
|
||||
export const getLockList = async params => {
|
||||
return await starCloudInstance.getLockList(params)
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动搜索wifi
|
||||
* @param params
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export const startSearchWiFi = async params => {
|
||||
return await starCloudInstance.startSearchWiFi(params)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 连接wifi
|
||||
* @param params.ssid wifi昵称
|
||||
* @param params.password wifi密码
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export const connectWiFi = async params => {
|
||||
return await starCloudInstance.connectWiFi(params)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user