切换主题
小程序插件接入
适用对象:宿主小程序开发人员。本指南用于插件页面接入,不适用于微信原生客服渠道。
前置条件
已完成门店和客服租户关联,接待组及客服已配置。准备当前门店 userId 与当前登录会员的银豹 customer.uid。
声明插件
在宿主 app.json 中声明插件:
json
{
"plugins": {
"baoketong": {
"version": "latest",
"provider": "wx608e288eac41d277"
}
}
}baoketong 是宿主自定义别名。正式接入使用已发布版本;latest 的可用性以微信平台和实际已发布插件版本为准,发布前应在微信开发者工具中验证。更新版本后重新构建或重新进入运行环境。
打开客服
js
const baoketong = requirePlugin('baoketong')
const chatUrl = baoketong.openChat({
storeUserId: currentStoreUserId,
customerUid: currentCustomerUid,
scene: 'store-home'
})
wx.navigateTo({ url: chatUrl })| 参数 | 说明 |
|---|---|
| storeUserId | 当前门店 userId,不能用客服租户编号替代 |
| customerUid | 当前会员的银豹 customer.uid |
| scene | 可选,标识商品详情、会员中心等入口 |
openChat 生成 URL,不自动跳转。宿主负责调用 wx.navigateTo 或 wx.redirectTo。
发送商品卡片
商品详情入口可以带上当前商品:
js
wx.navigateTo({
url: baoketong.openChat({
storeUserId: currentStoreUserId,
customerUid: currentCustomerUid,
scene: 'goods-detail',
product: {
uid: currentProduct.uid,
barcode: currentProduct.barcode,
name: currentProduct.name,
price: currentProduct.price,
imageUrl: currentProduct.imageUrl
}
})
})示例变量由宿主实际业务数据提供。卡片在会话初始化后发送,测试时检查内容和是否重复发送。
商品卡片点击
客服发送的商品卡片被客户点击时,宿主决定跳转页面,监听在页面销毁时解除:
js
let unbindGoodsClick = null
Page({
onLoad() {
baoketong._$init({
storeUserId: currentStoreUserId,
customerUid: currentCustomerUid
})
unbindGoodsClick = baoketong._$onGoodsCardClick((res) => {
const goodsId = res.uid || res.productUid || res.barcode
if (!goodsId) {
wx.showToast({ title: '商品标识缺失', icon: 'none' })
return
}
wx.navigateTo({
url: `/pages/goods/detail?id=${encodeURIComponent(goodsId)}`
})
})
},
onUnload() {
if (typeof unbindGoodsClick === 'function') unbindGoodsClick()
unbindGoodsClick = null
}
})商品详情路径需替换成宿主自己的页面,初始化参数也需使用当前真实登录上下文。
入口安全
插件内部申请短时一次性入口票据,宿主不需要手动传 timestamp、nonce、signature 或 tenantUserId。
不要使用固定的其他会员 UID 代替当前用户。验证时确认会员资料、门店和接待组匹配,再测试消息、商品卡片及历史记录。