fix:完善配网和远程开锁的逻辑
This commit is contained in:
parent
be37ae28be
commit
5a773fe04d
4
api.js
4
api.js
@ -811,7 +811,7 @@ export function getGatewayConfig(data) {
|
||||
*/
|
||||
export function getDeviceNetworkInfo(data) {
|
||||
return request({
|
||||
url: '/v1//deviceNetwork/getNetworkInfo',
|
||||
url: '/v1/deviceNetwork/getNetworkInfo',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
@ -830,7 +830,7 @@ export function getDeviceNetworkInfo(data) {
|
||||
*/
|
||||
export function updateDeviceNetworkInfo(data) {
|
||||
return request({
|
||||
url: '/v1//deviceNetwork/setting',
|
||||
url: '/v1/deviceNetwork/setting',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
|
||||
26
common.js
26
common.js
@ -3,7 +3,7 @@ import {
|
||||
arrayToTimestamp,
|
||||
convertWeekdaysToNumber,
|
||||
createPackageEnd,
|
||||
md5Encrypt, parseWifiList,
|
||||
md5Encrypt, parseNetworkJsonFromDecrypted, parseWifiList,
|
||||
removeTrailingZeros,
|
||||
timestampToArray,
|
||||
uint8ArrayToString
|
||||
@ -30,7 +30,7 @@ import {
|
||||
getLastRecordTimeRequest,
|
||||
getLockNetTokenRequest,
|
||||
getStarCloudToken,
|
||||
getUserNoListRequest,
|
||||
getUserNoListRequest, updateDeviceNetworkInfo,
|
||||
updateElectricQuantityRequest,
|
||||
updateFaceRequest,
|
||||
updateFingerprintRequest,
|
||||
@ -1494,7 +1494,27 @@ export async function parsingCharacteristicValue(binaryData) {
|
||||
break;
|
||||
case cmdIds.configureNetworkResult:
|
||||
if (decrypted[2] === Result.Success.code) {
|
||||
this.characteristicValueCallback(new Result(decrypted[2], null, "配网成功"))
|
||||
// 提取配网信息
|
||||
const {
|
||||
peerId,
|
||||
wifiName,
|
||||
secretKey,
|
||||
deviceMac,
|
||||
networkMac
|
||||
} = parseNetworkJsonFromDecrypted(decrypted);
|
||||
const {code, message} = await updateDeviceNetworkInfo({
|
||||
deviceType: 2, // 1-wifi网关 2-wifi锁
|
||||
deviceMac: deviceMac || this.lockInfo.mac,
|
||||
wifiName: wifiName || this.requestParams.wifiName,
|
||||
networkMac: networkMac || this.requestParams.wifiName,
|
||||
secretKey,
|
||||
peerId
|
||||
});
|
||||
if (code === Result.Success.code) {
|
||||
this.characteristicValueCallback(new Result(decrypted[2], null, "配网成功"))
|
||||
} else {
|
||||
this.characteristicValueCallback(code, null, message);
|
||||
}
|
||||
} else {
|
||||
this.characteristicValueCallback(new Result(decrypted[2], null, "配网失败"))
|
||||
}
|
||||
|
||||
4
env.js
4
env.js
@ -1,7 +1,7 @@
|
||||
// uni版本号
|
||||
export const uniVersion = '1.0.18'
|
||||
export const uniVersion = '1.0.19'
|
||||
// uni构建号
|
||||
export const uniBuildNumber = 19
|
||||
export const uniBuildNumber = 20
|
||||
|
||||
// web版本号
|
||||
export const webVersion = '1.0.1'
|
||||
|
||||
28
format.js
28
format.js
@ -217,4 +217,32 @@ function _bytesToString(bytes) {
|
||||
str += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 解析decrypted中的json数据,返回对象
|
||||
export function parseNetworkJsonFromDecrypted(decrypted) {
|
||||
let peerId, wifiName, secretKey, deviceMac, networkMac;
|
||||
try {
|
||||
const secretKeyJsonLength = (decrypted[4] << 8) + decrypted[3];
|
||||
const secretKeyList = decrypted.slice(5, 5 + secretKeyJsonLength);
|
||||
let result;
|
||||
if (typeof TextDecoder !== 'undefined') {
|
||||
result = new TextDecoder('utf-8').decode(secretKeyList);
|
||||
} else {
|
||||
// 兼容性处理
|
||||
result = uint8ArrayToString(secretKeyList);
|
||||
}
|
||||
const jsonMap = JSON.parse(result);
|
||||
peerId = jsonMap.peerId;
|
||||
wifiName = jsonMap.wifiName;
|
||||
secretKey = jsonMap.secretKey;
|
||||
deviceMac = jsonMap.deviceMac;
|
||||
networkMac = jsonMap.networkMac;
|
||||
console.log('解析配网信息:', jsonMap);
|
||||
} catch (e) {
|
||||
console.error('解析配网信息失败:', e);
|
||||
}
|
||||
return { peerId, wifiName, secretKey, deviceMac, networkMac };
|
||||
}
|
||||
@ -4,7 +4,7 @@ import {
|
||||
} from "../format.js";
|
||||
import {cmdIds, Result} from "../constant.js";
|
||||
import {searchAndConnectDevice, writeBLECharacteristicValue} from "../uni/basic.js";
|
||||
import {getGatewayConfig} from "../api.js";
|
||||
import {getDeviceNetworkInfo, getGatewayConfig} from "../api.js";
|
||||
|
||||
/**
|
||||
* 开始搜索wifi
|
||||
@ -79,17 +79,15 @@ export async function connectWiFi(params) {
|
||||
return new Result(Result.codes.Fail, null, `获取网关配置失败: ${config.message}`);
|
||||
}
|
||||
|
||||
console.log(config)
|
||||
|
||||
let {
|
||||
ssid,
|
||||
password,
|
||||
configureJson = JSON.stringify({
|
||||
starcloudRpcPeerId: "6HnEcGnXMUcLQoE7rnC4aXMVJmojMnKAjqKHrt4TmN1U",
|
||||
starcloudReportPeerId: "G3ehYz8djE35CTE2LWn5xe2nD51UpjC4hWd3vqVmXViE",
|
||||
starcloudUrl: "http://cloud.skychip.top",
|
||||
userPeerId: "C2HjHNy9LsjxW2QEmceiNDTN6XSXFDUZ3fYsnBigVQXA",
|
||||
scdUrl: "http://scd.skychip.top:8710",
|
||||
starcloudRpcPeerId: config.data.starcloudRpcPeerId,
|
||||
starcloudReportPeerId: config.data.starcloudReportPeerId,
|
||||
starcloudUrl: config.data.starcloudUrl,
|
||||
userPeerId: config.data.userPeerId,
|
||||
scdUrl: config.data.scdUrl,
|
||||
starlockPeerId: "0b3bd6327daafe2da24fdd0cae76c71477f32e3ef8ab",
|
||||
clientId: "sBfWAwdMqVKIMBj4dPuRextHViC266aE",
|
||||
secretKey: "zNn1AluC6sTVAtA4dX",
|
||||
@ -177,4 +175,30 @@ export async function connectWiFi(params) {
|
||||
return writeResult
|
||||
}
|
||||
return this.getWriteResult(this.connectWiFi, params)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取锁配网信息
|
||||
* @param params
|
||||
* @param {Number} params.uid uid
|
||||
* @param {Number} params.deviceMac 锁mac地址
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function getLockNetworkInfo(params) {
|
||||
const cardRequiredFields = ['uid', 'deviceMac'];
|
||||
const missingField = checkRequiredFields(params, cardRequiredFields);
|
||||
if (missingField) {
|
||||
return new Result(Result.codes.NotMoreData, null, `参数信息不完整: ${missingField}`);
|
||||
}
|
||||
// 设置执行账号
|
||||
const result = await this.login(params.uid)
|
||||
if (result.code !== Result.Success.code) {
|
||||
return result
|
||||
}
|
||||
|
||||
return await getDeviceNetworkInfo({
|
||||
deviceType: 2,
|
||||
deviceMac: params.deviceMac,
|
||||
})
|
||||
}
|
||||
@ -373,10 +373,16 @@ export async function getLockSupportFeatures(params) {
|
||||
/**
|
||||
* 远程开锁
|
||||
* @param params
|
||||
* @param {Number} params.uid uid
|
||||
* @param {Number} params.lockId 锁 Id
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function remoteUnLock(params) {
|
||||
const cardRequiredFields = ['uid', 'lockId'];
|
||||
const missingField = checkRequiredFields(params, cardRequiredFields);
|
||||
if (missingField) {
|
||||
return new Result(Result.codes.NotMoreData, null, `参数信息不完整: ${missingField}`);
|
||||
}
|
||||
// 设置执行账号
|
||||
const result = await this.login(params.uid)
|
||||
if (result.code !== Result.Success.code) {
|
||||
|
||||
11
uni/index.js
11
uni/index.js
@ -433,4 +433,15 @@ export const startSearchWiFi = async params => {
|
||||
*/
|
||||
export const connectWiFi = async params => {
|
||||
return await starCloudInstance.connectWiFi(params)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备配网信息
|
||||
* @param params.uid uid
|
||||
* @param params.deviceMac 锁mac地址
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export const getLockNetworkInfo = async params => {
|
||||
return await starCloudInstance.getLockNetworkInfo(params)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user