This commit is contained in:
sxu 2025-02-01 10:02:19 +08:00
parent e90d73ab73
commit d8c982d47d
3 changed files with 165 additions and 99 deletions

View File

@ -8,6 +8,6 @@ import org.apache.ibatis.annotations.Param;
public interface CustInfoMapper { public interface CustInfoMapper {
CustInfo selectOne(CustInfo custInfo); CustInfo selectOne(CustInfo custInfo);
int updateById(@Param("custId") Long custId); int updateById(CustInfo custInfo);
} }

View File

@ -1,98 +1,99 @@
//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.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.exception.ServiceException;
//import net.xnzn.constant.RetCodeEnum; import net.xnzn.constant.RetCodeEnum;
//import net.xnzn.core.customer.api.CustCasualApi; import net.xnzn.core.customer.api.CustCasualApi;
//import net.xnzn.core.customer.constants.PersonalStatusEnum; import net.xnzn.core.customer.constants.PersonalStatusEnum;
//import net.xnzn.core.customer.dto.CustChangePasswordDTO; import net.xnzn.core.customer.dto.CustChangePasswordDTO;
//import net.xnzn.core.customer.dto.CustForgetPasswordDTO; import net.xnzn.core.customer.dto.CustForgetPasswordDTO;
//import net.xnzn.core.customer.mapper.CustInfoMapper; import net.xnzn.core.customer.mapper.CustInfoMapper;
//import net.xnzn.core.customer.service.*; import net.xnzn.core.customer.service.*;
//import net.xnzn.core.merchant.dto.SmsCodeVerifyDTO; import net.xnzn.core.merchant.dto.SmsCodeVerifyDTO;
//import net.xnzn.domain.CustInfo; import net.xnzn.core.notice.notice.v2.api.SmsCodeApi;
//import net.xnzn.utils.AesEncryptUtil; import net.xnzn.domain.CustInfo;
//import net.xnzn.utils.SM4EncryptUtils; import net.xnzn.utils.AesEncryptUtil;
//import org.slf4j.Logger; import net.xnzn.utils.SM4EncryptUtils;
//import org.slf4j.LoggerFactory; import org.slf4j.Logger;
//import org.springframework.beans.factory.annotation.Autowired; import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Lazy; import org.springframework.beans.factory.annotation.Value;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.context.annotation.Lazy;
//import org.springframework.stereotype.Service; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import java.util.*; import org.springframework.stereotype.Service;
// import java.util.*;
//@Service
//public class CustInfoServiceImpl implements CustInfoService { @Service
// private static final Logger log = LoggerFactory.getLogger(CustInfoServiceImpl.class); public class CustInfoServiceImpl implements CustInfoService {
// @Autowired private static final Logger log = LoggerFactory.getLogger(CustInfoServiceImpl.class);
// @Lazy @Autowired
// private AesEncryptUtil aesEncryptUtil; @Lazy
// @Autowired private AesEncryptUtil aesEncryptUtil;
// @Lazy @Autowired
// private SmsCodeApi smsCodeApi; @Lazy
// @Autowired private SmsCodeApi smsCodeApi;
// @Lazy @Autowired
// private CustCasualApi custCasualApi; @Lazy
// @Autowired private CustCasualApi custCasualApi;
// private CustInfoMapper custInfoMapper; @Autowired
// private CustInfoMapper custInfoMapper;
//// @Value("${customer.h5-login-default-pwd}")
//// private String h5LoginPwd; // @Value("${customer.h5-login-default-pwd}")
// // private String h5LoginPwd;
// public void custChangePassword(CustChangePasswordDTO content) {
// CustInfo custInfoQuery = new CustInfo(); public void custChangePassword(CustChangePasswordDTO content) {
// custInfoQuery.setCustId(content.getCustId()); CustInfo custInfoQuery = new CustInfo();
// CustInfo custInfo = custInfoMapper.selectOne(custInfoQuery); custInfoQuery.setCustId(content.getCustId());
// if (ObjectUtil.isNull(custInfo)) { CustInfo custInfo = custInfoMapper.selectOne(custInfoQuery);
// log.error("小程序修改密码错误:人员不存在:" + String.valueOf(custInfo)); if (ObjectUtil.isNull(custInfo)) {
// throw new ServiceException("小程序修改密码错误:人员不存在"); log.error("小程序修改密码错误:人员不存在:" + String.valueOf(custInfo));
// } else { throw new ServiceException("小程序修改密码错误:人员不存在");
// String oldPassword = content.getOldPassword(); } else {
// String newPassword = content.getNewPassword(); String oldPassword = content.getOldPassword();
// if (Objects.equals(oldPassword, newPassword)) { String newPassword = content.getNewPassword();
// log.error("小程序修改密码错误:两次密码不能一致"); if (Objects.equals(oldPassword, newPassword)) {
// throw new ServiceException("小程序修改密码错误:两次密码不能一致"); log.error("小程序修改密码错误:两次密码不能一致");
// } else { throw new ServiceException("小程序修改密码错误:两次密码不能一致");
// BCryptPasswordEncoder bCrypt = new BCryptPasswordEncoder(); } else {
// if (!bCrypt.matches(oldPassword, custInfo.getPwd())) { BCryptPasswordEncoder bCrypt = new BCryptPasswordEncoder();
// log.error("小程序修改密码错误:原密码不正确"); if (!bCrypt.matches(oldPassword, custInfo.getPwd())) {
// throw new ServiceException("小程序修改密码错误:原密码不正确"); log.error("小程序修改密码错误:原密码不正确");
// } else { throw new ServiceException("小程序修改密码错误:原密码不正确");
// String password = bCrypt.encode(newPassword); } else {
// custInfo.setPwd(password); String password = bCrypt.encode(newPassword);
// custInfoMapper.updateById(custInfo); custInfo.setPwd(password);
// this.custCasualApi.updateLoginState(content.getCustId(), content.getOpenid()); custInfoMapper.updateById(custInfo);
// } this.custCasualApi.updateLoginState(content.getCustId(), content.getOpenid());
// } }
// } }
// } }
// }
// public void custForgetPassword(CustForgetPasswordDTO content) {
// content.setMobile(this.aesEncryptUtil.aesDecode(content.getMobile())); public void custForgetPassword(CustForgetPasswordDTO content) {
// content.setNewPassword(this.aesEncryptUtil.aesDecode(content.getNewPassword())); content.setMobile(this.aesEncryptUtil.aesDecode(content.getMobile()));
// SmsCodeVerifyDTO smsCodeVerifyDTO = new SmsCodeVerifyDTO(); content.setNewPassword(this.aesEncryptUtil.aesDecode(content.getNewPassword()));
// smsCodeVerifyDTO.setTelephoneNumber(content.getMobile()); SmsCodeVerifyDTO smsCodeVerifyDTO = new SmsCodeVerifyDTO();
// smsCodeVerifyDTO.setCode(content.getCode()); smsCodeVerifyDTO.setTelephoneNumber(content.getMobile());
// if (!this.smsCodeApi.verifySmsCode(smsCodeVerifyDTO)) { smsCodeVerifyDTO.setCode(content.getCode());
// throw new ServiceException("验证码异常"); if (!this.smsCodeApi.verifySmsCode(smsCodeVerifyDTO)) {
// } else { throw new ServiceException("验证码异常");
// CustInfo custInfoQuery = new CustInfo(); } else {
// custInfoQuery.setMobile(SM4EncryptUtils.sm4Encryptbyconfig(content.getMobile())); CustInfo custInfoQuery = new CustInfo();
// CustInfo custInfo = custInfoMapper.selectOne(custInfoQuery); custInfoQuery.setMobile(SM4EncryptUtils.sm4Encryptbyconfig(content.getMobile()));
// if (ObjectUtil.isNull(custInfo)) { CustInfo custInfo = custInfoMapper.selectOne(custInfoQuery);
// log.error("修改密码错误:人员不存在:" + String.valueOf(custInfo)); if (ObjectUtil.isNull(custInfo)) {
// throw new ServiceException("修改密码错误:人员不存在", RetCodeEnum.PAY_PERSONAL_NO_EXIT.getKey()); log.error("修改密码错误:人员不存在:" + String.valueOf(custInfo));
// } else { throw new ServiceException("修改密码错误:人员不存在", RetCodeEnum.PAY_PERSONAL_NO_EXIT.getKey());
// String newPassword = content.getNewPassword(); } else {
// BCryptPasswordEncoder bCrypt = new BCryptPasswordEncoder(); String newPassword = content.getNewPassword();
// String password = bCrypt.encode(newPassword); BCryptPasswordEncoder bCrypt = new BCryptPasswordEncoder();
// custInfo.setPwd(password); String password = bCrypt.encode(newPassword);
// custInfoMapper.updateById(custInfo); custInfo.setPwd(password);
// } custInfoMapper.updateById(custInfo);
// } }
// } }
// }
//}
}

View File

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