不清楚流程的看下这篇文章:
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('请求中')
}
})
}
效果如下:
因为被限制登陆了,所有后面的逻辑没办法玩了…