| <?php
|
| namespace lib;
|
| |
| |
|
|
|
|
| class Oauth{
|
| private $apiurl;
|
| private $appid;
|
| private $appkey;
|
| private $callback;
|
|
|
| function __construct($config){
|
| $this->apiurl = $config['apiurl'].'connect.php';
|
| $this->appid = $config['appid'];
|
| $this->appkey = $config['appkey'];
|
| $this->callback = $config['callback'];
|
| }
|
|
|
|
|
| public function login($type){
|
|
|
|
|
| $state = md5(uniqid(rand(), TRUE));
|
| $_SESSION['Oauth_state'] = $state;
|
|
|
|
|
| $keysArr = array(
|
| "act" => "login",
|
| "appid" => $this->appid,
|
| "appkey" => $this->appkey,
|
| "type" => $type,
|
| "redirect_uri" => $this->callback,
|
| "state" => $state
|
| );
|
| $login_url = $this->apiurl.'?'.http_build_query($keysArr);
|
| $response = get_curl($login_url);
|
| $arr = json_decode($response,true);
|
| return $arr;
|
| }
|
|
|
|
|
| public function callback(){
|
|
|
| $keysArr = array(
|
| "act" => "callback",
|
| "appid" => $this->appid,
|
| "appkey" => $this->appkey,
|
| "code" => $_GET['code']
|
| );
|
|
|
|
|
| $token_url = $this->apiurl.'?'.http_build_query($keysArr);
|
| $response = get_curl($token_url);
|
|
|
| $arr = json_decode($response,true);
|
| return $arr;
|
| }
|
|
|
|
|
| public function query($type, $social_uid){
|
|
|
| $keysArr = array(
|
| "act" => "query",
|
| "appid" => $this->appid,
|
| "appkey" => $this->appkey,
|
| "type" => $type,
|
| "social_uid" => $social_uid
|
| );
|
|
|
|
|
| $token_url = $this->apiurl.'?'.http_build_query($keysArr);
|
| $response = get_curl($token_url);
|
|
|
| $arr = json_decode($response,true);
|
| return $arr;
|
| }
|
| }
|
|
|