提交 be027d59 authored 作者: liuhaiquan's avatar liuhaiquan

Merge remote-tracking branch 'origin/v7.0_small_version_fix_20231120' into…

Merge remote-tracking branch 'origin/v7.0_small_version_fix_20231120' into v7.0_small_version_fix_20231120
......@@ -101,9 +101,15 @@ public enum PerformanceResultEnum implements ResultEnum {
USER_ID_IS_EMPTY(1900, "用户ID不能为空"),
MOBILE_IS_EMPTY(1901, "用户手机号不能为空"),
CAPTCHA_IS_EMPTY(1901, "验证码不能为空"),
USER_ACCOUNT_NOT_FOUND(1902, "用户账号未找到"),
CAPTCHA_IS_EMPTY(1902, "验证码不能为空"),
USER_ACCOUNT_NOT_FOUND(1903, "用户账号未找到"),
CAPTCHA_IS_EXPIRE(1904, "短信验证码已失效,请重新发送"),
CAPTCHA_MORE_COUNT(1905, "验证码发送过于频繁,请稍后再发"),
CAPTCHA_IS_FAIL(1906, "验证码错误"),
BUSINESS_NO_FAIL(1907, "营业执照校验不一致,请重新输入"),
TOKEN_IS_FAIL(1908, "token失效,请重新获取token"),
PASSWORD_RESET_IS_FAIL(1909, "重置密码出现异常"),
PASSWORD_CHECK_FAIL(1910, "交易密码填写错误,请重新输入"),
;
private final int code;
......
package com.clx.performance.param.app;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......@@ -8,20 +9,17 @@ import lombok.Setter;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Getter
@Setter
@NoArgsConstructor
@Data
public class CheckMobileParam {
@ApiModelProperty(value = "手机号", example = "1")
@NotBlank(message = "手机号")
private String mobile;
@ApiModelProperty(value = "用户Id", example = "1")
@NotNull(message = "用户Id")
private Long userNo;
@ApiModelProperty(value = "验证码", example = "1")
@NotBlank(message = "验证码")
private String captcha;
@ApiModelProperty(value = "调用发送短信接口返回的token", example = "1")
private String token;
}
package com.clx.performance.param.app;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
public class InformationParam {
@ApiModelProperty(value = "营业执照编号", example = "1")
@NotBlank(message = "营业执照编号")
private String businessLicenseNumber;
@ApiModelProperty(value = "验证手机号通过后Token", example = "1")
@NotBlank(message = "验证手机号通过后Token")
private String token;
@ApiModelProperty(value = "手机号", example = "1")
@NotBlank(message = "手机号")
private String mobile;
}
package com.clx.performance.param.app;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
public class ResetPasswordParam {
@ApiModelProperty(value = "交易密码", example = "1")
@NotBlank(message = "交易密码")
private String password;
@ApiModelProperty(value = "验证营业执照后通过后Token", example = "1")
@NotBlank(message = "验证营业执照后通过后Token")
private String token;
@ApiModelProperty(value = "手机号", example = "1")
@NotBlank(message = "手机号")
private String mobile;
}
package com.clx.performance.param.app;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Data
public class SendMobileCaptchaParam {
@ApiModelProperty(value = "手机号", example = "1")
@NotBlank(message = "手机号")
private String mobile;
}
......@@ -35,4 +35,7 @@ public class OwnerCaseOutParam {
@ApiModelProperty(value = "提现银行卡号", example = "62213545878787")
private String ownerBankAccount;
@ApiModelProperty(value = "交易密码")
private String accountPassword;
}
\ No newline at end of file
......@@ -38,6 +38,19 @@ public class OwnerTopUpParam {
@ApiModelProperty(value = "打款凭证", example = "/a.png")
private String drawingProof;
@ApiModelProperty(value = "收款人企业信息", example = "收款人企业信息")
private String enterpriseName;
@ApiModelProperty(value = "收款人开户行", example = "62213545878787")
private String openAccountBank;
@ApiModelProperty(value = "收款人开户行银行代码", example = "收款人开户行银行代码")
private String openAccountBankNumber;
@ApiModelProperty(value = "收款人账户账号", example = "")
private String accountNumber;
@ApiModelProperty(value = "交易密码")
private String accountPassword;
}
\ No newline at end of file
package com.clx.performance.vo.pc;
import com.msl.common.convertor.field.Converted;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class OwnerAccountAllVO {
@ApiModelProperty("保证金账户")
@Converted(isDynamic = true)
private OwnerAccountVO marginAccount;
@ApiModelProperty("预付运费账户")
@Converted(isDynamic = true)
private OwnerAccountVO prepaidFreightAccount;
@ApiModelProperty("0:没有交易密码 1:有交易密码")
private Integer ownerAccountPassword;
}
......@@ -91,4 +91,10 @@ public class OwnerTopUpVO {
@ApiModelProperty(value = "审批拒绝")
private String approvalTurnDown;
@ApiModelProperty(value = "收款人企业信息")
private String enterpriseName;
@ApiModelProperty(value = "收款人账户账号")
private String accountNumber;
}
\ No newline at end of file
package com.clx.performance.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ResetPassword {
//接口名称
String name() default "";
}
package com.clx.performance.aspect;
import cn.hutool.json.JSONUtil;
import com.clx.performance.annotation.ResetPassword;
import com.clx.performance.constant.RedisConstants;
import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.param.app.CheckMobileParam;
import com.clx.performance.param.app.InformationParam;
import com.clx.performance.param.app.ResetPasswordParam;
import com.msl.common.exception.ServiceSystemException;
import com.msl.common.result.Result;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Component
@Aspect
public class ResetPasswordAnnotationAop {
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Pointcut("@annotation(com.clx.performance.annotation.ResetPassword)")
private void annotationPointCut() {
}
@Around("annotationPointCut()")
public Object annotationAround(ProceedingJoinPoint jp) throws Throwable {
//获取方法
Method method = ((MethodSignature) jp.getSignature()).getMethod();
// 获取AspectAnnotation注解
ResetPassword aspectAnnotation = method.getAnnotation(ResetPassword.class);
String mobile = "";
String token = "";
String redisVal = "";
switch (aspectAnnotation.name()) {
case "checkMobile":
CheckMobileParam checkMobileParam = JSONUtil.toBean(JSONUtil.parse(jp.getArgs()[0]).toString(), CheckMobileParam.class);
mobile = checkMobileParam.getMobile();
token = checkMobileParam.getToken();
redisVal = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile);
if (!StringUtils.equals(token, redisVal)) {
throw new ServiceSystemException(PerformanceResultEnum.TOKEN_IS_FAIL);
}
break;
case "sendMobileCaptcha":
mobile = JSONUtil.parse(jp.getArgs()[0]).getByPath("mobile").toString();
String content = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_MOBILE_CAPTCHA + mobile);
if (StringUtils.isNoneBlank(content)) {
token = UUID.randomUUID().toString();
redisTemplate.opsForValue().set(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile, token);
redisTemplate.expire(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile, 60, TimeUnit.SECONDS);
return Result.ok(token);
}
break;
case "checkBusinessLicenseNumber":
InformationParam informationParam = JSONUtil.toBean(JSONUtil.parse(jp.getArgs()[0]).toString(), InformationParam.class);
mobile = informationParam.getMobile();
token = informationParam.getToken();
redisVal = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile);
if (!StringUtils.equals(token, redisVal)) {
throw new ServiceSystemException(PerformanceResultEnum.TOKEN_IS_FAIL);
}
break;
case "resetPassword":
ResetPasswordParam resetPasswordParam = JSONUtil.toBean(JSONUtil.parse(jp.getArgs()[0]).toString(), ResetPasswordParam.class);
mobile = resetPasswordParam.getMobile();
token = resetPasswordParam.getToken();
redisVal = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile);
if (!StringUtils.equals(token, redisVal)) {
throw new ServiceSystemException(PerformanceResultEnum.TOKEN_IS_FAIL);
}
break;
default:
throw new RuntimeException();
}
//执行方法前
Object returnVal = null;
returnVal = jp.proceed();
Result result = JSONUtil.toBean(JSONUtil.parse(returnVal).toString(), Result.class);
redisTemplate.opsForValue().set(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile, result.getData().toString());
redisTemplate.expire(RedisConstants.MESSAGE_RESET_PASSWORD_TOKEN + mobile, 60, TimeUnit.SECONDS);
return returnVal;
}
}
......@@ -42,84 +42,31 @@ public class RabbitBeanConfig {
@Bean
public Queue orderOnQueue() {
Map<String, Object> params = new HashMap<>(6);
params.put("x-dead-letter-exchange", RabbitKeyConstants.ORDER_ON_DEAD_EXCHANGE);
params.put("x-dead-letter-routing-key", RabbitKeyConstants.ORDER_ON_DEAD_ROUTE_KEY);
return new Queue(RabbitKeyConstants.ORDER_ON_QUEUE, true, false, false, params);
return new Queue(RabbitKeyConstants.ORDER_ON_QUEUE, true, false, false);
}
/**
* 订单挂单中交换机
**/
@Bean
public DirectExchange orderOnExchange() {
return new DirectExchange(RabbitKeyConstants.ORDER_ON_EXCHANGE);
public CustomExchange orderOnExchange() {
Map<String, Object> arguments = new HashMap<>();
//设置路由模式 direct模式
arguments.put("x-delayed-type", "direct");
return new CustomExchange(RabbitKeyConstants.ORDER_ON_EXCHANGE,"x-delayed-message", true, false, arguments);
}
/**
* 订单挂单中绑定
*/
@Bean
public Binding orderOnExchangeBind() {
return BindingBuilder.bind(orderOnQueue()).to(orderOnExchange()).with(RabbitKeyConstants.ORDER_ON_ROUTE_KEY);
public Binding orderOnExchangeBind(@Qualifier("orderOnQueue")Queue queue,@Qualifier("orderOnExchange")CustomExchange customExchange) {
return BindingBuilder.bind(queue).to(customExchange).with(RabbitKeyConstants.ORDER_ON_ROUTE_KEY).noargs();
}
/**
* 死信队列:死信队列处理延迟消息
* @return
*/
@Bean
public Queue orderOnDeadQueue() {
return new Queue(RabbitKeyConstants.ORDER_ON_DEAD_QUEUE, true, false, false);
}
/**
* 订单挂单中交换机:死信队列处理延迟消息
**/
@Bean
public DirectExchange orderOnDeadExchange() {
return new DirectExchange(RabbitKeyConstants.ORDER_ON_DEAD_EXCHANGE);
}
/**
* 订单挂单中绑定:死信队列处理延迟消息
*/
@Bean
public Binding orderDeadExchangeBind() {
return BindingBuilder.bind(orderOnDeadQueue()).to(orderOnDeadExchange()).with(RabbitKeyConstants.ORDER_ON_DEAD_ROUTE_KEY);
}
/**
// * 货单挂单队列
// * @return
// */
// @Bean
// public Queue orderGoodsOnQueue() {
// Map<String, Object> params = new HashMap<>(6);
// params.put("x-dead-letter-exchange", RabbitKeyConstants.ORDER_GOODS_ON_DEAD_EXCHANGE);
// params.put("x-dead-letter-routing-key", RabbitKeyConstants.ORDER_GOODS_ON_DEAD_ROUTE_KEY);
// return new Queue(RabbitKeyConstants.ORDER_GOODS_ON_QUEUE, true, false, false, params);
// }
//
// /**
// * 货单挂单中交换机
// **/
// @Bean
// public DirectExchange orderGoodsOnExchange() {
// return new DirectExchange(RabbitKeyConstants.ORDER_GOODS_ON_EXCHANGE);
// }
//
// /**
// * 货单挂单中绑定
// */
// @Bean
// public Binding orderGoodsOnExchangeBind() {
// return BindingBuilder.bind(orderGoodsOnQueue()).to(orderGoodsOnExchange()).with(RabbitKeyConstants.ORDER_GOODS_ON_ROUTE_KEY);
// }
/**
* 死信队列:死信队列处理延迟消息货单挂单
* 处理延迟消息货单挂单
* @return
*/
@Bean
......@@ -128,7 +75,7 @@ public class RabbitBeanConfig {
}
/**
* 货单挂单中交换机:死信队列处理延迟消息
* 货单挂单中交换机:处理延迟消息
**/
@Bean
public CustomExchange orderGoodsOnDeadExchange() {
......@@ -138,13 +85,6 @@ public class RabbitBeanConfig {
return new CustomExchange(RabbitKeyConstants.ORDER_GOODS_ON_DEAD_EXCHANGE,"x-delayed-message", true, false, arguments);
}
/**
* 货单挂单中绑定:死信队列处理延迟消息
*/
// @Bean
// public Binding orderGoodsDeadExchangeBind() {
// return BindingBuilder.bind(orderGoodsOnDeadQueue()).to(orderGoodsOnDeadExchange()).with(RabbitKeyConstants.ORDER_GOODS_ON_DEAD_ROUTE_KEY);
// }
//绑定交换机,队列和routingKey
@Bean
public Binding delayedQueueBindingDelayedExchange(@Qualifier("orderGoodsOnDeadQueue")Queue queue,@Qualifier("orderGoodsOnDeadExchange")CustomExchange customExchange) {
......
......@@ -31,4 +31,9 @@ public class RedisConstants {
* 雪花
*/
public static final String ID_SNOWFLAKE = "clx-performance:idsnowflake";
public static final String MESSAGE_MOBILE_CAPTCHA = "message:mobile:captcha:";
public static final String MESSAGE_RESET_PASSWORD_TOKEN = "message:resetpassword:token:";
}
package com.clx.performance.controller.app;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.clx.performance.annotation.ResetPassword;
import com.clx.performance.param.app.CheckMobileParam;
import com.clx.performance.param.app.InformationParam;
import com.clx.performance.param.app.ResetPasswordParam;
import com.clx.performance.param.app.SendMobileCaptchaParam;
import com.clx.performance.param.pc.PageAppPrepaidFreightAccountParam;
import com.clx.performance.service.OwnerAccountService;
import com.clx.performance.vo.pc.OwnerAccountRunningWaterRecordVO;
......@@ -38,10 +42,35 @@ public class AppOwnerAccountController {
}
@ApiOperation(value = "发送手机验证码", notes = "<br>By:胡宇帆")
@PostMapping("/sendMobileCaptcha")
@ResetPassword(name = "sendMobileCaptcha")
public Result<String> sendMobileCaptcha(@RequestBody SendMobileCaptchaParam param) {
String token = ownerAccountService.sendMobileCaptcha(param);
return Result.ok(token);
}
@ApiOperation(value = "验证手机号验证码", notes = "<br>By:胡宇帆")
@PostMapping("/checkMobile")
@ResetPassword(name = "checkMobile")
public Result<String> checkMobile(@RequestBody CheckMobileParam param) {
String token = ownerAccountService.checkMobile(param);
return Result.ok(token);
}
@ApiOperation(value = "验证营业执照编号", notes = "<br>By:胡宇帆")
@PostMapping("/checkBusinessLicenseNumber")
@ResetPassword(name = "checkBusinessLicenseNumber")
public Result<String> checkBusinessLicenseNumber(@RequestBody InformationParam param) {
String token = ownerAccountService.checkBusinessLicenseNumber(param);
return Result.ok(token);
}
@ApiOperation(value = "修改交易密码", notes = "<br>By:胡宇帆")
@PostMapping("/resetPassword")
@ResetPassword(name = "resetPassword")
public Result<Object> resetPassword(@RequestBody ResetPasswordParam param) {
ownerAccountService.resetPassword(param);
return Result.ok();
}
}
package com.clx.performance.dao;
import com.clx.performance.mapper.OwnerAccountPasswordMapper;
import com.clx.performance.model.OwnerAccountPassword;
import com.msl.common.dao.BaseDao;
/**
* @author kavin
* Date 2023-11-28
* Time 17:42
*/
public interface OwnerAccountPasswordDao extends BaseDao<OwnerAccountPasswordMapper, OwnerAccountPassword, Integer> {
OwnerAccountPassword findEntityByUserNo(Long userNo);
}
package com.clx.performance.dao.impl;
import com.clx.performance.dao.OwnerAccountPasswordDao;
import com.clx.performance.mapper.OwnerAccountPasswordMapper;
import com.clx.performance.model.OwnerAccountPassword;
import com.msl.common.dao.impl.BaseDaoImpl;
import org.springframework.stereotype.Repository;
/**
* @author kavin
* Date 2023-11-28
* Time 17:42
*/
@Repository
public class OwnerAccountPasswordDaoImpl extends BaseDaoImpl<OwnerAccountPasswordMapper, OwnerAccountPassword, Integer> implements OwnerAccountPasswordDao {
@Override
public OwnerAccountPassword findEntityByUserNo(Long userNo) {
return baseMapper.selectOne(lQrWrapper().eq(OwnerAccountPassword::getUserNo, userNo));
}
}
package com.clx.performance.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.clx.performance.model.OwnerAccountPassword;
/**
* @author kavin
* Date 2023-11-28
* Time 17:42
*/
public interface OwnerAccountPasswordMapper extends BaseMapper<OwnerAccountPassword> {
}
package com.clx.performance.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.msl.common.config.KeyColumn;
import com.msl.common.model.HasKey;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
/**
* @author kavin
* Date 2023-11-28
* Time 17:42
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("owner_account_password")
@Builder
public class OwnerAccountPassword implements HasKey<Integer> {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@TableField("user_no")
@ApiModelProperty("")
private Long userNo;
@TableField("password")
@ApiModelProperty("交易密码")
private String password;
@TableField("create_time")
@ApiModelProperty("创建时间")
private LocalDateTime createTime;
@TableField("modified_time")
@ApiModelProperty("修改时间")
private LocalDateTime modifiedTime;
@Override
@KeyColumn("id")
public Integer gainKey() {
return this.id;
}
}
......@@ -100,6 +100,31 @@ public class OwnerTopUp implements HasKey<Integer> {
*/
@TableField("modified_time")
private LocalDateTime modifiedTime;
/**
* 收款人企业信息
*/
@TableField("enterprise_name")
private String enterpriseName;
/**
*收款人开户行
*/
@TableField("open_account_bank")
private String openAccountBank;
/**
* 收款人开户行银行代码
*/
@TableField("open_account_bank_number")
private String openAccountBankNumber;
/**
* 收款人账户账号
*/
@TableField("account_number")
private String accountNumber;
@KeyColumn("id")
@Override
public Integer gainKey() {
......
......@@ -3,6 +3,9 @@ package com.clx.performance.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.clx.performance.model.OwnerTransferInfo;
import com.clx.performance.param.app.CheckMobileParam;
import com.clx.performance.param.app.InformationParam;
import com.clx.performance.param.app.ResetPasswordParam;
import com.clx.performance.param.app.SendMobileCaptchaParam;
import com.clx.performance.param.open.OpenOwnerBindCardParam;
import com.clx.performance.param.open.OpenOwnerCaseOutParam;
import com.clx.performance.param.open.OpenOwnerTopUpParam;
......@@ -92,4 +95,10 @@ public interface OwnerAccountService {
void ownerAccountThaw(ThawAccountParam param);
String checkMobile(CheckMobileParam param);
String sendMobileCaptcha(SendMobileCaptchaParam param);
String checkBusinessLicenseNumber(InformationParam param);
void resetPassword(ResetPasswordParam param);
}
......@@ -318,9 +318,9 @@ public class OrderGoodsSqlProvider {
WHERE("a.residue_transport_weight >=35");
if (ObjectUtil.isNotNull(param.getSearchType())) {
if (1 == param.getSearchType()) {
WHERE("a.send_address = "+ param.getSearchName());
WHERE("a.send_address_shorter like '%"+ param.getSearchName() +"%'");
}else if (2 == param.getSearchType()) {
WHERE("a.receive_address = "+ param.getSearchName());
WHERE("a.receive_address_shorter like '%"+ param.getSearchName()+"%'");
}
}
ORDER_BY("a.pending_order_time desc");
......
......@@ -13,7 +13,7 @@ public class OwnerTopUpProvider {
String sql = new SQL() {{
SELECT("a.id, a.owner_user_no," +
" a.top_up_no, a.top_up_balance, a.account_type, " +
" a.status,a.drawing_bank, a.drawing_bank_number,a.drawing_proof,date_format(a.approval_time, '%Y-%m-%d %H:%i:%s') as approval_time,a.approval_by,a.approval_turn_down,a.create_by,date_format(a.create_time, '%Y-%m-%d %H:%i:%s') as create_time,a.modified_time");
" a.status,a.drawing_bank,a.enterprise_name,a.account_number,a.drawing_bank_number,a.drawing_proof,date_format(a.approval_time, '%Y-%m-%d %H:%i:%s') as approval_time,a.approval_by,a.approval_turn_down,a.create_by,date_format(a.create_time, '%Y-%m-%d %H:%i:%s') as create_time,a.modified_time");
FROM("owner_top_up a");
if (StringUtils.isNotBlank(param.getBeginTime()) && StringUtils.isNotBlank(param.getEndTime())) {
WHERE("a.create_time >= #{param.beginTime} and a.create_time <= #{param.endTime}");
......
......@@ -87,7 +87,8 @@ public abstract class GoodsOrderStrategy {
log.info("执行订单状态更改,epochMilli时间不为0,时间为:{}", epochMilli);
rabbitTemplate.send(RabbitKeyConstants.ORDER_POSTED_EXCHANGE, RabbitKeyConstants.ORDER_POSTED_ROUTE_KEY, MessageBuilder.withBody(orderNo.getBytes()).build());
message.getMessageProperties().setExpiration(String.valueOf(epochMilli));
message.getMessageProperties().setHeader("x-delay", epochMilli);
rabbitTemplate.send(
RabbitKeyConstants.ORDER_ON_EXCHANGE, RabbitKeyConstants.ORDER_ON_ROUTE_KEY, message
);
......
package com.clx.performance.utils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
public class MyMD5Util {
private static final String HEX_NUMS_STR = "0123456789ABCDEF";
private static final Integer SALT_LENGTH = 12;
//将16进制字符转换为字节数组
public static byte[] hexStringToByte(String hex) {
int len = (hex.length() / 2);
byte[] result = new byte[len];
char[] hexChars = hex.toCharArray();
for (int i = 0; i < len; i++) {
int pos = i * 2;
result[i] = (byte) (HEX_NUMS_STR.indexOf(hexChars[pos]) << 4 | HEX_NUMS_STR
.indexOf(hexChars[pos + 1]));
}
return result;
}
//将指定byte数组转换成16进制字符串
public static String byteToHexString(byte[] b) {
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < b.length; i++) {
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
hexString.append(hex.toUpperCase());
}
return hexString.toString();
}
//验证口令是否合法
public static boolean validPassword(String password, String passwordInDb)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
// 将16进制字符串格式口令转换成字节数组
byte[] pwdInDb = hexStringToByte(passwordInDb);
// 声明盐变量
byte[] salt = new byte[SALT_LENGTH];
// 将盐从数据库中保存的口令字节数组中提取出来
System.arraycopy(pwdInDb, 0, salt, 0, SALT_LENGTH);
// 创建消息摘要对象
MessageDigest md = MessageDigest.getInstance("MD5");
// 将盐数据传入消息摘要对象
md.update(salt);
// 将口令的数据传给消息摘要对象
md.update(password.getBytes("UTF-8"));
// 生成输入口令的消息摘要
byte[] digest = md.digest();
// 声明一个保存数据库中口令消息摘要的变量
byte[] digestInDb = new byte[pwdInDb.length - SALT_LENGTH];
// 取得数据库中口令的消息摘要
System.arraycopy(pwdInDb, SALT_LENGTH, digestInDb, 0, digestInDb.length);
// 比较根据输入口令生成的消息摘要和数据库中消息摘要是否相同
if (Arrays.equals(digest, digestInDb)) {
// 口令正确返回口令匹配消息
return true;
} else {
// 口令不正确返回口令不匹配消息
return false;
}
}
//获得加密后的口令
public static String getEncryptedPwd(String password)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
// 声明加密后的口令数组变量
byte[] pwd = null;
// 随机数生成器
SecureRandom random = new SecureRandom();
// 声明盐数组变量
byte[] salt = new byte[SALT_LENGTH];
// 将随机数放入盐变量中
random.nextBytes(salt);
// 声明消息摘要对象
MessageDigest md = null;
// 创建消息摘要
md = MessageDigest.getInstance("MD5");
// 将盐数据传入消息摘要对象
md.update(salt);
// 将口令的数据传给消息摘要对象
md.update(password.getBytes("UTF-8"));
// 获得消息摘要的字节数组
byte[] digest = md.digest();
// 因为要在口令的字节数组中存放盐,所以加上盐的字节长度
pwd = new byte[digest.length + SALT_LENGTH];
// 将盐的字节拷贝到生成的加密口令字节数组的前12个字节,以便在验证口令时取出盐
System.arraycopy(salt, 0, pwd, 0, SALT_LENGTH);
// 将消息摘要拷贝到加密口令字节数组从第13个字节开始的字节
System.arraycopy(digest, 0, pwd, SALT_LENGTH, digest.length);
// 将字节数组格式加密后的口令转化为16进制字符串格式的口令
return byteToHexString(pwd);
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论