<?php
/**
 * [UQcms System] Copyright uqcms.com
 * QQ: 2200631718
 * Author: gj.name
 * This is NOT a freeware
*/  class login_weibo { private static $instance; public static function init(){ if (is_null(self::$instance)){ self::$instance = new self(); } return self::$instance; } function __construct($params, $referer_url, $state){ $this->app_id = $params['app_key']; $this->app_secret = $params['app_secret']; $this->redirect_uri = $referer_url; $this->state = $state; } function jump_url(){ $url = 'https://api.weibo.com/oauth2/authorize?client_id='.$this->app_id.'&state='.$this->state.'&response_type=code&redirect_uri='.urlencode($this->redirect_uri); header("Location:".$url); } function getAccessToken($code){ $url = 'https://api.weibo.com/oauth2/access_token'; $params = 'client_id='.$this->app_id.'&client_secret='.$this->app_secret.'&grant_type=authorization_code&redirect_uri='.urlencode($this->redirect_uri).'&code='.$code; $response = curl::post($url, $params); $result = json_decode($response); $data['openid'] = $result->uid; $data['access_token'] = $result->access_token; return $data; } function get_access_token(){ return $_SESSION['connect']['weibo']['access_token']; } function get_info($access_token, $openid){ $url = 'https://api.weibo.com/2/users/show.json?uid='.$openid.'&access_token='.$access_token; $info = curl::get($url); $winfo = json_decode($info); $data['nick'] = $winfo->screen_name; $data['avatar'] = $winfo->avatar_large; $sex = array( 'm'=>'1', 'f'=>'0', ); $data['sex'] = $sex[$winfo->gender]; return $data; } function oauth_info($access_token){ $request_url = 'https://api.weibo.com/oauth2/get_token_info'; $params = 'access_token='.$access_token; $info = curl::post($request_url, $params); return json_decode($info); } function update($access_token,$content){ $request_url = 'https://api.weibo.com/2/statuses/update.json'; $request_params = 'status='.urlencode($content).'&access_token='.$access_token; $info = curl::post($request_url,$request_params); return json_decode($info); } function upload($access_token, $content, $pic_con){ $request_url = 'https://upload.api.weibo.com/2/statuses/upload.json'; $data = array( 'status'=>urlencode($content), 'access_token'=>$access_token, 'pic'=>'@F:/'.$pic_con, ); $info = curl::post($request_url,$data); return json_decode($info); } }