<?php
/**
 * [UQcms System] Copyright uqcms.com
 * QQ: 2200631718
 * Author: gj.name
 * This is NOT a freeware
*/
 class login_wchatsssssss { private static $instance; public static function init(){ if (is_null(self::$instance)){ self::$instance = new self(); } return self::$instance; } function __construct(){ global $cfg; $this->redirect_uri = $cfg['site_url'].'member.php?a=redirect_wchat'; $this->appid = $cfg['connect_wchat_appkey']; $this->AppSecret = $cfg['connect_wchat_appsecret']; } function link(){ $rand = get_rand(16); $this->state = $rand; $_SESSION['connect']['wchat']['state'] = $rand; $url = 'https://open.weixin.qq.com/connect/qrconnect?appid='.$this->appid.'&redirect_uri='.urlencode($this->redirect_uri).'&response_type=code&scope=snsapi_login&state='.$this->state.'#wechat_redirect'; header('Location:'.$url); } function getAccessToken($code,$state){ if($state == $_SESSION['connect']['wchat']['state']){ $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$this->appid.'&secret='.$this->AppSecret.'&code='.$code.'&grant_type=authorization_code'; $result = curl::get($url); $data = json_decode($result); if($data->errcode){ exit('授权错误！'); } $data['access_token'] = $data->access_token; $data['openid'] = $data->openid; $data['unionid'] = $data->unionid; return $data; }else{ showmsg('本地认证出错，请重新登录'); } } function get_info($access_token, $openid){ $url = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid; $content = curl::get($url); pr($content); $result = json_decode($content); $data['nick'] = $result->nickname; $data['sex'] = $result->sex; $data['province'] = $result->province; $data['city'] = $result->city; $data['country'] = $result->country; $data['avatar'] = $result->headimgurl; $data['openid'] = $result->unionid; return $data; } }