public function run() { $user_list = config('user_list') ? config('user_list') : array(); $date = date("Y-m-d"); $user_check = array(); for (;;) { foreach ($user_list as $user => $user_info) { $log_head = date("H:i:s") . ':' . $user . '--'; $check = isset($user_check[$user]) ? $user_check[$user] : FALSE; if (!$check) { $baidu = new BaiduAction($user, $user_info['password']); $tieba = new TiebaAction($baidu->getCookie()); $result = $tieba->sign(); if ($result) { foreach ($result as $key => $value) { $result_info = implode(';', $result[$key]); switch ($key) { case 'success': $info = '以下贴吧签到成功:'; break; case 'repeat': $info = '以下贴吧已经签到:'; break; case 'ban': $info = '以下贴吧已被封:'; break; case 'error': $info = '以下贴吧签到失败:'; break; default: break; } Log::log($log_head . $info . $result_info . ENTER); } if ($tieba->success_count + $tieba->repeat_count + $tieba->ban_count == $tieba->num) { Log::log($log_head . '本日全部贴吧签到完成。' . ENTER); $user_check[$user] = TRUE; //完成标记 } } else { $info = 'COOKIE错误,可能需要验证码登录。--'; Log::log($log_head . $info); Log::log(Email::send($user_info['email'], $user, $info) . ENTER); unlink(COOKIE_PATH . '/' . md5($user)); } Log::save(); //保存日志 $date = date("Y-m-d"); } if ($date != date("Y-m-d")) { $user_check[$user] = FALSE; } //重置完成状态 } sleep(mt_rand(config('min_time'), config('max_time'))); } }
/** * 百度登陆方法 */ private function login() { //生成一个cookie $ret = $this->http_request("https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true", "", ""); //获取token并保存cookie $ret = $this->http_request("https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true", "", ""); preg_match_all('/login_token=\'(.+)\'/', $ret, $tokens); $login_token = $tokens[1][0]; //登陆并保存cookie $post_data = array(); $post_data['username'] = $this->username; $post_data['password'] = $this->password; $post_data['token'] = $login_token; $post_data['codestring'] = $this->codestring; $post_data['charset'] = 'UTF-8'; $post_data['callback'] = 'parent.bd12Pass.api.login._postCallback'; $post_data['index'] = '0'; $post_data['ppui_logintime'] = '8213'; $post_data['isPhone'] = 'false'; $post_data['mem_pass'] = '******'; $post_data['loginType'] = '1'; $post_data['safeflg'] = '0'; $post_data['staticpage'] = "https://passport.baidu.com/v2Jump.html"; $post_data['tpl'] = 'mn'; $post_data['u'] = "http://www.baidu.com/"; $post_data['verifycode'] = $this->verifycode; $ret = $this->http_request("http://passport.baidu.com/v2/api/?login", $post_data, "https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F"); if (strstr($ret, 'captchaservice')) { if (preg_match('/(captchaservice\\w{200,})/', $ret, $match)) { $this->codestring = $match[1]; $code_ini = VERIFY_PATH . config('code_ini'); Log::log('需要验证码,即将下载验证码' . ENTER); $img_path = VERIFY_PATH . config('img_name'); $img_url = 'https://passport.baidu.com/cgi-bin/genimage?' . $this->codestring; if (config('manual') == 1) { $this->getImg($img_url, $img_path); Log::log('当前为手动模式,请手动输入验证码到配置文件中' . ENTER); for (;;) { if (is_file($code_ini)) { $verifycode = parse_ini_file($code_ini); } if (isset($verifycode['verifycode']) && $verifycode['verifycode'] && isset($verifycode['status']) && $verifycode['status'] == 1) { $this->verifycode = $verifycode['verifycode']; Log::log('已获得验证码:' . $this->verifycode . ENTER); break; } sleep(10); } } else { Log::log('当前为自动模式,尝试获得验证码' . ENTER); for (;;) { $this->getImg($img_url, $img_path); $verifycode = Ocr::ocr($img_url, realpath($img_path)); Log::log('已识别验证码:' . $verifycode . ENTER); if (strlen($verifycode) == 4) { $this->verifycode = $verifycode; Log::log('格式符合,尝试登陆:' . ENTER); break; } else { Log::log('格式不符,再次识别:' . ENTER); } } } $this->login(); } } //记录下所有cookie $this->writeCookie(); Log::save(); }