public function indexAction() { $this->view->disable(); $content = array(); $res = Message::findFirst("keyword='aa'"); $arr = array(); $content['id'] = $res->getId(); $title = $res->getTitle(); $content['keyword'] = $res->getKeyword(); $text = $res->getContent(); $url = $res->getUrl(); $img = $res->getImg(); $content['add_time'] = $res->getAddTime(); $content['update_time'] = $res->getUpdateTime(); $len = count($title); for ($i = 0; $i < $len; $i++) { $content['data'][$i]['title'] = $title[$i]; $content['data'][$i]['description'] = $text[$i]; $content['data'][$i]['picurl'] = $img[$i]; $content['data'][$i]['url'] = $url[$i]; } echo "<pre>"; print_r($content); }
public function indexAction() { $this->view->disable(); if (!empty($_GET["echostr"])) { //验证 $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = $this->wechat->token; $tmpArr = array($token, $timestamp, $nonce); // use SORT_STRING rule sort($tmpArr, SORT_STRING); $tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); if ($tmpStr == $signature) { return true; } else { return false; } exit; } $postStr = file_get_contents("php://input"); if (!empty($postStr)) { //回复 libxml_disable_entity_loader(true); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $type = $postObj->MsgType; $eventKey = $postObj->EventKey; $keyword = trim($postObj->Content); $content = array(); $content['fromUser'] = $fromUsername; $content['toUser'] = $toUsername; if (strtolower($type) == 'event' && strtolower($postObj->Event) == 'click') { $content['data'] = array(['title' => 'TITLE', 'description' => 'DESCRIPTION', 'picurl' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/img/91b491.jpg', 'url' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $this->eventKey . '/' . $this->fromUsername]); $this->session->set("openid", $fromUsername); $this->newsMsg($content); // $this->textMsg("您好:".$this->eventKey); } if (!empty($keyword)) { //关键词回复 $res = Message::findFirst("keyword='" . $keyword . "'"); if ($res) { if ($res->getType() == 1) { $content['data'] = $res->getContent(); $this->wechat->textMsg($content); exit; } elseif ($res->getType() == 2) { $title = $res->getTitle(); $text = $res->getContent(); $img = $res->getImg(); $url = $res->getUrl(); $len = count($title); for ($i = 0; $i < $len; $i++) { $content['data'][$i]['title'] = $title[$i]; $content['data'][$i]['description'] = $text[$i]; $content['data'][$i]['picurl'] = $img[$i]; $content['data'][$i]['url'] = $url[$i]; } $this->wechat->newsMsg($content); } } else { $this->wechat->kefuMsg($content); } } else { echo "Input something..."; } } else { echo ""; exit; } }
public function delmsgAction() { $this->view->disable(); if ($this->request->isPost()) { $post = json_decode(file_get_contents("php://input"), true); $message = Message::findFirst($post['id']); $message->delete(); exit; } else { header("HTTP/1.1 404 Not Found"); include APP_PATH . '/public/show404.html'; exit; } }