Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lizheming
Last active February 6, 2017 18:15
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lizheming/4368496 to your computer and use it in GitHub Desktop.
Save lizheming/4368496 to your computer and use it in GitHub Desktop.
虾米自动签到
<?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);
?>
@Cufr
Copy link

Cufr commented Dec 27, 2012

这位大哥,这东西真有啊,求教下肿么用呢,还有…你密码暴露了 = =

@linkarys
Copy link

明显是测试账号嘛

@lizheming
Copy link
Author

@Cufr 你都搜到Github上来了肿么会不知道肿么用-_-!

@lizheming
Copy link
Author

@linkarys 是的,测试账号,不过没删掉也是有点小尴尬的,=——=!

@feiandxs
Copy link

这个代码一用就用到2015年,特地跑来感谢下……

@deqing
Copy link

deqing commented Nov 10, 2015

Good one! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment