-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathConnect.php
73 lines (64 loc) · 2.47 KB
/
Connect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
// +----------------------------------------------------------------------
// | SISOME
// +----------------------------------------------------------------------
// | Copyright (c) 2015 http://sisome.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 绛木子 <master@lixianhua.com>
// +----------------------------------------------------------------------
class Connect{
static public $connect = array();
static public function getConnect($type){
$options = TeConnect_Plugin::options($type);
if(!isset(self::$connect[$type])){
require_once 'Sdk/'.$type.'.php';
self::$connect[$type] = new $type($options['id'],$options['key']);
}
return self::$connect[$type];
}
static public function getLoginUrl($type,$callback){
if($type=='qq'){
$login_url = self::getConnect($type)->login_url($callback,'get_user_info,add_share');
}else{
$login_url = self::getConnect($type)->login_url($callback);
}
return $login_url;
}
static public function getToken($type,$callback,$code){
$rs = self::getConnect($type)->access_token($callback,$code);
if(isset($rs['access_token']) && $rs['access_token']!=''){
self::setToken($type, $rs['access_token']);
return $rs['access_token'];
}
return '';
}
static public function setToken($type,$token){
self::getConnect($type)->access_token = $token;
}
static public function getOpenId($type){
$openid = '';
if($type=='qq'){
$rs = self::getConnect($type)->get_openid();
if(isset($rs['openid']) && $rs['openid']!=''){
$openid = $rs['openid'];
}
}elseif($type=='weibo'){
$rs = self::getConnect($type)->get_uid();
if(isset($rs['uid']) && $rs['uid']!=''){
$openid = $rs['uid'];
}
}
return $openid;
}
static public function getNickName($type,$openid){
$nickname = '';
if($type=='qq'){
$rs = self::getConnect($type)->get_user_info($openid);
$nickname = $rs['nickname'];
}elseif($type=='weibo'){
$rs = self::getConnect($type)->show_user_by_id($openid);
$nickname = $rs['screen_name'];
}
return $nickname;
}
}