-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.php
71 lines (70 loc) · 2.46 KB
/
function.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
<?php
function curl_get($url,$bduss,$ua=false){
$cookie="BDUSS=$bduss";
$ch=curl_init($url);
if ($ua){
curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: bdtb for Android 6.8.3'));
}else{
curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0','Connection:keep-alive','Referer:http://wapp.baidu.com/'));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIE,$cookie);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
function curl_post($pda,$url="http://c.tieba.baidu.com/c/c/forum/sign"){
$header = array(
'Content-Type: application/x-www-form-urlencoded',
'User-Agent: bdtb for Android 6.8.3',
);
$p = array (
'_client_id' => 'wappc_1468200240475_882',
'_client_type' => '2',
'_client_version' => '6.8.3',
'_phone_imei' => '140706193242534',
'cuid' => strtoupper(md5('123')).'|0',
'from' => '1316a',
'model' => 'NX503A',
'stErrorNums' => '1',
'stMethod' => '1',
'stMode' => '1',
'stTime' => '442',
'stTimesNum' => '1',
'timestamp' => time().'123',
);
$pda = array_merge($p,$pda);
ksort($pda);
foreach($pda as $k => $v){
$u[] = $k.'='.urlencode($v);
$s[] = $k.'='.$v;
}
$data = implode("&", $u)."&sign=".md5(implode("", $s)."tiebaclient!!!");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$re = curl_exec($ch);
curl_close($ch);
return $re;
}
function testcookie($cookie){
preg_match('/BDUSS=(.+?);/', $cookie, $matches);
if(!$matches[1]) exit('{"msg":"cooike错误,未提交","no":1}');
$islogin = "http://tieba.baidu.com/dc/common/tbs?t=".time();
$check = json_decode(curl_get($islogin,$matches[1]));
if (!$check->is_login){
echo '{"msg":"cooike错误,未提交","no":1}';
exit();
}
$mylikeurl="http://c.tieba.baidu.com/c/f/forum/like";
$pda = array('BDUSS' => $matches[1]);
$result = curl_post($pda,$mylikeurl);
$jsonobj = json_decode($result,1);
$i = count($jsonobj['forum_list']['non-gconforum'])+count($jsonobj['forum_list']['gconforum']);
return $i;
}