private final function firewall($use = false) { if ($use) { try { $ip = array('127.0.0.2'); return $this->IpBlacklist($ip)->SpiderBlock()->BusyBlock(array(1, 20)); } catch (Exception $e) { $msg = $e->getMessage(); app::log($msg, 'ERROR'); return self::forbidden($msg); } } return $this; }
function Error($errno, $errstr, $errfile = null, $errline = null) { if ($errno == 404 || $errno == 500) { $str = "ERROR({$errno}) {$errstr}"; $code = $errno; } else { $str = "ERROR({$errno}) {$errstr} at {$errfile} on line {$errline} "; $code = 500; } http_response_code($code); DEBUG && app::log($str); if (ERROR_PAGE_404 && ERROR_PAGE_500) { $errorRouter = array($GLOBALS['APP']['router'][0], $errno == 404 ? ERROR_PAGE_404 : ERROR_PAGE_500, $str); $errorController = is_file(CONTROLLER_PATH . $errorRouter[0] . '.php') ? $errorRouter[0] : DEFAULT_CONTROLLER; if (method_exists($errorController, $errorRouter[1])) { $GLOBALS['APP']['controller'][$errorController] = isset($GLOBALS['APP']['controller'][$errorController]) ? $GLOBALS['APP']['controller'][$errorController] : $errorController; if (!$GLOBALS['APP']['controller'][$errorController] instanceof $errorController) { $GLOBALS['APP']['controller'][$errorController] = new $errorController(); ///实例化控制器 } exit(call_user_func_array(array($GLOBALS['APP']['controller'][$errorController], $errorRouter[1]), array($str))); //传入参数 } else { exit('No Error Handler Found In ' . $errorController . '::' . $errorRouter[1]); } } else { $trace = debug_backtrace(); $h1 =& $str; $i = count($trace) - 1; $li = null; while ($i >= 0) { if (!isset($trace[$i]['file'])) { $i--; continue; } $trace[$i]['class'] = isset($trace[$i]['class']) ? $trace[$i]['class'] : null; $trace[$i]['type'] = isset($trace[$i]['type']) ? $trace[$i]['type'] : null; $li .= '<p>' . $trace[$i]['file'] . '=>' . $trace[$i]['class'] . $trace[$i]['type'] . $trace[$i]['function'] . '() on line ' . $trace[$i]['line'] . '</p>'; $i--; } if (DEBUG != 2) { $h1 = 'Oops ! Something Error,Error Code:' . $errno; $li = '<p>If you are administartor,See the log for more information ! </p><p>Else please contact the administartor ! </p>'; } $html = '<div style="margin:2% auto;width:80%;box-shadow:0px 0px 8px #555;padding:2%;font:14px Monaco,Comic Sans MS">'; $html .= '<b>' . $h1 . '</b>' . $li; $html .= "</div>"; exit($html); } }
function test() { app::log("test"); }
/** * 资产配置,基金涨幅,每天抓取,所有基金 */ public function assets($code = 530008) { $url = "http://www.howbuy.com/fund/{$code}/"; $html = file_get_contents($url); $pattern = '/class="nTab9 jjzf_content" id="nTab9_0" style="display: block;">([\\s\\S]*?)sfw_tips_c/'; $data = array('increase' => '', 'increase_avg' => '', 'increase_300' => '', 'asset' => '', 'trade' => ''); if (preg_match_all($pattern, $html, $matches)) { $text = $matches[0][0]; if (preg_match_all('/区间回报<\\/td>([\\s\\S]*?)<\\/tr>/', $text, $matches2)) { $tmp = explode(PHP_EOL, $matches2[1][0]); $str = array(); foreach ($tmp as $item) { if (!empty(trim($item))) { $str[] = trim(strip_tags($item)); } } $data['increase'] = implode('|', $str); } else { app::log("QUJIAN ERROR {$code}"); } if (preg_match_all('/同类平均<\\/td>([\\s\\S]*?)<\\/tr>/', $text, $matches2)) { $tmp = explode(PHP_EOL, $matches2[1][0]); $str = array(); foreach ($tmp as $item) { if (!empty(trim($item))) { $str[] = trim(strip_tags($item)); } } $data['increase_avg'] = implode('|', $str); } else { app::log("TONGLEI ERROR {$code}"); } if (preg_match_all('/(沪深300|全债指数)<\\/td>([\\s\\S]*?)<\\/tr>/', $text, $matches2)) { $tmp = explode(PHP_EOL, $matches2[2][0]); $str = array(); foreach ($tmp as $item) { if (!empty(trim($item))) { $str[] = trim(strip_tags($item)); } } $data['increase_300'] = implode('|', $str); } else { app::log("TONGLEI ERROR {$code}"); } } else { app::log("Value Data Not Match {$code}"); } //下面资产配置,行业配置 $html = file_get_contents("http://static.howbuy.com/min/f=/upload/auto/script/fund/data_{$code}_v759.js"); if (preg_match_all('/hyPieData(.*?)jjpmChartData=\\{/', $html, $matches)) { $text = $matches[0][0]; if (preg_match_all('/hyPieData={(.*?)]/', $text, $matches2)) { $tmp = $matches2[1][0]; $str = array(); if (preg_match_all("/name:'(.*?)',y:([\\d.]+)\\}/", $tmp, $matches2)) { $names = $matches2[1]; $percent = $matches2[2]; foreach ($names as $index => $item) { $str[] = $item . ',' . $percent[$index]; } $data['trade'] = implode('|', $str); } } else { app::log("ERROR FOUND hyPieData {$code}"); } if (preg_match_all('/zcPieData={(.*?)]/', $text, $matches2)) { $tmp = $matches2[1][0]; $str = array(); if (preg_match_all("/name:'(.*?)',y:([\\d.]+)\\}/", $tmp, $matches2)) { $names = $matches2[1]; $percent = $matches2[2]; foreach ($names as $index => $item) { $str[] = $item . ',' . $percent[$index]; } $data['asset'] = implode('|', $str); } } else { app::log("ERROR FOUND zcPieData {$code}"); } } else { app::log("JS Data Not Match {$code}"); } //store to mysql if (!empty($data['increase']) && !empty($data['increase_avg']) && !empty($data['increase_300'])) { $sql = "UPDATE `fund_data` SET `increase`=:increase,`increase_avg`=:increase_avg,`increase_300`=:increase_300,`asset`=:asset,`trade`=:trade,`update_date`=:update_date WHERE code='{$code}' "; $stm = DB::prepare($sql); $now = date('Y-m-d H:i:s'); $stm->bindParam(':increase', $data['increase']); $stm->bindParam(':increase_avg', $data['increase_avg']); $stm->bindParam(':increase_300', $data['increase_300']); $stm->bindParam(':asset', $data['asset']); $stm->bindParam(':trade', $data['trade']); $stm->bindParam(':update_date', $now); $ret = $stm->execute(); self::log("update {$code} increase asset trade => {$ret}"); } else { self::log("ERROR DATA for {$code}", true); } }