多余的 util
核销码开头为0
This commit is contained in:
@@ -10,6 +10,11 @@ public class CzgRandomUtils {
|
|||||||
|
|
||||||
private static final char[] DEFAULT_ALPHABET =
|
private static final char[] DEFAULT_ALPHABET =
|
||||||
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
|
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
|
||||||
|
private static final char[] BASE_NUMBER =
|
||||||
|
"0123456789".toCharArray();
|
||||||
|
|
||||||
|
private static final char[] BASE_NUMBER_NO_ZERO =
|
||||||
|
"123456789".toCharArray();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认长度
|
* 默认长度
|
||||||
@@ -35,4 +40,17 @@ public class CzgRandomUtils {
|
|||||||
public static String randomString(int length) {
|
public static String randomString(int length) {
|
||||||
return NanoId.randomNanoId(null, DEFAULT_ALPHABET, length);
|
return NanoId.randomNanoId(null, DEFAULT_ALPHABET, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String randomNumber(int length) {
|
||||||
|
return NanoId.randomNanoId(null, BASE_NUMBER, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String randomNumFirstNoZero(int length) {
|
||||||
|
return NanoId.randomNanoId(null, BASE_NUMBER_NO_ZERO, 1) + NanoId.randomNanoId(null, BASE_NUMBER, length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(CzgRandomUtils.randomNumFirstNoZero(20));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,104 +0,0 @@
|
|||||||
package com.czg.utils;
|
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Miscellaneous methods for calculating digests.
|
|
||||||
*
|
|
||||||
* <p>Mainly for internal use within the framework; consider
|
|
||||||
* <a href="https://commons.apache.org/codec/">Apache Commons Codec</a>
|
|
||||||
* for a more comprehensive suite of digest utilities.
|
|
||||||
*
|
|
||||||
* @author Arjen Poutsma
|
|
||||||
* @author Juergen Hoeller
|
|
||||||
* @author Craig Andrews
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
public abstract class DigestUtils {
|
|
||||||
|
|
||||||
private static final String MD5_ALGORITHM_NAME = "MD5";
|
|
||||||
|
|
||||||
private static final char[] HEX_CHARS =
|
|
||||||
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate the MD5 digest of the given bytes.
|
|
||||||
* @param bytes the bytes to calculate the digest over
|
|
||||||
* @return the digest
|
|
||||||
*/
|
|
||||||
public static byte[] md5Digest(byte[] bytes) {
|
|
||||||
return digest(MD5_ALGORITHM_NAME, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a hexadecimal string representation of the MD5 digest of the given bytes.
|
|
||||||
* @param bytes the bytes to calculate the digest over
|
|
||||||
* @return a hexadecimal digest string
|
|
||||||
*/
|
|
||||||
public static String md5DigestAsHex(byte[] bytes) {
|
|
||||||
return digestAsHexString(MD5_ALGORITHM_NAME, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append a hexadecimal string representation of the MD5 digest of the given
|
|
||||||
* bytes to the given {@link StringBuilder}.
|
|
||||||
* @param bytes the bytes to calculate the digest over
|
|
||||||
* @param builder the string builder to append the digest to
|
|
||||||
* @return the given string builder
|
|
||||||
*/
|
|
||||||
public static StringBuilder appendMd5DigestAsHex(byte[] bytes, StringBuilder builder) {
|
|
||||||
return appendDigestAsHex(MD5_ALGORITHM_NAME, bytes, builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link MessageDigest} with the given algorithm.
|
|
||||||
* <p>Necessary because {@code MessageDigest} is not thread-safe.
|
|
||||||
*/
|
|
||||||
private static MessageDigest getDigest(String algorithm) {
|
|
||||||
try {
|
|
||||||
return MessageDigest.getInstance(algorithm);
|
|
||||||
}
|
|
||||||
catch (NoSuchAlgorithmException ex) {
|
|
||||||
throw new IllegalStateException("Could not find MessageDigest with algorithm \"" + algorithm + "\"", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static byte[] digest(String algorithm, byte[] bytes) {
|
|
||||||
return getDigest(algorithm).digest(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static String digestAsHexString(String algorithm, byte[] bytes) {
|
|
||||||
char[] hexDigest = digestAsHexChars(algorithm, bytes);
|
|
||||||
return new String(hexDigest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static StringBuilder appendDigestAsHex(String algorithm, byte[] bytes, StringBuilder builder) {
|
|
||||||
char[] hexDigest = digestAsHexChars(algorithm, bytes);
|
|
||||||
return builder.append(hexDigest);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static char[] digestAsHexChars(String algorithm, byte[] bytes) {
|
|
||||||
byte[] digest = digest(algorithm, bytes);
|
|
||||||
return encodeHex(digest);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static char[] encodeHex(byte[] bytes) {
|
|
||||||
char[] chars = new char[32];
|
|
||||||
for (int i = 0; i < chars.length; i = i + 2) {
|
|
||||||
byte b = bytes[i / 2];
|
|
||||||
chars[i] = HEX_CHARS[(b >>> 0x4) & 0xf];
|
|
||||||
chars[i + 1] = HEX_CHARS[b & 0xf];
|
|
||||||
}
|
|
||||||
return chars;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
package com.czg.utils;
|
package com.czg.utils;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.czg.utils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ww
|
|
||||||
*/
|
|
||||||
public class MD5Util {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MD5加密 十六进制
|
|
||||||
*/
|
|
||||||
public static String md5AsHex(String str) {
|
|
||||||
return DigestUtils.md5DigestAsHex(str.getBytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ package com.czg;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.crypto.digest.MD5;
|
||||||
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpRequest;
|
||||||
import cn.hutool.http.HttpResponse;
|
import cn.hutool.http.HttpResponse;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
@@ -14,7 +15,6 @@ import com.czg.entity.resp.*;
|
|||||||
import com.czg.enums.CzgPayEnum;
|
import com.czg.enums.CzgPayEnum;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
import com.czg.utils.MD5Util;
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ public class CzgPayUtils {
|
|||||||
private static <T> CzgResult<T> sendCzg(String url, CzgBaseReqParams params, Class<T> clazz) {
|
private static <T> CzgResult<T> sendCzg(String url, CzgBaseReqParams params, Class<T> clazz) {
|
||||||
CzgResult<T> result = CzgResult.success();
|
CzgResult<T> result = CzgResult.success();
|
||||||
Map<String, Object> reqMap = BeanUtil.beanToMap(params, false, false);
|
Map<String, Object> reqMap = BeanUtil.beanToMap(params, false, false);
|
||||||
params.setSign(MD5Util.md5AsHex(sortFields(new TreeMap<>(reqMap))));
|
params.setSign(MD5.create().digestHex(sortFields(new TreeMap<>(reqMap))));
|
||||||
log.info("超掌柜交易请求参数,{}", JSONObject.toJSONString(params));
|
log.info("超掌柜交易请求参数,{}", JSONObject.toJSONString(params));
|
||||||
try (HttpResponse resp = HttpRequest.post(url).body(JSONObject.toJSONString(params)).execute()) {
|
try (HttpResponse resp = HttpRequest.post(url).body(JSONObject.toJSONString(params)).execute()) {
|
||||||
if (resp.isOk()) {
|
if (resp.isOk()) {
|
||||||
@@ -208,7 +208,7 @@ public class CzgPayUtils {
|
|||||||
private static boolean validateSign(String sign, String dataJsonStr) {
|
private static boolean validateSign(String sign, String dataJsonStr) {
|
||||||
Map<String, Object> dataMap = JSONObject.parseObject(dataJsonStr, new TypeReference<>() {
|
Map<String, Object> dataMap = JSONObject.parseObject(dataJsonStr, new TypeReference<>() {
|
||||||
});
|
});
|
||||||
String newSign = MD5Util.md5AsHex(sortFields(new TreeMap<>(dataMap)));
|
String newSign = MD5.create().digestHex((sortFields(new TreeMap<>(dataMap))));
|
||||||
return !StrUtil.equals(sign, newSign);
|
return !StrUtil.equals(sign, newSign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import cn.hutool.core.date.LocalDateTimeUtil;
|
|||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import cn.hutool.crypto.digest.MD5;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||||
import com.czg.account.entity.*;
|
import com.czg.account.entity.*;
|
||||||
@@ -49,7 +50,6 @@ import com.czg.service.order.service.PayService;
|
|||||||
import com.czg.system.enums.SysParamCodeEnum;
|
import com.czg.system.enums.SysParamCodeEnum;
|
||||||
import com.czg.system.service.SysParamsService;
|
import com.czg.system.service.SysParamsService;
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
import com.czg.utils.MD5Util;
|
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
@@ -207,7 +207,7 @@ public class PayServiceImpl implements PayService {
|
|||||||
AssertUtil.isNull(userInfo, "用户信息不存在");
|
AssertUtil.isNull(userInfo, "用户信息不存在");
|
||||||
if (userInfo.getUsePayPwd() == 1) {
|
if (userInfo.getUsePayPwd() == 1) {
|
||||||
AssertUtil.isBlank(payParam.getPwd(), "支付密码不能为空");
|
AssertUtil.isBlank(payParam.getPwd(), "支付密码不能为空");
|
||||||
if (userInfo.getPayPwd() == null || !userInfo.getPayPwd().equals(MD5Util.md5AsHex(payParam.getPwd()))) {
|
if (userInfo.getPayPwd() == null || !userInfo.getPayPwd().equals(MD5.create().digestHex((payParam.getPwd())))) {
|
||||||
return CzgResult.failure("支付密码错误");
|
return CzgResult.failure("支付密码错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import com.czg.order.dto.PointGoodsRefundDTO;
|
|||||||
import com.czg.order.service.PointsGoodPayService;
|
import com.czg.order.service.PointsGoodPayService;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
import com.czg.service.order.service.PayService;
|
import com.czg.service.order.service.PayService;
|
||||||
|
import com.czg.utils.CzgRandomUtils;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -87,7 +88,7 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MkPointsGoodsRecord record = new MkPointsGoodsRecord();
|
MkPointsGoodsRecord record = new MkPointsGoodsRecord();
|
||||||
record.setOrderNo("DH" + IdUtil.getSnowflakeNextId());
|
record.setOrderNo("DH" + CzgRandomUtils.randomNumFirstNoZero(20));
|
||||||
record.setShopId(param.getShopId());
|
record.setShopId(param.getShopId());
|
||||||
record.setPointsGoodsId(param.getPointsGoodsId());
|
record.setPointsGoodsId(param.getPointsGoodsId());
|
||||||
record.setPointsGoodsName(goods.getGoodsName());
|
record.setPointsGoodsName(goods.getGoodsName());
|
||||||
@@ -232,7 +233,7 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
|
|||||||
return record;
|
return record;
|
||||||
} else {
|
} else {
|
||||||
record.setStatus("待核销");
|
record.setStatus("待核销");
|
||||||
record.setCouponCode(RandomUtil.randomNumbers(12));
|
record.setCouponCode(CzgRandomUtils.randomNumFirstNoZero(12));
|
||||||
goodsRecordService.saveOrUpdate(record);
|
goodsRecordService.saveOrUpdate(record);
|
||||||
goodsService.upNumberById(goods.getId(), goods.getQuantity() - record.getNumber(), goods.getTotalExchangeCount() + record.getNumber());
|
goodsService.upNumberById(goods.getId(), goods.getQuantity() - record.getNumber(), goods.getTotalExchangeCount() + record.getNumber());
|
||||||
//扣除积分
|
//扣除积分
|
||||||
|
|||||||
Reference in New Issue
Block a user