网页版微信协议登陆,没什么用...

不清楚流程的看下这篇文章:
https://www.cnblogs.com/sickle/p/10126246.html

    // GET请求
    private function getApi($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 6.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 10);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
    // 获取图片保存uuid
    private function getCodePic()
    {
        $picCode = $this->getApi('https://login.wx.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=1540887586026');
        $picCode = explode(";", $picCode);
        $picCode[1] = str_replace('"','',$picCode[1]);
        $picCode = explode(" = ",$picCode[1]);
        $code = $picCode[1];
        $this->weixinCode = $code;
        $url = 'https://login.weixin.qq.com/qrcode/'.$code;
        return ['code'=>$code,'url'=>$url];
    }
    // 显示登陆二维码以及渲染登陆界面
    public function wexin_img(){
        $view = new view;
        // uuid 传到模板中的JS
        $view->assign('uuid',Index::$code);
        // 图片地址 传导模板中的img标签
        $view->assign('img',$this->getCodePic());
        return $view->fetch('weixin1');
    }
    // 登陆状态判断
    public function wexin_code($code){
        $code = str_replace("==",'',$code);
        $url = 'https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid='.$code.'==&tip=0&r=-712832920&_='.time();
        $output = $this->getApi($url);
        $data = explode(";",$output);
        if(count($data[0])>0){
            $data['code'] = explode("=",$data[0])[1];
            if($data['code'] == 408){

            }
            elseif($data['code'] == 201){
                // 扫码了,但没点确定

            }
            elseif ($data['code'] == 200) {
                // 登陆成功
                $url = explode("=",$data[1])[1];
                $msg = $this->getApi($url);
                $data['code'] = 202;
                $data['msg'] = $msg;
            }
        }
        
        return json($data);
    }

HTML模板

		<div class="row justify-content-center container-bd">
			  <div class="col-sm-10 col-md-12 col-lg-12 col-xl-12 text-center" role="main" style="position: relative;">
			  	<img src="{$img.url}" style="margin-top: 20%" class="weixinimg">
			  	<h2>扫码二维码,微信登陆</h2>
			  </div>
		</div>

JS

// 每10秒钟发起一次状态确认
var loadWeiXin = window.setInterval(()=>{
	next();
},10000)
// ready发起一次状态确认
$("body").ready(function(){
	next();
})
// 状态确认AJAX
function next(a){
	$.ajax({
	    type:"get",
		url:'/wexin_code/{$img.code}',// img.code就是uuid
		success:function(res){
			if(res.code == 202){
				alert_msg('danger','该账号不支持微信接入,请更换其它账号!',4000,msg_id)
				window.clearInterval(loadWeiXin)
			}
			if(res.code == 201){
				console.log("请点击确认登陆")
				// $(".error p").before('<img src="data:image/png;'+res[2].substr(0, res[2].length - 1)+'">')
				// alert_msg('info','请点击确定登陆!',4000,msg_id)
				// $(".error").css({'z-index':222})
				setTimeout(()=>{
					// $(".weixinimg").css({"filter":'blur(5px)'})
					// $(".error").css({'z-index':222,'background-color':'rgba(0,0,0,0.8)','transform':'scale(1)'})
					// $(".error p").text("扫码成功,请点击确定登陆!")
					next();
				},600)
			}
			if(res.code == 200){
				// 清除登陆状态确认请求定时器
				window.clearInterval(loadWeiXin)
				console.log('授权成功,正在登陆中')
				// alert_msg('success','授权成功,正在登陆中',4000,msg_id)
				// $(".error p").text("授权成功,正在登陆中!")
			}
			if(res.code == 408){
			}
			
			
		},
		error:function(){
			console.log('请求中')
		}
	})
}

效果如下:
在这里插入图片描述
因为被限制登陆了,所有后面的逻辑没办法玩了…

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值