|
@@ -128,19 +128,37 @@ class AuthController
|
|
|
{
|
|
{
|
|
|
list($phone, $type, $key, $code) = UtilService::postMore([['phone', 0], ['type', ''], ['key', ''], ['code', '']], $request, true);
|
|
list($phone, $type, $key, $code) = UtilService::postMore([['phone', 0], ['type', ''], ['key', ''], ['code', '']], $request, true);
|
|
|
|
|
|
|
|
- $keyName = 'sms.key.' . $key;
|
|
|
|
|
- $nowKey = 'sms.' . date('YmdHi');
|
|
|
|
|
-
|
|
|
|
|
- if (!Cache::has($keyName))
|
|
|
|
|
- return app('json')->make(401, '发送验证码失败');
|
|
|
|
|
|
|
+ $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';
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- if (($num = Cache::get($keyName)) > 2) {
|
|
|
|
|
- if (!$code)
|
|
|
|
|
- return app('json')->make(402, '请输入验证码');
|
|
|
|
|
|
|
|
|
|
- if (!$this->checkCaptcha($key, $code))
|
|
|
|
|
- return app('json')->fail('验证码输入有误');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// $keyName = 'sms.key.' . $key;
|
|
|
|
|
+ $nowKey = 'sms.' . date('YmdHi');
|
|
|
|
|
+//
|
|
|
|
|
+// if (!Cache::has($keyName))
|
|
|
|
|
+// return app('json')->make(401, '发送验证码失败');
|
|
|
|
|
+//
|
|
|
|
|
+// if (($num = Cache::get($keyName)) > 2) {
|
|
|
|
|
+// if (!$code)
|
|
|
|
|
+// return app('json')->make(402, '请输入验证码');
|
|
|
|
|
+//
|
|
|
|
|
+// if (!$this->checkCaptcha($key, $code))
|
|
|
|
|
+// return app('json')->fail('验证码输入有误');
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
$total = 1;
|
|
$total = 1;
|
|
|
if ($has = Cache::has($nowKey)) {
|
|
if ($has = Cache::has($nowKey)) {
|
|
@@ -148,7 +166,6 @@ class AuthController
|
|
|
if ($total > Config::get('sms.maxMinuteCount', 20))
|
|
if ($total > Config::get('sms.maxMinuteCount', 20))
|
|
|
return app('json')->success('已发送');
|
|
return app('json')->success('已发送');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
validate(RegisterValidates::class)->scene('code')->check(['phone' => $phone]);
|
|
validate(RegisterValidates::class)->scene('code')->check(['phone' => $phone]);
|
|
|
} catch (ValidateException $e) {
|
|
} catch (ValidateException $e) {
|
|
@@ -161,25 +178,53 @@ class AuthController
|
|
|
$defaultMaxIpCount = Config::get('sms.maxIpCount', 50);
|
|
$defaultMaxIpCount = Config::get('sms.maxIpCount', 50);
|
|
|
$maxPhoneCount = Config::get('sms.stores.' . $default . '.maxPhoneCount', $defaultMaxPhoneCount);
|
|
$maxPhoneCount = Config::get('sms.stores.' . $default . '.maxPhoneCount', $defaultMaxPhoneCount);
|
|
|
$maxIpCount = Config::get('sms.stores.' . $default . '.maxIpCount', $defaultMaxIpCount);
|
|
$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('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) {
|
|
if (SmsRecord::where('add_ip', $request->ip())->whereDay('add_time')->count() >= $maxIpCount) {
|
|
|
return app('json')->fail('此IP今日发送次数已经达到上限');
|
|
return app('json')->fail('此IP今日发送次数已经达到上限');
|
|
|
}
|
|
}
|
|
|
$time = 60;
|
|
$time = 60;
|
|
|
- if (CacheService::get('code_' . $phone))
|
|
|
|
|
- return app('json')->fail($time . '秒内有效');
|
|
|
|
|
|
|
+// if (CacheService::get('code_' . $phone))
|
|
|
|
|
+// return app('json')->fail($time . '秒内有效');
|
|
|
$code = rand(100000, 999999);
|
|
$code = rand(100000, 999999);
|
|
|
$data['code'] = $code;
|
|
$data['code'] = $code;
|
|
|
- $res = ShortLetterRepositories::send(true, $phone, $data, 'VERIFICATION_CODE');
|
|
|
|
|
|
|
+ $res = self::NewSmsSend($phone, $data, $temp($type));
|
|
|
|
|
+// $res = ShortLetterRepositories::send(true, $phone, $data, 'VERIFICATION_CODE');
|
|
|
if ($res !== true)
|
|
if ($res !== true)
|
|
|
return app('json')->fail('短信平台验证码发送失败' . $res);
|
|
return app('json')->fail('短信平台验证码发送失败' . $res);
|
|
|
CacheService::set('code_' . $phone, $code, $time);
|
|
CacheService::set('code_' . $phone, $code, $time);
|
|
|
- Cache::set($keyName, $num + 1, 300);
|
|
|
|
|
- Cache::set($nowKey, $total, 61);
|
|
|
|
|
|
|
+// 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);
|
|
|
|
|
+// var_dump($res);
|
|
|
|
|
+// exit;
|
|
|
|
|
+ if ($res['status'] != '200') {
|
|
|
|
|
+ return $res['msg'];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ SmsRecord::sendRecord($phone, $data['code'], $template, '');
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (Exception $exception) {
|
|
|
|
|
+// Log::info($exception->getMessage());
|
|
|
|
|
+ return $exception->getMessage();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|