Demo.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 示例接口
  7. */
  8. class Demo extends Api
  9. {
  10. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  11. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  12. //如果接口已经设置无需登录,那也就无需鉴权了
  13. //
  14. // 无需登录的接口,*表示全部
  15. protected $noNeedLogin = ['*'];
  16. // 无需鉴权的接口,*表示全部
  17. protected $noNeedRight = ['test2'];
  18. /**
  19. * 测试方法
  20. *
  21. * @ApiTitle (测试名称)
  22. * @ApiSummary (测试描述信息)
  23. * @ApiMethod (POST)
  24. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  25. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  26. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  27. * @ApiParams (name="name", type="string", required=true, description="用户名")
  28. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  29. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  30. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  31. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  32. * @ApiReturn ({
  33. 'code':'1',
  34. 'msg':'返回成功'
  35. })
  36. */
  37. public function test()
  38. {
  39. $password = 123456;
  40. $salt = '460dd5';
  41. $password = $this->auth->getEncryptPassword($password,$salt);
  42. echo $password;exit;
  43. $this->success('返回成功', $this->request->param());
  44. }
  45. /**
  46. * 无需登录的接口
  47. *
  48. */
  49. public function test1()
  50. {
  51. $a = [
  52. '23' => [
  53. 'item_id' => 23,
  54. 'level' => 5,
  55. 'content' => '很好23',
  56. 'images' => [
  57. '/uploads/20241019/244017dc8c5a698037da7bab78da2d34.png',
  58. '/uploads/20241019/244017dc8c5a698037da7bab78da2d34.png'
  59. ],
  60. ],
  61. '24' => [
  62. 'item_id' => 24,
  63. 'level' => 4,
  64. 'content' => '很好24',
  65. 'images' => [
  66. '/uploads/20241019/244017dc8c5a698037da7bab78da2d34.png',
  67. '/uploads/20241019/244017dc8c5a698037da7bab78da2d34.png'
  68. ],
  69. ],
  70. ];
  71. /* $a = [
  72. '/uploads/20241019/244017dc8c5a698037da7bab78da2d34.png',
  73. '/uploads/20241019/244017dc8c5a698037da7bab78da2d34.png'
  74. ];*/
  75. dump(json_encode($a));
  76. }
  77. /**
  78. * 需要登录的接口
  79. *
  80. */
  81. public function test2()
  82. {
  83. $this->success('返回成功', ['action' => 'test2']);
  84. }
  85. /**
  86. * 需要登录且需要验证有相应组的权限
  87. *
  88. */
  89. public function test3()
  90. {
  91. //$this->success('返回成功', ['action' => 'test3']);
  92. $data = [
  93. 'order_paidnum' => ['inc',1],
  94. 'order_total_amount' => ['inc',11.25],
  95. 'goods_sales' => ['inc',5],
  96. ];
  97. Db::name('live_room_log')->where('id',23)->update($data);
  98. }
  99. }