终止轮询
/** * polling * @param data */ function checkLoginHandler (data) { /** * code: * 200: 成功 * 201:扫描成功,但未点确认 * 408:未扫描 * 400:未知 * 500: login poll srv exception * */ switch(data.code){ case 200: loginFactory.newLoginPage(data.redirect_uri).then(function (msg) { var ret = msg.match(/<ret>(.*)<\/ret>/), code = msg.match(/<script>(.*)<\/script>/), skey=msg.match(/<skey>(.*)<\/skey>/), wxsid=msg.match(/<wxsid>(.*)<\/wxsid>/), wxuin=msg.match(/<wxuin>(.*)<\/wxuin>/), passticket=msg.match(/<pass_ticket>(.*)<\/pass_ticket>/), message=msg.match(/<message>(.*)<\/message>/), redirecturl=msg.match(/<redirecturl>(.*)<\/redirecturl>/); if(redirecturl){ window.location.href = redirecturl[1]; return; } if(ret && (ret[1] != '0')){ alert((message && message[1])|| '登陆失败'); monitorService.report(monitorService.AUTH_FAIL_COUNT, 1); location.reload(); return; } $scope.$emit('newLoginPage',{ Ret:ret && ret[1], SKey:skey && skey[1], Sid:wxsid && wxsid[1], Uin:wxuin && wxuin[1], Passticket:passticket && passticket[1], Code:code }); if(!utilFactory.getCookie('webwx_data_ticket')){ reportService.report(reportService.ReportType.cookieError,{ text:'webwx_data_ticket 票据丢失', cookie:document.cookie }); } }); break; case 201: $scope.isScan = true; reportService.report(reportService.ReportType.timing,{ timing:{ scan:Date.now() } }); loginFactory.checkLogin($scope.uuid).then(checkLoginHandler, function (data){ if(!data && window.checkLoginPromise){ $scope.isBrokenNetwork = true; } }); break; case 408: loginFactory.checkLogin($scope.uuid).then(checkLoginHandler, function (data){ if(!data && window.checkLoginPromise){ $scope.isBrokenNetwork = true; } }); break; case 400: case 500: case 0: // 这里要累计次数 var refreshTimes = utilFactory.getCookie('refreshTimes') || 0; if(refreshTimes < 5){ refreshTimes++; utilFactory.setCookie('refreshTimes', refreshTimes, 0.5); document.location.reload(); } else{ $scope.isNeedRefresh = true; } break; case 202: // 点击取消 // 1. 关联登录,等待确认,取消 // 2. 扫码之后,等待确认,取消 $scope.isScan = false; $scope.isAssociationLogin = false; utilFactory.setCookie('login_frequency', 0, 2); // 终止轮询 if(window.checkLoginPromise){ window.checkLoginPromise.abort(); window.checkLoginPromise = null; } doQrcodeLogin(); break; default: //todo } $scope.code = data.code; $scope.userAvatar = data.userAvatar; utilFactory.log('get code',data.code); }