feat: 腾讯锁联调

This commit is contained in:
范鹏 2025-04-29 16:43:12 +08:00
parent 5af784a18d
commit f34f3aa14a
12 changed files with 136 additions and 132 deletions

View File

@ -1,7 +1,13 @@
export const transportType = {
TRANSPORT_BLUETOOTH: 0,
TRANSPORT_OFFLINE: 10,
TRANSPORT_GATEWAY: 20,
TRANSPORT_WIFI: 30,
TRANSPORT_TENCENT_YUN: 40
TRANSPORT_BLUETOOTH: 10,
TRANSPORT_OFFLINE: 20,
TRANSPORT_GATEWAY: 30,
TRANSPORT_WIFI: 40,
TRANSPORT_TENCENT_YUN: 50,
TRANSPORT_WIFI_PRIORITY: 60,
TRANSPORT_BLUETOOTH_PRIORITY: 70
}
export const model = {
TENCENT_YUN_LOCK: 'XB007'
}

View File

@ -12,22 +12,12 @@
</template>
<script setup>
import { onLoad } from '@dcloudio/uni-app'
import { ref } from 'vue'
import { useBluetoothStore } from '@/stores/bluetooth'
import { useBasicStore } from '@/stores/basic'
const bluetoothStore = useBluetoothStore()
const basicStore = useBasicStore()
const type = ref('bluetooth')
onLoad(options => {
if (options.type) {
type.value = options.type
}
})
const toSearchDevice = async () => {
if (bluetoothStore.bluetoothStatus !== 0) {
bluetoothStore.getBluetoothStatus()
@ -38,17 +28,10 @@
result = await bluetoothStore.initAndListenBluetooth()
}
if (result) {
if (type.value === 'bluetooth') {
basicStore.routeJump({
type: 'redirectTo',
name: 'searchDevice'
})
} else if (type.value === 'wifi') {
basicStore.routeJump({
type: 'redirectTo',
name: 'distributionNetwork'
})
}
basicStore.routeJump({
type: 'redirectTo',
name: 'searchDevice'
})
} else {
bluetoothStore.checkSetting()
}

View File

@ -13,7 +13,7 @@
>
<view class="flex items-center">
<view class="mr-4">WiFi</view>
<view>{{ wifiList[wifiIndex]?.SSID ?? '搜索中...' }}</view>
<view>{{ wifiList[wifiIndex]?.SSID ?? '请选择WiFi' }}</view>
<view class="ml-a">
<up-icon name="arrow-right" size="24rpx"></up-icon>
</view>
@ -61,12 +61,12 @@
<script setup>
import { onMounted, onUnmounted, ref } from 'vue'
import { useBluetoothStore } from '@/stores/bluetooth'
// import { useUserStore } from '@/stores/user'
import { useUserStore } from '@/stores/user'
import { useBasicStore } from '@/stores/basic'
import { passthrough } from '@/api/sdk'
const $bluetooth = useBluetoothStore()
// const $user = useUserStore()
const $user = useUserStore()
const $basic = useBasicStore()
const wifiList = ref([])
@ -77,42 +77,26 @@
const pending = ref(false)
const result = ref(false)
onMounted(async () => {
uni.showLoading({
title: '搜索中'
})
// const result = await $bluetooth.getWifiList({
// uid: $user.userInfo.uid.toString()
// })
// if (result.code !== 0) {
// uni.showModal({
// title: '',
// content: '',
// showCancel: false,
// success: () => {
// uni.navigateBack()
// }
// })
// }
listenEvent()
setTimeout(() => {
uni.hideLoading()
wifiList.value = [
{
SSID: '测试1',
rssi: 10
},
{
SSID: '测试2',
rssi: 20
},
{
SSID: '测试3',
rssi: 30
const result = await $bluetooth.getWifiList({
uid: $user.userInfo.uid.toString()
})
if (result.code !== 0) {
uni.showModal({
title: '提示',
content: '搜索失败,请返回重试',
showCancel: false,
success: () => {
uni.navigateBack()
}
]
wifiIndex.value = 0
}, 2000)
})
}
listenEvent()
})
onUnmounted(() => {
@ -124,6 +108,9 @@
uni.$on('wifiList', async data => {
if (data.status === 0) {
wifiList.value = data.wifiList
if (wifiList.value.length > 0) {
wifiIndex.value = 0
}
uni.hideLoading()
} else {
uni.showModal({
@ -137,6 +124,7 @@
}
})
uni.$on('distributionNetworkResult', async data => {
result.value = false
uni.hideLoading()
pending.value = false
if (data.status === 0) {
@ -192,35 +180,36 @@
if (result.code === 0) {
$bluetooth.updateCurrentLockInfo({
...$bluetooth.currentLockInfo,
tencentYunLock: {
productId: result.data.productId,
deviceName: result.data.deviceName,
devicePsk: result.data.devicePsk
}
tencentYunLock: result.data
})
// const result = await $bluetooth.distributionNetwork({
// SSID: wifiList.value[wifiIndex.value].SSID,
// password: password.value,
// json: JSON.stringify({
// productId: result.data.productId,
// deviceName: result.data.deviceName,
// devicePsk: result.data.devicePsk
// })
// })
// if (result.code !== 0) {
// uni.showToast({
// title: '',
// icon: 'none'
// })
// }
setTimeout(() => {
$basic.routeJump({
type: 'redirectTo',
name: 'selectAddress'
const res = await $bluetooth.distributionNetwork({
SSID: wifiList.value[wifiIndex.value].SSID,
password: password.value,
json: JSON.stringify(result.data)
})
if (res.code === 0) {
result.value = true
setTimeout(() => {
pending.value = false
if (result.value) {
uni.showToast({
title: '配网失败,请检查密码是否正确',
icon: 'none'
})
}
}, 10000)
} else {
pending.value = false
uni.showToast({
title: res.message,
icon: 'none'
})
}, 3000)
}
} else {
uni.hideLoading()
pending.value = false
uni.showToast({
title: result.message,
icon: 'none'

View File

@ -40,6 +40,7 @@
import { useBluetoothStore } from '@/stores/bluetooth'
import { useBasicStore } from '@/stores/basic'
import { useUserStore } from '@/stores/user'
import { model } from '@/constant/transportType'
export default {
data() {
@ -139,7 +140,10 @@
}
this.routeJump({
type: 'redirectTo',
name: false ? 'selectAddress' : 'distributionNetwork'
name:
this.currentLockInfo.lockConfig.model === model.TENCENT_YUN_LOCK
? 'distributionNetwork'
: 'selectAddress'
})
} else {
uni.hideLoading()

View File

@ -251,7 +251,7 @@
if (code === 0) {
eventChannel.emit('refresherList', {})
$basic.backAndToast('添加成功')
if ($bluetooth.currentLockInfo.transport_type === transportType.TRANSPORT_TENCENT_YUN) {
if ($bluetooth.currentLockInfo.transportType === transportType.TRANSPORT_TENCENT_YUN) {
$bluetooth.addLockUser({
name: $bluetooth.currentLockInfo.name,
keyId: $bluetooth.keyId,

View File

@ -307,7 +307,7 @@
cardName: params.cardName
})
if (code === 0) {
if ($bluetooth.currentLockInfo.transport_type === transportType.TRANSPORT_TENCENT_YUN) {
if ($bluetooth.currentLockInfo.transportType === transportType.TRANSPORT_TENCENT_YUN) {
const { code } = await $bluetooth.registerAuthentication(params)
if (code === 0) {
$basic.backAndToast('请在锁端添加卡片')

View File

@ -276,7 +276,7 @@
faceName: params.faceName
})
if (code === 0) {
if ($bluetooth.currentLockInfo.transport_type === transportType.TRANSPORT_TENCENT_YUN) {
if ($bluetooth.currentLockInfo.transportType === transportType.TRANSPORT_TENCENT_YUN) {
const { code } = await $bluetooth.registerAuthentication(params)
if (code === 0) {
$basic.backAndToast('请在锁端添加人脸')

View File

@ -307,7 +307,7 @@
fingerprintName: params.fingerprintName
})
if (code === 0) {
if ($bluetooth.currentLockInfo.transport_type === transportType.TRANSPORT_TENCENT_YUN) {
if ($bluetooth.currentLockInfo.transportType === transportType.TRANSPORT_TENCENT_YUN) {
const { code } = await $bluetooth.registerAuthentication(params)
if (code === 0) {
$basic.backAndToast('请在锁端添加指纹')

View File

@ -282,7 +282,7 @@
})
this.getKeyList(this.keySearch)
this.backAndToast('钥匙已发送')
if (this.currentLockInfo.transport_type === transportType.TRANSPORT_TENCENT_YUN) {
if (this.currentLockInfo.transportType === transportType.TRANSPORT_TENCENT_YUN) {
this.addLockUser({
name: this.currentLockInfo.name,
keyId: this.keyId,

View File

@ -308,7 +308,7 @@
palmVeinName: params.palmVeinName
})
if (code === 0) {
if ($bluetooth.currentLockInfo.transport_type === transportType.TRANSPORT_TENCENT_YUN) {
if ($bluetooth.currentLockInfo.transportType === transportType.TRANSPORT_TENCENT_YUN) {
const { code } = await $bluetooth.registerAuthentication(params)
if (code === 0) {
$basic.backAndToast('请在锁端添加掌静脉')

View File

@ -249,7 +249,7 @@
remoteName: params.remoteName
})
if (code === 0) {
if ($bluetooth.currentLockInfo.transport_type === transportType.TRANSPORT_TENCENT_YUN) {
if ($bluetooth.currentLockInfo.transportType === transportType.TRANSPORT_TENCENT_YUN) {
const { code } = await $bluetooth.registerAuthentication(params)
if (code === 0) {
$basic.backAndToast('请在锁端添加远程')

View File

@ -353,7 +353,8 @@ export const useBluetoothStore = defineStore('ble', {
const cebBinaryData = binaryData.slice(12, binaryData.length - 2)
const decrypted = sm4.decrypt(cebBinaryData, that.currentLockInfo.commKey, {
mode: 'ecb',
output: 'array'
output: 'array',
padding: 'none'
})
const length = binaryData[10] * 256 + binaryData[11]
console.log('ecb解密后的数据', decrypted)
@ -1313,22 +1314,37 @@ export const useBluetoothStore = defineStore('ble', {
}
return true
},
uint8ArrayToHex(uint8Array) {
return Array.from(uint8Array)
.map(b => b.toString(16).padStart(2, '0'))
.join('')
},
hexToArray(hexString) {
const result = []
for (let i = 0; i < hexString.length; i += 2) {
result.push(parseInt(hexString.slice(i, i + 2), 16))
}
return result
},
// 写入特征值
async transportMessage(binaryData) {
const that = this
if (that.currentLockInfo.transport_type === transportType.TRANSPORT_TENCENT_YUN) {
if (that.currentLockInfo.transportType === transportType.TRANSPORT_TENCENT_YUN) {
const content = that.uint8ArrayToHex(binaryData)
const { code, data, message } = await passthrough({
request_method: 'GET',
request_uri: '/api/v1/tencentYun/getTencentTriple',
request_method: 'POST',
request_uri: '/api/v1/tencentYun/CallDeviceActionSync',
post_args: {
lockId: that.currentLockInfo.lockId,
data: binaryData
actionId: 'starcloud_action',
len: content.length,
content
}
})
if (code === 0) {
that.parsingCharacteristicValue(data)
if (code === 0 && data.outputParams) {
that.parsingCharacteristicValue(that.hexToArray(data.outputParams))
} else {
characteristicValueCallback({
code,
@ -1336,10 +1352,14 @@ export const useBluetoothStore = defineStore('ble', {
})
}
} else {
console.log('设备ID', that.currentLockInfo.deviceId)
console.log('设备名称:', that.currentLockInfo.name)
console.log('设备主服务:', that.currentLockInfo.serviceId)
console.log('设备写入特征值:', that.currentLockInfo.writeCharacteristicId)
console.log(
'设备ID',
that.currentLockInfo.deviceId,
'设备名称:',
that.currentLockInfo.name,
'私钥:',
that.currentLockInfo.commKey
)
console.log('设备写入数据:', Array.from(binaryData))
// 次数
@ -1393,6 +1413,7 @@ export const useBluetoothStore = defineStore('ble', {
} else {
headArray[7] = 0x23
}
console.log('包标识', headArray[7])
// 数据长度
if (encryptionType === 0) {
@ -1563,7 +1584,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -1575,7 +1596,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -1765,7 +1786,7 @@ export const useBluetoothStore = defineStore('ble', {
}
const { SSID, password, json } = data
const length = 2 + 30 + 20 + json.length
const length = 2 + 30 + 20 + 2 + json.length
const headArray = this.createPackageHeader(3, length)
const contentArray = new Uint8Array(length)
@ -1788,7 +1809,8 @@ export const useBluetoothStore = defineStore('ble', {
const cebArray = sm4.encrypt(contentArray, this.currentLockInfo.commKey, {
mode: 'ecb',
output: 'array'
output: 'array',
padding: 'none'
})
const packageArray = this.createPackageEnd(headArray, cebArray)
@ -1816,7 +1838,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -1828,7 +1850,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -2111,7 +2133,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -2189,7 +2211,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code === 0) {
@ -2449,7 +2471,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -2461,7 +2483,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -2544,7 +2566,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -2556,7 +2578,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -2625,7 +2647,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -2637,7 +2659,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -2714,7 +2736,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -2726,7 +2748,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -2830,7 +2852,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -2842,7 +2864,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -3029,7 +3051,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -3041,7 +3063,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -3156,7 +3178,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -3168,7 +3190,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -3258,7 +3280,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -3270,7 +3292,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -3365,7 +3387,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -3377,7 +3399,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {
@ -3449,7 +3471,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认蓝牙状态正常
if (
this.bluetoothStatus !== 0 &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
console.log('写入未执行', this.bluetoothStatus)
this.getBluetoothStatus()
@ -3461,7 +3483,7 @@ export const useBluetoothStore = defineStore('ble', {
// 确认设备连接正常
if (
!this.currentLockInfo.connected &&
this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN
this.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
) {
const searchResult = await this.searchAndConnectDevice()
if (searchResult.code !== 0) {