Skip to content

Commit 4554c99

Browse files
committed
微信支付接口代码拉出到单独类中维护,单元测试暂时未完成
1 parent 47c8c08 commit 4554c99

File tree

5 files changed

+573
-490
lines changed

5 files changed

+573
-490
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package me.chanjar.weixin.mp.api;
2+
3+
import me.chanjar.weixin.common.exception.WxErrorException;
4+
import me.chanjar.weixin.mp.bean.result.*;
5+
6+
import java.util.Map;
7+
8+
/**
9+
* 微信支付相关接口
10+
* Created by Binary Wang on 2016/7/28.
11+
* @author binarywang (https://github.com/binarywang)
12+
*/
13+
public interface WxMpPayService {
14+
15+
16+
/**
17+
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
18+
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
19+
*
20+
* @param openId 支付人openId
21+
* @param outTradeNo 商户端对应订单号
22+
* @param amt 金额(单位元)
23+
* @param body 商品描述
24+
* @param tradeType 交易类型 JSAPI,NATIVE,APP,WAP
25+
* @param ip 发起支付的客户端IP
26+
* @param notifyUrl 通知地址
27+
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPrepayId(Map<String, String>) instead
28+
*/
29+
@Deprecated
30+
WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl);
31+
32+
/**
33+
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
34+
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
35+
*
36+
* @param parameters All required/optional parameters for weixin payment
37+
*/
38+
WxMpPrepayIdResult getPrepayId(Map<String, String> parameters);
39+
40+
/**
41+
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
42+
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
43+
*
44+
* @param parameters the required or optional parameters
45+
*/
46+
Map<String, String> getPayInfo(Map<String, String> parameters) throws WxErrorException;
47+
48+
/**
49+
* 该接口调用“统一下单”接口,并拼装NATIVE发起支付请求需要的参数
50+
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
51+
* tradeType 交易类型 NATIVE (其他交易类型JSAPI,APP,WAP)
52+
*
53+
* @param productId 商户商品ID
54+
* @param outTradeNo 商户端对应订单号
55+
* @param amt 金额(单位元)
56+
* @param body 商品描述
57+
* @param ip 发起支付的客户端IP
58+
* @param notifyUrl 通知地址
59+
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPayInfo(Map<String, String>) instead
60+
*/
61+
@Deprecated
62+
Map<String, String> getNativePayInfo(String productId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
63+
64+
/**
65+
* 该接口调用“统一下单”接口,并拼装JSAPI发起支付请求需要的参数
66+
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
67+
* tradeType 交易类型 JSAPI(其他交易类型NATIVE,APP,WAP)
68+
*
69+
* @param openId 支付人openId
70+
* @param outTradeNo 商户端对应订单号
71+
* @param amt 金额(单位元)
72+
* @param body 商品描述
73+
* @param ip 发起支付的客户端IP
74+
* @param notifyUrl 通知地址
75+
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPayInfo(Map<String, String>) instead
76+
*/
77+
@Deprecated
78+
Map<String, String> getJsapiPayInfo(String openId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
79+
80+
/**
81+
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
82+
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
83+
*
84+
*/
85+
WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo);
86+
87+
/**
88+
* 读取支付结果通知
89+
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
90+
*
91+
*/
92+
WxMpPayCallback getJSSDKCallbackData(String xmlData);
93+
94+
/**
95+
* 微信支付-申请退款
96+
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
97+
*
98+
* @param parameters 需要传入的退款参数的Map。以下几项为参数的必须项:<br/>
99+
* <li/> transaction_id
100+
* <li/> out_trade_no (仅在上述transaction_id为空时是必须项)
101+
* <li/> out_refund_no
102+
* <li/> total_fee
103+
* <li/> refund_fee
104+
* @return 退款操作结果
105+
*/
106+
WxMpPayRefundResult refundPay(Map<String, String> parameters) throws WxErrorException;
107+
108+
/**
109+
* <pre>
110+
* 计算Map键值对是否和签名相符,
111+
* 按照字段名的 ASCII 码从小到大排序(字典序)后,使用 URL 键值对的 格式(即 key1=value1&key2=value2...)拼接成字符串
112+
* </pre>
113+
*
114+
*/
115+
boolean checkJSSDKCallbackDataSignature(Map<String, String> kvm, String signature);
116+
117+
/**
118+
* 发送微信红包给个人用户
119+
* <p>
120+
* 需要传入的必填参数如下:
121+
* mch_billno//商户订单号
122+
* send_name//商户名称
123+
* re_openid//用户openid
124+
* total_amount//红包总额
125+
* total_num//红包发放总人数
126+
* wishing//红包祝福语
127+
* client_ip//服务器Ip地址
128+
* act_name//活动名称
129+
* remark //备注
130+
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5
131+
* <p>
132+
* 使用现金红包功能需要在xml配置文件中额外设置:
133+
* <partnerId></partnerId>微信商户平台ID
134+
* <partnerKey></partnerKey>商户平台设置的API密钥
135+
*
136+
*/
137+
WxRedpackResult sendRedpack(Map<String, String> parameters) throws WxErrorException;
138+
}

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

