<?php
/** 
 * UQ云商：	www.uqcms.com  
 * 联系QQ：	2200631718 
 * 可免费商用，需要留UQ云商链接作为交换，只首页底部留取即可，不影响使用。
 */
  class login_qq { private static $uq0; public static function init() { if (is_null(self::$uq0)){ self::$uq0 = new self(); } return self::$uq0; } function __construct($uq1 = []) { $this->app_id = $uq1['app_key']??error_404('QQ登录：app_key不能为空'); $this->app_secret = $uq1['app_secret']??error_404('QQ登录：app_secret不能为空'); $this->state = $uq1['state']??'123'; $this->redirect_uri = cfg['site_domain'].'member/connback?alias=qq'; } function jump_url() { $uq2 = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id='.$this->app_id.'&state='.$this->state.'&scope=get_user_info&redirect_uri='.urlencode($this->redirect_uri); header("Location:".$uq2); } function get_token($uq3) { $uq2 = 'https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id='.$this->app_id.'&code='.$uq3.'&client_secret='.$this->app_secret.'&redirect_uri='.urlencode($this->redirect_uri); $uq4 = curl::get($uq2); if(strpos($uq4, "callback") !== false){ $uq5 = strpos($uq4, "("); $uq6 = strrpos($uq4, ")"); $uq4 = substr($uq4, $uq5 + 1, $uq6 - $uq5 -1); $uq7 = json_decode($uq4); if(isset($uq7->error)){ error_404('QQ授权失败:'.$uq7->error); } } $uq1 = array(); parse_str($uq4, $uq1); $uq8= 'https://graph.qq.com/oauth2.0/me?access_token='.$uq1["access_token"]; $uq9 = curl::get($uq8); if(strpos($uq9, "callback") !== false){ $uq5 = strpos($uq9, "("); $uq6 = strrpos($uq9, ")"); $uq9 = substr($uq9, $uq5 + 1, $uq6 - $uq5 -1); } $uq10 = json_decode($uq9); if(isset($uq10->error)){ error_404('QQ获取信息失败：'.$uq10->error_description); } $uq11['openid'] = $uq10->openid; $uq11['access_token'] = $uq1['access_token']; return $uq11; } function user_info($uq12, $uq13) { $uq2 = 'https://graph.qq.com/user/get_user_info?access_token='.$uq12.'&oauth_consumer_key='.$this->app_id.'&openid='.$uq13; $uq4 = curl::get($uq2); $uq14 = json_decode($uq4); $uq11['nick'] = $uq14->nickname; $uq11['avatar'] = $uq14->figureurl_qq_2; $uq11['sex'] = $uq14->gender; return $uq11; } } 