This article mainly introduces PHP's methods for implementing automatic reply in the QQ space. It involves php's skills for calling an automatic reply Interface Based on curl. It has some reference value. For more information, see
This article mainly introduces PHP's methods for implementing automatic reply in the QQ space. It involves php's skills for calling an automatic reply Interface Based on curl. It has some reference value. For more information, see
<? Php header ("Content-type: text/html; charset = UTF-8"); $ qq = ''; // qq No. $ sid = ''; // enter the sid value $ con = ''; // custom content. If it is left empty, simsimi $ qzone = new qzone ($ qq, $ sid) is used ); 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. comcurl_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> :(. *?) Comments \ (\ d \) <\/a>/', $ html, $ match); foreach ($ match [0] as $ k) {if (strstr ($ k, 'comment (0) ') {$ k = str_replace (PHP_EOL, '', $ k); $ k = str_replace ('', '', $ k); $ k = html_entity_decode ($ k); preg_match ('/<\/a> :(. *?) /', $ K, $ content); // www. oicqzone. compreg_match ('/myfeed_mood.jsp \? Sid =. * & B _(.*?) & T1_source/', $ k, $ data); $ content = preg_replace ('/] +>/', '', $ content [1]); echo :'. $ content. 'Robot reply: '; $ data =' B _'. $ data [1]; $ content = talk ($ content); echo $ content.'
'; $ 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= Comment ', $ 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; }?>