|
@@ -7,6 +7,8 @@ use think\Db;
|
|
|
use app\common\library\Uploadvideo;
|
|
|
use app\utils\RedisKeyEnum;
|
|
|
use app\utils\RedisUtil;
|
|
|
+use think\Validate;
|
|
|
+use app\common\library\Sms;
|
|
|
/**
|
|
|
* 示例接口
|
|
|
*/
|
|
@@ -65,4 +67,43 @@ class Demo extends Api
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //////////////////////////////////////////////////////
|
|
|
+ private function getmobile(){
|
|
|
+ $start = 19300000000;
|
|
|
+ $mobile = RedisUtil::getInstance(RedisKeyEnum::MOBILE_REGISTER)->incr();
|
|
|
+ return $start + $mobile;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function auto_register()
|
|
|
+ {
|
|
|
+ $mobile = $this->getmobile();
|
|
|
+ $captcha = '1212';
|
|
|
+ if (!$mobile || !$captcha) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
+ $this->error(__('Mobile is incorrect'));
|
|
|
+ }
|
|
|
+ if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
|
|
|
+ $this->error(__('Captcha is incorrect'));
|
|
|
+ }
|
|
|
+ $user = \app\common\model\User::getByMobile($mobile);
|
|
|
+ if ($user) {
|
|
|
+ if ($user->status != 1) {
|
|
|
+ $this->error(__('Account is locked'));
|
|
|
+ }
|
|
|
+ //如果已经有账号则直接登录
|
|
|
+ $ret = $this->auth->direct($user->id);
|
|
|
+ } else {
|
|
|
+ $ret = $this->auth->register('', '', '', $mobile, []);
|
|
|
+ }
|
|
|
+ if ($ret) {
|
|
|
+ Sms::flush($mobile, 'mobilelogin');
|
|
|
+ $this->success(__('Logged in successful'), $this->auth->getUserinfo());
|
|
|
+ } else {
|
|
|
+ $this->error($this->auth->getError());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|