uniapp 调用微信企业客服

456 阅读1分钟
// 调用企业客服
function wechatService() {
    let cropid="ww2ad74f05xxxxxxxx" //企业ID 
    let curl="https://work.weixin.qq.com/kfid/xxxxxxx"  //客服链接
        //app调用企业克服
	// #ifdef APP-PLUS
	let sweixin = null
	let that = this
	plus.share.getServices(res => {
			sweixin = res.find(i => i.id === 'weixin')
			console.log('sweixin', sweixin, );
			if (sweixin) {
				sweixin.openCustomerServiceChat({
					corpid: cropid, // corpid: '企业id', 需要申请   	
					url: curl, //url: '客服地址',需要申请
				}, suc => {
					// that.errors = JSON.stringify(suc) + "sweixin成功"
					console.log("success", JSON.stringify(res))
				}, err => {
					// that.errors = JSON.stringify(err) + "sweixin失败"
					console.log("error", JSON.stringify(err))
				})
			} else {
				// that.errors = JSON.stringify(err) + "当前环境不支持微信操作"
				plus.nativeUI.alert('当前环境不支持微信操作!')
			}
		},
		err => {
			console.log("plus.share.getServices失败", err);
			// that.errors = JSON.stringify(err) + "plus.share.getServices失败"
		}
	)
	// #endif
        
        //微信小程序调用微信客服
	// #ifdef  MP-WEIXIN
  	console.log("微信环境");
        let link={
            title:"",//客服链接 
            wap_url:"",//企业ID 
        }
  	if (wx.openCustomerServiceChat) {
  		wx.openCustomerServiceChat({
  			extInfo: {
  				url: link.title,
  			},
  			corpId: link.wap_url,
  			success(res) {
  				console.log("打开成功", res);
  			},
  			fail(err) {
  				console.log("打开失败", err);
  
  				wx.showModal({
  					title: '提示',
  					content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。',
  					success(res) {
  						if (res.confirm) {
  							console.log('用户点击确定')
  							wx.updateWeChatApp({
  								success(re) {
  									console.log("去更新成功", re);
  								},
  								fail(er) {
  									console.log("去更新失败", er);
  								}
  							})
  						} else if (res.cancel) {
  							console.log('用户点击取消')
  						}
  					}
  				})
  			},
  		});
  	} else {
  		wx.showModal({
  			title: '提示',
  			content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。',
  			success(res) {
  				if (res.confirm) {
  					console.log('用户点击确定')
  					wx.updateWeChatApp({
  						success(re) {
  							console.log("去更新成功", re);
  						},
  						fail(er) {
  							console.log("去更新失败", er);
  						}
  					})
  				} else if (res.cancel) {
  					console.log('用户点击取消')
  				}
  			}
  		})
  	}
  
  	// #endif

}