Api.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace laytp\controller;
  3. use app\middleware\api\Auth;
  4. use app\middleware\api\CheckSign;
  5. use app\service\api\AuthServiceFacade;
  6. use app\service\api\CheckSignServiceFacade;
  7. use laytp\BaseController;
  8. use laytp\traits\JsonReturn;
  9. /**
  10. * Api应用控制器基类
  11. * @package laytp\controller
  12. */
  13. class Api extends BaseController
  14. {
  15. use JsonReturn;
  16. /**
  17. * 无需登录的方法,同时也就不需要鉴权了
  18. * @var array
  19. */
  20. protected $noNeedLogin = [];
  21. /**
  22. * 无需验证签名的方法
  23. * @var array
  24. */
  25. protected $noNeedCheckSign = [];
  26. /**
  27. * 中间件
  28. * @var array
  29. */
  30. protected $middleware = [
  31. Auth::class,
  32. CheckSign::class,
  33. ];
  34. protected function initialize()
  35. {
  36. //将无需登录的方法名数组设置到权限服务中,以方便中间件获取
  37. AuthServiceFacade::setNoNeedLogin($this->noNeedLogin);
  38. //将无需验证签名的方法名数组设置到Api验证签名服务中,以方便中间件获取
  39. CheckSignServiceFacade::setNoNeedCheckSign($this->noNeedCheckSign);
  40. $this->_initialize();
  41. }
  42. // 初始化
  43. protected function _initialize()
  44. {
  45. }
  46. }