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; }
public function setToken() { $res = json_decode(file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $this->appid . '&secret=' . $this->appsecret)); $token = array('token' => $res->access_token, 'add_time' => time()); $this->access_token = $res->access_token; $_SESSION["access_token"] = $res->access_token; $_SESSION["token_time"] = time(); if ($token = Weichat::findFirstByName("access_token")) { $token->setContent($res->access_token); $token->setUpdateTime(); $token->save(); } else { $token = new Weichat(); $token->setName("access_token"); $token->setContent($res->access_token); $token->setAddTime(); $token->setUpdateTime(); $token->save(); } }