Skip to content

Commit a0584e1

Browse files
lj128binarywang
authored andcommitted
#989 微信支付增加查询红包和拉取订单评论接口重载方法
1 parent 970ee51 commit a0584e1

File tree

6 files changed

+127
-46
lines changed

6 files changed

+127
-46
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EntPayService.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ public interface EntPayService {
4242
* @throws WxPayException the wx pay exception
4343
*/
4444
EntPayQueryResult queryEntPay(String partnerTradeNo) throws WxPayException;
45+
/**
46+
* <pre>
47+
* 查询企业付款API.
48+
* 用于商户的企业付款操作进行结果查询,返回付款操作详细结果。
49+
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3
50+
* 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo
51+
* </pre>
52+
*
53+
* @param partnerTradeNo 商户订单号
54+
* @return the ent pay query result
55+
* @throws WxPayException the wx pay exception
56+
*/
57+
EntPayQueryResult queryEntPay(EntPayQueryRequest request) throws WxPayException;
4558

4659
/**
4760
* <pre>
@@ -92,4 +105,17 @@ public interface EntPayService {
92105
* @throws WxPayException the wx pay exception
93106
*/
94107
EntPayBankQueryResult queryPayBank(String partnerTradeNo) throws WxPayException;
108+
/**
109+
* 企业付款到银行卡查询.
110+
* <pre>
111+
* 用于对商户企业付款到银行卡操作进行结果查询,返回付款操作详细结果。
112+
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_3
113+
* 接口链接:https://api.mch.weixin.qq.com/mmpaysptrans/query_bank
114+
* </pre>
115+
*
116+
* @param partnerTradeNo 商户订单号
117+
* @return the ent pay bank query result
118+
* @throws WxPayException the wx pay exception
119+
*/
120+
EntPayBankQueryResult queryPayBank(EntPayBankQueryRequest request) throws WxPayException;
95121
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,8 @@
1414
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
1515
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult;
1616
import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult;
17-
import com.github.binarywang.wxpay.bean.request.WxPayAuthcode2OpenidRequest;
18-
import com.github.binarywang.wxpay.bean.request.WxPayDownloadBillRequest;
19-
import com.github.binarywang.wxpay.bean.request.WxPayDownloadFundFlowRequest;
20-
import com.github.binarywang.wxpay.bean.request.WxPayMicropayRequest;
21-
import com.github.binarywang.wxpay.bean.request.WxPayOrderCloseRequest;
22-
import com.github.binarywang.wxpay.bean.request.WxPayOrderQueryRequest;
23-
import com.github.binarywang.wxpay.bean.request.WxPayOrderReverseRequest;
24-
import com.github.binarywang.wxpay.bean.request.WxPayRefundQueryRequest;
25-
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
26-
import com.github.binarywang.wxpay.bean.request.WxPayReportRequest;
27-
import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest;
28-
import com.github.binarywang.wxpay.bean.request.WxPayShorturlRequest;
29-
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
30-
import com.github.binarywang.wxpay.bean.result.WxPayBillResult;
31-
import com.github.binarywang.wxpay.bean.result.WxPayFundFlowResult;
32-
import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult;
33-
import com.github.binarywang.wxpay.bean.result.WxPayOrderCloseResult;
34-
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult;
35-
import com.github.binarywang.wxpay.bean.result.WxPayOrderReverseResult;
36-
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
37-
import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
38-
import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
39-
import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult;
40-
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
17+
import com.github.binarywang.wxpay.bean.request.*;
18+
import com.github.binarywang.wxpay.bean.result.*;
4119
import com.github.binarywang.wxpay.config.WxPayConfig;
4220
import com.github.binarywang.wxpay.exception.WxPayException;
4321

@@ -326,6 +304,20 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
326304
* @throws WxPayException the wx pay exception
327305
*/
328306
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException;
307+
/**
308+
* <pre>
309+
* 查询红包记录.
310+
* 用于商户对已发放的红包进行查询红包的具体信息,可支持普通红包和裂变包。
311+
* 请求Url:https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo
312+
* 是否需要证书:是(证书及使用说明详见商户证书)
313+
* 请求方式:POST
314+
* </pre>
315+
*
316+
* @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890
317+
* @return the wx pay redpack query result
318+
* @throws WxPayException the wx pay exception
319+
*/
320+
WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException;
329321

330322
/**
331323
* <pre>
@@ -685,4 +677,26 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
685677
* @throws WxPayException the wx pay exception
686678
*/
687679
String queryComment(Date beginDate, Date endDate, Integer offset, Integer limit) throws WxPayException;
680+
681+
/**
682+
* <pre>
683+
* 拉取订单评价数据.
684+
* 商户可以通过该接口拉取用户在微信支付交易记录中针对你的支付记录进行的评价内容。商户可结合商户系统逻辑对该内容数据进行存储、分析、展示、客服回访以及其他使用。如商户业务对评价内容有依赖,可主动引导用户进入微信支付交易记录进行评价。
685+
* 注意:
686+
* 1. 该内容所有权为提供内容的微信用户,商户在使用内容的过程中应遵从用户意愿
687+
* 2. 一次最多拉取200条评价数据,可根据时间区间分批次拉取
688+
* 3. 接口只能拉取最近三个月以内的评价数据
689+
* 接口链接:https://api.mch.weixin.qq.com/billcommentsp/batchquerycomment
690+
* 是否需要证书:需要
691+
* 文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_17&index=10
692+
* </pre>
693+
*
694+
* @param beginDate 开始时间
695+
* @param endDate 结束时间
696+
* @param offset 位移
697+
* @param limit 条数,建议填null,否则接口会报签名错误
698+
* @return the string
699+
* @throws WxPayException the wx pay exception
700+
*/
701+
String queryComment(WxPayQueryCommentRequest request) throws WxPayException;
688702
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayExcept
251251
result.checkResult(this, request.getSignType(), true);
252252
return result;
253253
}
254+
@Override
255+
public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException {
256+
request.setBillType(BillType.MCHT);
257+
request.checkAndSign(this.getConfig());
258+
259+
String url = this.getPayBaseUrl() + "/mmpaymkttransfers/gethbinfo";
260+
String responseContent = this.post(url, request.toXML(), true);
261+
WxPayRedpackQueryResult result = BaseWxPayResult.fromXML(responseContent, WxPayRedpackQueryResult.class);
262+
result.checkResult(this, request.getSignType(), true);
263+
return result;
264+
}
254265

