百度贴吧自动签到.php
用PHP写的,签到部分参考了从网上搜索到的源码(不过现在也找不到那个原网站了...如果有人知道的话提醒一下)
set_time_limit(7200);
include('config.php');
$today=date("Ymd",time());
$tiebalist=mysql_query("SELECT name,sign FROM tiebasign");
$tblist=Array();
while ($row=mysql_fetch_array($tiebalist)){
$tblist[$row['name']]=$row['sign'];
}
function curl_get($url,$ua=false){
global $cookie;
$ch=curl_init($url);
if ($ua){
curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent:Mozilla/5.0 (Linux; U; Android 2.3.4; zh-cn; W806 Build/GRJ22) AppleWebKit/530.17 (KHTML, like Gecko) FlyFlow/2.4 Version/4.0 Mobile Safari/530.17 baidubrowser/042_1.8.4.2_diordna_008_084/AIDIVN_01_4.3.2_608W/1000591a/9B673AC85965A58761CF435A48076629%7C880249110567268/1'));
}
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_TIMEOUT,5);
curl_setopt($ch,CURLOPT_COOKIE,$cookie);
$get_url = curl_exec($ch);
curl_close($ch);
return $get_url;
}
function sign(){
global $tblist,$today;
foreach ($tblist as $value => $sign){
if ($value == '' || $sign==$today){
continue;
}
$url = "http://wapp.baidu.com/f?kw={$value}";
$get_url = curl_get($url);
preg_match_all('/<td style="text-align:right;"><a href="(.*?)">签到<\/a>/', $get_url, $matches);
if (isset($matches[1][0])){
$s = str_replace('&', '&', $matches[1][0]);
$sign_url = 'http://tieba.baidu.com'.$s;
$get_sign = curl_get($sign_url,true);
if (strpos($get_sign, '经验')){
echo iconv("gb2312","utf-8//IGNORE",urldecode($value))."-签到成功<br/>";
}
mysql_query("UPDATE tiebasign SET sign='$today' WHERE name='$value'");
}elseif (stripos('502 Bad', $get_url)){
echo iconv("gb2312","utf-8//IGNORE",urldecode($value)).'-遇到错误<br/>';
}else{
echo iconv("gb2312","utf-8//IGNORE",urldecode($value))."-已经签到<br/>";
}
}
}
function getmylike(){
global $i,$cookie,$tblist,$new;
$page=1;
$bool=true;
$i=1;
$query='';
$new=0;
while ($bool){
$mylikeurl="http://tieba.baidu.com/f/like/mylike?&pn=$page";
$ch=curl_init($mylikeurl);
curl_setopt($ch,CURLOPT_URL,$mylikeurl);
curl_setopt($ch,CURLOPT_TIMEOUT,5);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_COOKIE,$cookie);
$result = curl_exec($ch);
curl_close($ch);
$pre_reg = '/f\?kw=(.*?)"/';
preg_match_all($pre_reg, $result, $matches);
$temp=$i;
foreach ($matches[1] as $key => $value) {
if (!array_key_exists($value,$tblist)){
$query.=($query?",":"")."('".$value."')";
$new++;
}else{
$tblist[$value]=0;
}
$i ++;
}
if ($temp<$i){
$page++;
}else{
$bool=false;
}
}
if ($query){
mysql_query("INSERT INTO tiebasign (name)VALUES".$query);
}
return $kw_name;
}
getmylike();
echo "获取结束,一共[ $i ]个贴吧<br/>新增了[ $new ]个贴吧<br />";
sign();
在config.php里面定义$cookie即可
然后里面关于query的部分,我在mysql里面建了一个tiebasign表,然后每天查这个表就可以知道哪些贴吧已经签到成功了.