| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?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
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- 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;
- }
- }
- }
|