-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathcallback.php
More file actions
65 lines (47 loc) · 1.64 KB
/
callback.php
File metadata and controls
65 lines (47 loc) · 1.64 KB
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
<?php
session_start();
unset($_SESSION['nick']);
unset($_SESSION['authenticated_user_id']);
unset($_SESSION['app_unique_key']);
unset($_SESSION['topsession']);
$root_directory = dirname(__FILE__)."/";
require($root_directory.'include/init.php');
define( "WB_AKEY" , '3020836644' );
define( "WB_SKEY" , 'd8a6a9c5a2053367e292801fc9234000' );
define( "WB_CALLBACK_URL" , 'http://1.crm123.sinaapp.com/callback.php' );
include_once( 'include/saetv2.ex.class.php' );
$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
if (isset($_REQUEST['code'])) {
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = WB_CALLBACK_URL;
try {
$token = $o->getAccessToken( 'code', $keys ) ;
} catch (OAuthException $e) {
}
}
if ($token) {
$_SESSION['topsession'] = $token;
setcookie( 'weibojs_'.$o->client_id, http_build_query($token) );
$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['topsession']['access_token'] );
$ms = $c->home_timeline(); // done
$uid_get = $c->get_uid();
$uid = $uid_get['uid'];
$user_message = $c->show_user_by_id($uid);//根据ID获取用户等基本信息
$username = $user_message["name"];
if(empty($username)) {
redirect("Login.php?login_error=".rawurlencode("error:".$user_message["error"].",error_code:".$user_message["error_code"]));
}
$_SESSION['nick'] = $user_message["name"];
$userid = getUserIDByNick($username);
if($userid == 0){
$userid = InsertNickInfo($username,"weibo");
}
$_SESSION['authenticated_user_id'] = $userid;
$_SESSION['app_unique_key'] = $application_unique_key;
$_SESSION['authenticated_user_language'] = 'zh_cn';
redirect("index.php");
} else {
redirect("Login.php");
}
?>