| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?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);
- if ($tmpStr == $signature) {
- return true;
- } else {
- return false;
- }
- }
- }
|