Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
虾米自动签到php
<?php
set_time_limit(0);
/*输入账号密码*/
$name = '';
$password = '';
//获取登陆cookie
$curl_post = 'email='.$name.'&password='.$password.'&done=/&submit=登 录';
$cookie_file = dirname(__FILE__).'/cookie.txt';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.xiami.com/member/login");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file);
$result = curl_exec($curl);
curl_close($curl);
//获取手机版首页
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.xiami.com/web");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
$data = curl_exec($curl);
curl_close($curl);
//获取签到URL,如果已经签到则获取签到天数
$preg = '/\<a class\=\"check\_in\" href\=\"(.*?)\"\>每日签到\<\/a\>/s';
preg_match_all($preg, $data, $match);
if(!isset($match[1][0])) {
$preg = '/\<div class\=\"idh\"\>(已连续签到.*?天)\<\/div\>/s';
preg_match_all($preg, $data, $match);
die($match[1][0]);
}
//定义签到页面
$url = 'http://www.xiami.com' . $match[1][0];
//以上代码验证没有问题
//自动签到
$headers = array("Host: www.xiami.com", "Referer: http://www.xiami.com/web");
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url . '?a=b');
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_exec($curl);
curl_close($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment