function _returnCryptAjax($result) { @header("Content-type: text/html; charset=" . YApp::getConfig('YUC_RESPONSE_CHARSET')); @header("Pragma:no-cache\r\n"); @header("Cache-Control:no-cache\r\n"); @header("Expires:0\r\n"); echo Crypt::encrypt(json_encode($result), YApp::getConfig("YUC_SECURE_KEY")); }
/** * 初始化系统 */ public static function start() { ob_start(); define('M_PRO_DIR', dirname(dirname(__FILE__))); //定义项目目录 require M_PRO_DIR . '/Core/YApp.php'; YApp::start(); spl_autoload_register(array('YApp', '_autoLoad')); //开启自动注册加载类 }
/** * 主动上报 * @param $code * @param string $content * @internal param $details * @internal param array $data */ static function report($code, $content = '') { $client = new YucRequest(YApp::getConfig('YUC_SERVICE_NAME'), YApp::getConfig('YUC_SERVICE_PORT')); $client->setTimeout(YApp::getConfig('YUC_CLIENT_TIMEOUT')); //设置超时 $client->post(YApp::getConfig('YUC_MONITOR_PATH'), array('site_key' => YApp::getConfig('YUC_SITE_KEY'), 'code' => $code, 'content' => $content, 'datetime' => date("Y-m-d H:i:s"), 'server' => $_SERVER)); $result = json_decode($client->getContent(), TRUE); YLog::Write(var_export($result, TRUE), YLog::DEBUG); if ($client->getStatus() == 200 && is_array($result) && count($result) == 2 && $result['result'] == 1) { YLog::Write('主动上报信息成功!Code:' . $code . ';Content:' . $content, YLog::DEBUG); } else { YLog::Write('主动上报信息失败!', YLog::DEBUG); } }
/** * 访问端口 * @return type */ public static function getServerPort() { $port = YApp::getConfig('YUC_LOCAL_PORT'); if (trim($port) == '') { return intval($_SERVER['SERVER_PORT']); } else { $port = intval($port); if ($port == 0) { return intval($_SERVER['SERVER_PORT']); } else { return $port; } } }
/** * 获取校验结果 * @param $ssid * @param $result * @param int $diff * @param array $extra * @return type */ public static function sendVerifyRemoteRequest($ssid, $result, $diff = 0, $extra = array()) { $client = new YucRequest(YApp::getConfig('YUC_SERVICE_NAME'), YApp::getConfig('YUC_SERVICE_PORT')); $client->setTimeout(YApp::getConfig('YUC_CLIENT_TIMEOUT')); //设置超时 $client->post(YApp::getConfig('YUC_VERIFY_PATH'), array('site_key' => YApp::getConfig('YUC_SITE_KEY'), 'secure_key' => YApp::getConfig('YUC_SECURE_KEY'), 'ssid' => $ssid, 'result' => $result, 'diffsec_client' => $diff, 'extra' => $extra)); $post_req = json_decode($client->getContent(), TRUE); YLog::Write('远程验证完成,输入结果为:' . $result . ',返回状态 :' . $client->getStatus() . ';' . 'POST 验证码正确性请求返回的数据:' . $client->getContent(), YLog::DEBUG); if ($client->getStatus() == 200 && is_array($post_req)) { self::$_code = $post_req['code']; self::$_details = $post_req['details']; self::$_result = $post_req['result']; } else { self::$_code = 'E_SEVERVALID_001'; self::$_details = '服务器请求失败!'; self::$_result = 0; } }
/** * 获取日志文件路径 * @param string $dest * @return string */ private static function getFile($dest = "") { if ($dest == '') { $dest = M_PRO_DIR . '/Runtime/Log/' . date('Ymd') . '.log.php'; } if (!file_exists($dest)) { @file_put_contents($dest, "<?php die('Access Defined!');?>\r\n", FILE_APPEND); } else { if (file_exists($dest)) { $size = filesize($dest); if ($size >= floor(YApp::getConfig('YUC_LOG_SIZE'))) { $new = dirname($dest) . '/' . time() . '-' . basename($dest); if (!file_exists($new)) { @rename($dest, $new); } } } } return $dest; }
/** * 初始化 */ private function init() { $conf = (require M_PRO_DIR . '/Config/conf.php'); $server = (require M_PRO_DIR . '/Config/server.php'); self::$_cache['config'] = array_merge($conf, $server); //加载配置文件 if (YApp::getConfig('YUC_SESSION_AUTO_START')) { session_start(); //启动会话 } self::$_cache['version'] = (require M_PRO_DIR . '/Config/version.php'); //加载版本配置信息 require M_PRO_DIR . '/Core/YLog.php'; //加载日志类 YLog::Write('System Start:' . date('Y-m-d h:i:s'), YLog::DEBUG); require M_PRO_DIR . '/Core/YIAction.php'; //加载Action的接口文件 require M_PRO_DIR . '/Core/YFileCache.php'; //加载文件缓存 require M_PRO_DIR . '/Core/YPrepose.php'; //加载前置控制器 require M_PRO_DIR . '/Core/Function.php'; //加载函数集合 }
/** * POST发送请求数据 * @return array */ private function doPost() { $client = new YucRequest(YApp::getConfig('YUC_SERVICE_NAME'), YApp::getConfig('YUC_SERVICE_PORT')); $client->setTimeout(YApp::getConfig('YUC_CLIENT_TIMEOUT')); //设置超时 $client->post(YApp::getConfig('YUC_REQUEST_PATH'), $this->_local->getPostData()); YLog::Write('请求:' . YApp::getConfig('YUC_SERVICE_NAME') . YApp::getConfig('YUC_REQUEST_PATH') . ';返回状态 :' . $client->getStatus() . ';POST请求返回的数据:' . $client->getContent(), YLog::DEBUG); $ret_back = json_decode($client->getContent(), TRUE); if (!is_array($ret_back)) { YucMonitor::report("REPORT_0004", $client->getContent()); } return array('status' => $client->getStatus(), 'content' => $ret_back); }
static function erypt_key() { $key = YApp::getConfig("YUC_SECURE_KEY") . date('Y-m-d'); return $key; }
/** * 构造函数 * @param string $prefix * @internal param $ <type> $path * @internal param $ <type> $config */ public function __construct($prefix = 'File') { $this->_prefix = $prefix; $this->_default_config = array_merge($this->_default_config, array('expire' => YApp::getConfig('YUC_CACHE_EXPIRE'))); $this->_safe_head_len = strlen($this->_safe_head); }
/** * 本地的公共参数 * @return type */ public function getComParams() { $ret = array(); $ret['localserver'] = YucServer::getServerDomain(); $ret['localport'] = YucServer::getServerPort(); $ret['installdir'] = $this->_plugin_path; $ret['charset'] = YApp::getConfig('YUC_RESPONSE_CHARSET'); return $ret; }