PHP實(shí)現(xiàn)QQ空間自動(dòng)回復(fù)說(shuō)說(shuō)的方法
本文實(shí)例講述了PHP實(shí)現(xiàn)QQ空間自動(dòng)回復(fù)說(shuō)說(shuō)的方法。分享給大家供大家參考,具體如下:
<?php
header("Content-type: text/html; charset=utf-8");
$qq = '';//QQ號(hào)
$sid = '';//填寫sid的值
$con = '';//自定義內(nèi)容,留空則使用simsimi
$qzone = new qzone($qq,$sid);
class qzone{
private $sid ='';
public function __construct($qq,$sid){
$this->sid = $sid;
$url = "http://ish.z.qq.com/infocenter_v2.jsp?B_UID={$qq}&sid={$sid}&g_ut=2";
$re = $this->fetch($url);
$this->getsaying($re);
}
private function fetch($url,$postdata=null){
$ch = curl_init();//www.oicqzone.com
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 820)");
if($postdata!=null) curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$re = curl_exec($ch);
curl_close($ch);
return $re;
}
private function getsaying($html){
preg_match_all('/<\/a>:(.*?)評(píng)論\(\d\)<\/a>/',$html,$match);
foreach($match[0] as $k){
if(strstr($k,'評(píng)論(0)')){
$k = str_replace(PHP_EOL, '', $k);
$k = str_replace(' ', '', $k);
$k = html_entity_decode($k);
preg_match('/<\/a>:(.*?)<span class="txt-fade">/',$k,$content);//www.oicqzone.com
preg_match('/myfeed_mood.jsp\?sid=.*&B_(.*?)&t1_source/',$k,$data);
$content = preg_replace('/<img[^>]+>/', '', $content[1]);
echo '找到一條說(shuō)說(shuō):'.$content.' 機(jī)器人的回復(fù)是:';
$data = 'B_'.$data[1];
$content = talk($content);
echo $content.'<br />';
$this->postcomment($content,$data);
sleep(3);
}
}
}
private function postcomment($content,$data){
$postdata = "content={$content}&{$data}&t1_source=1&feedcenter_pn=1&flag=1&type=all&channel=0&back=false&offset=0&ic=false&dl=null&to_tweet=0&submit=%E8%AF%84%E8%AE%BA";
$this->fetch("http://blog30.z.qq.com/mood/mood_reply.jsp?sid={$this->sid}&g_ut=2",$postdata);
}
}
function talk($content){
global $con;
if($con) return $con;
$content = str_replace(' ', '', $content);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'http://www.simsimi.com/talk.htm');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER,1);
curl_setopt($ch, CURLOPT_NOBODY, false);
$rs = curl_exec($ch);
preg_match_all('/Set-Cookie: (.+)=(.+)$/m', $rs, $regs);
foreach($regs[1] as $i=>$k);
$cc=str_replace(' Path','' ,$k);
$cc='simsimi_uid=507454034223;'.$cc;
$re = HTTPClient('http://www.simsimi.com/func/reqN?lc=ch&ft=1.0&req='.$content.'&fl=http%3A%2F%2Fwww.simsimi.com%2Ftalk.htm',$cc);
$re = json_decode($re,true);
return $re['sentence_resp'];
}
function HTTPClient($url,$cookie){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIE,$cookie);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$re = curl_exec($ch);
curl_close($ch);
return $re;
}
?>
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- php簡(jiǎn)單的留言板與回復(fù)功能具體實(shí)現(xiàn)
- ThinkPHP無(wú)限級(jí)分類原理實(shí)現(xiàn)留言與回復(fù)功能實(shí)例
- PHP微信開(kāi)發(fā)之文本自動(dòng)回復(fù)
- 微信公眾號(hào)開(kāi)發(fā)之文本消息自動(dòng)回復(fù)php代碼
- PHP微信開(kāi)發(fā)之模板消息回復(fù)
- php版微信開(kāi)發(fā)之接收消息,自動(dòng)判斷及回復(fù)相應(yīng)消息的方法
- PHP微信開(kāi)發(fā)之微信消息自動(dòng)回復(fù)下所遇到的坑
- 驗(yàn)證token、回復(fù)圖文\文本、推送消息的實(shí)用微信類php代碼
- php版微信公眾平臺(tái)回復(fù)中文出現(xiàn)亂碼問(wèn)題的解決方法
- php微信公眾號(hào)開(kāi)發(fā)(4)php實(shí)現(xiàn)自定義關(guān)鍵字回復(fù)
相關(guān)文章
PHP中empty,isset,is_null用法和區(qū)別
最近在閱讀項(xiàng)目的源碼,發(fā)現(xiàn)源碼中就對(duì)empty、isset和is_null函數(shù)(語(yǔ)言特性)亂用,有的地方很明顯的就挖坑了。不能正確的去理解這些東西,就很可能給后續(xù)的開(kāi)發(fā)挖坑了。2017-02-02
PHP中實(shí)現(xiàn)Bloom Filter算法
這篇文章主要介紹了PHP中實(shí)現(xiàn)Bloom Filter算法,本文直接給出實(shí)現(xiàn)代碼,代碼中給出詳細(xì)注釋,Bloom Filter算法介紹等內(nèi)容,需要的朋友可以參考下2015-03-03
php中g(shù)et_cfg_var()和ini_get()的用法及區(qū)別
這篇文章主要介紹了php中g(shù)et_cfg_var()和ini_get()的用法及區(qū)別,實(shí)例分析了get_cfg_var()和ini_get()函數(shù)的區(qū)別與使用技巧,需要的朋友可以參考下2015-03-03
簡(jiǎn)單的過(guò)濾字符串中的HTML標(biāo)記
簡(jiǎn)單的過(guò)濾字符串中的HTML標(biāo)記...2006-12-12
PHP數(shù)組生成XML格式數(shù)據(jù)的封裝類實(shí)例
這篇文章主要介紹了PHP數(shù)組生成XML格式數(shù)據(jù)的封裝類,結(jié)合完整實(shí)例形式分析了php針對(duì)數(shù)組的遞歸遍歷與XML格式數(shù)據(jù)轉(zhuǎn)換的相關(guān)操作技巧,需要的朋友可以參考下2016-11-11
php中simplexml_load_file函數(shù)用法實(shí)例
這篇文章主要介紹了php中simplexml_load_file函數(shù)用法,以實(shí)例形式詳細(xì)的講述了simplexml_load_file函數(shù)讀取XML文件的具體方法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-11-11

