首先说明下,代码非原创,已经保留版权。这是博猪浏览某博客时发现的,感觉蛮不错的,所以分享出来咯~

[callout class="danger" title=""]代码[/callout]

"; }else{ echo "帖子加精:{$thread['tid']}失败
";} break ; }elseif($thread['abstract']){ if(check_ad($thread['abstract'][0]['text'])){if(del_thread($kw,$fid,$thread['tid'])) {echo "删除帖子:{$thread['tid']}成功
"; }else{ echo "删除帖子:{$thread['tid']}失败
";}} } } function get_forum(){ global $kw; $data=array( '_client_id=wappc_1396611108603_817', '_client_type=2', '_client_version=5.7.0', '_phone_imei=642b43b58d21b7a5814e1fd41b08e2a6', 'from=tieba', "kw={$kw}", 'pn=1', 'q_type=2', 'rn=30', 'with_group=1'); $data=implode('&', $data).'&sign='.md5(implode('', $data).'tiebaclient!!!'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://c.tieba.baidu.com/c/f/frs/page'); curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/x-www-form-urlencoded')); 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 = json_decode(curl_exec($ch),true); curl_close($ch); return $re; } function get_tbs(){ global $bduss; $re=json_decode(fetch('http://tieba.baidu.com/dc/common/tbs','BDUSS='.$bduss),true); return $re['tbs']; } function fetch($url,$cookie=null,$postdata=null){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); if (!is_null($postdata)) curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata); if (!is_null($cookie)) curl_setopt($ch, CURLOPT_COOKIE,$cookie); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $re = curl_exec($ch); curl_close($ch); return $re; } function check_ad($content){ global $keywords; $preg = '/'.addslashes($keywords).'/i'; $res = preg_match($preg,$content); return $res; } function del_thread($kw,$fid,$tid){ global $bduss; $data = 'commit_fr=pb&ie=utf-8&tbs='.get_tbs()."&kw={$kw}&fid={$fid}&tid={$tid}"; $re = json_decode(fetch('http://tieba.baidu.com/f/commit/thread/good/add','BDUSS='.$bduss,$data),true); $re = json_decode(fetch('http://tieba.baidu.com/f/commit/thread/top/add','BDUSS='.$bduss,$data),true); return $re['no']==0; }

[callout class="warning" title=""]使用事项[/callout]
因为代码只是粗略的添加一下,暂时只能匹配帖子标题,在我的设计里面是匹配帖子作者然后再匹配帖子标题关键词进行加精置顶操作的,所以暂时是不完善的。