|
...
|
...
|
@@ -5,8 +5,12 @@ namespace App\Http\Controllers\Aside; |
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Http\Logic\Aside\LoginLogic;
|
|
|
|
use App\Models\Manage\Manage;
|
|
|
|
use App\Models\SmsLog;
|
|
|
|
use App\Models\User\User as UserModel;
|
|
|
|
use App\Rules\Mobile;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Mrgoon\AliSms\AliSms;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group 登录
|
|
...
|
...
|
@@ -55,4 +59,37 @@ class LoginController extends BaseController |
|
|
|
$data = $logic->accessAddress();
|
|
|
|
return $this->response('success',Code::SUCCESS,$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 发送登录短信
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function sendLoginSms()
|
|
|
|
{
|
|
|
|
$this->request->validate([
|
|
|
|
'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'],
|
|
|
|
],[
|
|
|
|
'mobile.required' => '手机号码不能为空',
|
|
|
|
'mobile.regex' => '请输入正确的手机号码',
|
|
|
|
]);
|
|
|
|
$mobile = $this->param['mobile'];
|
|
|
|
$manager = Manage::where(['mobile' => $mobile])->first();
|
|
|
|
if (empty($manager)) {
|
|
|
|
$this->response('请输入正确的手机号码!', Code::USER_LOGIN_ERROE);
|
|
|
|
}
|
|
|
|
$last_sms = SmsLog::getLastLog($mobile, SmsLog::TYPE_MANAGER_LOGIN);
|
|
|
|
if ($last_sms && $last_sms->use = SmsLog::USE_USABLE && time() - strtotime($last_sms->created_at) < 60) {
|
|
|
|
$this->response('请不要重复发送短信!', Code::USER_LOGIN_ERROE);
|
|
|
|
}
|
|
|
|
$template = config('aliyunsms.login_sms_temp');
|
|
|
|
$code['code'] = rand(100000,999999);
|
|
|
|
$ali_sms = new AliSms();
|
|
|
|
$send = $ali_sms->sendSms(strval($mobile), $template, $code);
|
|
|
|
if (empty($send->Code) && $send->Code != 'OK') {
|
|
|
|
$this->response('发送失败, 请稍后重试!', Code::USER_LOGIN_ERROE);
|
|
|
|
}
|
|
|
|
SmsLog::createLog($mobile, $code['code'],SmsLog::TYPE_MANAGER_LOGIN);
|
|
|
|
$this->response('success');
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|