扫描登录

Posted 伊人世界

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了扫描登录相关的知识,希望对你有一定的参考价值。

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>

 

以上是关于扫描登录的主要内容,如果未能解决你的问题,请参考以下文章

片段创建的 Intent 不会触发 onNewIntent

Zxing QR扫描仪onActivityResult未在片段中调用[重复]

pbootcms对接微信扫码登录代码核心片段和步骤(前后端)

在 zxing 片段库中打开/关闭手电筒

Android实现二维码扫描登录网页

PHP微信扫描二维码登录网站代码示例