uniapp接入企业微信客服

一、打开微信客服

file

二、启用客服并绑定微信号

file

三、选择接入场景

file
根据自己的场景选择,按照里面的步骤说明操作即可
比如:
在App中接入
在微信外的网页接入

注意复制保留:

  1. 客服链接
  2. 企业ID

四、代码

//界面代码
<u-tag :text="$t('联系客服')" shape="circle" class="u-m-r-30" @click="chat" type="info" />

//方法
chat() {
    //WORKWXCORPID 企业ID
    //WORKWXURL 企业客服链接

    // #ifdef H5
        // 触发跳转外链
        // 此处参考:
        // https://blog.fatterpig.com/uniapp跳转到外部链接/
        uni.navigateTo({
          url: '/pagesC/webview/webview?url='+WORKWXURL
        });
    // #endif

    // #ifdef MP-WEIXIN
    wx.openCustomerServiceChat({
      extInfo: {url: WORKWXURL},
      corpId: WORKWXCORPID,
      success(res) {}
    })
    // #endif

    // #ifdef APP-PLUS
    let sweixin = null
    plus.share.getServices(res => {
        sweixin = res.find(i => i.id === 'weixin')
        if (sweixin) {
            sweixin?sweixin.openCustomerServiceChat({
                    corpid: WORKWXCORPID,
                    url:WORKWXURL
                }, res => {
                    console.log(res)
                }, error=>{
                    console.log(error)
                }):plus.nativeUI.alert('当前环境不支持微信操作!');
        } else {
            uni.showToast({
                title: "当前环境不支持微信操作",
                icon: 'error'
            })
        }
    }, function() {
        uni.showToast({
            title: "获取服务失败,不支持该操作。" + JSON.stringify(e),
            icon: 'error'
        })
    })

    // #endif
}

发表评论