Demo.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. use think\Validate;
  9. use app\common\library\Sms;
  10. /**
  11. * 示例接口
  12. */
  13. class Demo extends Api
  14. {
  15. //如果$noNeedLogin为空表示所有接口都需要登录才能请求
  16. //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
  17. //如果接口已经设置无需登录,那也就无需鉴权了
  18. //
  19. // 无需登录的接口,*表示全部
  20. protected $noNeedLogin = ['*'];
  21. // 无需鉴权的接口,*表示全部
  22. protected $noNeedRight = ['test2'];
  23. //一次注册15w用户
  24. public function testreg(){
  25. exit;
  26. $mobile_s = 19000100000;
  27. $mobile_e = 19000250000;
  28. $user = [];
  29. for($i=$mobile_s;$i<=$mobile_e;$i++){
  30. $user[] = $this->register($i);
  31. }
  32. Db::name('user')->insertAll($user);
  33. }
  34. private function register($mobile = '')
  35. {
  36. $ip = '127.0.0.1';
  37. $time = 1731554772;
  38. $data = [
  39. 'mobile' => $mobile,
  40. 'avatar' => '/uploads/20241105/47eb7f0430d48a73346b1630692e20ae.png',
  41. 'nickname' => $mobile,
  42. 'bind_jigou_id' => 1,
  43. 'bind_jigou_times' => 1,
  44. ];
  45. $params = array_merge($data, [
  46. 'jointime' => $time,
  47. 'joinip' => $ip,
  48. 'logintime' => $time,
  49. 'loginip' => $ip,
  50. 'prevtime' => $time,
  51. 'createtime' => $time,
  52. 'updatetime' => $time,
  53. 'status' => 1
  54. ]);
  55. return $params;
  56. }
  57. //////////////////////////////////////////////////////
  58. private function getmobile(){
  59. $start = 19300000000;
  60. $mobile = RedisUtil::getInstance(RedisKeyEnum::MOBILE_REGISTER)->incr();
  61. return $start + $mobile;
  62. }
  63. public function auto_register()
  64. {
  65. $mobile = $this->getmobile();
  66. $captcha = '1212';
  67. if (!$mobile || !$captcha) {
  68. $this->error(__('Invalid parameters'));
  69. }
  70. if (!Validate::regex($mobile, "^1\d{10}$")) {
  71. $this->error(__('Mobile is incorrect'));
  72. }
  73. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  74. $this->error(__('Captcha is incorrect'));
  75. }
  76. $user = \app\common\model\User::getByMobile($mobile);
  77. if ($user) {
  78. if ($user->status != 1) {
  79. $this->error(__('Account is locked'));
  80. }
  81. //如果已经有账号则直接登录
  82. $ret = $this->auth->direct($user->id);
  83. } else {
  84. $ret = $this->auth->register('', '', '', $mobile, []);
  85. }
  86. if ($ret) {
  87. Sms::flush($mobile, 'mobilelogin');
  88. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  89. } else {
  90. $this->error($this->auth->getError());
  91. }
  92. }
  93. }