forked from friparia/tieba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tieba.class.php
executable file
·77 lines (68 loc) · 2.58 KB
/
Tieba.class.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
<?php
class CTieba{
private $_headers = array();
const TBS_URL = "http://tieba.baidu.com/dc/common/tbs";
const SIGN_URL = "http://tieba.baidu.com/c/c/forum/sign";
const POST_URL = "http://tieba.baidu.com/c/c/post/add";
const MSIGN_URL = "http://tieba.baidu.com/c/c/forum/msign";
const ADDTHREAD_URL = "http://tieba.baidu.com/c/c/thread/add";
const FAV_URL = "http://tieba.baidu.com/c/f/forum/like";
public function __construct($BDUSS){
$this->_headers = array(
'Cookie' => 'BDUSS='.$BDUSS,
'Host' => 'tieba.baidu.com',
'Referer' => 'http://tieba.baidu.com/',
'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36',
);
}
public function getTbs(){
//$response = Requests::get(self::TBS_URL, $this->_headers);
$response = wp_remote_get(self::TBS_URL,["headers"=>$this->_headers]);
$response = json_decode($response['body']);
return $response->tbs;
}
public function sign($kw){
$data = array('kw' => $kw,'tbs' => $this->getTbs());
$response = wp_remote_get(self::SIGN_URL."?".$this->encrypt($data),["headers"=>$this->_headers]);
//$response = Requests::get(self::SIGN_URL."?".$this->encrypt($data), $this->_headers);
$response = json_decode($response['body']);
$result = new StdClass;
if($response->error_code != 0){
$result->status = false;
}else{
$result->status = true;
}
$result->msg = $response->error_msg;
$result->kw = $kw;
return $result;
}
public function multisign(){
$forum_list = $this->getFavForums();
$result = array();
foreach($forum_list as $forum){
$forum = (array)$forum;
$kw = $forum['name'];
$result[] = $this->sign($kw);
}
return $result;
}
public function getFavForums(){
$data = array('tbs'=>$this->getTbs());
//$response = Requests::get(self::FAV_URL."?".$this->encrypt($data), $this->_headers);
$response = wp_remote_get(self::FAV_URL."?".$this->encrypt($data), ["headers"=>$this->_headers]);
$response = (array)json_decode($response['body']);
return $response['forum_list'];
}
public function encrypt($s){
ksort($s);
$a = '';
$b ='';
foreach($s as $j=>$i){
$a.=$j.'='.$i;
$b.=$j.'='.urlencode($i).'&';
};
$a=strtoupper(md5($a.'tiebaclient!!!'));
return $b.'sign='.$a;
}
}
?>