Demo.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. public function __construct(){
  24. $this->error('投票活动结束了');
  25. }
  26. //一次注册15w用户
  27. public function testreg(){
  28. exit;
  29. $mobile_s = 19000100000;
  30. $mobile_e = 19000250000;
  31. $user = [];
  32. for($i=$mobile_s;$i<=$mobile_e;$i++){
  33. $user[] = $this->register($i);
  34. }
  35. Db::name('user')->insertAll($user);
  36. }
  37. private function register($mobile = '')
  38. {
  39. $ip = '127.0.0.1';
  40. $time = 1731554772;
  41. $data = [
  42. 'mobile' => $mobile,
  43. 'avatar' => '/uploads/20241105/47eb7f0430d48a73346b1630692e20ae.png',
  44. 'nickname' => $mobile,
  45. 'bind_jigou_id' => 1,
  46. 'bind_jigou_times' => 1,
  47. ];
  48. $params = array_merge($data, [
  49. 'jointime' => $time,
  50. 'joinip' => $ip,
  51. 'logintime' => $time,
  52. 'loginip' => $ip,
  53. 'prevtime' => $time,
  54. 'createtime' => $time,
  55. 'updatetime' => $time,
  56. 'status' => 1
  57. ]);
  58. return $params;
  59. }
  60. //////////////////////////////////////////////////////
  61. private function getmobile(){
  62. $start = 19300000000;
  63. $mobile = RedisUtil::getInstance(RedisKeyEnum::MOBILE_REGISTER)->incr();
  64. return $start + $mobile;
  65. }
  66. public function auto_register()
  67. {
  68. $mobile = $this->getmobile();
  69. $captcha = '1212';
  70. if (!$mobile || !$captcha) {
  71. $this->error(__('Invalid parameters'));
  72. }
  73. if (!Validate::regex($mobile, "^1\d{10}$")) {
  74. $this->error(__('Mobile is incorrect'));
  75. }
  76. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  77. $this->error(__('Captcha is incorrect'));
  78. }
  79. $user = \app\common\model\User::getByMobile($mobile);
  80. if ($user) {
  81. if ($user->status != 1) {
  82. $this->error(__('Account is locked'));
  83. }
  84. //如果已经有账号则直接登录
  85. $ret = $this->auth->direct($user->id);
  86. } else {
  87. $ret = $this->auth->register('', '', '', $mobile, []);
  88. }
  89. if ($ret) {
  90. Sms::flush($mobile, 'mobilelogin');
  91. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  92. } else {
  93. $this->error($this->auth->getError());
  94. }
  95. }
  96. }