绑定企业微信

首先需要生成二维码,可以用两种方式显示。第一,用dialog弹出框显示,这种方式绑定成功之后后台会返回一个成功页面,直接刷新页面;第二,用JS中的子窗口来显示,返回的成功页面只在子窗口中。第一种方式如下:

1.引入微信JS

<script src="http://rescdn.qqmail.com/node/ww/wwopenmng/js/sso/wwLogin-1.0.0.js"></script>

2.渲染二维码的dialog

<el-dialog
	:visible.sync="dialogBindWeChat"
	width="30%"
	:before-close="handleCloseBindWeChat"
	style="margin-top: 50px">
	<div id="login_container"></div>
 </el-dialog>

3.从后台获取appid,agentid,redirect_rui

返回结果:

{
    "status": 1,
    "msg": "",
    "data": {
        "redirectUri": redirectURL,
        "agentid": 1000001,
        "appId": "aw9e9d1b93a6a27dd0"
    }
}

4.生成二维码

setTimeout(function(){
	window.WwLogin({
		 "id" : "login_container",
		  "appid" : appId,
		  "agentid" : agentId,
		  "redirect_uri" : redirectURL,
		  "state" : "",
		   "href" : ""
	});
},30);

绑定成功后会跳转到前端路由地址,即是成功页面。
第二种方式是直接打开一个子窗口:

//获得窗口的垂直位置
var iTop = (window.screen.availHeight - 30 - 600) / 2;
 //获得窗口的水平位置
var iLeft = (window.screen.availWidth - 10 - 600) / 2; //获取这些是为了让子窗口居中

var child = window.open('https://open.work.weixin.qq.com/connect?appid=' + appId + '&agentid=' + agentId + '&redirect_uri=redirectURL&state=lxw&usertype=admin',
                                '_blank','height=600, width=600, top='+ iTop + ', left=' + iLeft + ', toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');

绑定成功之后需要在返回成功页面里需要关闭子窗口,刷新父窗口:

setTimeout(function(){
	window.opener.location.reload(); //刷新父窗口中的网页
	window.close();//关闭当前窗窗口
},3000);

我们还可以监听子窗口关闭状态,用一个定时器去轮询:

var timer = setInterval(checkChild, 500);
	function checkChild() {
		if (child.closed) {
			clearInterval(timer);
		}
	}

关注微博、微信公众号搜索前端小木,让我们一起学习成长。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端小木

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值