外链跳转到小程序原生的企业客服

备注: 在外链中,不能直接调起小程序原生客服(wx.openCustomerServiceChat)。

解决方法: 小程序里新增一个原生的过渡页面。外链跳转到过渡页面,在过渡页面添加点击事件,打开原生客服

在外链中劫持跳转,并跳转到原生的小程序页面

// 检测是否是微信环境
					var isWeChat = /micromessenger/i.test(navigator.userAgent);
					if (isWeChat && qywx_company_id) {
						console.log("当前是微信环境");
						jWeixin.miniProgram.navigateTo({
							url: "/pageE/transitionPage/transitionPage?corpId="+qywx_company_id+"&extInfoUrl="+data_info.cs_link
						})
					} else {
						console.log("当前不是微信环境");
						window.location.href = data_info.cs_link
					}

当外链打开过渡页面时,注意过渡页面的生命周期执行顺序,

created() {
            setTimeout(() => {
                // 打开微信客服
                // #ifdef MP
                if (this.$Route.query.corpId || this.$Route.query.extInfoUrl) {
                    this.goChat()
                }
                // #endif

            }, 0)
        },
// 企业微信id
			getQywxCs() {
				let _this = this
				return new Promise((resolve, reject) => {
					this.$api.buy.getQywxCs().then(res => {
						if (res.code == 0) {
							this.qywx_company_id = res.data.qywx_company_id
							resolve(res.data)
						}
					})
				})

			},
			// 去客服
			goChat() {
				let _this = this
				uni.showModal({
					title: '微信客服',
					content: '您即将进入客服对话框。',
					complete(res) {
						if (res.confirm) {
							if (!_this.$Route.query.corpId && !_this.qywx_company_id) {
								_this.getQywxCs().then((res) => {
									wx.openCustomerServiceChat({
										extInfo: {
											url: _this.$Route.query.extInfoUrl
										},
										corpId: res.qywx_company_id,
										success(res) {
											console.log(res, 'success');
										},
										fail(err) {
											console.log(err, 'err');
										},
										complete(res) {
											setTimeout(()=>{
												uni.navigateBack()
											},1000)
										}
									})
								}).catch(err=>{
									console.log(err);
								})
							} else {
								wx.openCustomerServiceChat({
									extInfo: {
										url: _this.$Route.query.extInfoUrl
									},
									corpId: _this.$Route.query.corpId||_this.qywx_company_id,
									success(res) {
										console.log(res, 'success');
									},
									fail(err) {
										console.log(err, 'err');
									},
									complete(res) {
										setTimeout(()=>{
											uni.navigateBack()
										},1000)
									}
								})
							}

						} else {
							uni.navigateBack()
						}
					}
				})
			},

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值