255266
@Override
256267
public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxPayException {
@@ -822,4 +833,18 @@ public String queryComment(Date beginDate, Date endDate, Integer offset, Integer
822833

823834
return responseContent;
824835
}
836+
@Override
837+
public String queryComment(WxPayQueryCommentRequest request) throws WxPayException {
838+
request.checkAndSign(this.getConfig());
839+
request.setSignType(SignType.HMAC_SHA256);
840+
String url = this.getPayBaseUrl() + "/billcommentsp/batchquerycomment";
841+
842+
String responseContent = this.post(url, request.toXML(), true);
843+
if (responseContent.startsWith("<")) {
844+
throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class));
845+
}
846+
847+
return responseContent;
848+
}
849+
825850
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EntPayServiceImpl.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ public EntPayQueryResult queryEntPay(String partnerTradeNo) throws WxPayExceptio
7474
return result;
7575
}
7676

77+
@Override
78+
public EntPayQueryResult queryEntPay(EntPayQueryRequest request) throws WxPayException {
79+
request.checkAndSign(this.payService.getConfig());
80+
81+
String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/gettransferinfo";
82+
String responseContent = this.payService.post(url, request.toXML(), true);
83+
EntPayQueryResult result = BaseWxPayResult.fromXML(responseContent, EntPayQueryResult.class);
84+
result.checkResult(this.payService, request.getSignType(), true);
85+
return result;
86+
}
87+
7788
@Override
7889
public String getPublicKey() throws WxPayException {
7990
WxPayDefaultRequest request = new WxPayDefaultRequest();
@@ -118,6 +129,17 @@ public EntPayBankQueryResult queryPayBank(String partnerTradeNo) throws WxPayExc
118129
return result;
119130
}
120131

