Demo.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 示例接口
  6. */
  7. class Demo extends Api
  8. {
  9. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  10. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  11. //如果接口已经设置无需登录,那也就无需鉴权了
  12. //
  13. // 无需登录的接口,*表示全部
  14. protected $noNeedLogin = ['test', 'test1'];
  15. // 无需鉴权的接口,*表示全部
  16. protected $noNeedRight = ['test2'];
  17. /**
  18. * 测试方法
  19. *
  20. * @ApiTitle (测试名称)
  21. * @ApiSummary (测试描述信息)
  22. * @ApiMethod (POST)
  23. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  24. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  25. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  26. * @ApiParams (name="name", type="string", required=true, description="用户名")
  27. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  28. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  29. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  30. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  31. * @ApiReturn ({
  32. 'code':'1',
  33. 'msg':'返回成功'
  34. })
  35. */
  36. public function test()
  37. {
  38. $data = [
  39. [
  40. 'type' => 'video',
  41. 'url' => '/upload/20240712/aaaaa.mp4',
  42. ],
  43. [
  44. 'type' => 'img',
  45. 'url' => '/upload/20240712/bbbbb.jpg',
  46. ],
  47. [
  48. 'type' => 'video',
  49. 'url' => '/upload/20240712/ccccc.mp4',
  50. ],
  51. [
  52. 'type' => 'img',
  53. 'url' => '/upload/20240712/ddddd.png',
  54. ],
  55. ];
  56. echo json_encode($data);
  57. }
  58. /**
  59. * 无需登录的接口
  60. *
  61. */
  62. public function test1()
  63. {
  64. $rule = '246,230,240,259,260,317,253,261,262,263,100,265,102,103,104,120,267,269,270,110,266,113,114,289,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,271,272,274,290,280,281,282,283,284,286,273,278,279,275,276,277,291,292,293';
  65. $rule = explode(',',$rule);
  66. dump($rule);
  67. $b = array_count_values($rule);
  68. dump($b);
  69. }
  70. /**
  71. * 需要登录的接口
  72. *
  73. */
  74. public function test2()
  75. {
  76. $this->success('返回成功', ['action' => 'test2']);
  77. }
  78. /**
  79. * 需要登录且需要验证有相应组的权限
  80. *
  81. */
  82. public function test3()
  83. {
  84. $this->success('返回成功', ['action' => 'test3']);
  85. }
  86. }