fixed micropay
This commit is contained in:
parent
1a4bf6faa9
commit
ba3af7d154
@ -14,7 +14,6 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.alibaba.fastjson.TypeReference;
|
import com.alibaba.fastjson.TypeReference;
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
@ -107,12 +106,16 @@ public class PayApi extends MchApi {
|
|||||||
}
|
}
|
||||||
String tradeType = payPackage.getTradeType().toUpperCase();
|
String tradeType = payPackage.getTradeType().toUpperCase();
|
||||||
if (TradeType.MICROPAY.name().equals(tradeType)) {
|
if (TradeType.MICROPAY.name().equals(tradeType)) {
|
||||||
super.declareMerchant(payPackage);
|
MchPayPackage _payPackage = new MchPayPackage(payPackage.getBody(),
|
||||||
JSONObject _payPackage = (JSONObject) JSON.toJSON(payPackage);
|
payPackage.getDetail(), payPackage.getOutTradeNo(),
|
||||||
// 不需要设置TradeType参数
|
DateUtil.formatFee2Yuan(payPackage.getTotalFee()), null,
|
||||||
_payPackage.remove("trade_type");
|
null, payPackage.getCreateIp(), null, null,
|
||||||
payPackage.setSign(weixinSignature.sign(_payPackage));
|
payPackage.getAuthCode(), null, payPackage.getAttach(),
|
||||||
String para = XmlStream.toXML(payPackage);
|
null, null, payPackage.getGoodsTag(),
|
||||||
|
payPackage.getLimitPay(), payPackage.getSubAppId());
|
||||||
|
super.declareMerchant(_payPackage);
|
||||||
|
_payPackage.setSign(weixinSignature.sign(_payPackage));
|
||||||
|
String para = XmlStream.toXML(_payPackage);
|
||||||
WeixinResponse response = weixinExecutor.post(
|
WeixinResponse response = weixinExecutor.post(
|
||||||
getRequestUri("micropay_uri"), para);
|
getRequestUri("micropay_uri"), para);
|
||||||
MICROPayRequest microPayRequest = response
|
MICROPayRequest microPayRequest = response
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.foxinmy.weixin4j.payment.PayPackage;
|
import com.foxinmy.weixin4j.payment.PayPackage;
|
||||||
|
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||||
import com.foxinmy.weixin4j.type.TradeType;
|
import com.foxinmy.weixin4j.type.TradeType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,6 +33,12 @@ public class MchPayPackage extends PayPackage {
|
|||||||
@XmlElement(name = "trade_type")
|
@XmlElement(name = "trade_type")
|
||||||
@JSONField(name = "trade_type")
|
@JSONField(name = "trade_type")
|
||||||
private String tradeType;
|
private String tradeType;
|
||||||
|
/**
|
||||||
|
* 符合ISO 4217标准的三位字母代码,默认人民币:CNY 非必须
|
||||||
|
*/
|
||||||
|
@XmlElement(name = "fee_type")
|
||||||
|
@JSONField(name = "fee_type")
|
||||||
|
private String feeType;
|
||||||
/**
|
/**
|
||||||
* 用户在商户 appid 下的唯一 标识, trade_type 为 JSAPI 时,此参数必传
|
* 用户在商户 appid 下的唯一 标识, trade_type 为 JSAPI 时,此参数必传
|
||||||
*/
|
*/
|
||||||
@ -96,9 +103,9 @@ public class MchPayPackage extends PayPackage {
|
|||||||
public MchPayPackage(String body, String outTradeNo, double totalFee,
|
public MchPayPackage(String body, String outTradeNo, double totalFee,
|
||||||
String notifyUrl, String createIp, TradeType tradeType,
|
String notifyUrl, String createIp, TradeType tradeType,
|
||||||
String openId, String authCode, String productId, String attach) {
|
String openId, String authCode, String productId, String attach) {
|
||||||
this(body, null, outTradeNo, totalFee, notifyUrl, createIp, tradeType,
|
this(body, null, outTradeNo, totalFee, CurrencyType.CNY, notifyUrl,
|
||||||
openId, authCode, productId, attach, null, null, null, null,
|
createIp, tradeType, openId, authCode, productId, attach, null,
|
||||||
null);
|
null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,6 +125,8 @@ public class MchPayPackage extends PayPackage {
|
|||||||
* 订单生成的机器IP <font color="red">必填项</font>
|
* 订单生成的机器IP <font color="red">必填项</font>
|
||||||
* @param tradeType
|
* @param tradeType
|
||||||
* 交易类型 <font color="red">必填项</font>
|
* 交易类型 <font color="red">必填项</font>
|
||||||
|
* @param feeType
|
||||||
|
* 货币类型 非必填项
|
||||||
* @param openId
|
* @param openId
|
||||||
* 用户ID <font color="red">tradeType=JSAPI时必填</font>
|
* 用户ID <font color="red">tradeType=JSAPI时必填</font>
|
||||||
* @param authCode
|
* @param authCode
|
||||||
@ -139,13 +148,15 @@ public class MchPayPackage extends PayPackage {
|
|||||||
* openid和sub_openid可以选传其中之一,如果选择传sub_openid ,则必须传sub_appid
|
* openid和sub_openid可以选传其中之一,如果选择传sub_openid ,则必须传sub_appid
|
||||||
*/
|
*/
|
||||||
public MchPayPackage(String body, String detial, String outTradeNo,
|
public MchPayPackage(String body, String detial, String outTradeNo,
|
||||||
double totalFee, String notifyUrl, String createIp,
|
double totalFee, CurrencyType feeType, String notifyUrl,
|
||||||
TradeType tradeType, String openId, String authCode,
|
String createIp, TradeType tradeType, String openId,
|
||||||
String productId, String attach, Date timeStart, Date timeExpire,
|
String authCode, String productId, String attach, Date timeStart,
|
||||||
String goodsTag, String limitPay, String subOpenId) {
|
Date timeExpire, String goodsTag, String limitPay, String subOpenId) {
|
||||||
super(body, detial, outTradeNo, totalFee, notifyUrl, createIp, attach,
|
super(body, detial, outTradeNo, totalFee, notifyUrl, createIp, attach,
|
||||||
timeStart, timeExpire, goodsTag);
|
timeStart, timeExpire, goodsTag);
|
||||||
this.tradeType = tradeType.name();
|
this.tradeType = tradeType != null ? tradeType.name() : null;
|
||||||
|
this.feeType = feeType == null ? CurrencyType.CNY.name() : feeType
|
||||||
|
.name();
|
||||||
this.openId = openId;
|
this.openId = openId;
|
||||||
this.authCode = authCode;
|
this.authCode = authCode;
|
||||||
this.productId = productId;
|
this.productId = productId;
|
||||||
@ -157,6 +168,10 @@ public class MchPayPackage extends PayPackage {
|
|||||||
return tradeType;
|
return tradeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFeeType() {
|
||||||
|
return feeType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getOpenId() {
|
public String getOpenId() {
|
||||||
return openId;
|
return openId;
|
||||||
}
|
}
|
||||||
@ -187,9 +202,9 @@ public class MchPayPackage extends PayPackage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "MchPayPackage [tradeType=" + tradeType + ", openId=" + openId
|
return "MchPayPackage [tradeType=" + tradeType + ",feeType=" + feeType
|
||||||
+ ", productId=" + productId + ", authCode=" + authCode
|
+ ", openId=" + openId + ", productId=" + productId
|
||||||
+ ", limitPay=" + limitPay + ", subOpenId=" + subOpenId + ", "
|
+ ", authCode=" + authCode + ", limitPay=" + limitPay
|
||||||
+ super.toString() + "]";
|
+ ", subOpenId=" + subOpenId + ", " + super.toString() + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -119,4 +119,17 @@ public final class DateUtil {
|
|||||||
return _fee.multiply(new BigDecimal("100"))
|
return _fee.multiply(new BigDecimal("100"))
|
||||||
.setScale(0, BigDecimal.ROUND_HALF_EVEN).intValue();
|
.setScale(0, BigDecimal.ROUND_HALF_EVEN).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单位为分的金额格式化为元
|
||||||
|
*
|
||||||
|
* @param fee
|
||||||
|
* 金额 单位为分
|
||||||
|
* @return 四舍六入五成双的金额
|
||||||
|
*/
|
||||||
|
public static double formatFee2Yuan(int fee) {
|
||||||
|
BigDecimal _fee = new BigDecimal(Integer.toString(fee));
|
||||||
|
return _fee.divide(new BigDecimal("100"))
|
||||||
|
.setScale(0, BigDecimal.ROUND_HALF_EVEN).doubleValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user