View Javadoc
1   package com.foxinmy.weixin4j.pay;
2   
3   import com.alibaba.fastjson.JSON;
4   import com.foxinmy.weixin4j.pay.api.*;
5   import com.foxinmy.weixin4j.exception.WeixinException;
6   import com.foxinmy.weixin4j.http.weixin.XmlResult;
7   import com.foxinmy.weixin4j.pay.model.WeixinPayAccount;
8   import com.foxinmy.weixin4j.model.paging.Pageable;
9   import com.foxinmy.weixin4j.pay.payment.coupon.*;
10  import com.foxinmy.weixin4j.pay.payment.face.PayfaceAuthinfo;
11  import com.foxinmy.weixin4j.pay.payment.face.PayfaceAuthinfoRequest;
12  import com.foxinmy.weixin4j.pay.payment.mch.*;
13  import com.foxinmy.weixin4j.pay.profitsharing.*;
14  import com.foxinmy.weixin4j.pay.sign.WeixinSignature;
15  import com.foxinmy.weixin4j.pay.type.*;
16  import com.foxinmy.weixin4j.pay.type.mch.BillType;
17  import com.foxinmy.weixin4j.pay.type.mch.RefundAccountType;
18  import com.foxinmy.weixin4j.pay.type.profitsharing.ReturnAccountType;
19  import com.foxinmy.weixin4j.util.Consts;
20  import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
21  
22  import java.io.OutputStream;
23  import java.util.Date;
24  import java.util.List;
25  import java.util.concurrent.Future;
26  
27  /**
28   * 微信支付接口实现
29   *
30   * @className WeixinPayProxy
31   * @author jinyu(foxinmy@gmail.com)
32   * @date 2015年1月3日
33   * @since JDK 1.6
34   * @see <a href="http://pay.weixin.qq.com/wiki/doc/api/index.html">商户平台支付API</a>
35   */
36  public class WeixinPayProxy {
37  
38  	/**
39  	 * 微信支付API:js支付、扫码支付等接口
40  	 */
41  	private final PayApi payApi;
42  	/**
43  	 * 代金券API
44  	 */
45  	private final CouponApi couponApi;
46  	/**
47  	 * 现金API
48  	 */
49  	private final CashApi cashApi;
50  	/**
51  	 * 海关API
52  	 */
53  	private final CustomsApi customsApi;
54  	/**
55  	 * 商户信息
56  	 */
57  	private final WeixinPayAccount weixinPayAccount;
58  	/**
59  	 * 分帐接口
60  	 */
61  	private final ProfitSharingApi profitSharingApi;
62  
63  	/**
64  	 * 微信支付接口实现(使用weixin4j.properties配置的account商户信息)
65  	 */
66  	public WeixinPayProxy() {
67  		this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"),
68  				WeixinPayAccount.class));
69  	}
70  
71  	/**
72  	 * 微信支付接口实现
73  	 *
74  	 * @param weixinPayAccount
75  	 *            微信商户信息
76  	 */
77  	public WeixinPayProxy(WeixinPayAccount weixinPayAccount) {
78  		if (weixinPayAccount == null) {
79  			throw new IllegalArgumentException(
80  					"weixinPayAccount must not be empty");
81  		}
82  		this.weixinPayAccount = weixinPayAccount;
83  		this.payApi = new PayApi(weixinPayAccount);
84  		this.couponApi = new CouponApi(weixinPayAccount);
85  		this.cashApi = new CashApi(weixinPayAccount);
86  		this.customsApi = new CustomsApi(weixinPayAccount);
87  		this.profitSharingApi = new ProfitSharingApi(weixinPayAccount);
88  	}
89  
90  	/**
91  	 * 获取微信商户账号信息
92  	 *
93  	 * @return
94  	 */
95  	public WeixinPayAccount getWeixinPayAccount() {
96  		return weixinPayAccount;
97  	}
98  
99  	/**
100 	 * 获取微信签名类
101 	 *
102 	 * @return
103 	 */
104 	public WeixinSignature getWeixinSignature() {
105 		return payApi.getWeixinSignature();
106 	}
107 
108 	/**
109 	 * 统一下单接口</br>
110 	 * 除被扫支付场景以外,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易回话标识后再按扫码、JSAPI
111 	 * 、APP等不同场景生成交易串调起支付。
112 	 *
113 	 * @param payPackage
114 	 *            包含订单信息的对象
115 	 * @see PayApi
116 	 * @see MchPayPackage
117 	 * @see PrePay
118 	 * @see <a href=
119 	 *      "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1">统一下单接口
120 	 *      </a>
121 	 * @return 预支付对象
122 	 */
123 	public PrePay createPrePay(MchPayPackage payPackage) throws WeixinException {
124 		return payApi.createPrePay(payPackage);
125 	}
126 
127 	/**
128 	 * 创建支付请求对象
129 	 *
130 	 * @param payPackage
131 	 *            支付详情
132 	 * @return 支付请求对象
133 	 * @see PayApi
134 	 * @see JSAPIPayRequest JS支付
135 	 * @see NATIVEPayRequest 扫码支付
136 	 * @see MICROPayRequest 刷卡支付
137 	 * @see APPPayRequest APP支付
138 	 * @see WAPPayRequest WAP支付
139 	 * @see MchPayRequest#toRequestString()
140 	 * @throws WeixinException
141 	 */
142 	public MchPayRequest createPayRequest(MchPayPackage payPackage)
143 			throws WeixinException {
144 		return payApi.createPayRequest(payPackage);
145 	}
146 
147 	/**
148 	 * 创建JSAPI支付请求对象
149 	 *
150 	 * @param openId
151 	 *            用户ID
152 	 * @param body
153 	 *            订单描述
154 	 * @param outTradeNo
155 	 *            订单号
156 	 * @param totalFee
157 	 *            订单总额(元)
158 	 * @param notifyUrl
159 	 *            支付通知地址
160 	 * @param createIp
161 	 *            ip地址
162 	 * @param attach
163 	 *            附加数据 非必填
164 	 * @see PayApi
165 	 * @see JSAPIPayRequest
166 	 * @see MchPayRequest#toRequestString()
167 	 * @return JSAPI支付对象
168 	 * @throws WeixinException
169 	 */
170 	public MchPayRequest createJSPayRequest(String openId, String body,
171                                             String outTradeNo, double totalFee, String notifyUrl,
172                                             String createIp, String attach) throws WeixinException {
173 		return payApi.createJSPayRequest(openId, body, outTradeNo, totalFee,
174 				notifyUrl, createIp, attach);
175 	}
176 
177 	/**
178 	 * 创建Native支付(扫码支付)链接【模式一】
179 	 *
180 	 * @param productId
181 	 *            与订单ID等价
182 	 * @return 支付链接
183 	 * @see PayApi
184 	 * @see <a href=
185 	 *      "https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1">扫码支付
186 	 *      </a>
187 	 * @see <a href=
188 	 *      "https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4">模式一
189 	 *      </a>
190 	 */
191 	public String createNativePayRequest(String productId) {
192 		return payApi.createNativePayRequest(productId);
193 	}
194 
195 	/**
196 	 * 创建Native支付(扫码支付)回调对象【模式一】
197 	 *
198 	 * @param productId
199 	 *            商品ID
200 	 * @param body
201 	 *            商品描述
202 	 * @param outTradeNo
203 	 *            商户内部唯一订单号
204 	 * @param totalFee
205 	 *            商品总额 单位元
206 	 * @param notifyUrl
207 	 *            支付回调URL
208 	 * @param createIp
209 	 *            订单生成的机器 IP
210 	 * @param attach
211 	 *            附加数据 非必填
212 	 * @return Native回调对象
213 	 * @see PayApi
214 	 * @see NativePayResponse
215 	 * @see <a href=
216 	 *      "https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1">扫码支付
217 	 *      </a>
218 	 * @see <a href=
219 	 *      "https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4">模式一
220 	 *      </a>
221 	 * @throws WeixinException
222 	 */
223 	public NativePayResponse createNativePayResponse(String productId,
224                                                      String body, String outTradeNo, double totalFee, String notifyUrl,
225                                                      String createIp, String attach) throws WeixinException {
226 		return payApi.createNativePayResponse(productId, body, outTradeNo,
227 				totalFee, notifyUrl, createIp, attach);
228 	}
229 
230 	/**
231 	 * 创建Native支付(扫码支付)链接【模式二】
232 	 *
233 	 * @param productId
234 	 *            商品ID
235 	 * @param body
236 	 *            商品描述
237 	 * @param outTradeNo
238 	 *            商户内部唯一订单号
239 	 * @param totalFee
240 	 *            商品总额 单位元
241 	 * @param notifyUrl
242 	 *            支付回调URL
243 	 * @param createIp
244 	 *            订单生成的机器 IP
245 	 * @param attach
246 	 *            附加数据 非必填
247 	 * @return Native支付对象
248 	 * @see PayApi
249 	 * @see NATIVEPayRequest
250 	 * @see MchPayRequest#toRequestString()
251 	 * @see <a href=
252 	 *      "https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1">扫码支付
253 	 *      </a>
254 	 * @see <a href=
255 	 *      "https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5">模式二
256 	 *      </a>
257 	 * @throws WeixinException
258 	 */
259 	public MchPayRequest createNativePayRequest(String productId, String body,
260                                                 String outTradeNo, double totalFee, String notifyUrl,
261                                                 String createIp, String attach) throws WeixinException {
262 		return payApi.createNativePayRequest(productId, body, outTradeNo,
263 				totalFee, notifyUrl, createIp, attach);
264 	}
265 
266 	/**
267 	 * 创建APP支付请求对象
268 	 *
269 	 * @param body
270 	 *            商品描述
271 	 * @param outTradeNo
272 	 *            商户内部唯一订单号
273 	 * @param totalFee
274 	 *            商品总额 单位元
275 	 * @param notifyUrl
276 	 *            支付回调URL
277 	 * @param createIp
278 	 *            订单生成的机器 IP
279 	 * @param attach
280 	 *            附加数据 非必填
281 	 * @param store
282 	 *            APP支付已无门店信息,不需要再传
283 	 * @return APP支付对象
284 	 * @see PayApi
285 	 * @see SceneInfoStore
286 	 * @see APPPayRequest
287 	 * @see MchPayRequest#toRequestString()
288 	 * @see <a href=
289 	 *      "https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_1">
290 	 *      APP支付</a>
291 	 * @throws WeixinException
292 	 */
293 	public MchPayRequest createAppPayRequest(String body, String outTradeNo,
294                                              double totalFee, String notifyUrl, String createIp, String attach,
295                                              SceneInfoStore store) throws WeixinException {
296 		return payApi.createAppPayRequest(body, outTradeNo, totalFee,
297 				notifyUrl, createIp, attach, store);
298 	}
299 
300 	/**
301 	 * 创建WAP支付请求对象
302 	 *
303 	 * @param body
304 	 *            商品描述
305 	 * @param outTradeNo
306 	 *            商户内部唯一订单号
307 	 * @param totalFee
308 	 *            商品总额 单位元
309 	 * @param notifyUrl
310 	 *            支付回调URL
311 	 * @param createIp
312 	 *            订单生成的机器 IP
313 	 * @param attach
314 	 *            附加数据 非必填
315 	 * @param app
316 	 *            应用信息
317 	 * @return WAP支付对象
318 	 * @see PayApi
319 	 * @see SceneInfoApp
320 	 * @see WAPPayRequest
321 	 * @see MchPayRequest#toRequestString()
322 	 * @see <a href=
323 	 *      "https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=15_1">WAP支付
324 	 *      </a>
325 	 * @throws WeixinException
326 	 */
327 	public MchPayRequest createWapPayRequest(String body, String outTradeNo,
328                                              double totalFee, String notifyUrl, String createIp, String attach,
329                                              SceneInfoApp app) throws WeixinException {
330 		return payApi.createWapPayRequest(body, outTradeNo, totalFee,
331 				notifyUrl, createIp, attach, app);
332 	}
333 
334 	/**
335 	 * 提交被扫支付
336 	 *
337 	 * @param authCode
338 	 *            扫码支付授权码 ,设备读取用户微信中的条码或者二维码信息
339 	 * @param body
340 	 *            商品描述
341 	 * @param outTradeNo
342 	 *            商户内部唯一订单号
343 	 * @param totalFee
344 	 *            商品总额 单位元
345 	 * @param createIp
346 	 *            订单生成的机器 IP
347 	 * @param attach
348 	 *            附加数据 非必填
349 	 * @param store
350 	 *            门店信息 非必填
351 	 * @return 支付的订单信息
352 	 * @see PayApi
353 	 * @see Order
354 	 * @see SceneInfoStore
355 	 * @see MICROPayRequest
356 	 * @see MchPayRequest#toRequestString()
357 	 * @see <a href=
358 	 *      "http://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10">
359 	 *      提交被扫支付API</a>
360 	 * @throws WeixinException
361 	 */
362 	public MchPayRequest createMicroPayRequest(String authCode, String body,
363                                                String outTradeNo, double totalFee, String createIp, String attach,
364                                                SceneInfoStore store) throws WeixinException {
365 		return payApi.createMicroPayRequest(authCode, body, outTradeNo,
366 				totalFee, createIp, attach, store);
367 	}
368 
369 	/**
370 	 * 押金支付请求
371 	 * 注意:(此功能微信已下架,改为邀请开通,因此暂未使用)
372 	 *
373 	 * @param code
374 	 * 			授权码/人脸凭证
375 	 * @param body
376 	 * 			商品或支付单简要描述,格式要求:门店品牌名-城市分店名-实际商品名称
377 	 * @param outTradeNo
378 	 * 			商户系统内部的订单号,32个字符内、可包含字母;更换授权码必须要换新的商户订单号
379 	 * @param totalFee
380 	 * 			订单总金额,单位元
381 	 * @param createIp
382 	 * 			调用微信支付API的机器IP
383 	 * @param openId
384 	 * 			用户在商户appid 下的唯一标识,人脸支付押金时提供
385 	 * @param attach
386 	 * 			附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据,非必填
387 	 * @param store
388 	 * 			门店信息,仅在付款码支付押金时提供,非必填
389 	 * @param isFacePay
390 	 * 			是否人脸押金支付,否则是付款码押金支付
391 	 * @return
392 	 * @throws WeixinException
393 	 */
394 	public MchPayRequest createDepositPayRequest(String code, String body,
395 												 String outTradeNo, double totalFee, String createIp, String openId,
396 												 String attach, SceneInfoStore store, boolean isFacePay) throws WeixinException{
397 
398 		return payApi.createDepositPayRequest(code, body, outTradeNo, totalFee, createIp, openId, attach, store, isFacePay);
399 	}
400 
401 	/**
402 	 * 订单查询
403 	 * <p>
404 	 * 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知;</br> 调用支付接口后,返回系统错误或未知交易状态情况;</br>
405 	 * 调用被扫支付API,返回USERPAYING的状态;</br> 调用关单或撤销接口API之前,需确认支付状态;
406 	 * </P>
407 	 *
408 	 * @param idQuery
409 	 *            商户系统内部的订单号, transaction_id、out_trade_no 二 选一,如果同时存在优先级:
410 	 *            transaction_id> out_trade_no
411 	 * @since V3
412 	 * @see Order
413 	 * @see PayApi
414 	 * @see <a href=
415 	 *      "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2">
416 	 *      订单查询API</a>
417 	 * @return 订单详情
418 	 * @throws WeixinException
419 	 */
420 	public Order queryOrder(IdQuery idQuery) throws WeixinException {
421 		return payApi.queryOrder(idQuery);
422 	}
423 
424 	/**
425 	 * 申请退款
426 	 *
427 	 * @see PayApi#applyRefund(IdQuery, String, double, double, CurrencyType, String, String, RefundAccountType)
428 	 */
429 	public RefundResult applyRefund(IdQuery idQuery, String outRefundNo,
430                                     double totalFee, double refundFee, CurrencyType refundFeeType,
431                                     String opUserId, String refundDesc,
432                                     RefundAccountType refundAccountType) throws WeixinException {
433 		return payApi.applyRefund(idQuery, outRefundNo, totalFee, refundFee,
434 				refundFeeType, opUserId, refundDesc, refundAccountType);
435 	}
436 
437 	/**
438 	 * 申请退款
439 	 *
440 	 * @see PayApi#applyRefund(IdQuery, String, double)
441 	 */
442 	public RefundResult applyRefund(IdQuery idQuery, String outRefundNo,
443                                     double totalFee) throws WeixinException {
444 		return payApi.applyRefund(idQuery, outRefundNo, totalFee);
445 	}
446 
447 	/**
448 	 * 退款查询
449 	 * <p>
450 	 * 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。
451 	 * </p>
452 	 *
453 	 * @param idQuery
454 	 *            单号 refund_id、out_refund_no、 out_trade_no 、 transaction_id
455 	 *            四个参数必填一个,优先级为:
456 	 *            refund_id>out_refund_no>transaction_id>out_trade_no
457 	 * @return 退款记录
458 	 * @see PayApi
459 	 * @see RefundRecord
460 	 * @see <a href=
461 	 *      "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5">
462 	 *      退款查询API</a>
463 	 * @since V3
464 	 * @throws WeixinException
465 	 */
466 	public RefundRecord queryRefund(IdQuery idQuery) throws WeixinException {
467 		return payApi.queryRefund(idQuery);
468 	}
469 
470 	/**
471 	 * 下载对账单<br>
472 	 * 1.微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账 单中,跟原支付单订单号一致,bill_type 为
473 	 * REVOKED;<br>
474 	 * 2.微信在次日 9 点启动生成前一天的对账单,建议商户 9 点半后再获取;<br>
475 	 * 3.对账单中涉及金额的字段单位为“元”。<br>
476 	 *
477 	 * @param billDate
478 	 *            下载对账单的日期
479 	 * @param billType
480 	 *            下载对账单的类型 ALL,返回当日所有订单信息, 默认值 SUCCESS,返回当日成功支付的订单
481 	 *            REFUND,返回当日退款订单
482 	 * @para outputStream 输出流
483 	 * @param tarType
484 	 *            非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。
485 	 * @since V2 & V3
486 	 * @see PayApi
487 	 * @see <a href=
488 	 *      "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6">
489 	 *      下载对账单API</a>
490 	 * @throws WeixinException
491 	 */
492 	public void downloadBill(Date billDate, BillType billType,
493 			OutputStream outputStream, TarType tarType) throws WeixinException {
494 		payApi.downloadBill(billDate, billType, outputStream, tarType);
495 	}
496 
497 	/**
498 	 * 冲正订单(需要证书)</br> 当支付返回失败,或收银系统超时需要取消交易,可以调用该接口</br> 接口逻辑:支
499 	 * 付失败的关单,支付成功的撤销支付</br> <font color="red">7天以内的单可撤销,其他正常支付的单
500 	 * 如需实现相同功能请调用退款接口</font></br> <font
501 	 * color="red">调用扣款接口后请勿立即调用撤销,需要等待5秒以上。先调用查单接口,如果没有确切的返回,再调用撤销</font> </br>
502 	 *
503 	 * @param idQuery
504 	 *            商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级:
505 	 *            transaction_id> out_trade_no
506 	 * @return 撤销结果
507 	 * @see PayApi
508 	 * @since V3
509 	 * @throws WeixinException
510 	 */
511 	public MerchantResult reverseOrder(IdQuery idQuery) throws WeixinException {
512 		return payApi.reverseOrder(idQuery);
513 	}
514 
515 	/**
516 	 * 关闭订单
517 	 * <p>
518 	 * 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付;系统下单后,用户支付超时,系统退出不再受理,避免用户继续
519 	 * ,请调用关单接口,如果关单失败,返回已完 成支付请按正常支付处理。如果出现银行掉单,调用关单成功后,微信后台会主动发起退款。
520 	 * </p>
521 	 *
522 	 * @param outTradeNo
523 	 *            商户系统内部的订单号
524 	 * @return 执行结果
525 	 * @see PayApi
526 	 * @since V3
527 	 * @throws WeixinException
528 	 * @see <a href=
529 	 *      "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_3">
530 	 *      关闭订单API</a>
531 	 */
532 	public MerchantResult closeOrder(String outTradeNo) throws WeixinException {
533 		return payApi.closeOrder(outTradeNo);
534 	}
535 
536 	/**
537 	 * native支付URL转短链接:用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),减小二维码数据量
538 	 * ,提升扫描速度和精确度。
539 	 *
540 	 * @param url
541 	 *            具有native标识的支付URL
542 	 * @return 转换后的短链接
543 	 * @see PayApi
544 	 * @see <a href=
545 	 *      "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_9">
546 	 *      转换短链接API</a>
547 	 * @since V3
548 	 * @throws WeixinException
549 	 */
550 	public String getPayShorturl(String url) throws WeixinException {
551 		return payApi.getShorturl(url);
552 	}
553 
554 	/**
555 	 * 接口上报
556 	 *
557 	 * @param interfaceUrl
558 	 *            上报对应的接口的完整 URL, 类似: https://api.mch.weixin.q
559 	 *            q.com/pay/unifiedorder
560 	 * @param executeTime
561 	 *            接口耗时情况,单位为毫秒
562 	 * @param outTradeNo
563 	 *            商户系统内部的订单号,商 户可以在上报时提供相关商户订单号方便微信支付更好 的提高服务质量。
564 	 * @param ip
565 	 *            发起接口调用时的机器 IP
566 	 * @param time
567 	 *            商户调用该接口时商户自己 系统的时间
568 	 * @param returnXml
569 	 *            调用接口返回的基本数据
570 	 * @return 处理结果
571 	 * @see PayApi
572 	 * @see <a href=
573 	 *      "http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_8">
574 	 *      接口测试上报API</a>
575 	 * @throws WeixinException
576 	 */
577 	public XmlResult reportInterface(String interfaceUrl, int executeTime,
578 			String outTradeNo, String ip, Date time, XmlResult returnXml)
579 			throws WeixinException {
580 		return payApi.reportInterface(interfaceUrl, executeTime, outTradeNo,
581 				ip, time, returnXml);
582 	}
583 
584 	/**
585 	 * 发放代金券(需要证书)
586 	 *
587 	 * @param couponStockId
588 	 *            代金券批次id
589 	 * @param partnerTradeNo
590 	 *            商户发放凭据号(格式:商户id+日期+流水号),商户侧需保持唯一性
591 	 * @param openId
592 	 *            用户的openid
593 	 * @param opUserId
594 	 *            操作员帐号, 默认为商户号 可在商户平台配置操作员对应的api权限 可为空
595 	 * @return 发放结果
596 	 * @see CouponApi
597 	 * @see CouponResult
598 	 * @see <a href=
599 	 *      "https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_3">
600 	 *      发放代金券接口</a>
601 	 * @throws WeixinException
602 	 */
603 	public CouponResult sendCoupon(String couponStockId, String partnerTradeNo,
604                                    String openId, String opUserId) throws WeixinException {
605 		return couponApi.sendCoupon(couponStockId, partnerTradeNo, openId,
606 				opUserId);
607 	}
608 
609 	/**
610 	 * 查询代金券批次
611 	 *
612 	 * @param couponStockId
613 	 *            代金券批次ID
614 	 * @return 代金券批次信息
615 	 * @see CouponApi
616 	 * @see CouponStock
617 	 * @see <a href=
618 	 *      "https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_4">
619 	 *      查询代金券批次信息接口</a>
620 	 * @throws WeixinException
621 	 */
622 	public CouponStock queryCouponStock(String couponStockId)
623 			throws WeixinException {
624 		return couponApi.queryCouponStock(couponStockId);
625 	}
626 
627 	/**
628 	 * 查询代金券详细
629 	 *
630 	 * @param openId
631 	 *            用户ID
632 	 * @param couponId
633 	 *            代金券ID
634 	 * @param stockId
635 	 *            代金劵对应的批次号
636 	 * @return 代金券详细信息
637 	 * @see CouponApi
638 	 * @see CouponDetail
639 	 * @see <a href=
640 	 *      "https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_5">
641 	 *      查询代金券详细信息接口</a>
642 	 * @throws WeixinException
643 	 */
644 	public CouponDetail queryCouponDetail(String openId, String couponId,
645                                           String stockId) throws WeixinException {
646 		return couponApi.queryCouponDetail(openId, couponId, stockId);
647 	}
648 
649 	/**
650 	 * 发放红包 企业向微信用户个人发现金红包
651 	 *
652 	 * @param redpacket
653 	 *            红包信息
654 	 * @return 发放结果
655 	 * @see CashApi
656 	 * @see Redpacket
657 	 * @see RedpacketSendResult
658 	 * @see <a href=
659 	 *      "https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5">
660 	 *      发放现金红包接口</a>
661 	 * @see <a href=
662 	 *      "https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=16_5">
663 	 *      发放裂变红包接口</a>
664 	 * @throws WeixinException
665 	 */
666 	public RedpacketSendResult sendRedpack(Redpacket redpacket)
667 			throws WeixinException {
668 		return cashApi.sendRedpack(redpacket);
669 	}
670 
671 	/**
672 	 * 批量发放红包 企业向微信用户个人发现金红包
673 	 *
674 	 * @param redpackets
675 	 *            多个红包信息
676 	 * @return 发放结果
677 	 * @see CashApi
678 	 * @see #sendRedpacks(Redpacket...)
679 	 * @throws WeixinException
680 	 */
681 	public List<Future<RedpacketSendResult>> sendRedpacks(
682 			Redpacket... redpackets) {
683 		return cashApi.sendRedpacks(redpackets);
684 	}
685 
686 	/**
687 	 * 查询红包记录
688 	 *
689 	 * @param outTradeNo
690 	 *            商户发放红包的商户订单号
691 	 * @return 红包记录
692 	 * @see CashApi
693 	 * @see RedpacketRecord
694 	 * @see <a href=
695 	 *      "https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_7&index=6">
696 	 *      查询现金红包接口</a>
697 	 * @see <a href=
698 	 *      "https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=16_6">
699 	 *      查询裂变红包接口</a>
700 	 * @throws WeixinException
701 	 */
702 	public RedpacketRecord queryRedpack(String outTradeNo)
703 			throws WeixinException {
704 		return cashApi.queryRedpack(outTradeNo);
705 	}
706 
707 	/**
708 	 * 企业付款
709 	 *
710 	 * @see CashApi#sendCorpPayment(CorpPayment)
711 	 */
712 	public CorpPaymentResult sendCorpPayment(CorpPayment payment)
713 			throws WeixinException {
714 		return cashApi.sendCorpPayment(payment);
715 	}
716 
717 	/**
718 	 * 企业付款查询 用于商户的企业付款操作进行结果查询,返回付款操作详细结果
719 	 *
720 	 * @param outTradeNo
721 	 *            商户调用企业付款API时使用的商户订单号
722 	 * @return 付款记录
723 	 * @see CashApi
724 	 * @see CorpPaymentRecord
725 	 * @see <a href=
726 	 *      "https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3">
727 	 *      企业付款查询接口</a>
728 	 * @throws WeixinException
729 	 */
730 	public CorpPaymentRecord queryCorpPayment(String outTradeNo)
731 			throws WeixinException {
732 		return cashApi.queryCorpPayment(outTradeNo);
733 	}
734 
735 	/**
736 	 * 授权码查询OPENID
737 	 *
738 	 * @param authCode
739 	 *            扫码支付授权码,设备读取用户微信中的条码或者二维码信息
740 	 * @return 查询结果
741 	 * @see CashApi
742 	 * @see OpenIdResult
743 	 * @see <a href=
744 	 *      "https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_13&index=9">
745 	 *      授权码查询OPENID</a>
746 	 * @throws WeixinException
747 	 */
748 	public OpenIdResult authCode2openId(String authCode) throws WeixinException {
749 		return payApi.authCode2openId(authCode);
750 	}
751 
752 	/**
753 	 * 查询结算资金
754 	 *
755 	 * @param status
756 	 *            是否结算
757 	 * @param pageable
758 	 *            分页数据
759 	 * @param start
760 	 *            开始日期 查询未结算记录时,该字段可不传
761 	 * @param end
762 	 *            结束日期 查询未结算记录时,该字段可不传
763 	 * @return 结算金额记录
764 	 * @throws WeixinException
765 	 * @see CashApi
766 	 * @see SettlementRecord
767 	 * @see <a href=
768 	 *      "https://pay.weixin.qq.com/wiki/doc/api/external/micropay.php?chapter=9_14&index=7">
769 	 *      查询结算资金接口</a>
770 	 */
771 	public SettlementRecord querySettlement(boolean status, Pageable pageable,
772                                             Date start, Date end) throws WeixinException {
773 		return cashApi.querySettlement(status, pageable, start, end);
774 	}
775 
776 	/**
777 	 * 查询汇率
778 	 *
779 	 * @param currencyType
780 	 *            外币币种
781 	 * @param date
782 	 *            日期 不填则默认当天
783 	 * @return 汇率对象
784 	 * @throws WeixinException
785 	 * @see CashApi
786 	 * @see <a href=
787 	 *      "https://pay.weixin.qq.com/wiki/doc/api/external/micropay.php?chapter=9_15&index=8">
788 	 *      查询汇率接口</a>
789 	 */
790 	public double queryExchageRate(CurrencyType currencyType, Date date)
791 			throws WeixinException {
792 		return cashApi.queryExchageRate(currencyType, date);
793 	}
794 
795 	/**
796 	 * 订单附加信息提交
797 	 *
798 	 * @param customsOrder
799 	 *            附加订单信息
800 	 * @return 报关结果
801 	 * @see CustomsApi
802 	 * @see CustomsOrder
803 	 * @see CustomsOrderResult
804 	 * @see <a href=
805 	 *      "https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=18_1">
806 	 *      附加订单信息提交接口</a>
807 	 * @throws WeixinException
808 	 */
809 	public CustomsOrderResult declareCustomsOrder(CustomsOrder customsOrder)
810 			throws WeixinException {
811 		return customsApi.declareCustomsOrder(customsOrder);
812 	}
813 
814 	/**
815 	 * 订单附加信息查询
816 	 *
817 	 * @param idQuery
818 	 *            out_trade_no,transaction_id,sub_order_no,sub_order_id四选一
819 	 * @param customsCity
820 	 *            海关
821 	 * @return 报关记录
822 	 * @see CustomsOrderRecord
823 	 * @see CustomsApi
824 	 * @see <a href=
825 	 *      "https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=18_1">
826 	 *      附加订单信息查询接口</a>
827 	 * @throws WeixinException
828 	 */
829 	public CustomsOrderRecord queryCustomsOrder(IdQuery idQuery,
830                                                 CustomsCity customsCity) throws WeixinException {
831 		return customsApi.queryCustomsOrder(idQuery, customsCity);
832 	}
833 
834 	/**
835 	 * 微信刷脸支付,获取调用凭证
836 	 *
837 	 * @param storeId
838 	 * 			门店编号, 由商户定义, 各门店唯一。
839 	 * @param storeName
840 	 * 			门店名称,由商户定义。(可用于展示)
841 	 * @param deviceId
842 	 * 			终端设备编号,由商户定义。
843 	 * @param attach
844 	 * 			附加字段。字段格式使用Json, 非必填
845 	 * @param rawdata
846 	 * 			初始化数据。由微信人脸SDK的接口返回。
847 	 * @return SDK调用凭证
848 	 * @throws WeixinException
849 	 * @see <a href=
850 	 * 		"https://pay.weixin.qq.com/wiki/doc/wxfacepay/develop/sdk-android.html#获取数据-getwxpayfacerawdata">
851 	 *      获取数据-getwxpayfacerawdata</a>
852 	 * @see <a href=
853 	 *      "https://pay.weixin.qq.com/wiki/doc/wxfacepay/develop/sdk-android.html#获取调用凭证-get-wxpayface-authinfo">
854 	 *      获取调用凭证-get-wxpayface-authinfo</a>
855 	 * @see PayfaceAuthinfo
856 	 */
857 	public PayfaceAuthinfo getWxPayfaceAuthinfo(String storeId, String storeName, String deviceId,
858 												String attach, String rawdata) throws WeixinException {
859 		PayfaceAuthinfoRequest request = new PayfaceAuthinfoRequest(this.weixinPayAccount, storeId, storeName, deviceId,
860 				attach,  rawdata);
861 		return payApi.getWxPayfaceAuthinfo(request);
862 	}
863 
864 	/**
865 	 * 添加分账接收方
866 	 * 服务商代子商户发起添加分账接收方请求,后续可通过发起分账请求将结算后的钱分到该分账接收方。
867 	 *
868 	 * @param receiver
869 	 * 			分帐接收方
870 	 * @return
871 	 * @throws WeixinException
872 	 * @see Receiver
873 	 * @see ReceiverResult
874 	 * @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_3&index=4">添加分账接收方</a>
875 	 * @since weixin4j-pay 1.1.0
876 	 *
877 	 */
878 	public ReceiverResult addProfitSharingReceiver(Receiver receiver) throws WeixinException {
879 		return profitSharingApi.addReceiver(receiver);
880 	}
881 
882 	/**
883 	 * 删除分账接收方
884 	 * 商户发起删除分账接收方请求,删除后不支持将结算后的钱分到该分账接收方。
885 	 *
886 	 * @param receiver
887 	 * 			分帐接收方
888 	 * @return
889 	 * @throws WeixinException
890 	 * @see Receiver
891 	 * @see ReceiverResult
892 	 * @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_4&index=5">删除分账接收方</a>
893 	 * @since weixin4j-pay 1.1.0
894 	 */
895 	public ReceiverResult removeProfitSharingReceiver(Receiver receiver) throws WeixinException {
896 		return profitSharingApi.removeReceiver(receiver);
897 	}
898 
899 	/**
900 	 * 请求分帐
901 	 *
902 	 * @param transactionId
903 	 * 			微信订单号
904 	 * @param outOrderNo
905 	 * 			商户分帐单号
906 	 * @param receivers
907 	 * 			分帐接收方列表
908 	 * @param multi
909 	 * 			是否多次分帐,默认为单次分帐,即调用分帐成功后马上解冻剩余金额给商户,不需要完结分帐。多次分帐可多次调用分帐API,需调完结分帐结束分帐
910 	 * @return
911 	 * @throws WeixinException
912 	 * @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_1&index=1">请求单次分帐</a>
913 	 * @since weixin4j-pay 1.1.0
914 	 */
915 	public ProfitSharingResult profitSharing(String transactionId, String outOrderNo, List<ReceiverProfit> receivers,
916 											 Boolean multi) throws WeixinException{
917 		return profitSharingApi.profitSharing(transactionId, outOrderNo, receivers, multi);
918 	}
919 
920 	/**
921 	 * 分帐查询
922 	 *
923 	 * @param transactionId
924 	 * 			微信订单号
925 	 * @param outOrderNo
926 	 * 			商户分帐单号
927 	 * @return
928 	 * @throws WeixinException
929 	 * @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_2&index=3">分帐查询</a>
930 	 * @since weixin4j-pay 1.1.0
931 	 */
932 	public ProfitSharingResult profitSharingQuery(String transactionId, String outOrderNo) throws WeixinException{
933 		return profitSharingApi.profitSharingQuery(transactionId, outOrderNo);
934 	}
935 
936 	/**
937 	 * 完结分账
938 	 * 1、不需要进行分账的订单,可直接调用本接口将订单的金额全部解冻给本商户
939 	 * 2、调用多次分账接口后,需要解冻剩余资金时,调用本接口将剩余的分账金额全部解冻给特约商户
940 	 * 3、已调用请求单次分账后,剩余待分账金额为零,不需要再调用此接口。
941 	 *
942 	 * @param transactionId
943 	 * 			微信订单号
944 	 * @param outOrderNo
945 	 * 			商户分帐单号
946 	 * @param description
947 	 * 			分帐完结描述
948 	 * @return
949 	 * @throws WeixinException
950 	 * @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_5&index=6">完结分账</a>
951 	 * @since weixin4j-pay 1.1.0
952 	 */
953 	public ProfitSharingResult profitSharingFinish(String transactionId, String outOrderNo, String description)
954 		throws WeixinException{
955 		return profitSharingApi.profitSharingFinish(transactionId, outOrderNo, description);
956 	}
957 
958 	/**
959 	 * 分账回退
960 	 *
961 	 * @param id
962 	 *          分帐单号
963 	 * @param outReturnNo
964 	 *          商户回退单号
965 	 * @param returnAccountType
966 	 *          回退方类型
967 	 * @param returnAccount
968 	 *          回退方账号
969 	 * @param description
970 	 *          回退描述
971 	 * @return
972 	 * @throws WeixinException
973 	 * @see ProfitSharingReturnRequest
974 	 * @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_7&index=7">分账回退</a>
975 	 * @since weixin4j-pay 1.1.0
976 	 */
977 	public ProfitSharingReturnResult profitSharingReturn(ProfitId id, String outReturnNo,
978 												   ReturnAccountType returnAccountType, String returnAccount,
979 												   int returnAmount, String description)
980 			throws WeixinException{
981 		return profitSharingApi.profitSharingReturn(id, outReturnNo, returnAccountType, returnAccount, returnAmount,
982 				description);
983 	}
984 
985 	/**
986 	 * 回退结果查询
987 	 *
988 	 * @param id
989 	 *          分帐单号
990 	 * @param outReturnNo
991 	 *          商户回退单号
992 	 * @return
993 	 * @throws WeixinException
994 	 * @see ProfitSharingReturnRequest
995 	 * @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_8&index=8">回退结果查询</a>
996 	 */
997 	public ProfitSharingReturnResult profitSharingReturnQuery(ProfitId id, String outReturnNo) throws WeixinException{
998 		return profitSharingApi.profitSharingReturnQuery(id, outReturnNo);
999 	}
1000 
1001 	public final static String VERSION = Consts.VERSION;
1002 }