diff --git a/pay-java-common/src/main/java/com/egzosn/pay/common/util/Util.java b/pay-java-common/src/main/java/com/egzosn/pay/common/util/Util.java index 53b9ae5a..f730aa9b 100644 --- a/pay-java-common/src/main/java/com/egzosn/pay/common/util/Util.java +++ b/pay-java-common/src/main/java/com/egzosn/pay/common/util/Util.java @@ -1,7 +1,10 @@ package com.egzosn.pay.common.util; +import com.egzosn.pay.common.bean.result.PayException; +import com.egzosn.pay.common.exception.PayErrorException; import java.math.BigDecimal; import java.math.BigInteger; +import java.math.RoundingMode; import java.util.Collection; import java.util.Map; @@ -590,7 +593,11 @@ public static byte[] subByte(byte[] input, int startIndex, int length) { * @return 分的金额 */ public static int conversionCentAmount(BigDecimal amount) { - return amount.multiply(HUNDRED).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); + final BigDecimal decimal = amount.multiply(HUNDRED).setScale(0, RoundingMode.HALF_UP); + if (decimal.longValue() > (long) Integer.MAX_VALUE) { + throw new PayErrorException(new PayException("illegal parameter", "订单金额过大")); + } + return decimal.intValue(); } /** @@ -613,4 +620,4 @@ public static boolean isEmpty(Collection collection) { } -} \ No newline at end of file +}