132+
@Override
133+
public EntPayBankQueryResult queryPayBank(EntPayBankQueryRequest request) throws WxPayException {
134+
request.checkAndSign(this.payService.getConfig());
135+
136+
String url = this.payService.getPayBaseUrl() + "/mmpaysptrans/query_bank";
137+
String responseContent = this.payService.post(url, request.toXML(), true);
138+
EntPayBankQueryResult result = BaseWxPayResult.fromXML(responseContent, EntPayBankQueryResult.class);
139+
result.checkResult(this.payService, request.getSignType(), true);
140+
return result;
141+
}
142+
121143
private String encryptRSA(File publicKeyFile, String srcString) throws WxPayException {
122144
try {
123145
Security.addProvider(new BouncyCastleProvider());
@@ -145,26 +167,4 @@ private File buildPublicKeyFile() throws WxPayException {
145167
throw new WxPayException("生成加密公钥文件时发生异常", e);
146168
}
147169
}
148-
149-
/**
150-
* The entry point of application.
151-
*
152-
* @param args the input arguments
153-
* @throws WxPayException the wx pay exception
154-
* @throws IOException the io exception
155-
*/
156-
public static void main(String[] args) throws WxPayException, IOException {
157-
String key = "-----BEGIN RSA PUBLIC KEY-----\n" +
158-
"MIIBCgKCAQEAtEeUSop/YGqZ53Y++R9NapFSZmorj+SL/brmJUU7+hyClEnPOeG/\n" +
159-
"v6/ZrX9qo25JAojrBDbqaW9L+HtzI141vusarRYIGPvVqTV30L5db0Yq7AmX7Hs9\n" +
160-
"s+nEtoMAwMWUzQPXLUs2mt6rpu85HwAIK3F4Xb+OFIbXCJTbDvWYtQssn07lr+IY\n" +
161-
"jPA00sON71egmuRrCoQClkhf0vgrhj7eHUCRZRJ2zf4UU31fHv+kO441hVD5TTP8\n" +
162-
"bjJvFm6TW3sgQE8aCDbomtu+syk4Tv/4ONCqxG8d/kF1TlU+idGWEU179uR/KSjP\n" +
163-
"p7kM7BoaY2goFgYAe4DsI8Fh33dCOiKyVwIDAQAB\n" +
164-
"-----END RSA PUBLIC KEY-----";
165-
Path tmpFile = Files.createTempFile("payToBank", ".pem");
166-
Files.write(tmpFile, key.getBytes(StandardCharsets.UTF_8));
167-
System.out.println(new EntPayServiceImpl(null).encryptRSA(tmpFile.toFile(), "111111"));
168-
}
169-
170170
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
import java.nio.charset.StandardCharsets;
55
import javax.net.ssl.SSLContext;
66

7+
import com.github.binarywang.wxpay.bean.WxPayApiData;
8+
import com.github.binarywang.wxpay.bean.request.WxPayQueryCommentRequest;
9+
import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest;
10+
import com.github.binarywang.wxpay.bean.result.WxPayCommonResult;
11+
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
12+
import com.github.binarywang.wxpay.exception.WxPayException;
13+
import jodd.util.Base64;
714
import org.apache.commons.lang3.StringUtils;
815
import org.apache.http.HttpHost;
916
import org.apache.http.auth.AuthScope;

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package com.github.binarywang.wxpay.service.impl;
22

3+
import java.nio.charset.StandardCharsets;
4+
import javax.net.ssl.SSLContext;
5+
6+
import com.github.binarywang.wxpay.bean.request.WxPayQueryCommentRequest;
7+
import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest;
8+
import com.github.binarywang.wxpay.bean.result.WxPayCommonResult;
9+
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
10+
import org.apache.commons.lang3.StringUtils;
11+
312
import com.github.binarywang.wxpay.bean.WxPayApiData;
413
import com.github.binarywang.wxpay.exception.WxPayException;
514
import jodd.http.HttpConnectionProvider;

0 commit comments

Comments
 (0)