在电脑上使用微信时,你可能已经发现微信不提供传统的账号密码登陆,取而代之的是通过扫描二维码进行登陆。今天就要研究下次登陆方式微信时如何实现的?
创新互联专注于黄山区网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供黄山区营销型网站建设,黄山区网站制作、黄山区网页设计、黄山区网站官网定制、微信小程序服务,打造黄山区网络公司原创品牌,更为您提供黄山区网站排名全网营销落地服务。
1、每次用户打开PC端登陆请求,系统返回一个***的uid,并将uid的信息绘制成二维码返回给用户。这里的uid一定是***的,否则就会造成你登陆了其他用户的账号或者其他用户登陆你的账号。
2、当用户使用登陆后的微信扫描该二维码的时候,会将这个uid和手机上的微信账号及密码产生的token进行绑定,并上传到服务器。
3、WEB通过JS不断的向后端发起请求,查询有没有关于uid的登陆记录(uid和token是否存在于服务器上)。实现代码可以从微信页面获取:
- function _poll(_asUUID) {
- var _self = arguments.callee,
- _nTime = 0;
- _sCurUUId = _asUUID;
- _logInPage("_poll Request Start, time: " + new Date().getTime());
- _nTime = new Date().getTime();
- $.ajax({
- type: "GET",
- url: "https://login." + _sBaseHost + "/cgi-bin/mmwebwx-bin/login?uuid=" + _asUUID + "&tip=" + show_tip,
- dataType: "script",
- cache: false,
- timeout: _nAjaxTimeout,
- success: function(data, textStatus, jqXHR) {
- _logInPage("_poll Request Success, code: " + window.code + ", time: " + (new Date().getTime() - _nTime) + "ms");
- switch (_aoWin.code) {
- case 200:
- _sSecondRequestTime = new Date().getTime() - _sSecondRequestTime;
- _logInPage("Second Request Success, time: " + _sSecondRequestTime + "ms");
- clearTimeout(_oResetTimeout);
- $.get(_aoWin.redirect_uri + "&fun=new", function(msg) {
- _logInPage("new func reponse, reponseMsg: " + msg);
- _reportNow("new func reponse, reponseMsg: " + msg);
- var code = msg.match(/