曹え 5811 发布于:2019-06-05 12:05:05
<?php if(!defined('APP_PATH')||!defined('DOYO_PATH')){exit('Access Denied');} class index extends syController { function __construct(){ parent::__construct(); $this->sy_class_type=syClass('syclasstype'); } function index(){ if($this->syArgs('file',1)){ $this->custom=custom_html($this->syArgs('file',1)); if($this->custom['template']!=''){$this->display('custom/'.$this->custom['template']);}else{$this->display("index.html");} }else{ if(is_mobile()){ $this->display("m_index.html"); }else{ $this->display("index.html"); } } } function href_session(){ exit('true,'.date('Ym')); } function wxlogin(){ $redirect_uri="http://www.xxx.com/index.php?a=wxred"; $redirect_uri=urlencode($redirect_uri);//该回调需要url编码 $appID="wx9846aa09747fee00"; $scope="snsapi_login";//写死,微信暂时只支持这个值 //准备向微信发请求 $url = "https://open.weixin.qq.com/connect/qrconnect?appid=" . $appID."&redirect_uri=".$redirect_uri ."&response_type=code&scope=".$scope."&state=STATE#wechat_redirect"; jump($url); } function wxred(){ $url2= "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx98d6aad747fee00&secret=1ac57cd1cebb18a6778f2ddd56065571b6&code=".$_GET['code']."&grant_type=authorization_code"; $result = file_get_contents($url2); $array = json_decode(json_encode(json_decode($result)),true); $openid = $array['unionid']; //print_r($result); //eixt(); // 查询是否已经绑定过,绑定过直接登录 $conditions = array('token' => $openid); $m = syDB('member')->find($conditions,null,'id,user,token'); if($m){ $_SESSION['member'] = array( 'user' => $m['user'], 'id' => $m['id'], ); $this->gourl='?c=member'; jump($this->gourl); } else { // 没有绑定过,新注册或者绑定已注册账号 // 默认到注册页面 jump("index.php?c=member&a=reg&openid=".$openid); } } // 手机登录微信 function wxlogin2(){ $appid='wx4503ddc9c'; $redirect_rui=urlencode('http://www.bjzdzyyy.com/index.php?a=reponse'); $url='https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.$redirect_rui.'&response_type=code&scope=snsapi_userinfo&state=asd123#wechat_redirect'; header('Location:'.$url); } function reponse(){ header("Content-Type:text/html;charset=utf-8"); $appid='wx4503dd9c'; $appsecret='98559a212fddd8bc5ab29c1'; $code=$_GET['code']; $url='https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code'; $result=file_get_contents($url); $result=json_decode($result,true); $access_token=$result['access_token']; $openid=$result['openid']; // 获取用户信息 $url='https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN'; $result=file_get_contents($url); $o2=json_decode($result,true); $openid = $o2['unionid']; // 查询是否已经绑定过,绑定过直接登录 $conditions = array('token' => $openid); $m = syDB('member')->find($conditions,null,'id,user,token'); if($m){ $_SESSION['member'] = array( 'user' => $m['user'], 'id' => $m['id'], ); $this->gourl='?c=member'; jump($this->gourl); } else { // 没有绑定过,新注册或者绑定已注册账号 // 默认到注册页面 jump("index.php?c=member&a=reg&openid=".$openid); } } }
登录后可以留言提问!
微信扫码登录