|
@@ -103,30 +103,31 @@ public class PortalAuthController extends BaseController {
|
|
|
// 验证码缓存5分钟
|
|
// 验证码缓存5分钟
|
|
|
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
|
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
|
|
|
|
|
|
|
- if ("dev".equalsIgnoreCase(activeProfile)) {
|
|
|
|
|
- log.info("开发环境短信验证码: phone={}, code={}", phonenumber, code);
|
|
|
|
|
|
|
+ // 非生产环境不发送真实短信,仅打印验证码日志
|
|
|
|
|
+// if (!"prod".equalsIgnoreCase(activeProfile)) {
|
|
|
|
|
+ log.info("测试环境短信验证码: phone={}, code={},也可使用万能验证码 123456", phonenumber, code);
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
- }
|
|
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
// 发送短信验证码
|
|
// 发送短信验证码
|
|
|
// 验证码模板id 需要在短信服务商配置
|
|
// 验证码模板id 需要在短信服务商配置
|
|
|
- String templateId = "";
|
|
|
|
|
- LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
|
|
|
|
- map.put("code", code);
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
|
|
|
|
|
- SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
|
|
|
|
|
- if (!smsResponse.isSuccess()) {
|
|
|
|
|
- log.error("验证码短信发送异常 => {}", smsResponse);
|
|
|
|
|
- return R.fail(smsResponse.getData().toString());
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("验证码短信发送异常 => {}", e.getMessage());
|
|
|
|
|
- throw new ServiceException("短信发送失败,请稍后重试");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return R.ok();
|
|
|
|
|
|
|
+// String templateId = "";
|
|
|
|
|
+// LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
|
|
|
|
|
+// map.put("code", code);
|
|
|
|
|
+//
|
|
|
|
|
+// try {
|
|
|
|
|
+// SmsBlend smsBlend = SmsFactory.getSmsBlend("config1");
|
|
|
|
|
+// SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, templateId, map);
|
|
|
|
|
+// if (!smsResponse.isSuccess()) {
|
|
|
|
|
+// log.error("验证码短信发送异常 => {}", smsResponse);
|
|
|
|
|
+// return R.fail(smsResponse.getData().toString());
|
|
|
|
|
+// }
|
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
|
+// log.error("验证码短信发送异常 => {}", e.getMessage());
|
|
|
|
|
+// throw new ServiceException("短信发送失败,请稍后重试");
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -273,6 +274,11 @@ public class PortalAuthController extends BaseController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void validateSmsCode(String phonenumber, String smsCode) {
|
|
private void validateSmsCode(String phonenumber, String smsCode) {
|
|
|
|
|
+ // 万能验证码 123456,测试阶段使用
|
|
|
|
|
+ if ("123456".equals(smsCode)) {
|
|
|
|
|
+ log.info("测试万能验证码登录: phone={}", phonenumber);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
String cacheKey = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber;
|
|
String cacheKey = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber;
|
|
|
String cachedCode = RedisUtils.getCacheObject(cacheKey);
|
|
String cachedCode = RedisUtils.getCacheObject(cacheKey);
|
|
|
if (StringUtils.isBlank(cachedCode)) {
|
|
if (StringUtils.isBlank(cachedCode)) {
|