forked from netcccyun/qqapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
121 lines (118 loc) · 4.9 KB
/
Copy pathapi.php
File metadata and controls
121 lines (118 loc) · 4.9 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
include("./includes/common.php");
$act=isset($_GET['act'])?daddslashes($_GET['act']):null;
@header('Content-Type: application/json; charset=UTF-8');
$opentype = explode(',', $conf['opentype']);
$key = isset($_POST['key'])?trim($_POST['key']):trim($_GET['key']);
if(!$key) exit('{"code":-1,"msg":"No key"}');
switch($act){
case 'getcookie': //获取指定COOKIE
$type = isset($_POST['type'])?trim($_POST['type']):exit('{"code":-1,"msg":"No type"}');
$uin = isset($_POST['uin'])?trim($_POST['uin']):null;
if($conf['cookie_open']!=1)exit('{"code":-1,"msg":"未开启获取COOKIE接口"}');
if($key !== $conf['cookie_key'])exit('{"code":-1,"msg":"密钥错误"}');
if(!empty($uin)){
$account = $DB->find('account', '*', ['uin'=>$uin]);
if(!$account) exit('{"code":-1,"msg":"QQ不存在"}');
if($account['status']!=1) exit('{"code":-1,"msg":"QQ状态不正常"}');
$row = $DB->getRow("SELECT * FROM qqapi_cookie WHERE aid=:aid AND `type`=:type LIMIT 1", [':aid'=>$account['id'], ':type'=>$type]);
if($row){
if($row['status'] == 1 && (in_array($type, $opentype) || strtotime($row['addtime']) + 600 > time())){
$cookie = $row['content'];
}else{
try{
$cookie = \lib\Logic::updateCookie($row['id']);
}catch(Exception $e){
exit('{"code":-1,"msg":"'.$e->getMessage().'"}');
}
}
$DB->update('cookie', ['usetime'=>'NOW()'], ['id'=>$row['id']]);
}else{
try{
$cookie = \lib\Logic::addCookie($account['id'], $type);
}catch(Exception $e){
exit('{"code":-1,"msg":"'.$e->getMessage().'"}');
}
}
}else{
$row = $DB->getRow("SELECT A.uin,A.id aid,B.id,B.content,B.status,B.addtime FROM qqapi_account A LEFT JOIN qqapi_cookie B ON A.id=B.aid AND B.`type`=:type WHERE A.status=1 ORDER BY usetime ASC LIMIT 1", [':type'=>$type]);
if(!$row) exit('{"code":-1,"msg":"暂无可用的QQ"}');
$uin = $row['uin'];
if($row['id']){
if($row['status'] == 1 && (in_array($type, $opentype) || strtotime($row['addtime']) + 600 > time())){
$cookie = $row['content'];
}else{
try{
$cookie = \lib\Logic::updateCookie($row['id']);
}catch(Exception $e){
exit('{"code":-1,"msg":"'.$e->getMessage().'"}');
}
}
$DB->update('cookie', ['usetime'=>'NOW()'], ['id'=>$row['id']]);
}else{
try{
$cookie = \lib\Logic::addCookie($row['aid'], $type);
}catch(Exception $e){
exit('{"code":-1,"msg":"'.$e->getMessage().'"}');
}
}
}
exit(json_encode(['code'=>0, 'uin'=>$uin, 'type'=>$type, 'cookie'=>$cookie]));
break;
case 'getclientkey': //获取clientkey
$uin = isset($_POST['uin'])?trim($_POST['uin']):null;
if($conf['cookie_open']!=1)exit('{"code":-1,"msg":"未开启获取COOKIE接口"}');
if($key !== $conf['cookie_key'])exit('{"code":-1,"msg":"密钥错误"}');
if(!empty($uin)){
$account = $DB->find('account', '*', ['uin'=>$uin]);
if(!$account) exit('{"code":-1,"msg":"QQ不存在"}');
if($account['status']!=1) exit('{"code":-1,"msg":"QQ状态不正常"}');
}else{
$row = $DB->getRow("SELECT * FROM qqapi_account WHERE status=1 ORDER BY rand() LIMIT 1");
if(!$row) exit('{"code":-1,"msg":"暂无可用的QQ"}');
$uin = $row['uin'];
}
$qqlogin = new \lib\QQLogin();
$clientkey = $qqlogin->getClientKey($uin);
if($clientkey!==false){
exit(json_encode(['code'=>0, 'uin'=>$uin, 'clientkey'=>$clientkey]));
}else{
exit(json_encode(['code'=>-1, 'msg'=>'clientkey获取失败']));
}
break;
case 'getshuoshuo': //获取说说列表
$uin = isset($_POST['uin'])?trim($_POST['uin']):exit('{"code":-1,"msg":"No key"}');
$page = isset($_POST['page'])?$_POST['page']:1;
if($key !== $conf['apikey'])exit('{"code":-1,"msg":"密钥错误"}');
$result = qqtool_call('qzone', 'getshuoshuo', [$uin, $page]);
exit(json_encode($result));
break;
case 'getrizhi': //获取日志列表
$uin = isset($_POST['uin'])?trim($_POST['uin']):exit('{"code":-1,"msg":"No key"}');
$page = isset($_POST['page'])?$_POST['page']:1;
if($key !== $conf['apikey'])exit('{"code":-1,"msg":"密钥错误"}');
$result = qqtool_call('qzone', 'getrizhi', [$uin, $page]);
exit(json_encode($result));
break;
case 'getvisitcount': //获取空间人气
$uin = isset($_POST['uin'])?trim($_POST['uin']):exit('{"code":-1,"msg":"No key"}');
if($key !== $conf['apikey'])exit('{"code":-1,"msg":"密钥错误"}');
$result = qqtool_call('qzone', 'getvisitcount', [$uin]);
exit(json_encode($result));
break;
case 'getprivilege': //获取已开通权益
$uin = isset($_POST['uin'])?trim($_POST['uin']):exit('{"code":-1,"msg":"No key"}');
if($key !== $conf['apikey'])exit('{"code":-1,"msg":"密钥错误"}');
$result = qqtool_call('vip', 'getprivilege', [$uin]);
exit(json_encode($result));
break;
case 'getqqlevel': //获取QQ等级
$uin = isset($_POST['uin'])?trim($_POST['uin']):exit('{"code":-1,"msg":"No key"}');
if($key !== $conf['apikey'])exit('{"code":-1,"msg":"密钥错误"}');
$result = qqtool_call('vip', 'getqqlevel', [$uin]);
exit(json_encode($result));
break;
default:
exit('{"code":-4,"msg":"No Act"}');
break;
}