亚洲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]代碼
<?php
//使用時必須先配置
//$cookiefile(COOKIE 存放路徑)
//$user(用戶名,優(yōu)酷土豆來瘋都行)
//$pass(密碼,優(yōu)酷土豆來瘋都行);
class laifeng
{
//cookie存放路徑
private $cookiefile = "cookie.txt";
//房間號
private $id;
//用戶名
private $user='1234@qq.com';
//密碼
private $pass=12345678;
//初始化ID
public function __construct($idd=null){
$this->id=$idd;
}
//模擬登錄獲取yktk
public function getkey()
{
$user=urldecode($this->user);
$pass=urldecode(md5($this->pass));
$url = "http://www.laifeng.com/login/";
$data = "userName=".$user."&password=".$pass."&forever=1&returnurl=http%3a%2f%2fwww.laifeng.com%2f7437";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile);
curl_setopt($ch, CURLOPT_REFERER, "http://www.laifeng.com/login/");
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
$info = curl_exec($ch);
curl_close($ch);
$y = json_decode($info, true);
$yktk = $y['response'];
return $yktk;
}
//獲取cookie
private function login(){
$yktk=$this->getkey();
if($yktk['code']!=0){
echo $yktk['msg'];
exit();
}else{
$url=$yktk['data'];
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,"http://www.laifeng.com/".$this->id);
curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiefile);
curl_exec($ch);
curl_close($ch);
echo("<script>location.reload();</script>");
return $yktk['msg'];
//echo $y[1];
}
}
//輸出頁面
public function curl(){
$this->login();
$url="http://www.laifeng.com/".$this->id;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,"http://www.laifeng.com/".$this->id);
curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiefile);
$info=curl_exec($ch);
$info=str_replace('room/js','http://static.youku.com/ddshow/8125f00c/room/js',$info);
curl_close($ch);
return $info;
}
//獲取用戶名
public function top(){
$url="http://www.laifeng.com";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,"http://www.laifeng.com/");
curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile);
$m=curl_exec($ch);
curl_close($ch);
$mate="@<a class=\"user-name-link\" href=\"/my/profile/init\" target=\"_blank\" title=\"(.*)\">@iUs";
preg_match_all($mate,$m,$arr);
if(@$arr[1][0]){
echo $arr[1][0];
}else{
echo("<script>alert('登錄超時,正在嘗試自動登錄.....');</script>");
echo $this->login();
}
}
//發(fā)送信息模板
public function msg($msg,$url){
//$url="http://www.laifeng.com/room/7437/chat/save";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,"http://www.laifeng.com/".$this->id);
curl_setopt($ch,CURLOPT_POSTFIELDS,$msg);
curl_setopt($ch,CURLOPT_COOKIEFILE,$this->cookiefile);
$info=curl_exec($ch);
curl_close($ch);
$arr=json_decode($info,true);
if($arr['response']['code']==-2){
echo("<script>alert('登錄超時,正在嘗試自動登錄.....');</script>");
echo $this->login();
}else{
echo $arr['response']['msg'];
}
}
//發(fā)送文字 參數(shù)為發(fā)送內(nèi)容
public function msgtxt($data){
$msg="single=0&content=".urlencode($data)."&anchorId=0&roomId=".$this->id;
$url="http://www.laifeng.com/room/".$this->id."/chat/save";
return $this->msg($msg,$url);
}
//送花 參數(shù)為數(shù)量
public function flower($data=1){
$msg="roomId=".$this->id."&quantity=".$data;
$url="http://www.laifeng.com/room/".$this->id."/star/send";
return $this->msg($msg,$url);
}
//抓取正在直播的ID
}//laifeng class
class exe{
//抓取房間ID
public function anchor($pageid=1){
$page=file_get_contents("http://www.laifeng.com/anchor/search?pageNo=".$pageid);
//$count=file_get_contents("http://www.laifeng.com/anchor/search");
$mage="@<p class=\"name\">(.*)<a href=\"/(.*)\" title=\"(.*)\" target=\"_blank\">(.*)</a>@iUs";
$match="@//總頁數(shù)(.*)totalNum:(.*),(.*)//當前頁數(shù)@iUs";
preg_match_all($mage,$page,$arr);
preg_match_all($match,$page,$pagecount);
$page=array();
$page['count']=$pagecount[2][0];
$page['data']=$arr[2];
return $page;
}
//抓取房間總頁數(shù)
public function pagecount(){
$page=file_get_contents("http://www.laifeng.com/anchor/search");
$match="@//總頁數(shù)(.*)totalNum:(.*),(.*)//當前頁數(shù)@iUs";
preg_match_all($match,$page,$arr);
echo $arr[2][0];
}
}
//$exe=new exe();
//$exe->pagecount();
//$arr=$exe->anchor(1);
//foreach($arr as $k=>$v){
// $lai=new laifeng($v);
// echo"房間ID:".$v." ";
// echo $lai->msgtxt('嗨');
// echo"<br />";
//}
//echo $lai->msgtxt("這是一段測試文字1234");
//for($i=7437;$i<=7439;$i++){
// $lai=new laifeng($i);
// echo $lai->msgtxt("1111");
//}
1.jpg
(244.62 KB, 下載次數(shù): 100)
下載附件
2015-07-09 11:11 上傳
//$lai->flower(1);
//echo $lai->curl();
?>
復制代碼
作者:
reb00t
時間:
2015-07-10 09:49
贊!
作者:
renxiao2003
時間:
2015-07-10 09:56
不錯。樓主從哪整來的源碼。
歡迎光臨 Chinaunix (http://72891.cn/)
Powered by Discuz! X3.2