-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign.php
193 lines (178 loc) · 8.6 KB
/
sign.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
include('function.php');
include('connect.php');
header("content-Type: text/html; charset=utf-8");
class tiebasign{
private $db;
private $uid;
private $cid;
private $bduss;
private $tbs;
private $mslevel;
private $forumid;
private $forum_name;
const mylikeurl = 'http://c.tieba.baidu.com/c/f/forum/getforumlist';
const signurl = 'http://c.tieba.baidu.com/c/c/forum/sign';
const msignurl = 'http://c.tieba.baidu.com/c/c/forum/msign';
const tbsurl = 'http://tieba.baidu.com/dc/common/tbs';
public function __construct(){
global $pdo;
$this->db = $pdo;
}
private function _init_bduss(){
$res = $this->db->query("SELECT uid,cid,cookie FROM tieba_sign_cookies WHERE end_sign < CURRENT_DATE() AND status=1 ORDER BY last_sign ASC LIMIT 1;")->fetch();
if(empty($res)) return false;
$this->uid = $res['uid'];
$this->cid = $res['cid'];
preg_match('/BDUSS=(.*?);/', $res['cookie'], $matches);
if($matches[1]) $this->bduss = $matches[1]; else exit('bduss');
$check = json_decode(curl_get(self::tbsurl,$this->bduss,false));
if (!$check->is_login){
$pre = $this->db->prepare("UPDATE tieba_sign_cookies SET status = 0 WHERE cid=:cid");
$pre->bindParam(':cid',$this->cid);
$pre->execute();
$errorInfo =$this->db->errorInfo();
if($errorInfo[0] != 0) var_dump($errorInfo[2]);
echo "当前用户可能是BDUSS/cookie设置错误了,切换到下一个用户。<br/>";
$this->_init_();
}
$this->tbs = $check->tbs;
}
public function _init_(){
$this->_init_bduss();
$this->getmylike();
$this->sign();
}
public function getmylike(){
$day = date('Y-m-d');
$pre = $this->db->prepare("UPDATE tieba_sign_cookies SET last_sign = CURRENT_TIMESTAMP() WHERE cid=:cid");
$pre->bindParam(':cid',$this->cid);
$pre->execute();
$errorInfo = $this->db->errorInfo();
if($errorInfo[0] != 0) var_dump($errorInfo[2]);
$pda = array(
'BDUSS'=>$this->bduss
);
$result = curl_post($pda,self::mylikeurl);
$jsonobj = json_decode($result,1);
/* $pre = $this->db->prepare("replace into tieba_signlevel set level=:level, uid=:uid");
$pre->bindParam(':level',$jsonobj['level']);
$pre->bindParam(':uid',$this->uid);
$pre->execute();
$errorInfo = $pre->errorInfo();
if($errorInfo[0] != 0) var_dump($errorInfo[2]); */
$this->mslevel = $jsonobj['level'];
$forumid = array();
foreach ($jsonobj['forum_info'] as $key => $value) {
if($value['is_sign_in'] == 1)continue;
$forumid[$value['forum_id']] = $value['user_level'];
$forum_name[$value['forum_id']] = $value['forum_name'];
/* $pre = $this->db->prepare("INSERT INTO tieba_list (kw_name,forumid,level,uid) VALUES (:kw_name,:forumid,:level,:uid)");
$pre->bindParam(':kw_name',$value['forum_name']);
$pre->bindParam(':forumid',$value['forum_id']);
$pre->bindParam(':level',$value['user_level']);
$pre->bindParam(':uid',$this->uid);
$pre->execute();
$errorInfo = $pre->errorInfo();
if($errorInfo[0] != 0) var_dump($errorInfo[2]); */
}
$this->forumid = $forumid;
$this->forum_name = $forum_name;
$i = count($jsonobj['forum_info']);
$this->db->query("UPDATE tieba_sign_cookies SET forum_num = $i WHERE cid={$this->cid}");
echo "获取结束,一共[ $i ]个贴吧。<br/>";
return true;
}
public function sign(){
$m_forumid = $s_forumid = array();
foreach ($this->forumid as $forumid => $level) {
if($level >= $this->mslevel) $m_forumid[] = $forumid;
else $s_forumid[] = $forumid;
}
if($m_forumid){
$pda = array(
'BDUSS'=>$this->bduss,
'tbs'=>$this->tbs,
'forum_ids'=>implode(',',$m_forumid)
);
$result = curl_post($pda,self::msignurl);
$jsonobj = json_decode($result,1);var_dump($jsonobj);
if($jsonobj['error_code'] == 0 ){
if($jsonobj['error']['errno'] == 0){
foreach ($jsonobj['info'] as $forum) {
if($forum['signed'] == 1){
$pre = $this->db->prepare("INSERT INTO tieba_sign_history (kw,cid,uid,type,time) VALUES (:kw_name,:cid,:uid,1,CURRENT_TIMESTAMP())");
$pre->bindParam(':kw_name',$forum['forum_name']);
$pre->bindParam(':cid',$this->cid);
$pre->bindParam(':uid',$this->uid);
$pre->execute();
}else{
$pre = $this->db->prepare("INSERT INTO tieba_sign_history (kw,cid,uid,type,time) VALUES (:kw_name,:cid,:uid,0,CURRENT_TIMESTAMP())");//0未签到
$pre->bindParam(':kw_name',$forum['forum_name']);
$pre->bindParam(':cid',$this->cid);
$pre->bindParam(':uid',$this->uid);
$pre->execute();
}
$errorInfo = $this->db->errorInfo();
if($errorInfo[0] != 0) var_dump($errorInfo[2]);
}
}else{
$pre = $this->db->prepare("INSERT INTO tieba_sign_error_code (code,usermsg,errmsg) VALUES (:code,:usermsg,:errmsg)");
$pre->bindParam(':code',$jsonobj['error']['errno']);
$pre->bindParam(':usermsg',$jsonobj['error']['usermsg']);
$pre->bindParam(':errmsg',$jsonobj['error']['errmsg']);
$pre->execute();
$errorInfo = $this->db->errorInfo();
if($errorInfo[0] != 0) var_dump($errorInfo[2]);
}
}
}
if($s_forumid){
$pda = array(
'BDUSS'=>$this->bduss,
'tbs'=>$this->tbs,
);
foreach ($s_forumid as $forumid) {
$pda['fid'] = $forumid;
$pda['kw'] = $this->forum_name[$forumid];
$result = curl_post($pda,self::signurl);
$jsonobj = json_decode($result,1);var_dump($jsonobj);
if($jsonobj['error_code'] == 0 ){
if($jsonobj['user_info']['is_sign_in'] == 1){
$pre = $this->db->prepare("INSERT INTO tieba_sign_history (kw,cid,uid,type,time) VALUES (:kw_name,:cid,:uid,1,CURRENT_TIMESTAMP())");
$pre->bindParam(':kw_name',$pda['kw']);
$pre->bindParam(':cid',$this->cid);
$pre->bindParam(':uid',$this->uid);
$pre->execute();
$errorInfo = $this->db->errorInfo();
if($errorInfo[0] != 0) var_dump($errorInfo[2]);
}else{
$pre = $this->db->prepare("INSERT INTO tieba_sign_history (kw,cid,uid,type,time) VALUES (:kw_name,:cid,:uid,0,CURRENT_TIMESTAMP())");//0未签到
$pre->bindParam(':kw_name',$pda['kw']);
$pre->bindParam(':cid',$this->cid);
$pre->bindParam(':uid',$this->uid);
$pre->execute();
}
$errorInfo = $this->db->errorInfo();
if($errorInfo[0] != 0) var_dump($errorInfo[2]);
}else{
$pre = $this->db->prepare("INSERT INTO tieba_sign_error_code (code,usermsg,errmsg) VALUES (:code,:usermsg,:errmsg)");
$pre->bindParam(':code',$jsonobj['error_code']);
$pre->bindParam(':usermsg',$forumid);
$pre->bindParam(':errmsg',$jsonobj['error_msg']);
$pre->execute();
$errorInfo = $this->db->errorInfo();
if($errorInfo[0] != 0) var_dump($errorInfo[2]);
}
}
}
$this->db->query("UPDATE tieba_sign_cookies SET last_sign = CURRENT_TIMESTAMP() WHERE cid={$this->cid}");
//签到完成检查是否都签到成功
$this->getmylike();
if(empty($this->forumid)){
$this->db->query("UPDATE tieba_sign_cookies SET end_sign = CURRENT_DATE() WHERE cid={$this->cid}");
}
}
}
$obj = new tiebasign();
$obj->_init_();