Lines changed: 7 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import me.chanjar.weixin.mp.bean.result.*;
88

99
import java.text.SimpleDateFormat;
10-
import java.util.Map;
1110

1211
/**
1312
* 微信API的Service
@@ -90,8 +89,6 @@ public interface WxMpService {
9089
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
9190
* </pre>
9291
*
93-
* @param news
94-
* @throws WxErrorException
9592
* @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassGroupMessage)
9693
* @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage)
9794
*/
@@ -134,7 +131,6 @@ public interface WxMpService {
134131
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=长链接转短链接接口
135132
* </pre>
136133
*
137-
* @param long_url
138134
*/
139135
String shortUrl(String long_url) throws WxErrorException;
140136

@@ -144,9 +140,7 @@ public interface WxMpService {
144140
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=模板消息接口
145141
* </pre>
146142
*
147-
* @param templateMessage
148143
* @return msgid
149-
* @throws WxErrorException
150144
*/
151145
String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException;
152146

@@ -164,8 +158,6 @@ public interface WxMpService {
164158
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
165159
* </pre>
166160
*
167-
* @param scope
168-
* @param state
169161
* @return url
170162
*/
171163
String oauth2buildAuthorizationUrl(String scope, String state);
@@ -177,8 +169,6 @@ public interface WxMpService {
177169
* </pre>
178170
*
179171
* @param redirectURI 用户授权完成后的重定向链接,无需urlencode, 方法内会进行encode
180-
* @param scope
181-
* @param state
182172
* @return url
183173
*/
184174
String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state);
@@ -203,7 +193,6 @@ public interface WxMpService {
203193
* 用oauth2获取用户信息, 当前面引导授权时的scope是snsapi_userinfo的时候才可以
204194
* </pre>
205195
*
206-
* @param oAuth2AccessToken
207196
* @param lang zh_CN, zh_TW, en
208197
*/
209198
WxMpUser oauth2getUserInfo(WxMpOAuth2AccessToken oAuth2AccessToken, String lang) throws WxErrorException;
@@ -213,7 +202,6 @@ public interface WxMpService {
213202
* 验证oauth2的access token是否有效
214203
* </pre>
215204
*
216-
* @param oAuth2AccessToken
217205
*/
218206
boolean oauth2validateAccessToken(WxMpOAuth2AccessToken oAuth2AccessToken);
219207

@@ -265,146 +253,13 @@ public interface WxMpService {
265253
*/
266254
void setMaxRetryTimes(int maxRetryTimes);
267255

268-
/**
269-
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
270-
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
271-
*
272-
* @param openId 支付人openId
273-
* @param outTradeNo 商户端对应订单号
274-
* @param amt 金额(单位元)
275-
* @param body 商品描述
276-
* @param tradeType 交易类型 JSAPI,NATIVE,APP,WAP
277-
* @param ip 发起支付的客户端IP
278-
* @param notifyUrl 通知地址
279-
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPrepayId(Map<String, String>) instead
280-
*/
281-
@Deprecated
282-
WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl);
283-
284-
/**
285-
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
286-
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
287-
*
288-
* @param parameters All required/optional parameters for weixin payment
289-
* @throws IllegalArgumentException
290-
*/
291-
WxMpPrepayIdResult getPrepayId(Map<String, String> parameters);
292-
293-
/**
294-
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
295-
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
296-
*
297-
* @param parameters the required or optional parameters
298-
*/
299-
Map<String, String> getPayInfo(Map<String, String> parameters) throws WxErrorException;
300-
301-
/**
302-
* 该接口调用“统一下单”接口,并拼装NATIVE发起支付请求需要的参数
303-
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
304-
* tradeType 交易类型 NATIVE (其他交易类型JSAPI,APP,WAP)
305-
*
306-
* @param productId 商户商品ID
307-
* @param outTradeNo 商户端对应订单号
308-
* @param amt 金额(单位元)
309-
* @param body 商品描述
310-
* @param ip 发起支付的客户端IP
311-
* @param notifyUrl 通知地址
312-
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPayInfo(Map<String, String>) instead
313-
*/
314-
@Deprecated
315-
Map<String, String> getNativePayInfo(String productId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
316-
317-
/**
318-
* 该接口调用“统一下单”接口,并拼装JSAPI发起支付请求需要的参数
319-
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
320-
* tradeType 交易类型 JSAPI(其他交易类型NATIVE,APP,WAP)
321-
*
322-
* @param openId 支付人openId
323-
* @param outTradeNo 商户端对应订单号
324-
* @param amt 金额(单位元)
325-
* @param body 商品描述
326-
* @param ip 发起支付的客户端IP
327-
* @param notifyUrl 通知地址
328-
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPayInfo(Map<String, String>) instead
329-
*/
330-
@Deprecated
331-
Map<String, String> getJsapiPayInfo(String openId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
332-
333-
/**
334-
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
335-
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
336-
*
337-
* @param transactionId
338-
* @param outTradeNo
339-
*/
340-
WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo);
341-
342-
/**
343-
* 读取支付结果通知
344-
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
345-
*
346-
* @param xmlData
347-
*/
348-
WxMpPayCallback getJSSDKCallbackData(String xmlData);
349-
350-
/**
351-
* 微信支付-申请退款
352-
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
353-
*
354-
* @param parameters 需要传入的退款参数的Map。以下几项为参数的必须项:<br/>
355-
* <li/> transaction_id
356-
* <li/> out_trade_no (仅在上述transaction_id为空时是必须项)
357-
* <li/> out_refund_no
358-
* <li/> total_fee
359-
* <li/> refund_fee
360-
* @return 退款操作结果
361-
* @throws WxErrorException
362-
*/
363-
WxMpPayRefundResult refundPay(Map<String, String> parameters) throws WxErrorException;
364-
365-
/**
366-
* <pre>
367-
* 计算Map键值对是否和签名相符,
368-
* 按照字段名的 ASCII 码从小到大排序(字典序)后,使用 URL 键值对的 格式(即 key1=value1&key2=value2...)拼接成字符串
369-
* </pre>
370-
*
371-
* @param kvm
372-
* @param signature
373-
*/
374-
boolean checkJSSDKCallbackDataSignature(Map<String, String> kvm, String signature);
375-
376-
/**
377-
* 发送微信红包给个人用户
378-
* <p>
379-
* 需要传入的必填参数如下:
380-
* mch_billno//商户订单号
381-
* send_name//商户名称
382-
* re_openid//用户openid
383-
* total_amount//红包总额
384-
* total_num//红包发放总人数
385-
* wishing//红包祝福语
386-
* client_ip//服务器Ip地址
387-
* act_name//活动名称
388-
* remark //备注
389-
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5
390-
* <p>
391-
* 使用现金红包功能需要在xml配置文件中额外设置:
392-
* <partnerId></partnerId>微信商户平台ID
393-
* <partnerKey></partnerKey>商户平台设置的API密钥
394-
*
395-
* @param parameters
396-
*/
397-
WxRedpackResult sendRedpack(Map<String, String> parameters) throws WxErrorException;
398-
399256
/**
400257
* <pre>
401258
* 预览接口
402259
* 详情请见:http://mp.weixin.qq.com/wiki/15/40b6865b893947b764e2de8e4a1fb55f.html#.E9.A2.84.E8.A7.88.E6.8E.A5.E5.8F.A3.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91
403260
* </pre>
404261
*
405-
* @param wxMpMassPreviewMessage
406262
* @return wxMpMassSendResult
407-
* @throws WxErrorException
408263
*/
409264
WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception;
410265

@@ -415,9 +270,7 @@ public interface WxMpService {
415270
* 详情请见:http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1.9E.E8.A1.8C.E4.B8.9A
416271
* </pre>
417272
*
418-
* @param wxMpIndustry
419273
* @return JsonObject
420-
* @throws WxErrorException
421274
*/
422275
String setIndustry(WxMpIndustry wxMpIndustry) throws WxErrorException;
423276

@@ -428,7 +281,6 @@ public interface WxMpService {
428281
* </pre>
429282
*
430283
* @return wxMpIndustry
431-
* @throws WxErrorException
432284
*/
433285
WxMpIndustry getIndustry() throws WxErrorException;
434286

@@ -487,4 +339,11 @@ public interface WxMpService {
487339
* @return WxMpCardService
488340
*/
489341
WxMpCardService getCardService();
342+
343+
/**
344+
* 返回微信支付相关接口的方法实现类,以方便调用个其各种接口
345+
*
346+
* @return WxMpPayService
347+
*/
348+
WxMpPayService getPayService();
490349
}

0 commit comments

Comments
 (0)