From 38e2f6215478d4a952b5cb5707cf80762cafd268 Mon Sep 17 00:00:00 2001 From: jinyu Date: Tue, 11 Apr 2017 14:30:47 +0800 Subject: [PATCH] PrePay codeUrl file change to payUrl --- pom.xml | 3 +- .../java/com/foxinmy/weixin4j/api/PayApi.java | 17 +++++----- .../foxinmy/weixin4j/payment/mch/PrePay.java | 19 ++++++----- .../weixin4j/payment/mch/WAPPayRequest.java | 34 +++++++++++-------- .../com/foxinmy/weixin4j/type/TradeType.java | 2 +- .../foxinmy/weixin4j/base/test/PayTest.java | 2 +- weixin4j-server/pom.xml | 8 ++++- 7 files changed, 50 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index c243c16d..ce3457b5 100644 --- a/pom.xml +++ b/pom.xml @@ -45,12 +45,13 @@ weixin4j-qy weixin4j-server weixin4j-example + weixin4j-serverX UTF-8 1.6 1.6 - 1.2.3 + 1.2.31 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 db860ac0..89ffab25 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 @@ -134,9 +134,10 @@ public class PayApi extends MchApi { return new JSAPIPayRequest(prePay.getPrepayId(), weixinAccount); } else if (TradeType.NATIVE.name().equals(tradeType)) { return new NATIVEPayRequest(prePay.getPrepayId(), - prePay.getCodeUrl(), weixinAccount); - } else if (TradeType.WAP.name().equals(tradeType)) { - return new WAPPayRequest(prePay.getPrepayId(), weixinAccount); + prePay.getPayUrl(), weixinAccount); + } else if (TradeType.MWEB.name().equals(tradeType)) { + return new WAPPayRequest(prePay.getPrepayId(), prePay.getPayUrl(), + weixinAccount); } else { throw new WeixinException("unknown tradeType:" + tradeType); } @@ -341,7 +342,8 @@ public class PayApi extends MchApi { } /** - * 创建WAP支付请求对象 + * 创建WAP支付请求对象:正常流程用户支付完成后会返回至发起支付的页面,如需返回至指定页面, + * 则可以在MWEB_URL后拼接上redirect_url参数,来指定回调页面 * * @param body * 商品描述 @@ -366,8 +368,8 @@ public class PayApi extends MchApi { double totalFee, String notifyUrl, String createIp, String attach) throws WeixinException { MchPayPackage payPackage = new MchPayPackage(body, outTradeNo, - totalFee, notifyUrl, createIp, TradeType.WAP, null, null, null, - attach); + totalFee, notifyUrl, createIp, TradeType.MWEB, null, null, + null, attach); return createPayRequest(payPackage); } @@ -470,7 +472,6 @@ public class PayApi extends MchApi { double totalFee, double refundFee, CurrencyType refundFeeType, String opUserId, RefundAccountType refundAccountType) throws WeixinException { - WeixinResponse response = null; Map map = createBaseRequestMap(idQuery); map.put("out_refund_no", outRefundNo); map.put("total_fee", @@ -491,7 +492,7 @@ public class PayApi extends MchApi { map.put("refund_account", refundAccountType.name()); map.put("sign", weixinSignature.sign(map)); String param = XmlStream.map2xml(map); - response = getWeixinSSLExecutor().post( + WeixinResponse response = getWeixinSSLExecutor().post( getRequestUri("refund_apply_uri"), param); return response.getAsObject(new TypeReference() { }); diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/PrePay.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/PrePay.java index 55c8c823..7c7306c1 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/PrePay.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/PrePay.java @@ -3,6 +3,7 @@ package com.foxinmy.weixin4j.payment.mch; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; import javax.xml.bind.annotation.XmlRootElement; import com.foxinmy.weixin4j.type.TradeType; @@ -35,10 +36,12 @@ public class PrePay extends MerchantResult { @XmlElement(name = "prepay_id") private String prepayId; /** - * trade_type 为 NATIVE 是有 返回,此参数可直接生成二 维码展示出来进行扫码支付 可能为空 + * 对于trade_type 为 NATIVE 或者 MWEB 是有 返回
NATVIE支付:可直接生成二维码展示出来进行扫码支付可能为空
+ * MWEB支付:可直接作为跳转支付的URL */ - @XmlElement(name = "code_url") - private String codeUrl; + @XmlElements({ @XmlElement(name = "code_url"), + @XmlElement(name = "mweb_url") }) + private String payUrl; protected PrePay() { // jaxb required @@ -64,17 +67,17 @@ public class PrePay extends MerchantResult { this.prepayId = prepayId; } - public String getCodeUrl() { - return codeUrl; + public String getPayUrl() { + return payUrl; } - public void setCodeUrl(String codeUrl) { - this.codeUrl = codeUrl; + public void setPayUrl(String payUrl) { + this.payUrl = payUrl; } @Override public String toString() { return "PrePay [tradeType=" + tradeType + ", prepayId=" + prepayId - + ", codeUrl=" + codeUrl + ", " + super.toString() + "]"; + + ", payUrl=" + payUrl + ", " + super.toString() + "]"; } } diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/WAPPayRequest.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/WAPPayRequest.java index 754fe66b..17ce2bad 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/WAPPayRequest.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/payment/mch/WAPPayRequest.java @@ -3,10 +3,6 @@ package com.foxinmy.weixin4j.payment.mch; import com.foxinmy.weixin4j.model.WeixinPayAccount; import com.foxinmy.weixin4j.payment.PayRequest; import com.foxinmy.weixin4j.type.TradeType; -import com.foxinmy.weixin4j.util.Consts; -import com.foxinmy.weixin4j.util.DigestUtil; -import com.foxinmy.weixin4j.util.MapUtil; -import com.foxinmy.weixin4j.util.URLEncodingUtil; /** * WAP支付 @@ -21,14 +17,21 @@ import com.foxinmy.weixin4j.util.URLEncodingUtil; * href="https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=15_1">WAP支付 */ public class WAPPayRequest extends AbstractPayRequest { + /** + * 微信支付URL + */ + private final String payUrl; - public WAPPayRequest(String prePayId, WeixinPayAccount payAccount) { + public WAPPayRequest(String prePayId, String payUrl, + WeixinPayAccount payAccount) { super(prePayId, payAccount); + this.payUrl = payUrl; + } @Override public TradeType getPaymentType() { - return TradeType.WAP; + return TradeType.MWEB; } /** @@ -44,14 +47,15 @@ public class WAPPayRequest extends AbstractPayRequest { @Override public String toRequestString() { - PayRequest payRequest = toRequestObject(); - String original = MapUtil.toJoinString(payRequest, true, true); - String sign = DigestUtil.MD5( - String.format("%s&key=%s", original, getPaymentAccount() - .getPaySignKey())).toUpperCase(); - return String.format("weixin://wap/pay?%s", - URLEncodingUtil.encoding( - String.format("%s&sign=%s", original, sign), - Consts.UTF_8, true)); + // PayRequest payRequest = toRequestObject(); + // String original = MapUtil.toJoinString(payRequest, true, true); + // String sign = DigestUtil.MD5( + // String.format("%s&key=%s", original, getPaymentAccount() + // .getPaySignKey())).toUpperCase(); + // return String.format("weixin://wap/pay?%s", + // URLEncodingUtil.encoding( + // String.format("%s&sign=%s", original, sign), + // Consts.UTF_8, true)); + return this.payUrl; } } diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/type/TradeType.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/type/TradeType.java index b5b413cc..c660a2ec 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/type/TradeType.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/type/TradeType.java @@ -29,5 +29,5 @@ public enum TradeType { /** * WAP支付 */ - WAP; + MWEB; } diff --git a/weixin4j-base/src/test/java/com/foxinmy/weixin4j/base/test/PayTest.java b/weixin4j-base/src/test/java/com/foxinmy/weixin4j/base/test/PayTest.java index 1fc30171..d59535f4 100644 --- a/weixin4j-base/src/test/java/com/foxinmy/weixin4j/base/test/PayTest.java +++ b/weixin4j-base/src/test/java/com/foxinmy/weixin4j/base/test/PayTest.java @@ -91,7 +91,7 @@ public class PayTest { c.set(Calendar.DAY_OF_MONTH, 4); System.err.println(c.getTime()); OutputStream os = new FileOutputStream("/tmp/bill20160813.txt"); - PAY.downloadBill(c.getTime(), BillType.ALL, os,null); + PAY.downloadBill(c.getTime(), BillType.ALL, os, null); } @Test diff --git a/weixin4j-server/pom.xml b/weixin4j-server/pom.xml index 51580a6e..3b1b7d78 100644 --- a/weixin4j-server/pom.xml +++ b/weixin4j-server/pom.xml @@ -13,11 +13,17 @@ https://github.com/foxinmy/weixin4j/tree/master/weixin4j-server 微信消息netty服务器 - + io.netty netty-all 4.1.8.Final + + javax.servlet + servlet-api + 2.5 + provided + com.alibaba fastjson