Demo.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Tenim;
  5. use think\Db;
  6. /**
  7. * 示例接口
  8. */
  9. class Demo extends Api
  10. {
  11. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  12. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  13. //如果接口已经设置无需登录,那也就无需鉴权了
  14. //
  15. // 无需登录的接口,*表示全部
  16. protected $noNeedLogin = ['test', 'test1','im_reg_all'];
  17. // 无需鉴权的接口,*表示全部
  18. protected $noNeedRight = ['test2'];
  19. /**
  20. * 注册所有账号到腾讯im
  21. * user_用户端小程序,master_师傅,kefu_客服
  22. */
  23. public function im_reg_all()
  24. {
  25. $list = Db::name('user')->select();
  26. $tenim = new Tenim();
  27. foreach($list as $key => $val){
  28. $rs = $tenim->register('user_'. $val['id'], $val['nickname'], localpath_to_netpath($val['avatar']));
  29. dump($rs);
  30. }
  31. //
  32. $list = Db::name('worker')->select();
  33. $tenim = new Tenim();
  34. foreach($list as $key => $val){
  35. $rs = $tenim->register('master_'. $val['id'], $val['truename'], localpath_to_netpath($val['avatar']));
  36. dump($rs);
  37. }
  38. //
  39. $list = Db::name('company')->select();
  40. $tenim = new Tenim();
  41. foreach($list as $key => $val){
  42. $rs = $tenim->register('kefu_'. $val['id'], $val['companyname'], localpath_to_netpath($val['avatar']));
  43. dump($rs);
  44. }
  45. }
  46. /**
  47. * 测试方法
  48. *
  49. * @ApiTitle (测试名称)
  50. * @ApiSummary (测试描述信息)
  51. * @ApiMethod (POST)
  52. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  53. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  54. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  55. * @ApiParams (name="name", type="string", required=true, description="用户名")
  56. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  57. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  58. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  59. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  60. * @ApiReturn ({
  61. 'code':'1',
  62. 'msg':'返回成功'
  63. })
  64. */
  65. public function test()
  66. {
  67. $data = [
  68. [
  69. 'type' => 'video',
  70. 'url' => '/upload/20240712/aaaaa.mp4',
  71. ],
  72. [
  73. 'type' => 'img',
  74. 'url' => '/upload/20240712/bbbbb.jpg',
  75. ],
  76. [
  77. 'type' => 'video',
  78. 'url' => '/upload/20240712/ccccc.mp4',
  79. ],
  80. [
  81. 'type' => 'img',
  82. 'url' => '/upload/20240712/ddddd.png',
  83. ],
  84. ];
  85. echo json_encode($data);
  86. }
  87. /**
  88. * 无需登录的接口
  89. *
  90. */
  91. public function test1()
  92. {
  93. $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';
  94. $rule = explode(',',$rule);
  95. dump($rule);
  96. $b = array_count_values($rule);
  97. dump($b);
  98. }
  99. /**
  100. * 需要登录的接口
  101. *
  102. */
  103. public function test2()
  104. {
  105. $this->success('返回成功', ['action' => 'test2']);
  106. }
  107. /**
  108. * 需要登录且需要验证有相应组的权限
  109. *
  110. */
  111. public function test3()
  112. {
  113. $this->success('返回成功', ['action' => 'test3']);
  114. }
  115. }