| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\api\controller;
- use app\api\model\Area;
- use app\common\controller\Api;
- use think\Request;
- /**
- * 系统数据
- */
- class Index extends Api
- {
- protected $noNeedLogin = ['*'];
- private $bannerModel;
- public function __construct(Request $request = null)
- {
- $this->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);
- return $tmpStr == $signature;
- }
- }
|