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) {
|
export function getDeviceNetworkInfo(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/v1//deviceNetwork/getNetworkInfo',
|
url: '/v1/deviceNetwork/getNetworkInfo',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
@ -830,7 +830,7 @@ export function getDeviceNetworkInfo(data) {
|
|||||||
*/
|
*/
|
||||||
export function updateDeviceNetworkInfo(data) {
|
export function updateDeviceNetworkInfo(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/v1//deviceNetwork/setting',
|
url: '/v1/deviceNetwork/setting',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
|
|||||||
26
common.js
26
common.js
@ -3,7 +3,7 @@ import {
|
|||||||
arrayToTimestamp,
|
arrayToTimestamp,
|
||||||
convertWeekdaysToNumber,
|
convertWeekdaysToNumber,
|
||||||
createPackageEnd,
|
createPackageEnd,
|
||||||
md5Encrypt, parseWifiList,
|
md5Encrypt, parseNetworkJsonFromDecrypted, parseWifiList,
|
||||||
removeTrailingZeros,
|
removeTrailingZeros,
|
||||||
timestampToArray,
|
timestampToArray,
|
||||||
uint8ArrayToString
|
uint8ArrayToString
|
||||||
@ -30,7 +30,7 @@ import {
|
|||||||
getLastRecordTimeRequest,
|
getLastRecordTimeRequest,
|
||||||
getLockNetTokenRequest,
|
getLockNetTokenRequest,
|
||||||
getStarCloudToken,
|
getStarCloudToken,
|
||||||
getUserNoListRequest,
|
getUserNoListRequest, updateDeviceNetworkInfo,
|
||||||
updateElectricQuantityRequest,
|
updateElectricQuantityRequest,
|
||||||
updateFaceRequest,
|
updateFaceRequest,
|
||||||
updateFingerprintRequest,
|
updateFingerprintRequest,
|
||||||
@ -1494,7 +1494,27 @@ export async function parsingCharacteristicValue(binaryData) {
|
|||||||
break;
|
break;
|
||||||
case cmdIds.configureNetworkResult:
|
case cmdIds.configureNetworkResult:
|
||||||
if (decrypted[2] === Result.Success.code) {
|
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 {
|
} else {
|
||||||
this.characteristicValueCallback(new Result(decrypted[2], null, "配网失败"))
|
this.characteristicValueCallback(new Result(decrypted[2], null, "配网失败"))
|
||||||
}
|
}
|
||||||
|
|||||||
4
env.js
4
env.js
@ -1,7 +1,7 @@
|
|||||||
// uni版本号
|
// uni版本号
|
||||||
export const uniVersion = '1.0.18'
|
export const uniVersion = '1.0.19'
|
||||||
// uni构建号
|
// uni构建号
|
||||||
export const uniBuildNumber = 19
|
export const uniBuildNumber = 20
|
||||||
|
|
||||||
// web版本号
|
// web版本号
|
||||||
export const webVersion = '1.0.1'
|
export const webVersion = '1.0.1'
|
||||||
|
|||||||
28
format.js
28
format.js
@ -218,3 +218,31 @@ function _bytesToString(bytes) {
|
|||||||
}
|
}
|
||||||
return str;
|
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";
|
} from "../format.js";
|
||||||
import {cmdIds, Result} from "../constant.js";
|
import {cmdIds, Result} from "../constant.js";
|
||||||
import {searchAndConnectDevice, writeBLECharacteristicValue} from "../uni/basic.js";
|
import {searchAndConnectDevice, writeBLECharacteristicValue} from "../uni/basic.js";
|
||||||
import {getGatewayConfig} from "../api.js";
|
import {getDeviceNetworkInfo, getGatewayConfig} from "../api.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始搜索wifi
|
* 开始搜索wifi
|
||||||
@ -79,17 +79,15 @@ export async function connectWiFi(params) {
|
|||||||
return new Result(Result.codes.Fail, null, `获取网关配置失败: ${config.message}`);
|
return new Result(Result.codes.Fail, null, `获取网关配置失败: ${config.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(config)
|
|
||||||
|
|
||||||
let {
|
let {
|
||||||
ssid,
|
ssid,
|
||||||
password,
|
password,
|
||||||
configureJson = JSON.stringify({
|
configureJson = JSON.stringify({
|
||||||
starcloudRpcPeerId: "6HnEcGnXMUcLQoE7rnC4aXMVJmojMnKAjqKHrt4TmN1U",
|
starcloudRpcPeerId: config.data.starcloudRpcPeerId,
|
||||||
starcloudReportPeerId: "G3ehYz8djE35CTE2LWn5xe2nD51UpjC4hWd3vqVmXViE",
|
starcloudReportPeerId: config.data.starcloudReportPeerId,
|
||||||
starcloudUrl: "http://cloud.skychip.top",
|
starcloudUrl: config.data.starcloudUrl,
|
||||||
userPeerId: "C2HjHNy9LsjxW2QEmceiNDTN6XSXFDUZ3fYsnBigVQXA",
|
userPeerId: config.data.userPeerId,
|
||||||
scdUrl: "http://scd.skychip.top:8710",
|
scdUrl: config.data.scdUrl,
|
||||||
starlockPeerId: "0b3bd6327daafe2da24fdd0cae76c71477f32e3ef8ab",
|
starlockPeerId: "0b3bd6327daafe2da24fdd0cae76c71477f32e3ef8ab",
|
||||||
clientId: "sBfWAwdMqVKIMBj4dPuRextHViC266aE",
|
clientId: "sBfWAwdMqVKIMBj4dPuRextHViC266aE",
|
||||||
secretKey: "zNn1AluC6sTVAtA4dX",
|
secretKey: "zNn1AluC6sTVAtA4dX",
|
||||||
@ -178,3 +176,29 @@ export async function connectWiFi(params) {
|
|||||||
}
|
}
|
||||||
return this.getWriteResult(this.connectWiFi, params)
|
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 params
|
||||||
|
* @param {Number} params.uid uid
|
||||||
* @param {Number} params.lockId 锁 Id
|
* @param {Number} params.lockId 锁 Id
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
export async function remoteUnLock(params) {
|
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)
|
const result = await this.login(params.uid)
|
||||||
if (result.code !== Result.Success.code) {
|
if (result.code !== Result.Success.code) {
|
||||||
|
|||||||
11
uni/index.js
11
uni/index.js
@ -434,3 +434,14 @@ export const startSearchWiFi = async params => {
|
|||||||
export const connectWiFi = async params => {
|
export const connectWiFi = async params => {
|
||||||
return await starCloudInstance.connectWiFi(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