feat: add mock-bind endpoint to bypass token flow for testing
The bind + confirm two-step flow has timezone issues between Node.js (UTC on SCF) and MySQL (timezone +08:00) that cause bind_token to fail validation. Add POST /api/v1/device/mock-bind that does bind + confirm in one atomic step, skipping the token entirely. Only available when NODE_ENV != production. Update ble-connect and index page mock buttons to use mock-bind.
这个提交包含在:
@@ -96,16 +96,13 @@ Page({
|
||||
this.startBleConnect()
|
||||
},
|
||||
|
||||
_mockConfirmBind: function () {
|
||||
onMockConnect: function () {
|
||||
var self = this
|
||||
clearTimeout(this._scanTimer)
|
||||
ble.stopScan()
|
||||
self.setData({ state: 'binding' })
|
||||
http.post('/api/v1/device/bind', {
|
||||
http.post('/api/v1/device/mock-bind', {
|
||||
device_id: self.data.deviceId
|
||||
}).then(function (data) {
|
||||
return http.post('/api/v1/device/bind/confirm', {
|
||||
device_id: data.device_id,
|
||||
bind_token: data.bind_token
|
||||
})
|
||||
}).then(function () {
|
||||
self.setData({ state: 'done' })
|
||||
wx.redirectTo({
|
||||
@@ -116,15 +113,7 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
onMockConnect: function () {
|
||||
clearTimeout(this._scanTimer)
|
||||
ble.stopScan()
|
||||
this._mockConfirmBind()
|
||||
},
|
||||
|
||||
onMockBindSuccess: function () {
|
||||
clearTimeout(this._scanTimer)
|
||||
ble.stopScan()
|
||||
this._mockConfirmBind()
|
||||
this.onMockConnect()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -150,18 +150,14 @@ Page({
|
||||
|
||||
onMockBind: function () {
|
||||
var self = this
|
||||
var mockDeviceId = 'MOCK_' + Date.now().toString(36).toUpperCase()
|
||||
wx.showModal({
|
||||
title: '模拟绑定',
|
||||
content: '将创建一个模拟设备 ' + mockDeviceId + ' 并绑定到当前账号',
|
||||
editable: true,
|
||||
placeholderText: '输入设备编号(需先在后台创建)',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
http.post('/api/v1/device/bind', { device_id: mockDeviceId }).then(function (data) {
|
||||
return http.post('/api/v1/device/bind/confirm', {
|
||||
device_id: data.device_id,
|
||||
bind_token: data.bind_token
|
||||
})
|
||||
}).then(function () {
|
||||
if (res.confirm && res.content) {
|
||||
var deviceId = res.content.trim()
|
||||
http.post('/api/v1/device/mock-bind', { device_id: deviceId }).then(function () {
|
||||
wx.showToast({ title: '模拟绑定成功', icon: 'success' })
|
||||
self.checkState()
|
||||
}).catch(function (err) {
|
||||
|
||||
在新工单中引用
屏蔽一个用户