|
@@ -129,9 +129,27 @@ class AuthController
|
|
|
{
|
|
|
list($phone, $type, $key, $code) = UtilService::postMore([['phone', 0], ['type', ''], ['key', ''], ['code', '']], $request, true);
|
|
|
|
|
|
- $keyName = 'sms.key.' . $key;
|
|
|
- $nowKey = 'sms.' . date('YmdHi');
|
|
|
+ $temp = function ($item) {
|
|
|
+ switch ($item) {
|
|
|
+ case "register":
|
|
|
+ return 'REGISTER';
|
|
|
+ case "login":
|
|
|
+ return 'LOGIN';
|
|
|
+ case "reset":
|
|
|
+ return 'RESET';
|
|
|
+ case "reset_2":
|
|
|
+ return 'RESET_2';
|
|
|
+ case "trade":
|
|
|
+ return 'TRADE';
|
|
|
+ default:
|
|
|
+ return 'DEFAULT';
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ $nowKey = 'sms.' . date('YmdHi');
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -149,7 +167,6 @@ class AuthController
|
|
|
if ($total > Config::get('sms.maxMinuteCount', 20))
|
|
|
return app('json')->success('已发送');
|
|
|
}
|
|
|
-
|
|
|
try {
|
|
|
validate(RegisterValidates::class)->scene('code')->check(['phone' => $phone]);
|
|
|
} catch (ValidateException $e) {
|
|
@@ -162,25 +179,53 @@ class AuthController
|
|
|
$defaultMaxIpCount = Config::get('sms.maxIpCount', 50);
|
|
|
$maxPhoneCount = Config::get('sms.stores.' . $default . '.maxPhoneCount', $defaultMaxPhoneCount);
|
|
|
$maxIpCount = Config::get('sms.stores.' . $default . '.maxIpCount', $defaultMaxIpCount);
|
|
|
- if (SmsRecord::where('phone', $phone)->where('add_ip', $request->ip())->whereDay('add_time')->count() >= $maxPhoneCount) {
|
|
|
- return app('json')->fail('您今日发送得短信次数已经达到上限');
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
if (SmsRecord::where('add_ip', $request->ip())->whereDay('add_time')->count() >= $maxIpCount) {
|
|
|
return app('json')->fail('此IP今日发送次数已经达到上限');
|
|
|
}
|
|
|
$time = 60;
|
|
|
- if (CacheService::get('code_' . $phone))
|
|
|
- return app('json')->fail($time . '秒内有效');
|
|
|
+
|
|
|
+
|
|
|
$code = rand(100000, 999999);
|
|
|
$data['code'] = $code;
|
|
|
- $res = ShortLetterRepositories::send(true, $phone, $data, 'VERIFICATION_CODE');
|
|
|
+ $res = self::NewSmsSend($phone, $data, $temp($type));
|
|
|
+
|
|
|
if ($res !== true)
|
|
|
return app('json')->fail('短信平台验证码发送失败' . $res);
|
|
|
CacheService::set('code_' . $phone, $code, $time);
|
|
|
- Cache::set($keyName, $num + 1, 300);
|
|
|
- Cache::set($nowKey, $total, 61);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return app('json')->success('短信验证发送成功');
|
|
|
+ }
|
|
|
|
|
|
- return app('json')->success('发送成功');
|
|
|
+
|
|
|
+ * 发送短信
|
|
|
+ * @param string $phone 手机号码
|
|
|
+ * @param array $data 模板替换内容
|
|
|
+ * @param string $template 模板编号
|
|
|
+ * @return bool|string
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ */
|
|
|
+ public static function NewSmsSend(string $phone, array $data, string $template)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $res = ZjSMSServerService::send($phone, $data);
|
|
|
+
|
|
|
+
|
|
|
+ if ($res['status'] != '200') {
|
|
|
+ return $res['msg'];
|
|
|
+ } else {
|
|
|
+ SmsRecord::sendRecord($phone, $data['code'], $template, '');
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } catch (Exception $exception) {
|
|
|
+
|
|
|
+ return $exception->getMessage();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -197,11 +242,11 @@ class AuthController
|
|
|
return app('json')->fail($e->getError());
|
|
|
}
|
|
|
$verifyCode = CacheService::get('code_' . $account);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ if (!$verifyCode)
|
|
|
+ return app('json')->fail('请先获取验证码');
|
|
|
+ $verifyCode = substr($verifyCode, 0, 6);
|
|
|
+ if ($verifyCode != $captcha)
|
|
|
+ return app('json')->fail('验证码错误');
|
|
|
if (strlen(trim($password)) < 6 || strlen(trim($password)) > 16)
|
|
|
return app('json')->fail('密码必须是在6到16位之间');
|
|
|
if ($password == '123456') return app('json')->fail('密码太过简单,请输入较为复杂的密码');
|