indexController.class.php
public function scanLogin(){
$key = I('key','');
$name = I('name','xiaosu');
$res = M('scan')->where("keyword = '{$key}'")->find();
$agent = $_SERVER ['HTTP_USER_AGENT'];
$iphone = (stripos ( $agent, 'iphone' )) ? true : false;
$Android = (stripos ( $agent, 'Android' )) ? true : false;
'.$res['keyword'];exit;
if($res && $key == $res['keyword'] && ($iphone || $Android)){
$map['id'] = $res['id'];
$map['name'] = $name;
$dr = M('scan')->save($map);
if(!empty($dr)){
echo '执行成功';exit;
}
}
$resAgain = M('scan')->where("keyword = '{$key}'")->find();
if(!empty($resAgain) && !empty($resAgain['name'])){
$this->ajaxReturn(['msg'=>$resAgain['name'],'state'=>1,'url'=>"http://www.xxxx.cn/index.php/stage/index/sucessLogin?key={$key}"],'json');
$this->assign('name',$resAgain['name']);
$this->display('sucess');
}
$this->ajaxReturn(['msg'=>'登陆失败','state'=>0],'json');
}
public function sucessLogin(){
$key = I('key','');
$res = M('scan')->where("keyword = '{$key}'")->find();
$this->assign('name',$res['name']);
$this->display('success');
}
scan.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<script type="text/javascript" src="http://<?php echo $_SERVER['SERVER_NAME'].'__ROOT__' ?>/Public/js/jquery.js"></script>
<body>
<img src="http://qr.liantu.com/api.php?text={$url}" width="300px"/>
<input hidden="hidden" type="text" name="randnumber" id="randnumber"value="{$key}"/>
</body>
<script>
$(function(){
// xmlHttpRequest.onreadystatechange = function(){
// if(xmlHttpRequest.status == 200 && xmlHttpRequest.readyState ==4){
// result = xmlHttp.responseText;
// if(result==true){//username不为空则跳转页面
// window.location.href='welcome.php';
// }
// }
// };
function polling(){
//执行轮询操作
// var xmlHttpRequest;
// if(window.XMLHttpRequest){
// xmlHttpRequest = new XMLHttpRequest();
// }
// else{
// xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
// }
// randnumber = document.getElementById('randnumber').value;
// xmlHttpRequest.open("GET","scanLogin?key="+ randnumber,true);
// xmlHttpRequest.send();
$.ajax({
url:"<?php echo $url ?>",
type:"GET",
data:{},
dataType:'json',
success:function($data){
if($data == null || $data.state == 0){
var msg = $data.msg;
setInterval(polling(),1000);
}else if($data.state == 1){
window.location.href=$data.url;
}
}
})
}
setInterval(polling(),1000);
})
</script>
</html>