Merge #49 into master from cc_20260302_login_password
验证码登录 * cc_20260302_login_password: (3 commits squashed) - fix:新增验证码登录,发送验证码,修改密码接口 - fix - fix Signed-off-by: 王非凡 <accounts_67eba0c5fee9c49c80c8e2b4@mail.teambition.com> Merged-by: 正新 <accounts_6964c7bcd2a2c377c5bbd01b@mail.teambition.com> CR-link: https://codeup.aliyun.com/692ea314dec569489f6f167c/hangzhou/java/custom_zxjp/change/49
This commit is contained in:
@@ -68,6 +68,14 @@ public enum ErrorCodeEnum {
|
||||
IMPROVE_USER_INFO(1021086,"请联系管理员,完善用户信息!",null),
|
||||
PASSWORD_ERROR(1021087, "密码输入错误",null),
|
||||
PASSWORD_ERROR_MULTI(1021088, "密码错误{0}次,请使用验证码登录",null),
|
||||
|
||||
MOBILE_NOT_MATCH(1023001, "修改失败,手机号与当前用户不匹配",null),
|
||||
SMS_CODE_EXPIRE(1023002, "验证码已过期!",null),
|
||||
SMS_CODE_ERROR(1023003, "验证码错误!",null),
|
||||
SEND_SMS_LIMIT_COUNT(1023004, "短信发送失败,今日发送短信已达上限",null),
|
||||
NONSUPPORT_MOBILE(1023005, "暂不支持的手机号格式", null),
|
||||
SMS_CODE_MISSING(1023006, "验证码缺失!",null),
|
||||
|
||||
//红圈通
|
||||
HQT_SHOP_DECORATION_ATTRIBUTES(1022000, "获取红圈通装修属性错误", null),
|
||||
HQT_PARAMS_ERROR(1022001, "构建红圈通请求参数错误", null),
|
||||
|
||||
@@ -16,6 +16,7 @@ import lombok.Getter;
|
||||
public enum LoginTypeEnum {
|
||||
|
||||
PASSWORD("账号密码", "passwordLoginServiceImpl"),
|
||||
SMS("短信验证码","smsLoginServiceImpl"),
|
||||
|
||||
;
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@ package com.cool.store.enums;
|
||||
public enum SmsCodeTypeEnum {
|
||||
|
||||
LOGIN("SMS_220325070","验证码登录", 10 * 60),
|
||||
FORGOT_PWD("SMS_220325070","忘记密码", 10 * 60),
|
||||
// FORGOT_PWD("SMS_220325070","忘记密码", 10 * 60),
|
||||
MODIFY_PWD("SMS_220325070","修改密码", 10 * 60),
|
||||
IMPROVE_INFO("SMS_220325070","完善用户信息", 10 * 60),
|
||||
USER_REGISTER("SMS_220325070","用户注册", 10 * 60),
|
||||
ENTERPRISE_REGISTER("SMS_220325070","企业注册", 10 * 60),
|
||||
LOGIN2("SMS_232163403","验证码登录", 10 * 60),
|
||||
|
||||
LOGIN2("SMS_498720063","验证码登录", 10 * 60),
|
||||
|
||||
LOGIN_INTERNATIONAL("SMS_474876096", "国际验证码登录", 10 * 60),
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.cool.store.enums.sms;
|
||||
|
||||
import cn.hutool.core.lang.PatternPool;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.PhoneUtil;
|
||||
import com.cool.store.enums.SmsCodeTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* describe: 短信手机区号类型
|
||||
*
|
||||
* @author wangff
|
||||
* @date 2024/11/8
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum SmsZoneEnum {
|
||||
INDONESIA("+62", "印度尼西亚", SmsCodeTypeEnum.LOGIN_INTERNATIONAL.getTemplateCode(), Pattern.compile("\\d{10,12}")),
|
||||
|
||||
MALAYSIA("+60", "马来西亚", SmsCodeTypeEnum.LOGIN_INTERNATIONAL.getTemplateCode(), Pattern.compile("\\d{6,12}")),
|
||||
|
||||
CHINA("+86", "中国", SmsCodeTypeEnum.LOGIN2.getTemplateCode(), PatternPool.MOBILE),
|
||||
;
|
||||
|
||||
/**
|
||||
* 区号
|
||||
*/
|
||||
private final String code;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private final String msg;
|
||||
|
||||
/**
|
||||
* 短信模板code
|
||||
*/
|
||||
private final String templateCode;
|
||||
|
||||
/**
|
||||
* 手机号格式
|
||||
*/
|
||||
private final Pattern mobilePattern;
|
||||
|
||||
/**
|
||||
* 根据手机号获取枚举类型
|
||||
* @param mobile 手机号
|
||||
* @return 短信手机区号类型
|
||||
*/
|
||||
public static SmsZoneEnum getByMobile(String mobile) {
|
||||
if (StringUtils.isBlank(mobile)) {
|
||||
return null;
|
||||
}
|
||||
if (PhoneUtil.isMobile(mobile)) {
|
||||
return CHINA;
|
||||
}
|
||||
String[] split = mobile.split(" ");
|
||||
if (split.length < 2) {
|
||||
return null;
|
||||
}
|
||||
return ArrayUtil.firstMatch(v -> split[0].startsWith(v.getCode()) && Validator.isMatchRegex(v.getMobilePattern(), split[1]), values());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2026/3/2
|
||||
*/
|
||||
public class HttpHelper {
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.enums.sms.SmsZoneEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* describe: 手机号工具类
|
||||
*
|
||||
* @author wangff
|
||||
* @date 2024/11/8
|
||||
*/
|
||||
public class MobileUtil {
|
||||
|
||||
/**
|
||||
* 根据手机号获取短信手机区号类型枚举
|
||||
* @param mobile 手机号
|
||||
* @return 短信手机区号类型枚举
|
||||
*/
|
||||
public static String getSmsTemplateCode(String mobile) {
|
||||
SmsZoneEnum smsZoneEnum = SmsZoneEnum.getByMobile(mobile);
|
||||
if (ObjectUtil.isNull(smsZoneEnum)) {
|
||||
throw new ServiceException(ErrorCodeEnum.NONSUPPORT_MOBILE);
|
||||
}
|
||||
return smsZoneEnum.getTemplateCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除手机号中的+号和空格
|
||||
* @param mobile 手机号
|
||||
* @return 手机号
|
||||
*/
|
||||
public static String transNoPlusAndBlank(String mobile) {
|
||||
if (StringUtils.isBlank(mobile)) {
|
||||
return mobile;
|
||||
}
|
||||
String[] array = StringUtils.split(mobile, ' ');
|
||||
if (array.length < 2) {
|
||||
return mobile;
|
||||
}
|
||||
return array[0].substring(1).trim() + array[1].trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验手机号格式
|
||||
* @param mobile 手机号
|
||||
* @return 格式是否正确
|
||||
*/
|
||||
public static boolean validateMobile(String mobile) {
|
||||
SmsZoneEnum smsZoneEnum = SmsZoneEnum.getByMobile(mobile);
|
||||
return ObjectUtil.isNotNull(smsZoneEnum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号统一存储格式
|
||||
* <p>
|
||||
* 国内手机号去除86/+86,国外手机号格式不变
|
||||
* </p>
|
||||
* @param mobile 手机号
|
||||
* @return 格式化后手机号
|
||||
*/
|
||||
public static String unifyMobile(String mobile) {
|
||||
SmsZoneEnum smsZoneEnum = SmsZoneEnum.getByMobile(mobile);
|
||||
if (SmsZoneEnum.CHINA.equals(smsZoneEnum) && (mobile.startsWith("+86") || mobile.startsWith("86"))) {
|
||||
mobile = mobile.substring(mobile.indexOf("86") + 2).trim();
|
||||
}
|
||||
return mobile;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user