Appearance
功能说明
在微信小程序中,用户点击“在线客服”时,通过微信官方提供的 wx.openCustomerServiceChat 接口直接唤起企业微信客服聊天会话。
前端实现机制(view/uniapp)
在移动端工程 view/uniapp/utils/util.js 中,封装了客服类型的统一调度与跳转逻辑:
javascript
/**
* 统一客服跳转处理
*/
getCustomer(userInfo, url) {
const self = this;
customerType().then(res => {
const data = res.data;
if (data.customer_type == 1) {
// 拨打客服电话
uni.makePhoneCall({ phoneNumber: data.customer_phone });
} else if (data.customer_type == 2) {
// #ifdef MP
// 小程序环境下检测为企业微信客服链接,调用官方直跳能力
if (data.customer_url && data.customer_url.indexOf('work.weixin.qq.com') > 0) {
uni.openCustomerServiceChat({
extInfo: { url: data.customer_url },
corpId: data.wechat_work_corpid,
success(res) {},
fail(err) {
self.Tips({ title: err.errMsg });
}
});
return;
}
// #endif
// 其他第三方客服 H5 Webview 跳转
uni.navigateTo({
url: `/pages/annex/web_view/index?url=${encodeURIComponent(data.customer_url)}`
});
} else {
// 系统内置在线客服聊天室
uni.navigateTo({
url: url || '/pages/extension/customer_list/chat'
});
}
});
}接入前置要求与排查
- 微信公众平台绑定 CorpID:登录小程序后台 -> 【功能】 -> 【客服】 -> 【微信客服】,必须事先完成该企业微信 CorpID 的授权绑定。
- 基础库版本要求:
openCustomerServiceChat要求微信客户端基础库版本>= 2.19.2。 - 后台参数配置:确保在 EBAOZU 后台【客服设置】中填写的客服链接与企业微信后台生成的
https://work.weixin.qq.com/kfid/...链接完全一致。