1,'msg'=>'扫码成功'))); }else{ echo base64_encode(json_encode(array('status'=>2,'msg'=>'扫码失败'))); } } /** * 获取唯一token */ public function getToken(){ $token = think_encrypt(time(),1,120); $res['token']= $token; $this->ajaxReturn($res); } /** * 生成二维码 * @param string $url * @param int $level * @param int $size */ public function QrCode($url='',$level=3,$size=4){ $url = base64_decode(base64_decode($url)); Vendor('phpqrcode.phpqrcode'); $errorCorrectionLevel =intval($level) ;//容错级别 $matrixPointSize = intval($size);//生成图片大小 //生成二维码图片 //echo $_SERVER['REQUEST_URI']; ob_clean(); $object = new \QRcode(); return $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2); } /** * 获取二维码 * @param $token */ public function inQrCode($token) { session('QrLogin_token',$token); $url = "http://".$_SERVER['HTTP_HOST']."/sdk.php/OTP/QrLogin/token/".$token; $url = U('QrLogin/QrCode',(array('url'=>base64_encode(base64_encode($url))))); echo ''; } /** * 扫码登录 * @param $token */ public function qrLogin($token){ if($token === session('QrLogin_token') && !empty(think_encrypt($token,1))){ $data = M('qr_login','tab_')->where(array('token'=>$token,'status'=>1))->field('id,uid')->find(); if(!empty($data)){ $user = M('user','tab_')->where(array('id'=>$data['uid']))->field('account')->find(); $member = new MemberApi(); $res = $member->qrLogin($user['account'],''); if ($res > 0) { parent::autoLogin($res); $data['status'] = 2; $res = M('qr_login','tab_')->save($data); $this->ajaxReturn(array('status' => 1, 'msg' => '登录成功')); } }else{ $this->ajaxReturn(array('status' => 2, 'msg' => '登录失败')); } } } }