Demo.php 2.9 KB

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