Exemple #1
0
 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;
 }
Exemple #2
0
 /**
  * 生成新的二维码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;
 }
Exemple #3
0
 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();
 }
Exemple #5
0
 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;
     }
 }
Exemple #7
0
 private function _subscribe()
 {
     $resource = $this->getResource();
     Vera_Log::addNotice('event', $resource['Event']);
     $conf = Vera_Conf::getAppConf('common');
     return $conf['subscribe'];
     //回复欢迎信息
 }
Exemple #8
0
 /**
  * 微信特有路由
  * @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;
         }
     }
 }