Skip to content

Instantly share code, notes, and snippets.

@lizheming
Last active February 6, 2017 18:15
Show Gist options
  • Select an option

  • Save lizheming/4368496 to your computer and use it in GitHub Desktop.

Select an option

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);
?>
@deqing

deqing commented Nov 10, 2015

Copy link
Copy Markdown

Good one! Thanks!

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