123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- namespace weixin;
- class Wxauth
- {
-
- private $Host="https://open.weixin.qq.com/connect/oauth2/authorize?";
- private $Response_type="code";
- private $Scope="snsapi_base";
- private $State="1";
- private $Appid="";
- private $Appsecret="";
- private $Redirect_uri="";
- private $Auth_url="";
-
- public function __construct()
- {
-
-
- $this->Redirect_uri = urlencode('');
- $this->APPID =sysconfig('wchat.wxmini_user_appid');
- $this->APPSECRET =sysconfig('wchat.wxmini_user_secret');
- $this->Auth_url =$this->Host."appid=".$this->APPID."&redirect_uri=".$this->Redirect_uri."&response_type=".$this->Response_type."&scope=".$this->Scope."&state=".$this->State."#wechat_redirect";
-
- }
-
-
- public function getAccesstoken(string $code=''){
- $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?';
- $url .= "appid=$this->APPID&secret=$this->APPSECRET&CODE=$code&grant_type=authorization_code";
- $result = file_get_contents($url);
- $result = json_decode($result,true);
- WLog('wxlogin',serialize($result));
- if(empty($result['access_token'])){
- return Result(0,'微信登录失败');
- }else{
- return Result(1,'登录成功',$result);
- }
- }
-
-
- public function GetLoginUrl()
- {
- return $this->Auth_url;
- }
-
-
- public function Login()
- {
- J($this->Auth_url);
- }
-
-
- public function Auth()
- {
- $code=input('code');
- if($code==""){
- $this->error('微信登录回调失败',url('index/login'));
- }
- $result = $this->getAccesstoken($code);
- if($result['status']==1){
- $this->error("微信登录失败",url('index/login'));
- }else{
- $access_token = $result['data']['access_token'];
- $openid = $result['data']['openid'];
- }
- $url='https://api.weixin.qq.com/sns/userinfo?access_token=';
- $wxuserinfo=file_get_contents($url.$access_token."&openid=".$openid);
- $wxuserinfo=json_decode($wxuserinfo,true);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- public function LoginStatus($id)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }
- ?>
|