Exemplo n.º 1
0
 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')));
     }
 }
Exemplo n.º 2
0
 /**
  * 获取关注贴吧列表
  * @return boolean
  */
 private function getmylike()
 {
     $islogin = "******" . time();
     $check = json_decode($this->curl_get($islogin));
     if (!$check->is_login) {
         return FALSE;
     }
     $mylikeurl = "http://tieba.baidu.com/f/like/mylike?";
     $result = $this->curl_get($mylikeurl);
     $page = 2;
     $result2 = $this->curl_get($mylikeurl . '&pn=2');
     $result .= $result2;
     while (strpos($result2, '/f?kw')) {
         $page++;
         $result2 = $this->curl_get($mylikeurl . '&pn=' . $page);
         $result .= $result2;
     }
     $pre_reg = '/f\\?kw=(.*?)"/';
     preg_match_all($pre_reg, $result, $matches);
     $i = 0;
     $kw_name = '';
     foreach ($matches[1] as $value) {
         $kw_name .= $value . ';';
         $i++;
     }
     Log::log("获取结束,一共[ {$i} ]个贴吧。" . ENTER);
     $this->num = $i;
     return $kw_name;
 }
Exemplo n.º 3
0
 public static function handleException($e)
 {
     if (error_reporting() == 0) {
         return;
     }
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     $eS = $e->getMessage();
     $eN = $e->getCode();
     $eC = $e->getTrace();
     // Put current context into stack trace
     array_unshift($eC, array('file' => $e->getFile(), 'line' => $e->getLine()));
     if ($e instanceof ErrorException) {
         switch ($e->getSeverity()) {
             case E_ERROR:
             case E_PARSE:
             case E_CORE_ERROR:
             case E_USER_ERROR:
             default:
                 $logType = LogLevel::CRITICAL;
                 break;
             case E_WARNING:
             case E_CORE_WARNING:
             case E_USER_WARNING:
                 $logType = LogLevel::WARNING;
                 break;
             case E_DEPRECATED:
             case E_NOTICE:
             case E_USER_DEPRECATED:
             case E_USER_NOTICE:
                 $logType = LogLevel::NOTICE;
                 break;
             case E_STRICT:
                 $logType = LogLevel::INFO;
                 break;
         }
         $exceptionType = 'error';
     } else {
         $exceptionType = get_class($e);
         if (strpos($exceptionType, '\\') !== false) {
             $exceptionType = substr(strrchr($exceptionType, '\\'), 1);
         }
         $logType = LogLevel::ERROR;
     }
     $logString = sprintf('[Gateway] Uncaught %s#%d with message: "%s".', $exceptionType, $eN, $eS);
     unset($exceptionType);
     // Current request context
     $resolver = Resolver::getActiveInstance();
     if ($resolver) {
         if ($resolver->request()) {
             $client = $resolver->request()->client();
         }
         $response = $resolver->response();
     }
     unset($resolver);
     // Prevent recursive errors on logging when database fails to connect.
     if (Database::isConnected()) {
         // Release table locks of current session.
         @Database::unlockTables(false);
         if (Database::inTransaction()) {
             @Database::rollback();
         }
     }
     $logContext = array_filter(array('errorContext' => $eC, 'client' => @$client));
     // Log the error
     try {
         @Log::log($logType, $logString, $logContext);
     } catch (\Exception $e) {
     }
     unset($logContext);
     // Send the error to output
     $output = array('error' => $eS, 'code' => $eN);
     if (System::environment(false) != System::ENV_PRODUCTION) {
         $output['trace'] = $eC;
     }
     // Display error message
     if (isset($response) && @$client['type'] != 'cli') {
         // Do i18n when repsonse context is available
         if ($e instanceof GeneralException) {
             $errorMessage = $response->__($eS, $logType);
             if ($errorMessage) {
                 $output['error'] = $errorMessage;
             }
         }
         if ($e instanceof ErrorException) {
             $statusCode = 500;
         } else {
             $statusCode = 400;
         }
         if ($e instanceof ValidationException) {
             $output['errors'] = $e->getErrors();
         }
         $response->clearHeaders();
         $response->header('Content-Type', 'application/json; charset=utf-8');
         $response->send($output, $statusCode);
     } else {
         header('Content-Type: text/plain', true, 500);
         echo "{$logString}\n";
         // Debug stack trace
         if (System::environment(false) != System::ENV_PRODUCTION) {
             echo "Trace:\n";
             array_walk($eC, function ($stack, $index) {
                 $trace = $index + 1 . '.';
                 $function = implode('->', array_filter(array(@$stack['class'], @$stack['function'])));
                 if ($function) {
                     $trace .= " {$function}()";
                 }
                 unset($function);
                 if (@$stack['file']) {
                     $trace .= " {$stack['file']}";
                     if (@$stack['line']) {
                         $trace .= ":{$stack['line']}";
                     }
                 }
                 echo "{$trace}\n";
             });
         }
     }
     // CLI exit code on Exceptions and Errors
     if (in_array($logType, array(LogLevel::ERROR, LogLevel::CRITICAL, LogLevel::ALERT, LogLevel::EMERGENCY))) {
         $exitCode = $e->getCode();
         if ($exitCode <= 0) {
             $exitCode = 1;
         }
         die($exitCode);
     }
 }
Exemplo n.º 4
0
 /**
  * 百度登陆方法
  */
 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();
 }