/** * 发布一篇博客 * @param string $title 标题 * @param string $content 内容(html) */ protected function _publish($title, $content) { $add_url = 'http://control.blog.sina.com.cn/admin/article/article_add.php'; $ret = $this->get($add_url); Log::customLog('sinablog.txt', "GET http://control.blog.sina.com.cn/admin/article/article_add.php:\r\n{$ret}"); $vtoken = $this->getMatch1('/<input type="hidden" name="vtoken" value="([^"]+)"/', $ret); if (empty($vtoken)) { return '模拟登 录已过期,需重新<a href="bind.php">绑定账号</a>。'; } $param = array('album' => '', 'album_cite' => '', 'articleStatus_preview' => 1, 'article_BGM' => '', 'articletj' => '', 'assoc_article' => '', 'assoc_article_data' => '', 'assoc_style' => 1, 'blog_body' => $content, 'blog_class' => '00', 'blog_id' => '', 'blog_title' => $title, 'book_worksid' => '', 'channel' => '', 'channel_id' => '', 'commentGlobalSwitch' => '', 'commenthideGlobalSwitch' => '', 'conlen' => mb_strlen($content, 'utf-8'), 'date_pub' => date('Y-m-d'), 'fromuid' => '', 'is_album' => 0, 'is_media' => 0, 'is_stock' => 0, 'is_tpl' => 0, 'join_circle' => 1, 'newsid' => '', 'ptype' => '', 'sina_sort_id' => 117, 'sno' => '', 'source' => '', 'stag' => '', 'tag' => '', 'teams' => '', 'time' => date('H:i:s'), 'topic_channel' => 0, 'topic_id' => 0, 'topic_more' => '', 'url' => '', 'utf8' => 1, 'vtoken' => $vtoken, 'wid' => '', 'worldcuptags' => '', 'xRankStatus' => '', 'x_cms_flag' => 0); $this->referer = $add_url; Log::customLog('sinablog.txt', "POST http://control.blog.sina.com.cn/admin/article/article_post.php:\r\n" . print_r($param, true)); $ret = $this->post('http://control.blog.sina.com.cn/admin/article/article_post.php', $param); Log::customLog('sinablog.txt', "Response:\r\n" . print_r($this->http_header, true) . print_r($ret, true)); if (!$ret) { return '接口返回 NULL,一般是网络问题。'; } switch ($ret['code']) { case 'B06001': case 'B06011': case 'B06012': return true; case 'B06013': return '出现验证码!'; case 'B07005': case 'B08001': return '不能一分钟内连续发博文,请稍后再试。'; default: return '错误码: ' . $ret['code']; } return true; }
/** * 模拟登录 */ public function Login($verifycode = NULL) { $data = $this->account; if (!is_numeric($data['username']) && !str_contains($data['username'], '@')) { return '用户名格式错误,请输入QQ号或QQ邮箱。'; } Session::Set('qq', $data['username']); if (!$verifycode) { $ret = $this->get('http://check.ptlogin2.qq.com/check?appid=15000101&uin=' . $data['username']); // $arr = explode("'", $ret); $verifycode = $arr[3]; if (strlen($verifycode) != 4) { return '绑定账号失败:请输入验证码'; //'登录服务暂时不可用,请稍后再试!'; } } $param = array('aid' => 15000101, 'fp' => 'loginerroralert', 'from_ui' => 1, 'g' => 1, 'h' => 1, 'u' => $data['username'], 'p' => $this->encpwd($data['password'], $data['username'], $verifycode), 'verifycode' => $verifycode, 'u1' => 'http://imgcache.qq.com/qzone/v5/loginsucc.html?para=izone'); Log::customLog('qzone.txt', "GET http://ptlogin2.qq.com/login:\r\n" . print_r($param, true)); $ret = $this->get('http://ptlogin2.qq.com/login?' . http_build_query($param)); Log::customLog('qzone.txt', "Response:\r\n" . print_r($this->http_header, true) . print_r($ret, true)); $arr = explode("'", $ret); $ret = $arr[9]; if (start_with($ret, '登录成功')) { return true; } return $ret; }
/** * @name sysLog * @desc 采用 syslog 记录系统日志,操作系统必须为linux,记录至系统日志local4中,请修改/etc/syslog.conf文件 * @param string $ident 日志 * @param string $string 日志信息 */ public static function sysLog($ident, $errstr) { if (!defined('LOG_LOCAL4') && !empty($_ENV['OS']) && substr($_ENV['OS'], 0, 7) == 'Windows') { $filename = "syslog_" . date('Ymd') . '.log'; return Log::customLog($filename, $errstr); } else { openlog($ident, LOG_PID | LOG_PERROR, LOG_SYSLOG); syslog(LOG_ALERT, $errstr); closelog(); } }
/** * 更新账户有效状态 * @param string $type 第三方平台类型 */ public function fail($third, $error_msg = NULL) { $pid = $third['pid']; $type = $third['type']; ob_start(); debug_print_backtrace(); $trace = ob_get_contents(); ob_clean(); Log::customLog('token_expires_error.txt', $this->rep_platform("Token 过期,平台:{pid}|{type}, {platform},{weibo},原因:{$error_msg}\r\n调用堆栈:\r\n{$trace}", $pid, $type)); $mail = Config::get_mail('token_expire'); sendmail($mail['to'], $this->rep_platform($mail['subject'], $pid, $type), $this->rep_platform($mail['content'], $pid, $type) . "<br>原因:{$error_msg}"); return $this->update(array('valid' => 0), array('pid' => $pid, 'type' => $type)); }
/** * 增加任务 * @param string $type * @param string $content * @param int|string $send_time * @param string $pic * @param int $status * @param string $msg * @param string $cat * @param string $title */ public function AddTask($type, $content, $send_time, $pic = NULL, $status = Task::TASK, $msg = NULL, $cat = 'weibo', $title = NULL) { if (!is_int($send_time)) { $send_time = strtotime($send_time); } $type_arr = explode('|', $type); $thirdAccount = new ThirdAccount(); $third = $thirdAccount->getThird(Passport::GetLoginUid(), $type_arr[0], $type_arr[1]); $tableInfo = array('uid' => Passport::GetLoginUid(), 'pid' => $type_arr[1], 'type' => $type, 'url' => $third['url'], 'cat' => $cat, 'pic' => $pic, 'title' => $title, 'content' => $content, 'send_time' => $send_time, 'status' => $status, 'msg' => $msg); if (intval($tableInfo['uid']) <= 0) { Log::customLog('uid_0_error.txt', "产生UID为空的任务: \r\n" . print_r($tableInfo, true) . "\r\n-----------------------------------------\r\n" . print_r($_SERVER, true)); } $this->insertIgnore($tableInfo); }
/** * 获取登录URL * @param string $oauth_callback 登录回调url * @param string $scope 权限标志,只有开心001用到 */ public function GetAuthorizationUrl($oauth_callback, $scope = NULL) { $this->token = NULL; $token = $this->getRequestToken($oauth_callback, $scope); $app_key_invalid = false; if (array_key_exists('Invalid signature', $token)) { $app_key_invalid = true; } else { if ($token['oauth_problem'] == 'consumer not found') { $app_key_invalid = true; } else { if ($token['error'] == 'token_rejected') { $app_key_invalid = true; } else { if ($token['error_code'] == 11000) { $app_key_invalid = true; } else { $arr = explode(':', $token['error']); $error_code = intval($arr[0]); switch ($error_code) { case 40109: case 40111: $app_key_invalid = true; break; } } } } } if ($app_key_invalid) { return 'App Key 无效,请到平台设定修改。<span style="color:#fff">' . print_r($token, true) . '</span>'; } if (empty($token['oauth_token'])) { Log::customLog('oauth_error.txt', '获取 RequestToken 失败! 请求信息:' . print_r($this, true)); return '获取 RequestToken 失败!请稍后再试。<span style="color:#ccc">' . print_r($token, true) . '</span>'; } $oauth_callback = urlencode($oauth_callback); return $this->authorizeURL() . "?oauth_callback={$oauth_callback}&oauth_consumer_key={$this->consumer->key}&oauth_token=" . $token['oauth_token']; }
/** * @name show * @desc 显示调试信息 * @todo 目前只实现了在FirePHP中显示结果.需要实现记录LOG日志形式 * @return null * @access public */ public static function show() { global $YOKA, $TEMPLATE, $CFG; if (!defined('DEBUG_SHOW_LOG') || defined('DEBUG_SHOW_LOG') && DEBUG_SHOW_LOG) { //用户记录变量 Debug::fb(array('Custom Log Object', self::$log_table), FirePHP::TABLE); } if (!defined('DEBUG_SHOW_TIME') || defined('DEBUG_SHOW_TIME') && DEBUG_SHOW_TIME) { //页面执行时间 Debug::fb(array('This Page Spend Times ' . self::getTime(), self::$time_table), FirePHP::TABLE); } /*---------记录至日记文件中------------*/ if (count(self::$log_table) > 1 || count(self::$time_table) > 1) { if (isset($_SERVER['TERM'])) { $string = "PWD:" . $_SERVER['PWD'] . "\n"; $string .= "SCRIPT_NAME:" . $_SERVER['SCRIPT_NAME'] . "\n"; $string .= "ARGV:" . var_export($_SERVER['argv'], true) . "\n"; } else { $string = "HTTP_HOST:" . $_SERVER['HTTP_HOST'] . "\n"; $string .= "SCRIPT_NAME:" . $_SERVER['SCRIPT_NAME'] . "\n"; $string .= "QUERY_STRING:" . $_SERVER['QUERY_STRING'] . "\n"; } $string .= 'This Page Spend Times:' . self::getTime() . "\n"; array_shift(self::$log_table); array_shift(self::$time_table); if (!empty(self::$time_table)) { $string .= "\n"; foreach (self::$time_table as $v) { $string .= "|-- " . $v[0] . " " . $v[1] . " " . $v[2] . " --|\n"; } } if (!empty(self::$log_table)) { $string .= "\n"; foreach (self::$log_table as $v) { $string .= "|---- " . $v[0] . " " . $v[2] . " ----|\n"; $string .= var_export($v[1], true) . "\n"; } } $filename = "debug_" . date("Ymd") . ".log"; Log::customLog($filename, $string); } //数据库执行时间 if (count(self::$db_table) > 0) { $i = 0; $db_total_times = 0; foreach (self::$db_table as $v) { $db_total_times += $v[2]; $i++; } array_unshift(self::$db_table, array('IP', 'Database', 'Time', 'SQL Statement', 'Results')); Debug::fb(array($i . ' SQL queries took ' . $db_total_times . ' seconds', self::$db_table), FirePHP::TABLE); } //Cache执行时间 if (count(self::$cache_table) > 0) { $i = 0; $cache_total_times = 0; foreach (self::$cache_table as $v) { $cache_total_times += $v[2]; $i++; } array_unshift(self::$cache_table, array('Server', 'Cache Key', 'Time', 'Results', 'Method')); Debug::fb(array($i . ' Cache queries took ' . $cache_total_times . ' seconds', self::$cache_table), FirePHP::TABLE); } //Form执行时间 if (self::$form_table) { $i = 0; $form_total_times = 0; foreach (self::$form_table as $v) { $form_total_times += $v[2]; $i++; } array_unshift(self::$form_table, array('Label', 'FormHtml', 'Times', 'Results', 'Caller')); Debug::fb(array($i . ' Form action request took ' . $form_total_times . ' seconds', self::$form_table), FirePHP::TABLE); } if (!defined('DEBUG_SHOW_UTILITY') || defined('DEBUG_SHOW_UTILITY') && DEBUG_SHOW_UTILITY) { //自定义函数 $functions = get_defined_functions(); //定义的常量 $constants = get_defined_constants(true); $sessions = isset($_SESSION) ? $_SESSION : array(); Debug::fb(array('Utility Variables', array(array('name', 'values'), array('GET Variables', $_GET), array('POST Variables', $_POST), array('Custom Defined Functions', $functions['user']), array('Include Files', get_included_files()), array('Defined Constants', $constants['user']), array('SESSION Variables', $sessions), array('SERVER Variables', $_SERVER), array('$YOKA', $YOKA), array('$TEMPLATE', $TEMPLATE), array('$CFG', $CFG))), FirePHP::TABLE); } }
/** * 发布一篇博客 * @param string $title 标题 * @param string $content 内容(html) */ protected function _publish($title, $content) { if (preg_match_all('#<img .*?src="(.+?)".*?>#i', $content, $matches)) { foreach ($matches[1] as $img) { $mappath = UPLOAD_PATH . basename($img); $ret = $this->post('http://upload.pp.sohu.com/blogUpload.do', array('Filedata' => "@{$mappath}"), 'UTF-8', true); $src = $ret['data']['image'][1]; if ($src) { $content = str_replace("\"{$img}\"", "\"{$src}\"", $content); } } } $url = "http://i.sohu.com/a/blog/home/entry/save.htm?_input_encode=UTF-8&_output_encode=UTF-8"; $param = array('title' => $title, 'content' => $content, 'oper' => 'art_ok'); $ret = $this->post($url, $param); if (is_string($ret)) { $ret = json_decode(iconv('gbk//IGNORE', 'utf-8//IGNORE', $ret), true); } switch ($this->http_code) { case 500: return '模拟登录已过期,需重新<a href="bind.php">绑定账号</a>。'; } if (!$ret) { return '接口返回 NULL,一般是网络问题。'; } if (is_array($ret)) { if ($ret['status'] === 0) { return true; } else { return $ret['statusText']; } } else { Log::customLog('isohu_error.txt', '发布失败:' . print_r($param, true) . print_r($this->http_header, true) . $ret); return '未知错误,详细原因请参阅<a href="_LOG/isohu_error.txt" target="_blank">isohu_error.log</a>。'; } }
$code_key = 'oauth_vericode'; break; case 'renren': case 'sina': $code_key = 'code'; break; default: $code_key = 'oauth_verifier'; break; } $token = $api->getAccessToken($_GET[$code_key], $_GET['oauth_token']); if ($token['oauth_token']) { $api->openid = $token['openid']; $thirdAccount = new ThirdAccount(); $tableInfo = array('uid' => Passport::GetLoginUid(), 'pid' => $pid, 'type' => $api->type, 'token' => $token['oauth_token'], 'token_secret' => $token['oauth_token_secret'], 'openid' => $token['openid'], 'nick' => $api->getNick(), 'url' => $api->getUrl(), 'valid' => 1); Log::customLog('token_expires_error.txt', "绑定 Token,信息:" . print_r($tableInfo, true)); $user = new User(); $users = $user->getsAll(); foreach ($users as $uid => $item) { $tableInfo['uid'] = $uid; $thirdAccount->replace($tableInfo); } redirect($_GET['redir']); echo <<<HTML <script> opener.location=opener.location; window.close(); </script> HTML; } else { echo '获取 AccessToken 失败!请稍后再试。' . $token["error_msg"] . '<span style="color:#ccc">' . print_r($token, true) . '</span>';
/** * 发布一篇博客 * @param string $title 标题 * @param string $content 内容(html) */ protected function _publish($title, $content) { $url = "http://site.douban.com/widget/notes/{$this->blogname}/create"; $ret = $this->get($url); $ck = $this->getMatch1('#name="ck".*? value="(.*?)"#', $ret); $nid = $this->getMatch1('#name="note_id".*? value="(.*?)"#', $ret); if (empty($nid)) { return '模拟登录已过期或Widget ID填写错误!需重新<a href="bind.php">绑定账号</a>。'; } $param = array('ck' => $ck, 'note_id' => $nid, 'note_title' => $title, 'note_text' => $content, 'note_submit' => '发表'); if (preg_match_all('#<img .*?src="(.+?)".*?>#i', $content, $matches)) { foreach ($matches[1] as $img) { $mappath = UPLOAD_PATH . basename($img); $upload_data = array('image_file' => "@{$mappath}", 'note_id' => $nid, 'ct' => 'text', 'ck' => $ck); $this->referer = $url; $ret = $this->post("http://site.douban.com/j/note/add_photo", $upload_data, 'UTF-8', true); $seqid = $ret['photo']['seq']; if ($seqid) { $content = preg_replace('#<img .*?src="' . preg_quote($img) . '".*?>#i', "[图片{$seqid}]", $content); $param["p{$seqid}_layout"] = 'C'; $param["p{$seqid}_title"] = ''; } } } $param['note_text'] = preg_replace('#\\[(图片\\d+)\\]#', '<$1>', html_decode($content)); $ret = $this->post($url, $param); if (!$ret) { return '接口返回 NULL,一般是网络问题。'; } if (start_with($this->http_code, '40')) { return '模拟登录已过期!需重新<a href="bind.php">绑定账号</a>。'; } if (empty($this->http_header['Location'])) { Log::customLog('douban_site_error.txt', '发布失败:' . print_r($param, true) . print_r($this->http_header, true) . $ret); return '发布失败,详细原因请参阅<a href="_LOG/douban_site_error.txt" target="_blank">douban_site_error.log</a>。'; } else { if (str_contains($this->http_header['Location'], $nid)) { Log::customLog('douban_site_error.txt', '发布成功:' . print_r($param, true) . print_r($this->http_header, true) . $ret); return true; } } }
/** * 发布一篇博客 * @param string $title 标题 * @param string $content 内容(html) */ protected function _publish($title, $content) { $rtk = $this->getMatch1("#get_check:'(.+?)'#", $this->get($this->getUrl())); if (empty($rtk)) { return '模拟登录已过期或个性域名填写错误!需重新<a href="bind.php">绑定账号</a>。'; } $url = "http://zhan.renren.com/{$this->blogname}/word/create"; if (preg_match_all('#<img .*?src="(.+?)".*?>#i', $content, $matches)) { foreach ($matches[1] as $img) { $mappath = UPLOAD_PATH . basename($img); $upload_data = array('theFile' => "@{$mappath}"); $this->referer = $url; $ret = $this->post("http://upload.renren.com/uploadblog.do", $upload_data, 'UTF-8', true); $ret = @json_decode($this->getMatch1('#\\[\\{(.*?)\\}\\]#', $ret), true); if ($ret[0] && $ret[0]['url']) { $content = str_replace($img, $ret[0]['url'], $content); } } } $param = array('subject' => $title, 'body' => $content, '_rtk' => $rtk); $ret = $this->post($url, $param); if (!$ret) { return '接口返回 NULL,一般是网络问题。'; } if (start_with($this->http_code, '40')) { return '模拟登录已过期!需重新<a href="bind.php">绑定账号</a>。'; } if ($ret['code'] != 0) { if ($ret['msg']) { return $ret['msg']; } else { Log::customLog('renren_zhan_error.txt', '发布失败:' . print_r($param, true) . print_r($this->http_header, true) . print_r($ret, true)); return '发布失败,详细原因请参阅<a href="_LOG/renren_zhan_error.txt" target="_blank">renren_zhan_error.log</a>。'; } } return true; }