Index.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\Area;
  4. use app\common\controller\Api;
  5. use think\Request;
  6. /**
  7. * 系统数据
  8. */
  9. class Index extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. private $bannerModel;
  13. public function __construct(Request $request = null)
  14. {
  15. $this->bannerModel = new \app\api\model\Banner();
  16. parent::__construct($request);
  17. }
  18. /**
  19. * 获取banner
  20. * @return void
  21. */
  22. public function fetchBanner()
  23. {
  24. $module_type = input("module_type", "user");
  25. $banners = $this->bannerModel->fetchBanner($module_type, 5);
  26. $this->success($banners);
  27. }
  28. public function fetchArea()
  29. {
  30. $this->success(Area::fetchArea());
  31. }
  32. public function check()
  33. {
  34. $signature = $this->request->param('signature', "");
  35. $timestamp = $this->request->param('timestamp', "");
  36. $nonce = $this->request->param('nonce', "");
  37. $echostr = $this->request->param('echostr', "");
  38. if ($this->checkSignature($signature, $timestamp, $nonce)) {
  39. ob_clean();
  40. echo $echostr;
  41. die;//这里特别注意,如果不用die结束程序会token验证失败
  42. } else {
  43. echo false;
  44. }
  45. }
  46. private function checkSignature($signature, $timestamp, $nonce)
  47. {
  48. $token = "M1xMa324s5sa6geYsdhU342";//这里写你在微信公众平台里面填写的token
  49. $tmpArr = array($token, $timestamp, $nonce);
  50. sort($tmpArr, SORT_STRING);
  51. $tmpStr = implode($tmpArr);
  52. $tmpStr = sha1($tmpStr);
  53. return $tmpStr == $signature;
  54. }
  55. }