Demo.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Easemob;
  5. use app\common\library\Tenim;
  6. use think\Db;
  7. /**
  8. * 示例接口
  9. */
  10. class Demo extends Api
  11. {
  12. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  13. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  14. //如果接口已经设置无需登录,那也就无需鉴权了
  15. //
  16. // 无需登录的接口,*表示全部
  17. protected $noNeedLogin = ['*'];
  18. // 无需鉴权的接口,*表示全部
  19. protected $noNeedRight = ['test2'];
  20. /**
  21. * 测试方法
  22. *
  23. * @ApiTitle (测试名称)
  24. * @ApiSummary (测试描述信息)
  25. * @ApiMethod (POST)
  26. * @ApiRoute (/api/demo/test/id/{id}/name/{name})
  27. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  28. * @ApiParams (name="id", type="integer", required=true, description="会员ID")
  29. * @ApiParams (name="name", type="string", required=true, description="用户名")
  30. * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
  31. * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  32. * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  33. * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  34. * @ApiReturn ({
  35. 'code':'1',
  36. 'msg':'返回成功'
  37. })
  38. */
  39. public function test()
  40. {
  41. $easemob = new Easemob();
  42. $rs = $easemob->user_create('doctor1');
  43. }
  44. /**
  45. * 无需登录的接口
  46. *
  47. */
  48. public function test1()
  49. {
  50. $list = Db::name('user')->select();
  51. foreach($list as $key => $val){
  52. $tenim = new Tenim();
  53. $rs = $tenim->register('user'. $val['id'], $val['nickname'], '');
  54. dump($rs);
  55. }
  56. }
  57. public function test12()
  58. {
  59. $list = Db::name('doctor')->where('status',1)->select();
  60. foreach($list as $key => $val){
  61. $tenim = new Tenim();
  62. $rs = $tenim->register('doctor'. $val['id'], $val['nickname'], '');
  63. dump($rs);
  64. }
  65. }
  66. /**
  67. * 需要登录的接口
  68. *
  69. */
  70. public function test2()
  71. {
  72. $tenim = new Tenim();
  73. $order_id = 26;
  74. $message = [
  75. 'businessID' => 'order_status',
  76. 'name' => '待接单',
  77. 'status' => '10',
  78. 'id' => (string)$order_id,
  79. 'content' => '已通知医生尽快接诊,超时自动取消订单并退款',
  80. ];
  81. $rs = $tenim->sendCustomMessageToUser('user7','doctor7',$message);
  82. dump($rs);
  83. }
  84. /**
  85. * 需要登录且需要验证有相应组的权限
  86. *
  87. */
  88. public function test3()
  89. {
  90. $tv_userid = input('tv_userid');
  91. $tv_signtime = input('tv_signtime');
  92. $salt = 'be7bcf1499b0fec801406f6aafbd04c4';
  93. $get_sign = md5(md5($tv_userid) . $tv_signtime . $salt);
  94. dump($get_sign);
  95. }
  96. public function test4(){
  97. $wenzhen_order['user_id'] = 13;
  98. //判断患者在线状态
  99. $tenim = new Tenim();
  100. $rs_online = $tenim->is_online('user'.$wenzhen_order['user_id']);
  101. if($rs_online != true){
  102. $this->error('患者现在不在线,请稍后拨打');
  103. }
  104. echo '在线';
  105. }
  106. public function test5(){
  107. $checkmap = [
  108. 'user_id' => 34,
  109. 'comefrom'=> 2,
  110. 'status' => ['IN','10,20,25,30'],//有效订单
  111. ];
  112. $check_order = Db::name('wenzhen_order')->where($checkmap)->whereTime('createtime','month')->find();
  113. echo db()->getLastSql();
  114. }
  115. }