diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/PayApi.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/PayApi.java index 5106276e..ada206a9 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/PayApi.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/PayApi.java @@ -465,8 +465,8 @@ public class PayApi extends MchApi { try { Map map = createBaseRequestMap(idQuery); map.put("out_refund_no", outRefundNo); - map.put("total_fee", DateUtil.formaFee2Fen(totalFee)); - map.put("refund_fee", DateUtil.formaFee2Fen(refundFee)); + map.put("total_fee", DateUtil.formatFee2Fen(totalFee)); + map.put("refund_fee", DateUtil.formatFee2Fen(refundFee)); if (StringUtil.isBlank(opUserId)) { opUserId = weixinAccount.getMchId(); } diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayPackage.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayPackage.java index e0469ccd..e8041b5f 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayPackage.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/PayPackage.java @@ -117,7 +117,7 @@ public class PayPackage extends MerchantResult { this.body = body; this.detail = detail; this.outTradeNo = outTradeNo; - this.totalFee = DateUtil.formaFee2Fen(totalFee); + this.totalFee = DateUtil.formatFee2Fen(totalFee); this.notifyUrl = notifyUrl; this.createIp = createIp; this.attach = attach; @@ -163,7 +163,7 @@ public class PayPackage extends MerchantResult { * 订单总额 单位为元 */ public void setTotalFee(double totalFee) { - this.totalFee = DateUtil.formaFee2Fen(totalFee); + this.totalFee = DateUtil.formatFee2Fen(totalFee); } public String getNotifyUrl() { diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/CorpPayment.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/CorpPayment.java index 72912772..2f35dfab 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/CorpPayment.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/CorpPayment.java @@ -91,7 +91,7 @@ public class CorpPayment extends MerchantResult { this.openId = openId; this.checkNameType = checkNameType; this.desc = desc; - this.amount = DateUtil.formaFee2Fen(amount); + this.amount = DateUtil.formatFee2Fen(amount); this.clientIp = clientIp; } diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/Redpacket.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/Redpacket.java index acbdd645..f49d592c 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/Redpacket.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/Redpacket.java @@ -134,7 +134,7 @@ public class Redpacket extends MerchantResult { this.clientIp = clientIp; this.actName = actName; this.remark = remark; - this.totalAmount = DateUtil.formaFee2Fen(totalAmount); + this.totalAmount = DateUtil.formatFee2Fen(totalAmount); this.amtType = totalNum > 1 ? "ALL_RAND" : null; } diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/DateUtil.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/DateUtil.java index 61464544..49bfd1e6 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/DateUtil.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/DateUtil.java @@ -1,5 +1,6 @@ package com.foxinmy.weixin4j.util; +import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -73,10 +74,13 @@ public class DateUtil { * * @param fee * 金额 单位为分 - * @return + * @return 四舍五入后的字符串形式金额 */ - public static String formaFee2Fen(double fee) { - return new DecimalFormat("#").format(fee * 100); + public static String formatFee2Fen(double fee) { + BigDecimal _fee = new BigDecimal(Double.toString(fee)); + fee = _fee.multiply(new BigDecimal("100")) + .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + return new DecimalFormat("#").format(fee); } /** diff --git a/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/api/PayOldApi.java b/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/api/PayOldApi.java index e0847c6d..3b5120e9 100644 --- a/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/api/PayOldApi.java +++ b/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/api/PayOldApi.java @@ -261,8 +261,8 @@ public class PayOldApi extends MpApi { map.put("service_version", "1.1"); map.put("partner", weixinAccount.getPartnerId()); map.put("out_refund_no", outRefundNo); - map.put("total_fee", DateUtil.formaFee2Fen(totalFee)); - map.put("refund_fee", DateUtil.formaFee2Fen(refundFee)); + map.put("total_fee", DateUtil.formatFee2Fen(totalFee)); + map.put("refund_fee", DateUtil.formatFee2Fen(refundFee)); map.put(idQuery.getType().getName(), idQuery.getId()); if (StringUtil.isBlank(opUserId)) { opUserId = weixinAccount.getPartnerId(); diff --git a/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/oldpayment/PayPackageV2.java b/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/oldpayment/PayPackageV2.java index 5e88e4bb..5693ac34 100644 --- a/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/oldpayment/PayPackageV2.java +++ b/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/oldpayment/PayPackageV2.java @@ -133,8 +133,8 @@ public class PayPackageV2 extends PayPackage { this.inputCharset = "UTF-8"; this.partner = partner; this.transportFee = transportFee > 0d ? DateUtil - .formaFee2Fen(transportFee) : null; - this.productFee = productFee > 0 ? DateUtil.formaFee2Fen(productFee) + .formatFee2Fen(transportFee) : null; + this.productFee = productFee > 0 ? DateUtil.formatFee2Fen(productFee) : null; } @@ -165,7 +165,7 @@ public class PayPackageV2 extends PayPackage { * 物流费用 单位为元 */ public void setTransportFee(double transportFee) { - this.transportFee = DateUtil.formaFee2Fen(transportFee); + this.transportFee = DateUtil.formatFee2Fen(transportFee); } public String getProductFee() { @@ -179,7 +179,7 @@ public class PayPackageV2 extends PayPackage { * 商品 单位为元 */ public void setProductFee(double productFee) { - this.productFee = DateUtil.formaFee2Fen(productFee); + this.productFee = DateUtil.formatFee2Fen(productFee); } public String getInputCharset() {