Demo.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use app\common\library\Uploadvideo;
  6. use app\utils\RedisKeyEnum;
  7. use app\utils\RedisUtil;
  8. /**
  9. * 示例接口
  10. */
  11. class Demo extends Api
  12. {
  13. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  14. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  15. //如果接口已经设置无需登录,那也就无需鉴权了
  16. //
  17. // 无需登录的接口,*表示全部
  18. protected $noNeedLogin = ['*'];
  19. // 无需鉴权的接口,*表示全部
  20. protected $noNeedRight = ['test2'];
  21. /**
  22. * 测试方法
  23. *
  24. * @ApiTitle (测试名称)
  25. * @ApiSummary (测试描述信息)
  26. * @ApiMethod (POST)
  27. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  28. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  29. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  30. * @ApiParams (name="name", type="string", required=true, description="用户名")
  31. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  32. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  33. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  34. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  35. * @ApiReturn ({
  36. 'code':'1',
  37. 'msg':'返回成功'
  38. })
  39. */
  40. public function test()
  41. {
  42. $params = [
  43. 'video_file' => '/uploads/20241101/b472251c04af8842b14f6c15a57fca9b.mp4',
  44. 'title' => '测试',
  45. ];
  46. $full_filepath = config('upload.cdnurl').$params['video_file'];
  47. $uploadvideo = new Uploadvideo();
  48. $res = $uploadvideo->testUploadWebVideo($full_filepath,$params['title']);
  49. $params['vodid'] = $res;
  50. }
  51. //因后缀问题被拒了
  52. public function test33()
  53. {
  54. $params = [
  55. 'video_file' => 'C:\Windows\Temp\php4F8B.tmp',
  56. 'title' => '测试'.rand(10,99),
  57. ];
  58. $full_filepath = $params['video_file'];
  59. $uploadvideo = new Uploadvideo();
  60. $res = $uploadvideo->testUploadLocalVideo($full_filepath,$params['title']);
  61. $params['vodid'] = $res;
  62. }
  63. /**
  64. * 无需登录的接口
  65. *
  66. */
  67. public function test1()
  68. {
  69. RedisUtil::getInstance('test'.date('Y-m-d'))->incrby_expire(3,86400);
  70. }
  71. /**
  72. * 需要登录的接口
  73. *
  74. */
  75. public function test2()
  76. {
  77. $data = [
  78. [
  79. 'id' => 1,
  80. 'answer' => 'A',
  81. ],
  82. [
  83. 'id' => 2,
  84. 'answer' => 'B',
  85. ],
  86. ];
  87. echo json_encode($data);
  88. }
  89. /**
  90. * 需要登录且需要验证有相应组的权限
  91. *
  92. */
  93. public function test3()
  94. {
  95. $this->success('返回成功', ['action' => 'test3']);
  96. }
  97. }