唤起插件
宿主前端通过 wx.navigateTo 携带参数跳转到插件入口页, 完成检测后插件将结果写入 Storage,宿主在 onShow 读取。
跳转入口
| 入口页 | URL | 适用场景 |
|---|---|---|
| 检测流程(默认) | plugin://xiaobao-measure/bind | 所有设备统一入口;完成后停留在结果页 |
| 历史报告列表 | plugin://xiaobao-measure/index | 直达用户历史检测记录(需商务额外开通) |
跳转参数
安全要求:所有跳转参数由宿主服务端生成后下发前端, 前端不持有
appSecret,不自行计算签名或加密。| 参数 | 必填 | 纳入签名 | 类型 | 说明 |
|---|---|---|---|---|
appKey | ✅ | ✅ | string | 应用标识,商务下发,可明文传输 |
thirdUserId | ✅ | ✅ | string | 贵方用户唯一 ID,插件全程透传 |
timestamp | ✅ | ✅ | string | 10 位 Unix 秒,有效窗口 ±5 分钟 |
nonce | ✅ | ✅ | string | 随机串(建议 16 位十六进制),防重放 |
sign | ✅ | — | string | HMAC-SHA256 签名(hex 小写),详见服务端实现 |
userProfile | ✅ | — | string | AES-256-CBC 加密的用户档案(base64),详见服务端实现 |
deviceKey | 按设备 | — | string | 目标设备标识,见「设备场景速查」 |
measureMode | 多功能设备 | — | string | 检测模式:BP(血压)/ BG(血糖);多合一仪必传 |
env | 否 | — | string | sandbox = 沙箱环境,不传默认生产,发布前务必移除 |
签名字段顺序固定为 4 个:
appKey | thirdUserId | timestamp | nonce(管道符拼接)。userProfile、deviceKey、measureMode 出现在 URL 中但不参与签名计算。前端示例(完整跳转)
// pages/health/index.js
Page({
async onStartMeasure() {
// 向宿主服务端请求跳转参数
const res = await this.fetchPluginParams({
thirdUserId: this.data.userId,
deviceKey: 'HOME_MULTI_BIO_MONITOR',
measureMode: 'BP',
})
const p = res.data
const queryParts = [
`appKey=${p.appKey}`,
`thirdUserId=${encodeURIComponent(p.thirdUserId)}`,
`userProfile=${encodeURIComponent(p.userProfile)}`,
`timestamp=${p.timestamp}`,
`nonce=${p.nonce}`,
`sign=${p.sign}`,
`deviceKey=${p.deviceKey}`,
`measureMode=${p.measureMode}`,
// 沙箱联调时取消注释:
// 'env=sandbox',
]
wx.navigateTo({
url: `plugin://xiaobao-measure/bind?${queryParts.join('&')}`,
})
},
})设备场景速查
| 场景 | deviceKey | measureMode | userProfile 必填字段 |
|---|---|---|---|
| 血压检测 | HOME_MULTI_BIO_MONITOR | BP | — |
| 血糖检测 | HOME_MULTI_BIO_MONITOR | BG | — |
| 血氧检测 | HOME_SPO2_RING | — | — |
| 体脂检测 | BODY_COMPOSITION_ANALYSIS | — | height / gender / birth_date(缺失报 2003) |
| 心电检测 | HEARTLOG_ECG_RECORDER | — | — |
| 历史报告列表 | — | — | 入口改用 plugin://xiaobao-measure/index |
体脂秤(BCA):插件调用服务端 resolveUser 时,服务端自动将 userProfile 中的
height / age / gender / weight转换为 SDK 口径返回,宿主无需额外传明文参数。插件出参
检测完成(或取消)后,插件将结果写入 wx.setStorageSync('xiaobao_measure_result', result), 宿主在页面 onShow 中读取(读一次后清除):
| 字段 | 类型 | 说明 |
|---|---|---|
status | string | success / cancel / error |
measureId | string | 检测编号,与 Webhook measurement_no 对应 |
deviceKey | string | 实际检测设备 key |
summary | string | 结果摘要文字,如「收缩压 128 mmHg,正常」 |
errorCode | number | 失败时的错误码,见错误码 |
onShow() {
const result = wx.getStorageSync('xiaobao_measure_result')
if (!result) return
wx.removeStorageSync('xiaobao_measure_result') // 读一次后清除
if (result.status === 'success') {
console.log('检测成功,measureId:', result.measureId)
// 可用 measureId 与 Webhook 回调的 measurement_no 关联
} else if (result.status === 'cancel') {
console.log('用户取消检测')
} else {
console.log('检测失败,错误码:', result.errorCode)
}
}