亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: 優(yōu)酷來瘋直播間模擬登錄群發(fā)信息 [打印本頁]

作者: gjfer    時間: 2015-07-09 11:11
標題: 優(yōu)酷來瘋直播間模擬登錄群發(fā)信息
來瘋直播間模擬登錄,抓取正在直播的房間ID并群發(fā)信息,來瘋首頁http://www.laifeng.com/,代碼注釋每個方法前都寫的很清楚,我想這么幾行代碼沒辦要每行都加注釋吧?請大家注意口德
最底行有DEMO下載地址

[PHP]代碼
  1. <?php

  2. //使用時必須先配置
  3. //$cookiefile(COOKIE 存放路徑)
  4. //$user(用戶名,優(yōu)酷土豆來瘋都行)
  5. //$pass(密碼,優(yōu)酷土豆來瘋都行);

  6. class laifeng

  7. {

  8.     //cookie存放路徑

  9.     private $cookiefile = "cookie.txt";

  10.     //房間號

  11.     private $id;

  12.     //用戶名

  13.     private $user='1234@qq.com';

  14.     //密碼

  15.     private $pass=12345678;

  16.     //初始化ID

  17.     public function __construct($idd=null){

  18.         $this->id=$idd;

  19.     }

  20.     //模擬登錄獲取yktk

  21.     public function getkey()

  22.     {

  23.         $user=urldecode($this->user);

  24.         $pass=urldecode(md5($this->pass));

  25.         $url = "http://www.laifeng.com/login/";

  26.         $data = "userName=".$user."&password=".$pass."&forever=1&returnurl=http%3a%2f%2fwww.laifeng.com%2f7437";

  27.         $ch = curl_init();

  28.         curl_setopt($ch, CURLOPT_URL, $url);

  29.         curl_setopt($ch, CURLOPT_HEADER, 0);

  30.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  31.         curl_setopt($ch, CURLOPT_POST, 1);

  32.         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

  33.         curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiefile);

  34.         curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile);

  35.         curl_setopt($ch, CURLOPT_REFERER, "http://www.laifeng.com/login/");

  36.         curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");

  37.         $info = curl_exec($ch);

  38.         curl_close($ch);

  39.         $y = json_decode($info, true);

  40.         $yktk = $y['response'];

  41.         return $yktk;

  42.     }

  43.     //獲取cookie

  44.     private function login(){

  45.         $yktk=$this->getkey();

  46.         if($yktk['code']!=0){

  47.             echo $yktk['msg'];

  48.             exit();

  49.         }else{

  50.             $url=$yktk['data'];

  51.             $ch=curl_init();

  52.             curl_setopt($ch,CURLOPT_URL,$url);

  53.             curl_setopt($ch,CURLOPT_HEADER,1);

  54.             curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile);

  55.             curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

  56.             curl_setopt($ch,CURLOPT_REFERER,"http://www.laifeng.com/".$this->id);

  57.             curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiefile);

  58.             curl_exec($ch);

  59.             curl_close($ch);

  60.             echo("<script>location.reload();</script>");

  61.             return $yktk['msg'];

  62.             //echo $y[1];

  63.         }

  64.     }

  65.     //輸出頁面

  66.     public function curl(){

  67.         $this->login();

  68.         $url="http://www.laifeng.com/".$this->id;

  69.         $ch=curl_init();

  70.         curl_setopt($ch,CURLOPT_URL,$url);

  71.         curl_setopt($ch,CURLOPT_HEADER,0);

  72.         curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile);

  73.         curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

  74.         curl_setopt($ch,CURLOPT_REFERER,"http://www.laifeng.com/".$this->id);

  75.         curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiefile);

  76.         $info=curl_exec($ch);

  77.         $info=str_replace('room/js','http://static.youku.com/ddshow/8125f00c/room/js',$info);

  78.         curl_close($ch);

  79.         return $info;

  80.     }

  81.      

  82.     //獲取用戶名

  83.     public function top(){

  84.         $url="http://www.laifeng.com";

  85.         $ch=curl_init();

  86.         curl_setopt($ch,CURLOPT_URL,$url);

  87.         curl_setopt($ch,CURLOPT_HEADER,1);

  88.         curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

  89.         curl_setopt($ch,CURLOPT_REFERER,"http://www.laifeng.com/");

  90.         curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile);

  91.         $m=curl_exec($ch);

  92.         curl_close($ch);

  93.         $mate="@<a class=\"user-name-link\" href=\"/my/profile/init\" target=\"_blank\" title=\"(.*)\">@iUs";

  94.         preg_match_all($mate,$m,$arr);

  95.         if(@$arr[1][0]){

  96.             echo $arr[1][0];

  97.         }else{

  98.             echo("<script>alert('登錄超時,正在嘗試自動登錄.....');</script>");

  99.             echo $this->login();

  100.         }

  101.          

  102.     }

  103.     //發(fā)送信息模板

  104.     public function msg($msg,$url){

  105.         //$url="http://www.laifeng.com/room/7437/chat/save";

  106.         $ch=curl_init();

  107.         curl_setopt($ch,CURLOPT_URL,$url);

  108.         curl_setopt($ch,CURLOPT_HEADER,0);

  109.         curl_setopt($ch,CURLOPT_POST,1);

  110.         curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

  111.         curl_setopt($ch,CURLOPT_REFERER,"http://www.laifeng.com/".$this->id);

  112.         curl_setopt($ch,CURLOPT_POSTFIELDS,$msg);

  113.         curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile);

  114.         $info=curl_exec($ch);

  115.         curl_close($ch);

  116.         $arr=json_decode($info,true);

  117.         if($arr['response']['code']==-2){

  118.             echo("<script>alert('登錄超時,正在嘗試自動登錄.....');</script>");

  119.             echo $this->login();

  120.         }else{

  121.           echo $arr['response']['msg'];  

  122.         }

  123.     }

  124.     //發(fā)送文字 參數(shù)為發(fā)送內(nèi)容

  125.     public function msgtxt($data){

  126.         $msg="single=0&content=".urlencode($data)."&anchorId=0&roomId=".$this->id;

  127.         $url="http://www.laifeng.com/room/".$this->id."/chat/save";

  128.         return $this->msg($msg,$url);

  129.     }

  130.      

  131.     //送花  參數(shù)為數(shù)量

  132.     public function flower($data=1){

  133.         $msg="roomId=".$this->id."&quantity=".$data;

  134.         $url="http://www.laifeng.com/room/".$this->id."/star/send";

  135.         return $this->msg($msg,$url);

  136.     }

  137.     //抓取正在直播的ID

  138.      

  139. }//laifeng class

  140. class exe{

  141.     //抓取房間ID

  142.     public function anchor($pageid=1){

  143.         $page=file_get_contents("http://www.laifeng.com/anchor/search?pageNo=".$pageid);

  144.         //$count=file_get_contents("http://www.laifeng.com/anchor/search");

  145.         $mage="@<p class=\"name\">(.*)<a href=\"/(.*)\" title=\"(.*)\" target=\"_blank\">(.*)</a>@iUs";

  146.         $match="@//總頁數(shù)(.*)totalNum:(.*),(.*)//當前頁數(shù)@iUs";

  147.         preg_match_all($mage,$page,$arr);

  148.         preg_match_all($match,$page,$pagecount);

  149.         $page=array();

  150.         $page['count']=$pagecount[2][0];

  151.         $page['data']=$arr[2];

  152.         return $page;

  153.     }

  154.     //抓取房間總頁數(shù)

  155.     public function pagecount(){

  156.         $page=file_get_contents("http://www.laifeng.com/anchor/search");

  157.         $match="@//總頁數(shù)(.*)totalNum:(.*),(.*)//當前頁數(shù)@iUs";

  158.         preg_match_all($match,$page,$arr);

  159.         echo $arr[2][0];

  160.     }

  161. }

  162. //$exe=new exe();

  163. //$exe->pagecount();

  164. //$arr=$exe->anchor(1);

  165. //foreach($arr as $k=>$v){

  166. //    $lai=new laifeng($v);

  167. //    echo"房間ID:".$v."&nbsp;";

  168. //    echo $lai->msgtxt('嗨');

  169. //    echo"<br />";

  170. //}



  171. //echo $lai->msgtxt("這是一段測試文字1234");

  172. //for($i=7437;$i<=7439;$i++){

  173. //    $lai=new laifeng($i);

  174. //   echo $lai->msgtxt("1111");

  175. //}



  176. //$lai->flower(1);

  177. //echo $lai->curl();

  178. ?>
復制代碼

作者: reb00t    時間: 2015-07-10 09:49
贊!
作者: renxiao2003    時間: 2015-07-10 09:56
不錯。樓主從哪整來的源碼。




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2