bannerModel = new \app\api\model\Banner(); parent::__construct($request); } /** * 获取banner * @return void */ public function fetchBanner() { $module_type = input("module_type", "user"); $banners = $this->bannerModel->fetchBanner($module_type, 5); $this->success($banners); } public function fetchArea() { $this->success(Area::fetchArea()); } public function check() { $signature = $this->request->param('signature', ""); $timestamp = $this->request->param('timestamp', ""); $nonce = $this->request->param('nonce', ""); $echostr = $this->request->param('echostr', ""); if ($this->checkSignature($signature, $timestamp, $nonce)) { ob_clean(); echo $echostr; die;//这里特别注意,如果不用die结束程序会token验证失败 } else { echo false; } } private function checkSignature($signature, $timestamp, $nonce) { $token = "M1xMa324s5sa6geYsdhU342";//这里写你在微信公众平台里面填写的token $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr, SORT_STRING); $tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); if ($tmpStr == $signature) { return true; } else { return false; } } }