php实现在百度贴吧回帖

mengkun 3.2K 0

上篇博文博主提到要做一个百度贴吧抢楼器,并且已经实现了获取指定帖子楼层的功能。这篇继续~

要达到抢楼的目的,最最关键的一步就是实现自动回复。

下面就给出利用PHP在百度贴吧回帖的代码

 

  1. <?php
  2. //注:本代码来源网络,原作者不详
  3. $content="";//你要回复的内容,如要换行请用\n,如要用图片请按照这个格式 #(pic,2b8806e93901213f3c8b371655e736d12d2e95dc,442,614) 表情是这个格式 #(滑稽)
  4. $bduss="";  //你的bduss
  5. $tid="";//你要回复贴子的tid
  6. header("content-Type: text/html; charset=Utf-8");
  7. function curl_post($pda,$url){
  8.     $header = array ("Content-Type: application/x-www-form-urlencoded");
  9.     $data=implode("&"$pda)."&sign=".md5(implode(""$pda)."tiebaclient!!!");
  10.     $ch = curl_init();
  11.     curl_setopt($ch, CURLOPT_URL, $url);
  12.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  13.     curl_setopt($ch, CURLOPT_HEADER, 0);
  14.     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  15.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  16.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  17.     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  18.     $re = json_decode(curl_exec($ch));
  19.     curl_close($ch);
  20.     return $re;
  21. }
  22. function rand_int($l) { //生成指定位数的随机数
  23.     $int = null;
  24.     for ($e=0; $e < $l$e++) {
  25.         $int .= mt_rand(0,9);
  26.     }
  27.     return $int;
  28. }
  29. function getPage(){
  30.     global $bduss,$tid;
  31.     $pd=array(
  32.         "BDUSS=".$bduss,
  33.         "_client_id=wappc_136" . rand_int(10) . "_" . rand_int(3),
  34.         "_client_type=".mt_rand(1,4),
  35.         "_client_version=5.0.0",
  36.         "_phone_imei=".md5(rand_int(16)),
  37.         "back=0",
  38.         "kz=".$tid,
  39.         "net_type=3",
  40.         "pn=1",
  41.         "rn=2",
  42.         "with_floor=1",
  43.     );
  44.     $gd=curl_post($pd,'http://c.tieba.baidu.com/c/f/pb/page');
  45.     if($gd->error_code!=0)exit('发生错误:'.$gd->error_msg.'<br>');
  46.     $tbs=$gd->anti->tbs;
  47.     $fid=$gd->forum->id;
  48.     $kw=$gd->forum->name;
  49.     $title=$gd->thread->title;
  50.     return replyPost($kw,$tbs,$fid,$title);
  51. }
  52. function replyPost($kw,$tbs,$fid,$title){
  53.     global $bduss,$tid,$content;
  54.     $pd=array(
  55.         "BDUSS=".$bduss,
  56.         "_client_id=wappc_136" . rand_int(10) . "_" . rand_int(3),
  57.         "_client_type=".mt_rand(1,4),   //设备标识,1-iPhone,2-Android,3-Windows Phone,4-Windows 8
  58.         "_client_version=5.0.0",
  59.         "_phone_imei=".md5(rand_int(16)),
  60.         'anonymous=0',
  61.         'content='.$content,
  62.         'fid='.$fid,
  63.         //'is_ad=0',
  64.         "kw=".$kw,
  65.         "net_type=3",
  66.         'tbs='.$tbs,
  67.         'tid='.$tid,
  68.         'title='
  69.     );
  70.     $gd=curl_post($pd,'http://c.tieba.baidu.com/c/c/post/add');
  71.     if($gd->error_code!=0)exit($kw.'吧|'.$title.'|发生错误:'.$gd->error_msg.'<br>');
  72.     echo $kw.'吧|'.$title.'|回复成功<br>';
  73. }
  74. getPage();
  75. ?>

注:BDUSS可在这里获取☞http://tool.mkblog.cn/BDUSS/

 

发表评论 取消回复
表情 图片 链接 代码

分享