This commit is contained in:
sxu 2025-02-01 13:14:54 +08:00
parent 4b5d194d99
commit 23e15ad00d
3 changed files with 30 additions and 16 deletions

View File

@ -1,6 +1,8 @@
package net.xnzn.api; package net.xnzn.api;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.redis.service.RedisService; import com.bonus.common.redis.service.RedisService;
import net.xnzn.domain.SmsCodeVerifyDTO; import net.xnzn.domain.SmsCodeVerifyDTO;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -8,6 +10,13 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Service @Service
public class SmsCodeApi { public class SmsCodeApi {
private static final Logger log = LoggerFactory.getLogger(SmsCodeApi.class); private static final Logger log = LoggerFactory.getLogger(SmsCodeApi.class);
@ -18,26 +27,26 @@ public class SmsCodeApi {
// public void sendSmsCodePost(String telephoneNumber) { // public void sendSmsCodePost(String telephoneNumber) {
// this.sendSmsCodePost(telephoneNumber, "code_"); // this.sendSmsCodePost(telephoneNumber, "code_");
// } // }
//
// public void sendSmsCodePost(String telephoneNumber, String cacheKey) { // public void sendSmsCodePost(String telephoneNumber, String cacheKey) {
// String limitKey = "limit_" + telephoneNumber; // String limitKey = "limit_" + telephoneNumber;
// LocalDateTime now = LocalDateTime.now(); // LocalDateTime now = LocalDateTime.now();
// LocalDateTime endOfDay = now.with(LocalTime.MAX); // LocalDateTime endOfDay = now.with(LocalTime.MAX);
// long expirTime = Math.max(1L, Duration.between(now, endOfDay).getSeconds()); // long expirTime = Math.max(1L, Duration.between(now, endOfDay).getSeconds());
// String lastSendTimeKey = "last_send_time_" + telephoneNumber; // String lastSendTimeKey = "last_send_time_" + telephoneNumber;
// String lastSendTime = RedisUtil.getString(lastSendTimeKey); // String lastSendTime = redisService.getCacheObject(lastSendTimeKey);
// if (lastSendTime != null) { // if (lastSendTime != null) {
// long lastSendTimestamp = Long.parseLong(lastSendTime); // long lastSendTimestamp = Long.parseLong(lastSendTime);
// long currentTimestamp = System.currentTimeMillis(); // long currentTimestamp = System.currentTimeMillis();
// long timeElapsed = currentTimestamp - lastSendTimestamp; // long timeElapsed = currentTimestamp - lastSendTimestamp;
// if (timeElapsed < 60000L) { // if (timeElapsed < 60000L) {
// throw new LeException(I18n.getMessage("notice_verify_repeat_sms_code_exception", new Object[]{60})); // throw new ServiceException("notice_verify_repeat_sms_code_exception");
// } // }
// } // }
// //
// Integer times = RedisUtil.incr(limitKey, expirTime); // Integer times = RedisUtil.incr(limitKey, expirTime);
// if (times > 5) { // if (times > 5) {
// throw new LeException(I18n.getMessage("notice_verify_limit_sms_code_time", new Object[0])); // throw new ServiceException("notice_verify_limit_sms_code_time");
// } else { // } else {
// int code = (int)((Math.random() * 9.0 + 1.0) * 100000.0); // int code = (int)((Math.random() * 9.0 + 1.0) * 100000.0);
// String codeString = "" + code; // String codeString = "" + code;
@ -45,16 +54,16 @@ public class SmsCodeApi {
// maps.put("telephoneNumber", telephoneNumber); // maps.put("telephoneNumber", telephoneNumber);
// maps.put("sendCode", codeString); // maps.put("sendCode", codeString);
// log.info("验证码发送code : {}", codeString); // log.info("验证码发送code : {}", codeString);
// MqUtil.send(JSON.toJSONString(maps), LeMqConstant.Topic.NOTICE_VERIFICATION_CODE); // //MqUtil.send(JSON.toJSONString(maps), LeMqConstant.Topic.NOTICE_VERIFICATION_CODE);
// String key = cacheKey + telephoneNumber; // String key = cacheKey + telephoneNumber;
// RedisUtil.setString(key, codeString, 300L); // redisService.setCacheObject(key, codeString, 300L, TimeUnit.SECONDS);
// RedisUtil.setString(lastSendTimeKey, String.valueOf(System.currentTimeMillis())); // redisService.setCacheObject(lastSendTimeKey, String.valueOf(System.currentTimeMillis()));
// } // }
// } // }
public boolean verifySmsCode(SmsCodeVerifyDTO smsCodeVerifyDTO) { // public boolean verifySmsCode(SmsCodeVerifyDTO smsCodeVerifyDTO) {
return this.verifySmsCode(smsCodeVerifyDTO, "code_"); // return this.verifySmsCode(smsCodeVerifyDTO, "code_");
} // }
public boolean verifySmsCode(SmsCodeVerifyDTO smsCodeVerifyDTO, String cacheKey) { public boolean verifySmsCode(SmsCodeVerifyDTO smsCodeVerifyDTO, String cacheKey) {
String key = cacheKey + smsCodeVerifyDTO.getTelephoneNumber(); String key = cacheKey + smsCodeVerifyDTO.getTelephoneNumber();

View File

@ -2,6 +2,7 @@ package com.bonus.auth.controller;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.bonus.common.core.constant.CacheConstants;
import net.xnzn.api.SmsCodeApi; import net.xnzn.api.SmsCodeApi;
import net.xnzn.constant.CustLoginTypeEnum; import net.xnzn.constant.CustLoginTypeEnum;
import net.xnzn.constant.DelFlagEnum; import net.xnzn.constant.DelFlagEnum;
@ -128,14 +129,10 @@ public class TokenController {
SmsCodeVerifyDTO smsCodeVerifyDTO = new SmsCodeVerifyDTO(); SmsCodeVerifyDTO smsCodeVerifyDTO = new SmsCodeVerifyDTO();
smsCodeVerifyDTO.setCode(content.getCode()); smsCodeVerifyDTO.setCode(content.getCode());
smsCodeVerifyDTO.setTelephoneNumber(content.getMobile()); smsCodeVerifyDTO.setTelephoneNumber(content.getMobile());
boolean flag = this.smsCodeApi.verifySmsCode(smsCodeVerifyDTO); boolean flag = this.smsCodeApi.verifySmsCode(smsCodeVerifyDTO, CacheConstants.VERIFICATION_CODE);
if (!flag) { if (!flag) {
throw new ServiceException("验证码错误"); throw new ServiceException("验证码错误");
} }
// R<?> result = sysLoginService.getPhoneCode(content.getMobile(), content.getVerificationCodeType());
// if (result.getCode() != 200) {
// throw new ServiceException("验证码错误");
// }
custInfo.setMobile(SM4EncryptUtils.sm4Encryptbyconfig(content.getMobile())); custInfo.setMobile(SM4EncryptUtils.sm4Encryptbyconfig(content.getMobile()));
} else { } else {
if (!CustLoginTypeEnum.ID_CARD_PWD.key().equals(content.getLoginType())) { if (!CustLoginTypeEnum.ID_CARD_PWD.key().equals(content.getLoginType())) {
@ -159,6 +156,13 @@ public class TokenController {
} }
} }
public static void main(String[] args) {
boolean flag = encoder.matches("abc", "$2a$10$UMNFdXSz5S1NQSDXv/B4L.iCTppSO1FFE4g6c4Mab.Z7VPWvGcLwG");
String encodedStr = encoder.encode("abc");
System.out.println(encodedStr);
System.out.println(flag);
}
public CustInfoAppIdLoginVO addOrUpdateCustCasual(Integer sourceType, CustInfoAppIdLoginVO result) { public CustInfoAppIdLoginVO addOrUpdateCustCasual(Integer sourceType, CustInfoAppIdLoginVO result) {
Long custId = result.getCustId(); Long custId = result.getCustId();
CustCasual custCasual = this.custCasualMapper.selectCustCasualByCustId(custId, sourceType, DelFlagEnum.DEL_FALSE.key()); CustCasual custCasual = this.custCasualMapper.selectCustCasualByCustId(custId, sourceType, DelFlagEnum.DEL_FALSE.key());

View File

@ -1,6 +1,7 @@
package net.xnzn.core.customer.service.impl; package net.xnzn.core.customer.service.impl;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.bonus.common.core.constant.CacheConstants;
import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.exception.ServiceException;
import net.xnzn.api.SmsCodeApi; import net.xnzn.api.SmsCodeApi;
import net.xnzn.constant.RetCodeEnum; import net.xnzn.constant.RetCodeEnum;
@ -73,7 +74,7 @@ public class CustInfoServiceImpl implements CustInfoService {
SmsCodeVerifyDTO smsCodeVerifyDTO = new SmsCodeVerifyDTO(); SmsCodeVerifyDTO smsCodeVerifyDTO = new SmsCodeVerifyDTO();
smsCodeVerifyDTO.setTelephoneNumber(content.getMobile()); smsCodeVerifyDTO.setTelephoneNumber(content.getMobile());
smsCodeVerifyDTO.setCode(content.getCode()); smsCodeVerifyDTO.setCode(content.getCode());
if (!this.smsCodeApi.verifySmsCode(smsCodeVerifyDTO)) { if (!this.smsCodeApi.verifySmsCode(smsCodeVerifyDTO, CacheConstants.VERIFICATION_CODE)) {
throw new ServiceException("验证码异常"); throw new ServiceException("验证码异常");
} else { } else {
CustInfo custInfoQuery = new CustInfo(); CustInfo custInfoQuery = new CustInfo();