| | |
| | | private static final String LOGIN_CODE_CACHE_PREFIX = "app:sms:login:"; |
| | | private static final String REGISTER_CODE_CACHE_PREFIX = "app:sms:register:"; |
| | | private static final String PASSWORD_RESET_CODE_CACHE_PREFIX = "app:sms:password-reset:"; |
| | | private static final String PHONE_CHANGE_CODE_CACHE_PREFIX = "app:sms:phone-change:"; |
| | | |
| | | private final StringRedisTemplate stringRedisTemplate; |
| | | private final AppSmsSender appSmsSender; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 生成并发送修改手机号验证码,同时写入缓存。 |
| | | */ |
| | | public AppSmsCodeSendResponse createPhoneChangeCode(String phone) { |
| | | return createCode(phone, PHONE_CHANGE_CODE_CACHE_PREFIX, "phone-change"); |
| | | } |
| | | |
| | | /** |
| | | * 校验登录验证码,成功后销毁缓存中的一次性验证码。 |
| | | */ |
| | | public void validateLoginCode(String phone, String code) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 校验修改手机号验证码,成功后销毁缓存中的一次性验证码。 |
| | | */ |
| | | public void validatePhoneChangeCode(String phone, String code) { |
| | | validateCode(phone, code, PHONE_CHANGE_CODE_CACHE_PREFIX); |
| | | } |
| | | |
| | | /** |
| | | * 统一生成指定场景的验证码并写入缓存。 |
| | | */ |
| | | private AppSmsCodeSendResponse createCode(String phone, String cachePrefix, String scene) { |
| | |
| | | appSmsSender.sendLoginCode(phone, code); |
| | | } else if ("register".equals(scene)) { |
| | | appSmsSender.sendRegisterCode(phone, code); |
| | | } else { |
| | | } else if ("password-reset".equals(scene)) { |
| | | appSmsSender.sendPasswordResetCode(phone, code); |
| | | } else { |
| | | appSmsSender.sendPhoneChangeCode(phone, code); |
| | | } |
| | | return new AppSmsCodeSendResponse(appSmsAuthProperties.getExpireSeconds()); |
| | | } |