Last active
February 6, 2017 18:15
-
-
Save lizheming/4368496 to your computer and use it in GitHub Desktop.
虾米自动签到
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
curl_setopt($curl, CURLOPT_COOKIEJAR, $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"); | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); | |
curl_exec($curl); | |
echo '<pre>'; | |
print_r(curl_getinfo($curl, CURLINFO_HEADER_OUT)); | |
echo '</pre>'; | |
curl_close($curl); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这个代码一用就用到2015年,特地跑来感谢下……