轻松将你的账号打造成类似豌豆荚的聊天机器人(一)

源码来自Giuem:贴吧聊天机器人php源码(类似豌豆荚吧)

轻松将你的账号打造成类似豌豆荚的聊天机器人(一)-极客公园

想不想让你的账号也能和豌豆荚那样自动回复@自己的人,不再冷落@自己的人

源代码

 <html lang="zh-cn"><head><meta charset="utf-8">
<!--源码来自www.giuem.com-->
<?php
/**
*Author:Giuem
*Blog:http://www.giuem.com/
*Version: Alpha 0.0.1
*/
$bduss="填写你的BDUSS";//编辑你的BDUSS
$id=" @无法诉说的吟荡 ";//机器人的id,例 @xxxx
/*=======================以下内容禁止编辑============================ */
$tbs=$tbs=json_decode(url_get("http://tieba.baidu.com/dc/common/tbs","","BDUSS=".$bduss))->tbs;

function url_get($url,$POSTcontent="",$cookie=""){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    if ($POSTcontent!=""){curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTcontent);}
    if ($cookie!=""){curl_setopt($ch, CURLOPT_COOKIE,$cookie);}
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
function getData(){ //re[1]回复 re[2]@
    global $bduss;
    $re = url_get("http://wapp.baidu.com/","","BDUSS=".$bduss);
    echo base64_decode('PGEgaHJlZj0iaHR0cDovL3d3dy5naXVlbS5jb20iPkdpdWVtJ3MgQmxvZzwvYT48YnI+');
    preg_match_all("/回复我的((d+)).*?@我的((d+))/",$re,$re);
    return $re;
}
function getAtData(){
    global $bduss;
    $header = array ("Content-Type: application/x-www-form-urlencoded");
    $data=array("BDUSS=".$bduss,"_client_id=wappc_1396611108603_817","_client_type=2","_client_version=6.1.2","_phone_imei=642b43b58d21b7a5814e1fd41b08e2a6","from=tieba","net_type=3","pn=1");
    $data=implode("&", $data)."&sign=".md5(implode("", $data)."tiebaclient!!!");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://c.tieba.baidu.com/c/u/feed/atme");
    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 = json_decode(curl_exec($ch));
    curl_close($ch);
    return $re;
}
function reply($tid="",$pid="",$content="",$kw=""){
    global $tbs , $bduss;
    $fid=json_decode(file_get_contents("http://tieba.baidu.com/sign/info?kw=$kw&ie=utf-8"))->data->forum_info->forum_info->forum_id;
    $header = array ("Content-Type: application/x-www-form-urlencoded");
    $data=array("BDUSS=".$bduss,"_client_id=wappc_1396611108603_817","_client_type=2","_client_version=6.1.2","_phone_imei=642b43b58d21b7a5814e1fd41b08e2a6","anonymous=0","content=".$content,"fid=".$fid,"from=tieba","kw=".$kw,"net_type=3","quote_id=".$pid,"tbs=".$tbs,"tid=".$tid);
    $data=implode("&", $data)."&sign=".md5(implode("", $data)."tiebaclient!!!");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://c.tieba.baidu.com/c/c/post/add");
    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 = json_decode(curl_exec($ch));
    curl_close($ch);
    if($re->error_code == 0){
        return "回帖成功";
    }else{
        return $re->error_msg;
    }
}
function talk($content) {
    $re=file_get_contents("http://rmbz.net/Api/AiTalk.aspx?key=rmbznet&word=".$content);
    $re=json_decode($re)->content;
    return $re;
}
$array_num=getData();
$at_num=$array_num[2][0];
echo "@数目:".$at_num."<br>";
for($i=0;$i<$at_num;$i++){
    $re=getAtData()->at_list;
    $re_content=$re[$i]->content;
    if(str_replace(" ","",$re_content) !== $id){$re_content=str_replace($id," ",$re_content);}
    $content=talk($re_content);
    $result=reply($re[$i]->thread_id,$re[$i]->post_id,$content,$re[$i]->fname);
    echo "贴吧:".$re[$i]->fname.",贴号:".$re[$i]->thread_id.",回复内容:{$content},{$result}<br>";
    sleep(5);
}
?>

编辑代码必须用UTF-8编码方式


使用方法

请戳链接君→_→
和这个基本一样,可以看这个,照着来就是了


使用注意

本代码目前处于测试阶段,不太稳定,也不太智能,只能做到基本的回复而已,别当真。

代码下载

代码下载


-- 完 --

发表评论

电子邮件地址不会被公开。 必填项已用*标注

16 Replies to “轻松将你的账号打造成类似豌豆荚的聊天机器人(一)”