微信模拟登陆php投票,PHP爬虫和微信自动投票

layout: post

title: "PHP爬虫和微信自动投票"

date: 2016-05-17 23:38:25 +0800

comments: true

categories: [php]

今天接触了PHP的模拟登陆和爬虫实战,涉及到了PHP获取远程文件的几种方式,防采集的一些方法,以及微信自动投票实战。

PHP获取远程文件

PHP获取远程文件主要有以下几种方式:

fopen

file_get_centents

socket

curl

过几天我们在结合实际代码分析这几种方式

防采集的一些方法

防采集的方法有很多,这里主要列出几种比较有效的

短时间访问次数限制

ip校验

机器特征校验

复杂加密

混淆代码

微信自动投票工具

这次主要分析这个。

http://wx.asplay.cn/index.php?

g=Wap&

m=Vote&

a=index& //ThinkPHP里面一些参数

token=jdfsam1432614294& //当前主用户标示

wecha_id=oQIrdjjmrAZXwKOh3Y6-1HeuwvEc&

id=27& //当前投票ID

sgssz=mp.weixin.qq.com

下面是请求的地址:

http://wx.asplay.cn/index.php?g=Wap&m=Vote&a=add_vote&token=jdfsam1432614294&wecha_id=oQIrdjjArAZYwKOh3Y6-1HeuwvEc

发送的数据:

wecha_id=oQIrdjjArAZYwKOh3Y6-1HeuwvEc&tid=27&chid=53%2C&token=jdfsam1432614294&action=add_vote、

投票成功返回的数据:

{"success":1,"token":"jdfsam1432614294","wecha_id":"oQIrdjjArAZYwKOh3Y6-1HeuwvEc","tid":"27","chid":"53","arrpre":{"53":33.33,"54":0,"55":0,"56":66.67}}

基于以上的这些信息,我们就能自己模拟POST的数据,和用户标示了。但是仅仅做到这些是不够的,我们还需要模拟微信的内核。

 
 

微信内核的ua://网上能找到

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.158888800.95 Safari/537.36 SE 2.X MetaSr 1.0

class curlajax{

public $cookiejar;

public $cookiefile;

public $ua;

public $debug;

function __construct(){

$this->debug = 0;

$this->ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.158888800.95 Safari/537.36 SE 2.X MetaSr 1.0'; //这里模拟微信内核

$this->cookiejar = 'cookie.txt';

$this->cookiefile = 'cookie.txt';

}

/****************************

*get 请求资源

*@param string 地址

*@param string referer

*@param boolen 是否返回头部

*@param array 头部附加cookie

****************************/

function httpget($url,$referer='',$withhead=0){

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);

curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiejar);

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

curl_setopt($ch,CURLOPT_HEADER,$withhead);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);

//curl_setopt($ch,CURLOPT_AUTOREFERER,1);

curl_setopt($ch,CURLOPT_USERAGENT,$this->ua);

curl_setopt($ch,CURLOPT_REFERER,$referer);

$r = curl_exec($ch);

if($this->debug){

echo '

';

var_dump(curl_getinfo($ch));

}

curl_close($ch);

return $r;

}

/****************************

*post 请求资源

*@param string 地址

*@param string referer

*@param array 提交数据

*@param boolen 是否返回头部

****************************/

function httppost($url,$referer='',$postdata=array(),$withhead=0){

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);

curl_setopt($ch,CURLOPT_HEADER,$withhead);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);

//curl_setopt($ch,CURLOPT_AUTOREFERER,1);

curl_setopt($ch,CURLOPT_COOKIEJAR,$this->cookiejar);

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

curl_setopt($ch,CURLOPT_USERAGENT,$this->ua);

curl_setopt($ch,CURLOPT_REFERER,$referer);

curl_setopt($ch,CURLOPT_POST,1);

curl_setopt($ch,CURLOPT_POSTFIELDS,$postdata);

$r = curl_exec($ch);

if($this->debug){

echo '

';

var_dump(curl_getinfo($ch));

}

curl_close($ch);

return $r;

}

}

网上的cURL方法,我们这里有要用到

require_once("../03/curlajax.class.php");

?>

微信自动投票工具

/*模拟POST登录*/

echo "

这是微信自动投票工具

";

$jkxy = new curlajax();

$jkxy->debug = 0;

$jkxy->cookiejar = dirname(__FILE__).'\cookie1.txt';

$jkxy->cookiefile = dirname(__FILE__).'\cookie1.txt';

/*模拟提交信息*/

$username="oQIrdjj".rand(500,50000)."wKOh3Y6-1HeuwvEc";//用随机数来产生不同的用户ID

$data = "wecha_id=".$username."&tid=27&chid=53%2C&token=jdfsam1432614294&action=add_vote";//模拟不同的用户提交的数据

$url = 'http://wx.asplay.cn/index.php?g=Wap&m=Vote&a=add_vote&token=jdfsam1432614294&wecha_id='.$username;

$r = $jkxy->httppost($url,$url,$data,0);//获取返回数据

if(checkstr($r,'"success":1')==true){ //根据返回的数据判断是否投票成功

echo "投票成功";

}

else{

echo "投票失败";

}

/****************************

*检查$needle中是否含有$findstr

*@param string needle

*@param string findstr

****************************/

function checkstr($needle,$findstr){

$tempstr=explode($findstr,$needle);

if($tempstr>1){

return true;

}

else{

return false;

}

}

?>

通过这个实战,感觉突然打开了一扇大门。要仔细研究下爬虫的相关知识了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值