Skip to content

Commit e68abe7

Browse files
author
HaiJun Liu
committed
Merge branch 'develop' of https://github.com/wechat-group/weixin-java-tools into develop
2 parents 81b7a2c + f0192cc commit e68abe7

File tree

5 files changed

+417
-3
lines changed

5 files changed

+417
-3
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpPayService.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public interface WxMpPayService {
1818
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
1919
* 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder
2020
* @throws WxErrorException
21+
* @param request 请求对象
2122
*
2223
*/
2324
WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request)
@@ -26,11 +27,10 @@ WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request)
2627
/**
2728
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
2829
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
29-
*
30+
* @param request 请求对象
3031
*/
3132
Map<String, String> getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException;
3233

33-
3434
/**
3535
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
3636
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
@@ -53,6 +53,7 @@ WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo)
5353
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
5454
* 接口链接:https://api.mch.weixin.qq.com/secapi/pay/refund
5555
* </pre>
56+
* @param request 请求对象
5657
* @param keyFile 证书文件对象
5758
* @return 退款操作结果
5859
*/
@@ -74,6 +75,7 @@ WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo)
7475
* 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
7576
* 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
7677
* </pre>
78+
* @param request 请求对象
7779
* @param keyFile 证书文件对象
7880
*/
7981
WxRedpackResult sendRedpack(WxSendRedpackRequest request, File keyFile) throws WxErrorException;
@@ -86,9 +88,22 @@ WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo)
8688
* 注意:与商户微信支付收款资金并非同一账户,需要单独充值。
8789
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
8890
* 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers
89-
* @param keyFile 证书文件对象
9091
* </pre>
92+
* @param request 请求对象
93+
* @param keyFile 证书文件对象
9194
*/
9295
WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException;
9396

97+
/**
98+
* <pre>
99+
* 查询企业付款API
100+
* 用于商户的企业付款操作进行结果查询,返回付款操作详细结果。
101+
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3
102+
* 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo
103+
* </pre>
104+
* @param partnerTradeNo 商户订单号
105+
* @param keyFile 证书文件对象
106+
*/
107+
WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException;
108+
94109
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,31 @@ public WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErr
369369
return result;
370370
}
371371

372+
@Override
373+
public WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException {
374+
XStream xstream = XStreamInitializer.getInstance();
375+
xstream.processAnnotations(WxEntPayQueryRequest.class);
376+
xstream.processAnnotations(WxEntPayQueryResult.class);
377+
378+
WxEntPayQueryRequest request = new WxEntPayQueryRequest();
379+
request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
380+
request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId());
381+
request.setNonceStr(System.currentTimeMillis() + "");
382+
383+
String sign = this.createSign(xmlBean2Map(request), this.wxMpService.getWxMpConfigStorage().getPartnerKey());
384+
request.setSign(sign);
385+
386+
String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo";
387+
388+
String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId());
389+
WxEntPayQueryResult result = (WxEntPayQueryResult) xstream.fromXML(responseContent);
390+
if ("FAIL".equals(result.getResultCode())) {
391+
throw new WxErrorException(
392+
WxError.newBuilder().setErrorMsg(result.getErrCode() + ":" + result.getErrCodeDes()).build());
393+
}
394+
return result;
395+
}
396+
372397
private String executeRequestWithKeyFile( String url, File keyFile, String requestStr, String mchId) throws WxErrorException {
373398
try (FileInputStream inputStream = new FileInputStream(keyFile)) {
374399
KeyStore keyStore = KeyStore.getInstance("PKCS12");
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package me.chanjar.weixin.mp.bean.pay;
2+
3+
import com.thoughtworks.xstream.annotations.XStreamAlias;
4+
import me.chanjar.weixin.common.annotation.Required;
5+
import org.apache.commons.lang3.builder.ToStringBuilder;
6+
import org.apache.commons.lang3.builder.ToStringStyle;
7+
8+
/**
9+
* <pre>
10+
* 企业付款请求对象
11+
* 注释中各行每个字段描述对应如下:
12+
* <li>字段名
13+
* <li>变量名
14+
* <li>是否必填
15+
* <li>类型
16+
* <li>示例值
17+
* <li>描述
18+
* </pre>
19+
* Created by Binary Wang on 2016/10/19.
20+
* @author binarywang (https://github.com/binarywang)
21+
*/
22+
@XStreamAlias("xml")
23+
public class WxEntPayQueryRequest {
24+
/**
25+
* <pre>
26+
* Appid
27+
* appid
28+
* 是
29+
* wxe062425f740d30d8
30+
* String(32)
31+
* 商户号的appid
32+
* </pre>
33+
*/
34+
@XStreamAlias("appid")
35+
private String appid;
36+
37+
/**
38+
* <pre>
39+
* 商户号
40+
* mch_id
41+
* 是
42+
* 10000098
43+
* String(32)
44+
* 微信支付分配的商户号
45+
* </pre>
46+
*/
47+
@XStreamAlias("mchid")
48+
private String mchId;
49+
50+
/**
51+
* <pre>
52+
* 随机字符串
53+
* nonce_str
54+
* 是
55+
* 5K8264ILTKCH16CQ2502SI8ZNMTM67VS
56+
* String(32)
57+
* 随机字符串,不长于32位
58+
* </pre>
59+
*/
60+
@XStreamAlias("nonce_str")
61+
private String nonceStr;
62+
63+
/**
64+
* <pre>
65+
* 签名
66+
* sign
67+
* 是
68+
* C380BEC2BFD727A4B6845133519F3AD6
69+
* String(32)
70+
*签名,详见签名算法
71+
* </pre>
72+
*/
73+
@XStreamAlias("sign")
74+
private String sign;
75+
76+
/**
77+
* <pre>
78+
* 商户订单号
79+
* partner_trade_no
80+
* 是
81+
* 10000098201411111234567890
82+
* String
83+
* 商户订单号
84+
* </pre>
85+
*/
86+
@Required
87+
@XStreamAlias("partner_trade_no")
88+
private String partnerTradeNo;
89+
90+
public String getAppid() {
91+
return appid;
92+
}
93+
94+
public void setAppid(String appid) {
95+
this.appid = appid;
96+
}
97+
98+
public String getMchId() {
99+
return mchId;
100+
}
101+
102+
public void setMchId(String mchId) {
103+
this.mchId = mchId;
104+
}
105+
106+
public String getNonceStr() {
107+
return nonceStr;
108+
}
109+
110+
public void setNonceStr(String nonceStr) {
111+
this.nonceStr = nonceStr;
112+
}
113+
114+
public String getSign() {
115+
return sign;
116+
}
117+
118+
public void setSign(String sign) {
119+
this.sign = sign;
120+
}
121+
122+
public String getPartnerTradeNo() {
123+
return partnerTradeNo;
124+
}
125+
126+
public void setPartnerTradeNo(String partnerTradeNo) {
127+
this.partnerTradeNo = partnerTradeNo;
128+
}
129+
130+
@Override
131+
public String toString() {
132+
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
133+
}
134+
135+
}

0 commit comments

Comments
 (0)