public static function run($exception) { $log = 'File: ' . $exception->getFile() . ' '; $log .= 'Line: ' . $exception->getLine() . ' '; $log .= 'Message: ' . $exception->getMessage(); Vera_Log::addErr($log); return true; }
public function run() { $resource = $this->getResource(); $openId = $resource['FromUserName']; Vera_Log::addNotice('content', $resource['Content']); $avatar = Data_Wechat_User::getAvatar($openId); if ($resource['Content'] != '') { //此处添加发弹幕逻辑 $data = 'w=' . $resource['Content'] . '&a=' . $avatar; $url = 'http://127.0.0.1:3000/message'; $handle = curl_init(); $options = array(CURLOPT_URL => $url, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data, CURLOPT_TIMEOUT => 1); curl_setopt_array($handle, $options); $content = curl_exec($handle); $text = '快抬头看大屏幕~!'; if (curl_errno($handle)) { //检查是否有误 $text = '啊哦..服务器好像生病了...'; } curl_close($handle); } else { $text = '呃..你是不是发了表情?暂时不支持哟~'; } $ret['type'] = 'text'; $ret['data']['Content'] = $text; //寻找模板 $view = new View_Wechat($resource); $view->assign($ret); $view->display(); return true; // --------------end-------------- $conf = Vera_Conf::getAppConf('common'); $reply = Data_Wechat_Db::keywordReply($resource['Content']); if (!$reply) { //默认回复 $ret = $conf['defaultReply']; } elseif (in_array($reply['replyType'], $conf['replyType'])) { //固定回复 $ret['type'] = $reply['replyType']; $ret['data'] = json_decode($reply['reply'], true); } else { //功能性回复 $class = 'Service_' . $reply['replyType']; $instance = new $class($resource); $ret = $instance->{$reply['reply']}(); } if (empty($ret)) { throw new Exception("很抱歉公众号出现异常", 1); } //寻找模板 $view = new View_Wechat($resource); $view->assign($ret); $view->display(); return true; }
/** * 设置模板 * @param string $template 模板文件名 */ public function setTemplate($template = 'text') { //构成完整文件路径 $file = SERVER_ROOT . 'app/wechat/view/template/' . $template . '.php'; if (file_exists($file)) { self::$_tpl = $file; } else { Vera_Log::addErr('cannot find template ' . $file); exit; } }
/** * 获取某App配置 * @param string $name 配置文件名 * @param string $app App名称 * @return array 配置内容 */ public static function getAppConf($name, $app = NULL) { if ($app === NULL) { $app = $GLOBALS['APP_NAME']; } $path = SERVER_ROOT . 'conf/' . $app . '/' . $name . '.conf'; $ret = self::_getFile($path); if (!$ret) { Vera_Log::addErr('prase conf ' . $path . ' error'); return false; } return $ret; }
public static function run() { return true; //暂时无法解决signature校验不一致的问题 $conf = Vera_Conf::getConf('global'); $conf = $conf['wechat']; if (!isset($conf['token']) || empty($conf['token'])) { Vera_Log::addErr('cannot find token'); exit; } $token = $conf['token']; return self::_checkSignature($token); }
/** * 生成新的二维码token * @param string $act 活动token * @return string 新的二维码token */ public static function newToken($act, $expire) { $cache = Vera_Cache::getInstance(); $key = 'rollcall_' . $act . '_token'; $token = ''; for ($i = 0; $i < 12; $i++) { $token .= chr(mt_rand(48, 122)); } $token = md5($token); $cache->add($key, $token, $expire); if ($cache->getResultCode() == Memcached::RES_NOTSTORED) { $token = $cache->get($key); } Vera_Log::addNotice('token', $token); return $token; }
public static function run($exception) { $log = 'file[' . $exception->getFile() . '] '; $log .= 'line[' . $exception->getLine() . '] '; $log .= 'message[' . $exception->getMessage() . '] '; Vera_Log::addErr($log); $resource = parent::getResource(); if ($resource === NULL) { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $resource = (array) simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); } $msg = $exception->getMessage(); $errMsg = empty($msg) ? parent::$commonConf['errMsg'] : $msg; $ret = "<xml>\n \t\t <ToUserName><![CDATA[" . $resource['FromUserName'] . "]]></ToUserName>\n \t\t <FromUserName><![CDATA[" . $resource['ToUserName'] . "]]></FromUserName>\n \t\t <CreateTime>" . time() . "</CreateTime>\n \t\t <MsgType><![CDATA[text]]></MsgType>\n \t\t <Content><![CDATA[" . $errMsg . "]]></Content>\n \t\t</xml>"; echo $ret; exit; }
public function push($openid) { $postData = $this->_content; $postData['touser'] = $openid; $postData = json_encode($postData, JSON_UNESCAPED_UNICODE); $handle = curl_init(); $options = array(CURLOPT_URL => $this->_api, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $postData); curl_setopt_array($handle, $options); $result = curl_exec($handle); //执行 $json = json_decode($result, true); if ($errno = curl_errno($handle) || $json['errcode'] != 0) { Vera_Log::addWarning('push to [' . $openid . '] failed, return ' . $result); return false; } return true; }
public static function run() { return true; session_start(); if (ACTION_NAME == 'Test') { return true; } // @temp: 网络文化节抽奖页面无条件通过 if (ACTION_NAME == 'Luck' || ACTION_NAME == 'Api_Luck' || ACTION_NAME == 'Data' || ACTION_NAME == 'Api_Data' || ACTION_NAME == 'Rank') { return true; } if (in_array(ACTION_NAME, self::$passList) && isset($_SESSION['culture'])) { return true; } if (!isset($_SESSION['num'])) { return false; } $resource = array('num' => $_SESSION['num']); parent::setResource($resource); Vera_Log::addNotice('name', $_SESSION['num']); //http://blog.csdn.net/cityice/article/details/9427035 //session文件锁的问题导致并发长轮询页面挂起,并附带整个网站无响应 session_write_close(); switch (ACTION_NAME) { case 'Api_Token': case 'Api_Act': if (!isset($_GET['m']) || !isset($_GET['act'])) { return false; } return true; break; case 'Index': if (!isset($_GET['act'])) { return false; } return true; break; default: break; } return true; }
/** * 初始化环境,返回action层对应类的实例 * @return class 触发到的action层对应类 */ public function init() { Vera_Autoload::init(); $router = new Vera_Router(); if (!Vera_Router::isApp()) { //如果app未开启,停止运行 exit; } set_exception_handler('Action_Error::run'); //最高级的异常捕获,统一显示为每个app自定的错误 self::$Log = new Vera_Log(); self::$Log->init(); if (Vera_Autoload::isExists('Action_Auth')) { if (!Action_Auth::run()) { Vera_Log::addNotice('auth', 'fail'); exit; } Vera_Log::addNotice('auth', 'success'); } return $router->getAction(); }
function __construct($debug) { parent::__construct(); $this->setTemplateDir(SERVER_ROOT . 'templates/'); $this->setCompileDir(SERVER_ROOT . 'cache/smarty/templates_c/' . $GLOBALS['APP_NAME'] . '/'); $this->setConfigDir(SERVER_ROOT . 'templates/' . $GLOBALS['APP_NAME'] . '/conf/'); //Smarty配置文件 $this->setCacheDir(SERVER_ROOT . 'cache/smarty/cache/' . $GLOBALS['APP_NAME'] . '/'); $this->setCaching(Smarty::CACHING_LIFETIME_SAVED); // 让每个模板缓存的过期时间都可以在display执行前单独设置。 if ($debug) { //开启调试模式 $this->caching = Smarty::CACHING_OFF; //关闭缓存 $this->debugging = false; //弹窗 Vera_Log::addNotice('isDebug', '1'); } else { $this->force_compile = false; $this->setCompileCheck(false); } $this->assign('base', '/templates/'); //view文件夹根目录 }
private static function _loadClass($className) { $appRoot = SERVER_ROOT . "app/" . $GLOBALS['APP_NAME']; $filePath = explode('_', $className); switch (array_shift($filePath)) { case 'Action': $nextDir = '/action/'; break; case 'Data': $nextDir = '/model/data/'; break; case 'Service': $nextDir = '/model/service/'; break; case 'Vera': $appRoot = SERVER_ROOT; $nextDir = '/tools/'; break; case 'Smarty': return smartyAutoload($className); //使用Smarty自带的Autoload函数加载Smarty引擎相关的类 break; case 'View': $nextDir = '/view/'; break; case 'Library': $nextDir = '/library/'; break; default: Vera_Log::addErr('unknown classname ' . $className); exit; } $classPath = $appRoot . $nextDir; $file = array_pop($filePath); if (count($filePath) != 0) { foreach ($filePath as $each) { $classPath .= strtolower($each) . "/"; } } $classPath .= $file . ".php"; if (file_exists($classPath)) { include_once $classPath; } else { Vera_Log::addErr($className . ' not found'); Vera_Log::addNotice('classPath', $classPath); return false; } }
public static function run($exception) { $log = 'Message: ' . $exception->getMessage(); Vera_Log::addErr($log); return true; }
/** * 写入文件 * @param string $level 日志文件名 * @param string $log 日志内容 * @return bool 写入状态 */ private static function _writeLog($level = '', $log = '') { if (!Vera_Router::isApp()) { //检查是否为合法的App return false; } $logDir = SERVER_ROOT . 'log/' . $GLOBALS['APP_NAME']; if (!is_dir($logDir)) { mkdir($logDir); } $file = $logDir . "/" . strtolower($level) . ".log"; $fp = fopen($file, 'a'); if (!$fp) { return false; } if (flock($fp, LOCK_EX)) { fwrite($fp, $log . PHP_EOL); flock($fp, LOCK_UN); //释放锁定 } else { Vera_Log::addErr('can`t lock file!'); } fclose($fp); return true; }
private function _subscribe() { $resource = $this->getResource(); Vera_Log::addNotice('event', $resource['Event']); $conf = Vera_Conf::getAppConf('common'); return $conf['subscribe']; //回复欢迎信息 }
private function _connect($conf = NULL) { if ($conf == NULL) { return false; } $this->isConnected = $this->mysql->real_connect($conf['host'], $conf['username'], $conf['password'], $conf['dbname'], $conf['port']); if (!$this->isConnected) { Vera_Log::addErr('connect to MySQL failed'); exit; } return $this->isConnected; }
/** * 记录推送日志 * @param array $content 推送内容数组 * @param array $log 各用户推送结果 */ public static function addLog($content, $log) { $content = json_encode($content, JSON_UNESCAPED_UNICODE); $buffer = PHP_EOL . '==' . date("Y-m-d H:i:s", time()) . '==' . PHP_EOL; $buffer .= $content . PHP_EOL; $buffer .= '---' . PHP_EOL; $buffer .= json_encode($log, JSON_UNESCAPED_UNICODE); Vera_Log::addLog('push', $buffer); }
/** * 微信特有路由 * @return class action实例 */ private function wechatRouter(&$arg) { if (isset($GLOBALS["HTTP_RAW_POST_DATA"]) && !empty($GLOBALS["HTTP_RAW_POST_DATA"])) { //解析XML包 $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $arg = (array) simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); Vera_Log::addNotice('userID', $arg['FromUserName']); Vera_Log::addNotice('serverID', $arg['ToUserName']); Vera_Log::addNotice('createTime', $arg['CreateTime']); Vera_Log::addNotice('msgType', $arg['MsgType']); if (isset($arg['MsgId'])) { Vera_Log::addNotice('msgId', $arg['MsgId']); } //记录访问日志 Library_List::add($arg['FromUserName']); return ucfirst($arg['MsgType']); } else { if (isset($_GET["echostr"])) { //初次接入微信号 echo $_GET["echostr"]; exit; } else { //异常访问 $url = "/wap"; header("Location: {$url}"); exit; } } }