Exemple #1
0
 public function __construct()
 {
     if ($GLOBALS['config']['wechat']['open']) {
         $weichat = Weichat::find();
         foreach ($weichat->toArray() as $v) {
             'appid' == trim($v['name']) && ($this->appid = trim($v['content']));
             'appsecret' == trim($v['name']) && ($this->appsecret = trim($v['content']));
             'token' == trim($v['name']) && ($this->token = trim($v['content']));
             if ('access_token' == trim($v['name'])) {
                 $this->access_token = trim($v['content']);
                 $_SESSION['access_token'] = trim($v['content']);
                 $_SESSION['token_time'] = trim($v['update_time']);
             }
         }
     } else {
         $this->appid = $GLOBALS['config']['wechat']['appid'];
         $this->appsecret = $GLOBALS['config']['wechat']['appsecret'];
         $this->token = $GLOBALS['config']['wechat']['token'];
         if ($weichat = Weichat::findFirstByName("access_token")) {
             $weichat = $weichat->toArray();
             $_SESSION['access_token'] = trim($weichat['content']);
             $_SESSION['token_time'] = trim($weichat['update_time']);
             $this->access_token = trim($weichat['content']);
         } else {
             $this->setToken();
         }
     }
     if (intval($_SESSION['token_time']) + 7200 < time()) {
         $this->setToken();
     }
 }
Exemple #2
0
 public function indexAction()
 {
     if ($this->request->isPost()) {
         $this->view->disable();
         $w = Weichat::findFirst($this->request->getPost('id', 'int'));
         $w->setContent($this->request->getPost('content', 'string'));
         $w->setUpdateTime();
         $w->save();
         exit($w->getUpdateTime());
     }
     $wechat = Weichat::find();
     $this->view->wechats = $wechat->toArray();
     $this->view->open = $this->config->wechat->open;
 }