diff --git a/pay-java-ali/src/main/java/com/egzosn/pay/ali/api/AliPayService.java b/pay-java-ali/src/main/java/com/egzosn/pay/ali/api/AliPayService.java index 56b933e9..1e0f6a4c 100644 --- a/pay-java-ali/src/main/java/com/egzosn/pay/ali/api/AliPayService.java +++ b/pay-java-ali/src/main/java/com/egzosn/pay/ali/api/AliPayService.java @@ -200,7 +200,9 @@ private Map getOrder(PayOrder order) { bizContent.put("product_code", "QUICK_MSECURITY_PAY"); } } - + if (null != order.getExpirationTime()){ + bizContent.put("timeout_express", ((order.getExpirationTime().getTime() - System.currentTimeMillis())/1000/60 + "m")); + } orderInfo.put("biz_content", JSON.toJSONString(bizContent)); return orderInfo; } @@ -382,6 +384,31 @@ public Map refundquery(String tradeNo, String outTradeNo) { return secondaryInterface(tradeNo, outTradeNo, AliTransactionType.REFUNDQUERY); } + /** + * 查询退款 + * + * @param refundOrder 退款订单单号信息 + * @return 返回支付方查询退款后的结果 + */ + @Override + public Map refundquery(RefundOrder refundOrder){ + + //获取公共参数 + Map parameters = getPublicParameters(AliTransactionType.REFUNDQUERY); + + Map bizContent = getBizContent(refundOrder.getTradeNo(), refundOrder.getOutTradeNo(), null); + if (!StringUtils.isEmpty(refundOrder.getRefundNo())){ + bizContent.put("out_request_no", refundOrder.getRefundNo()); + } + //设置请求参数的集合 + parameters.put("biz_content", JSON.toJSONString(bizContent)); + + //设置签名 + setSign(parameters); + return requestTemplate.getForObject(getReqUrl() + "?" + UriVariables.getMapToParameters(parameters), JSONObject.class); + + } + /** * 目前只支持日账单 * @param billDate 账单类型,商户通过接口或商户经开放平台授权后其所属服务商通过接口可以获取以下账单类型:trade、signcustomer;trade指商户基于支付宝交易收单的业务账单;signcustomer是指基于商户支付宝余额收入及支出等资金变动的帐务账单; @@ -507,10 +534,10 @@ private Map getBizContent(String tradeNo, String outTradeNo, M if (null == bizContent){ bizContent = new TreeMap<>(); } - if (null != outTradeNo){ + if (!StringUtils.isEmpty(outTradeNo)){ bizContent.put("out_trade_no", outTradeNo); } - if (null != tradeNo){ + if (!StringUtils.isEmpty(tradeNo)){ bizContent.put("trade_no", tradeNo); } return bizContent; diff --git a/pay-java-ali/src/main/java/com/egzosn/pay/ali/before/api/AliPayService.java b/pay-java-ali/src/main/java/com/egzosn/pay/ali/before/api/AliPayService.java index 943ee0f5..a5000b1d 100644 --- a/pay-java-ali/src/main/java/com/egzosn/pay/ali/before/api/AliPayService.java +++ b/pay-java-ali/src/main/java/com/egzosn/pay/ali/before/api/AliPayService.java @@ -16,7 +16,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.awt.image.BufferedImage; -import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.net.URLEncoder; @@ -39,7 +38,10 @@ public class AliPayService extends BasePayService { private static final String HTTPS_REQ_URL = "https://mapi.alipay.com/gateway.do"; private static final String QUERY_REQ_URL = "https://openapi.alipay.com/gateway.do"; - + DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + { + df.setTimeZone(TimeZone.getTimeZone("GMT+8")); + } public AliPayService(PayConfigStorage payConfigStorage) { super(payConfigStorage); } @@ -389,7 +391,30 @@ public Map refund(RefundOrder refundOrder) { public Map refundquery(String tradeNo, String outTradeNo) { return secondaryInterface(tradeNo, outTradeNo, AliTransactionType.REFUNDQUERY); } + /** + * 查询退款 + * + * @param refundOrder 退款订单单号信息 + * @return 返回支付方查询退款后的结果 + */ + @Override + public Map refundquery(RefundOrder refundOrder){ + //获取公共参数 + Map parameters = getPublicParameters(AliTransactionType.REFUNDQUERY); + + Map bizContent = getBizContent(refundOrder.getTradeNo(), refundOrder.getOutTradeNo(), null); + if (!StringUtils.isEmpty(refundOrder.getRefundNo())){ + bizContent.put("out_request_no", refundOrder.getRefundNo()); + } + //设置请求参数的集合 + parameters.put("biz_content", JSON.toJSONString(bizContent)); + + //设置签名 + setSign(parameters); + return requestTemplate.getForObject(QUERY_REQ_URL + "?" + UriVariables.getMapToParameters(parameters), JSONObject.class); + + } /** @@ -406,8 +431,7 @@ public Map downloadbill(Date billDate, String billType) { Map bizContent = new TreeMap<>(); bizContent.put("bill_type", billType); //目前只支持日账单 - DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - df.setTimeZone(TimeZone.getTimeZone("GMT+8")); + bizContent.put("bill_date", df.format(billDate)); //设置请求参数的集合 parameters.put("biz_content", JSON.toJSONString(bizContent)); diff --git a/pay-java-common/src/main/java/com/egzosn/pay/common/api/BasePayService.java b/pay-java-common/src/main/java/com/egzosn/pay/common/api/BasePayService.java index d911f321..dea0d775 100644 --- a/pay-java-common/src/main/java/com/egzosn/pay/common/api/BasePayService.java +++ b/pay-java-common/src/main/java/com/egzosn/pay/common/api/BasePayService.java @@ -224,6 +224,19 @@ public T refundquery(String tradeNo, String outTradeNo, Callback callback return callback.perform(refundquery(tradeNo, outTradeNo)); } + /** + * 查询退款 + * + * @param refundOrder 退款订单信息 + * @param callback 处理器 + * @param 返回类型 + * @return 返回支付方查询退款后的结果 + */ + @Override + public T refundquery(RefundOrder refundOrder, Callback callback){ + return callback.perform(refundquery(refundOrder)); + } + /** * 目前只支持日账单 * diff --git a/pay-java-common/src/main/java/com/egzosn/pay/common/api/PayService.java b/pay-java-common/src/main/java/com/egzosn/pay/common/api/PayService.java index 3efe7a66..9d8c804c 100644 --- a/pay-java-common/src/main/java/com/egzosn/pay/common/api/PayService.java +++ b/pay-java-common/src/main/java/com/egzosn/pay/common/api/PayService.java @@ -248,6 +248,7 @@ public interface PayService { * @param outTradeNo 商户单号 * @return 返回支付方查询退款后的结果 */ + @Deprecated Map refundquery(String tradeNo, String outTradeNo); /** * 查询退款 @@ -258,7 +259,24 @@ public interface PayService { * @param 返回类型 * @return 返回支付方查询退款后的结果 */ + @Deprecated T refundquery(String tradeNo, String outTradeNo, Callback callback); + /** + * 查询退款 + * + * @param refundOrder 退款订单单号信息 + * @return 返回支付方查询退款后的结果 + */ + Map refundquery(RefundOrder refundOrder); + /** + * 查询退款 + * + * @param refundOrder 退款订单信息 + * @param callback 处理器 + * @param 返回类型 + * @return 返回支付方查询退款后的结果 + */ + T refundquery(RefundOrder refundOrder, Callback callback); /** * 下载对账单 diff --git a/pay-java-common/src/main/java/com/egzosn/pay/common/bean/PayOrder.java b/pay-java-common/src/main/java/com/egzosn/pay/common/bean/PayOrder.java index e522d331..f295d8c7 100644 --- a/pay-java-common/src/main/java/com/egzosn/pay/common/bean/PayOrder.java +++ b/pay-java-common/src/main/java/com/egzosn/pay/common/bean/PayOrder.java @@ -1,6 +1,7 @@ package com.egzosn.pay.common.bean; import java.math.BigDecimal; +import java.util.Date; /** * 支付订单信息 @@ -38,6 +39,10 @@ public class PayOrder { private TransactionType transactionType; //支付币种 private CurType curType; + //订单过期时间 + private Date expirationTime; + + public CurType getCurType() { @@ -191,6 +196,14 @@ public void setOpenid(String openid) { this.openid = openid; } + public Date getExpirationTime() { + return expirationTime; + } + + public void setExpirationTime(Date expirationTime) { + this.expirationTime = expirationTime; + } + @Override public String toString() { return "PayOrder{" + diff --git a/pay-java-common/src/main/java/com/egzosn/pay/common/bean/RefundOrder.java b/pay-java-common/src/main/java/com/egzosn/pay/common/bean/RefundOrder.java index 286d0f8e..be5061a2 100644 --- a/pay-java-common/src/main/java/com/egzosn/pay/common/bean/RefundOrder.java +++ b/pay-java-common/src/main/java/com/egzosn/pay/common/bean/RefundOrder.java @@ -34,7 +34,7 @@ public class RefundOrder { private BigDecimal totalAmount; /** - * 交易日期 + * 退款交易日期 */ private Date orderDate; diff --git a/pay-java-fuiou/src/main/java/com/egzosn/pay/fuiou/api/FuiouPayService.java b/pay-java-fuiou/src/main/java/com/egzosn/pay/fuiou/api/FuiouPayService.java index c74aef51..8a5eb69f 100644 --- a/pay-java-fuiou/src/main/java/com/egzosn/pay/fuiou/api/FuiouPayService.java +++ b/pay-java-fuiou/src/main/java/com/egzosn/pay/fuiou/api/FuiouPayService.java @@ -154,7 +154,12 @@ private LinkedHashMap getOrderInfo(PayOrder order) { parameters.put("order_pay_type", order.getTransactionType());//支付类型 parameters.put("page_notify_url", payConfigStorage.getReturnUrl());//商户接受支付结果通知地址 parameters.put("back_notify_url", StringUtils.isBlank(payConfigStorage.getNotifyUrl()) ? "" : payConfigStorage.getNotifyUrl());//商户接受的支付结果后台通知地址 //非必填 - parameters.put("order_valid_time", "30m");//超时时间 1m-15天,m:分钟、h:小时、d天、1c当天有效, + + if (null != order.getExpirationTime()){ + parameters.put("order_valid_time", ((order.getExpirationTime().getTime() - System.currentTimeMillis())/1000/60 + "m")); + }else { + parameters.put("order_valid_time", "30m");//超时时间 1m-15天,m:分钟、h:小时、d天、1c当天有效, + } parameters.put("iss_ins_cd", order.getBankType());//银行代码 parameters.put("goods_name", order.getSubject()); parameters.put("goods_display_url", "");//商品展示网址 //非必填 @@ -378,7 +383,18 @@ public Map refund (RefundOrder refundOrder) { @Override public Map refundquery(String tradeNo, String outTradeNo) { - return null; + return Collections.emptyMap(); + } + + /** + * 查询退款 + * + * @param refundOrder 退款订单单号信息 + * @return 返回支付方查询退款后的结果 + */ + @Override + public Map refundquery(RefundOrder refundOrder) { + return Collections.emptyMap(); } @@ -390,7 +406,7 @@ public Map refundquery(String tradeNo, String outTradeNo) { */ @Override public Map downloadbill(Date billDate, String billType) { - return null; + return Collections.emptyMap(); } /** @@ -403,7 +419,7 @@ public Map downloadbill(Date billDate, String billType) { */ @Override public Map secondaryInterface(Object tradeNoOrBillDate, String outTradeNoBillType, TransactionType transactionType) { - return null; + return Collections.emptyMap(); } diff --git a/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerPayService.java b/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerPayService.java index f1bbd1cd..abd92369 100644 --- a/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerPayService.java +++ b/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerPayService.java @@ -337,7 +337,18 @@ public Map refund(RefundOrder refundOrder) { */ @Override public Map refundquery(String tradeNo, String outTradeNo) { - return new HashMap<>(0); + return Collections.emptyMap(); + } + + /** + * 查询退款 + * + * @param refundOrder 退款订单单号信息 + * @return 返回支付方查询退款后的结果 + */ + @Override + public Map refundquery(RefundOrder refundOrder) { + return Collections.emptyMap(); } /** @@ -351,7 +362,7 @@ public Map refundquery(String tradeNo, String outTradeNo) { @Override public Map downloadbill(Date billDate, String billType) { - return new HashMap<>(0); + return Collections.emptyMap(); } /** diff --git a/pay-java-paypal/src/main/java/com/egzosn/pay/paypal/api/PayPalPayService.java b/pay-java-paypal/src/main/java/com/egzosn/pay/paypal/api/PayPalPayService.java index 067ea43a..412075b5 100644 --- a/pay-java-paypal/src/main/java/com/egzosn/pay/paypal/api/PayPalPayService.java +++ b/pay-java-paypal/src/main/java/com/egzosn/pay/paypal/api/PayPalPayService.java @@ -291,13 +291,24 @@ public Map refundquery(String tradeNo, String outTradeNo) { return resp; } + /** + * 查询退款 + * + * @param refundOrder 退款订单单号信息 + * @return 返回支付方查询退款后的结果 + */ + @Override + public Map refundquery(RefundOrder refundOrder) { + return refundquery(refundOrder.getTradeNo(), refundOrder.getOutTradeNo()); + } + @Override public Map downloadbill(Date billDate, String billType) { - return null; + return Collections.emptyMap(); } @Override public Map secondaryInterface(Object tradeNoOrBillDate, String outTradeNoBillType, TransactionType transactionType) { - return null; + return Collections.emptyMap(); } } diff --git a/pay-java-union/src/main/java/com/egzosn/pay/union/api/UnionPayService.java b/pay-java-union/src/main/java/com/egzosn/pay/union/api/UnionPayService.java index dd990d2d..8ac35049 100644 --- a/pay-java-union/src/main/java/com/egzosn/pay/union/api/UnionPayService.java +++ b/pay-java-union/src/main/java/com/egzosn/pay/union/api/UnionPayService.java @@ -55,7 +55,10 @@ public class UnionPayService extends BasePayService { private static final String FILE_TRANS_URL= "https://filedownload.%s/"; private static final String APP_TRANS_URL= "https://gateway.%s/gateway/api/appTransReq.do"; private static final String CARD_TRANS_URL= "https://gateway.%s/gateway/api/cardTransReq.do"; - + public final static DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); + { + df.setTimeZone(TimeZone.getTimeZone("GMT+8")); + } /** * 构造函数 @@ -207,12 +210,15 @@ public Map orderInfo (PayOrder order) { case B2B: params.put(SDKConstants.param_txnAmt, order.getPrice().multiply(new BigDecimal(100))); params.put("orderDesc", order.getSubject()); - DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); // 订单超时时间。 // 超过此时间后,除网银交易外,其他交易银联系统会拒绝受理,提示超时。 跳转银行网银交易如果超时后交易成功,会自动退款,大约5个工作日金额返还到持卡人账户。 // 此时间建议取支付时的北京时间加15分钟。 // 超过超时时间调查询接口应答origRespCode不是A6或者00的就可以判断为失败。 - params.put(SDKConstants.param_payTimeout, df.format(System.currentTimeMillis() + 30 * 60 * 1000)); + if (null != order.getExpirationTime()){ + params.put(SDKConstants.param_payTimeout, order.getExpirationTime()); + }else { + params.put(SDKConstants.param_payTimeout, df.format(System.currentTimeMillis() + 30 * 60 * 1000)); + } params.put(SDKConstants.param_frontUrl, payConfigStorage.getReturnUrl()); break; case CONSUME: @@ -431,17 +437,17 @@ public String buildRequest(Map orderInfo, MethodType method) { } + /** - * 交易查询接口,带处理器 + * 交易查询接口 * * @param tradeNo 支付平台订单号 * @param outTradeNo 商户单号 - * @param callback 处理器 * - * @return 返回查询回来的结果集 + * @return 返回查询回来的结果集,支付方原值返回 */ @Override - public T query(String tradeNo, String outTradeNo, Callback callback) { + public Map query(String tradeNo, String outTradeNo) { Map params = this.getCommonParam(); UnionTransactionType.QUERY.convertMap(params); params.put(SDKConstants.param_orderId,outTradeNo); @@ -454,7 +460,7 @@ public T query(String tradeNo, String outTradeNo, Callback callback) { if ((SDKConstants.OK_RESP_CODE).equals(origRespCode)) { //交易成功,更新商户订单状态 //TODO - return callback.perform(response); + return response; } } throw new PayErrorException(new PayException(response.getString(SDKConstants.param_respCode), response.getString(SDKConstants.param_respMsg), response.toJSONString())); @@ -463,25 +469,6 @@ public T query(String tradeNo, String outTradeNo, Callback callback) { } - /** - * 交易查询接口 - * - * @param tradeNo 支付平台订单号 - * @param outTradeNo 商户单号 - * - * @return 返回查询回来的结果集,支付方原值返回 - */ - @Override - public Map query(String tradeNo, String outTradeNo) { - - return query(tradeNo, outTradeNo, new Callback>() { - @Override - public Map perform(Map map) { - return map; - } - }); - } - /** * 消费撤销/退货接口 @@ -519,9 +506,9 @@ public Map unionRefundOrConsumeUndo (RefundOrder refundOrder,Uni return response; } - throw new PayErrorException(new PayException(response.getString(SDKConstants.param_respCode), response.getString(SDKConstants.param_respMsg), response.toJSONString())); + throw new PayErrorException(new PayException(response.getString(SDKConstants.param_respCode), response.getString(SDKConstants.param_respMsg), response.toJSONString())); } - throw new PayErrorException(new PayException("failure", "验证签名失败", response.toJSONString())); + throw new PayErrorException(new PayException("failure", "验证签名失败", response.toJSONString())); } /** * 交易关闭接口 @@ -532,20 +519,7 @@ public Map unionRefundOrConsumeUndo (RefundOrder refundOrder,Uni */ @Override public Map close (String tradeNo, String outTradeNo) { - return null; - } - - /** - * 交易关闭接口 - * - * @param tradeNo 支付平台订单号 - * @param outTradeNo 商户单号 - * @param callback 处理器 - * @return 返回支付方交易关闭后的结果 - */ - @Override - public T close (String tradeNo, String outTradeNo, Callback callback) { - return null; + return Collections.emptyMap(); } /** @@ -561,47 +535,15 @@ public T close (String tradeNo, String outTradeNo, Callback callback) { @Deprecated @Override public Map refund (String tradeNo, String outTradeNo, BigDecimal refundAmount, BigDecimal totalAmount) { - return refund(tradeNo, outTradeNo, refundAmount, totalAmount, new Callback>() { - @Override - public Map perform(Map map) { - return map; - } - }); + return refund(new RefundOrder(tradeNo, outTradeNo, refundAmount, totalAmount)); } - /** - * 申请退款接口 - * - * @param tradeNo 支付平台订单号 - * @param outTradeNo 商户单号 - * @param refundAmount 退款金额 - * @param totalAmount 总金额 - * @param callback 处理器 - * @return 返回支付方申请退款后的结果 - * @see #refund(RefundOrder, Callback) - */ - @Deprecated - @Override - public T refund (String tradeNo, String outTradeNo, BigDecimal refundAmount, BigDecimal totalAmount, Callback callback) { - return refund(new RefundOrder(tradeNo, outTradeNo, refundAmount, totalAmount), callback); - } @Override public Map refund(RefundOrder refundOrder) { - return refund(refundOrder, new Callback>() { - - @Override - public Map perform(Map map) { - return map; - } - }); - } - - @Override - public T refund(RefundOrder refundOrder, Callback callback) { - return callback.perform(unionRefundOrConsumeUndo(refundOrder, UnionTransactionType.REFUND)); + return unionRefundOrConsumeUndo(refundOrder, UnionTransactionType.REFUND); } /** @@ -613,20 +555,20 @@ public T refund(RefundOrder refundOrder, Callback callback) { */ @Override public Map refundquery (String tradeNo, String outTradeNo) { - return null; + return Collections.emptyMap(); } + + /** * 查询退款 * - * @param tradeNo 支付平台订单号 - * @param outTradeNo 商户单号 - * @param callback 处理器 + * @param refundOrder 退款订单单号信息 * @return 返回支付方查询退款后的结果 */ @Override - public T refundquery (String tradeNo, String outTradeNo, Callback callback) { - return null; + public Map refundquery(RefundOrder refundOrder) { + return Collections.emptyMap(); } /** @@ -670,7 +612,7 @@ public Map downloadbill (Date billDate, String billType) { */ @Override public Map secondaryInterface(Object tradeNoOrBillDate, String outTradeNoBillType, TransactionType transactionType) { - return null; + return Collections.emptyMap(); } diff --git a/pay-java-wx-youdian/src/main/java/com/egzosn/pay/wx/youdian/api/WxYouDianPayService.java b/pay-java-wx-youdian/src/main/java/com/egzosn/pay/wx/youdian/api/WxYouDianPayService.java index 06f6b182..73b5bdec 100644 --- a/pay-java-wx-youdian/src/main/java/com/egzosn/pay/wx/youdian/api/WxYouDianPayService.java +++ b/pay-java-wx-youdian/src/main/java/com/egzosn/pay/wx/youdian/api/WxYouDianPayService.java @@ -381,7 +381,7 @@ public Map query(String tradeNo, String outTradeNo) { @Override public Map close(String tradeNo, String outTradeNo) { - return new HashMap<>(0); + return Collections.emptyMap(); } @@ -415,14 +415,24 @@ public Map refund(RefundOrder refundOrder) { @Override public Map refundquery(String tradeNo, String outTradeNo) { - return new HashMap<>(0); + return Collections.emptyMap(); } + /** + * 查询退款 + * + * @param refundOrder 退款订单单号信息 + * @return 返回支付方查询退款后的结果 + */ + @Override + public Map refundquery(RefundOrder refundOrder) { + return Collections.emptyMap(); + } @Override public Map downloadbill(Date billDate, String billType) { - return new HashMap<>(0); + return Collections.emptyMap(); } @@ -436,7 +446,7 @@ public Map downloadbill(Date billDate, String billType) { */ @Override public Map secondaryInterface(Object tradeNoOrBillDate, String outTradeNoBillType, TransactionType transactionType) { - throw new UnsupportedOperationException(); + return Collections.emptyMap(); } diff --git a/pay-java-wx/src/main/java/com/egzosn/pay/wx/api/WxPayService.java b/pay-java-wx/src/main/java/com/egzosn/pay/wx/api/WxPayService.java index 9b5fceeb..652a263d 100644 --- a/pay-java-wx/src/main/java/com/egzosn/pay/wx/api/WxPayService.java +++ b/pay-java-wx/src/main/java/com/egzosn/pay/wx/api/WxPayService.java @@ -54,7 +54,15 @@ public class WxPayService extends BasePayService { public final static String SIGN = "sign"; public final static String CIPHER_ALGORITHM = "RSA/ECB/OAEPWITHSHA-1ANDMGF1PADDING"; public final static String FAILURE = "failure"; - + public final static String APPID = "appid"; + private final static DateFormat downloadbillDf = new SimpleDateFormat("yyyyMMdd"); + private final static DateFormat df = new SimpleDateFormat("yyyyMMddHHmms"); + + { + TimeZone timeZone = TimeZone.getTimeZone("GMT+8"); + downloadbillDf.setTimeZone(timeZone); + df.setTimeZone(timeZone); + } @@ -146,7 +154,7 @@ public boolean signVerify(Map params, String sign) { private Map getPublicParameters() { Map parameters = new TreeMap(); - parameters.put("appid", payConfigStorage.getAppid()); + parameters.put(APPID, payConfigStorage.getAppid()); parameters.put("mch_id", payConfigStorage.getPid()); parameters.put("nonce_str", SignUtils.randomStr()); return parameters; @@ -174,6 +182,10 @@ public JSONObject unifiedOrder(PayOrder order) { parameters.put("attach", order.getBody()); parameters.put("notify_url", payConfigStorage.getNotifyUrl()); parameters.put("trade_type", order.getTransactionType().getType()); + if (null != order.getExpirationTime()){ + parameters.put("time_start", df.format(new Date())); + parameters.put("time_expire", df.format(order.getExpirationTime())); + } ((WxTransactionType) order.getTransactionType()).setAttribute(parameters, order); String sign = createSign(SignUtils.parameterText(parameters), payConfigStorage.getInputCharset()); @@ -221,7 +233,7 @@ public Map orderInfo(PayOrder order) { params.put("package", "prepay_id=" + result.get("prepay_id")); } else if (WxTransactionType.APP == order.getTransactionType()) { params.put("partnerid", payConfigStorage.getPid()); - params.put("appid", payConfigStorage.getAppid()); + params.put(APPID, payConfigStorage.getAppid()); params.put("prepayid", result.get("prepay_id")); params.put("timestamp", System.currentTimeMillis() / 1000); params.put("noncestr", result.get("nonce_str")); @@ -401,6 +413,13 @@ public Map refund(String transactionId, String outTradeNo, BigDe } + private Map setParameters(Map parameters, String key, String value){ + if (!StringUtils.isEmpty(value)){ + parameters.put(key, value); + } + return parameters; + } + /** * 申请退款接口 * @@ -411,12 +430,10 @@ public Map refund(String transactionId, String outTradeNo, BigDe public Map refund(RefundOrder refundOrder) { //获取公共参数 Map parameters = getPublicParameters(); - if (null != refundOrder.getTradeNo()) { - parameters.put("transaction_id", refundOrder.getTradeNo()); - } else { - parameters.put("out_trade_no", refundOrder.getOutTradeNo()); - } - parameters.put("out_refund_no", refundOrder.getRefundNo()); + + setParameters(parameters, "transaction_id", refundOrder.getTradeNo()); + setParameters(parameters, "out_trade_no", refundOrder.getOutTradeNo()); + setParameters(parameters, "out_refund_no", refundOrder.getRefundNo()); parameters.put("total_fee", conversion(refundOrder.getTotalAmount())); parameters.put("refund_fee", conversion(refundOrder.getRefundAmount())); parameters.put("op_user_id", payConfigStorage.getPid()); @@ -428,6 +445,8 @@ public Map refund(RefundOrder refundOrder) { + + /** * 查询退款 * @@ -440,6 +459,24 @@ public Map refundquery(String transactionId, String outTradeNo) return secondaryInterface(transactionId, outTradeNo, WxTransactionType.REFUNDQUERY); } + /** + * 查询退款 + * + * @param refundOrder 退款订单单号信息 + * @return 返回支付方查询退款后的结果 + */ + @Override + public Map refundquery(RefundOrder refundOrder) { + + //获取公共参数 + Map parameters = getPublicParameters(); + setParameters(parameters, "transaction_id", refundOrder.getTradeNo()); + setParameters(parameters, "out_trade_no", refundOrder.getOutTradeNo()); + setParameters(parameters, "out_refund_no", refundOrder.getRefundNo()); + //设置签名 + setSign(parameters); + return requestTemplate.postForObject(getUrl( WxTransactionType.REFUNDQUERY), XML.getMap2Xml(parameters) , JSONObject.class); + } /** @@ -457,9 +494,8 @@ public Map downloadbill(Date billDate, String billType) { parameters.put("bill_type", billType); //目前只支持日账单 - DateFormat df = new SimpleDateFormat("yyyyMMdd"); - df.setTimeZone(TimeZone.getTimeZone("GMT+8")); - parameters.put("bill_date", df.format(billDate)); + + parameters.put("bill_date", downloadbillDf.format(billDate)); //设置签名 setSign(parameters);