All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.ipokerface.weixin.proxy.WeixinPaymentProxy Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package cn.ipokerface.weixin.proxy;

import cn.ipokerface.weixin.exception.WeixinException;
import cn.ipokerface.weixin.model.WeixinPayAccount;
import cn.ipokerface.weixin.model.custom.CustomCity;
import cn.ipokerface.weixin.model.page.Pageable;
import cn.ipokerface.weixin.proxy.company.CompanyPayment;
import cn.ipokerface.weixin.proxy.company.CompanyPaymentRecord;
import cn.ipokerface.weixin.proxy.company.CompanyPaymentResult;
import cn.ipokerface.weixin.proxy.coupon.CouponDetail;
import cn.ipokerface.weixin.proxy.coupon.CouponResult;
import cn.ipokerface.weixin.proxy.coupon.CouponStock;
import cn.ipokerface.weixin.proxy.merchant.*;
import cn.ipokerface.weixin.proxy.order.CustomOrder;
import cn.ipokerface.weixin.proxy.order.CustomOrderRecord;
import cn.ipokerface.weixin.proxy.order.CustomOrderResult;
import cn.ipokerface.weixin.proxy.payment.*;
import cn.ipokerface.weixin.proxy.redpack.RedPacket;
import cn.ipokerface.weixin.proxy.redpack.RedPacketRecord;
import cn.ipokerface.weixin.proxy.redpack.RedPacketSendResult;
import cn.ipokerface.weixin.proxy.refund.RefundAccountType;
import cn.ipokerface.weixin.proxy.refund.RefundRecord;
import cn.ipokerface.weixin.proxy.refund.RefundResult;
import cn.ipokerface.weixin.proxy.settle.SettlementRecord;
import cn.ipokerface.weixin.request.ApiXmlResult;
import cn.ipokerface.weixin.sign.WeixinSignature;

import java.io.OutputStream;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Future;

/**
 * Created by       PokerFace
 * Create Date      2019-12-28.
 * Email:           [email protected]
 * Version          1.0.0
 * 

* Description: */ public class WeixinPaymentProxy { /** * 微信支付API:js支付、扫码支付等接口 */ private final PaymentProxy paymentProxy; /** * 代金券API */ private final CouponProxy couponProxy; /** * 现金API */ private final CashProxy cashProxy; /** * 海关API */ private final OrderProxy orderProxy; /** * 商户信息 */ private final WeixinPayAccount weixinPayAccount; /** * 微信支付接口实现 * * @param weixinPayAccount * 微信商户信息 */ public WeixinPaymentProxy(WeixinPayAccount weixinPayAccount) { if (weixinPayAccount == null) { throw new IllegalArgumentException( "weixinPayAccount must not be empty"); } this.weixinPayAccount = weixinPayAccount; this.paymentProxy = new PaymentProxy(weixinPayAccount); this.couponProxy = new CouponProxy(weixinPayAccount); this.cashProxy = new CashProxy(weixinPayAccount); this.orderProxy = new OrderProxy(weixinPayAccount); } /** * 获取微信商户账号信息 * * @return */ public WeixinPayAccount getWeixinPayAccount() { return weixinPayAccount; } /** * 获取微信签名类 * * @return */ public WeixinSignature getWeixinSignature() { return paymentProxy.getWeixinSignature(); } /** * 统一下单接口 * 除被扫支付场景以外,商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易回话标识后再按扫码、JSAPI * 、APP等不同场景生成交易串调起支付。 * * @param payPackage * 包含订单信息的对象 * @see PaymentProxy * @see MerchantPaymentPackage * @see PrePayment * @see 统一下单接口 * * @return 预支付对象 */ public PrePayment createPrePay(MerchantPaymentPackage payPackage) throws WeixinException { return paymentProxy.createPrePay(payPackage); } /** * 创建支付请求对象 * * @param payPackage * 支付详情 * @return 支付请求对象 * @see PaymentProxy * @see cn.ipokerface.weixin.proxy.payment.JsapiPaymentRequest JS支付 * @see cn.ipokerface.weixin.proxy.payment.NativePaymentRequest 扫码支付 * @see cn.ipokerface.weixin.proxy.payment.MicroPaymentRequest 刷卡支付 * @see cn.ipokerface.weixin.proxy.payment.AppPaymentRequest APP支付 * @see cn.ipokerface.weixin.proxy.payment.WapPaymentRequest WAP支付 * @see cn.ipokerface.weixin.proxy.payment.MerchantPaymentRequest#toRequestString() * @throws WeixinException */ public MerchantPaymentRequest createPayRequest(MerchantPaymentPackage payPackage) throws WeixinException { return paymentProxy.createPayRequest(payPackage); } /** * 创建JSAPI支付请求对象 * * @param openId * 用户ID * @param body * 订单描述 * @param outTradeNo * 订单号 * @param totalFee * 订单总额(元) * @param notifyUrl * 支付通知地址 * @param createIp * ip地址 * @param attach * 附加数据 非必填 * @see PaymentProxy * @see JsapiPaymentRequest * @see MerchantPaymentRequest#toRequestString() * @return JSAPI支付对象 * @throws WeixinException */ public MerchantPaymentRequest createJSPayRequest(String openId, String body, String outTradeNo, double totalFee, String notifyUrl, String createIp, String attach) throws WeixinException { return paymentProxy.createJSPayRequest(openId, body, outTradeNo, totalFee, notifyUrl, createIp, attach); } /** *

* 生成编辑地址请求 *

* * err_msg edit_address:ok获取编辑收货地址成功 edit_address:fail获取编辑收货地址失败 * userName 收货人姓名 telNumber 收货人电话 addressPostalCode 邮编 * proviceFirstStageName 国标收货地址第一级地址 addressCitySecondStageName * 国标收货地址第二级地址 addressCountiesThirdStageName 国标收货地址第三级地址 * addressDetailInfo 详细收货地址信息 nationalCode 收货地址国家码 * * @param url * 当前访问页的URL * @param oauthToken * oauth授权时产生的token * @see PaymentProxy * @see * 收货地址共享 * @return 编辑地址请求JSON串 */ public String createAddressRequestJSON(String url, String oauthToken) { return paymentProxy.createAddressRequestJSON(url, oauthToken); } /** * 创建Native支付(扫码支付)链接【模式一】 * * @param productId * 与订单ID等价 * @return 支付链接 * @see PaymentProxy * @see 扫码支付 * * @see 模式一 * */ public String createNativePayRequest(String productId) { return paymentProxy.createNativePayRequest(productId); } /** * 创建Native支付(扫码支付)回调对象【模式一】 * * @param productId * 商品ID * @param body * 商品描述 * @param outTradeNo * 商户内部唯一订单号 * @param totalFee * 商品总额 单位元 * @param notifyUrl * 支付回调URL * @param createIp * 订单生成的机器 IP * @param attach * 附加数据 非必填 * @return Native回调对象 * @see PaymentProxy * @see NativePaymentResponse * @see 扫码支付 * * @see 模式一 * * @throws WeixinException */ public NativePaymentResponse createNativePayResponse(String productId, String body, String outTradeNo, double totalFee, String notifyUrl, String createIp, String attach) throws WeixinException { return paymentProxy.createNativePayResponse(productId, body, outTradeNo, totalFee, notifyUrl, createIp, attach); } /** * 创建Native支付(扫码支付)链接【模式二】 * * @param productId * 商品ID * @param body * 商品描述 * @param outTradeNo * 商户内部唯一订单号 * @param totalFee * 商品总额 单位元 * @param notifyUrl * 支付回调URL * @param createIp * 订单生成的机器 IP * @param attach * 附加数据 非必填 * @return Native支付对象 * @see PaymentProxy * @see NativePaymentRequest * @see MerchantPaymentRequest#toRequestString() * @see 扫码支付 * * @see 模式二 * * @throws WeixinException */ public MerchantPaymentRequest createNativePayRequest(String productId, String body, String outTradeNo, double totalFee, String notifyUrl, String createIp, String attach) throws WeixinException { return paymentProxy.createNativePayRequest(productId, body, outTradeNo, totalFee, notifyUrl, createIp, attach); } /** * 创建APP支付请求对象 * * @param body * 商品描述 * @param outTradeNo * 商户内部唯一订单号 * @param totalFee * 商品总额 单位元 * @param notifyUrl * 支付回调URL * @param createIp * 订单生成的机器 IP * @param attach * 附加数据 非必填 * @param store * 门店信息 非必填 * @return APP支付对象 * @see PaymentProxy * @see SceneInfoStore * @see AppPaymentRequest * @see MerchantPaymentRequest#toRequestString() * @see * APP支付 * @throws WeixinException */ public MerchantPaymentRequest createAppPayRequest(String body, String outTradeNo, double totalFee, String notifyUrl, String createIp, String attach, SceneInfoStore store) throws WeixinException { return paymentProxy.createAppPayRequest(body, outTradeNo, totalFee, notifyUrl, createIp, attach, store); } /** * 创建WAP支付请求对象 * * @param body * 商品描述 * @param outTradeNo * 商户内部唯一订单号 * @param totalFee * 商品总额 单位元 * @param notifyUrl * 支付回调URL * @param createIp * 订单生成的机器 IP * @param attach * 附加数据 非必填 * @param app * 应用信息 * @return WAP支付对象 * @see PaymentProxy * @see SceneInfoApp * @see WapPaymentRequest * @see MerchantPaymentRequest#toRequestString() * @see WAP支付 * * @throws WeixinException */ public MerchantPaymentRequest createWapPayRequest(String body, String outTradeNo, double totalFee, String notifyUrl, String createIp, String attach, SceneInfoApp app) throws WeixinException { return paymentProxy.createWapPayRequest(body, outTradeNo, totalFee, notifyUrl, createIp, attach, app); } /** * 提交被扫支付 * * @param authCode * 扫码支付授权码 ,设备读取用户微信中的条码或者二维码信息 * @param body * 商品描述 * @param outTradeNo * 商户内部唯一订单号 * @param totalFee * 商品总额 单位元 * @param createIp * 订单生成的机器 IP * @param attach * 附加数据 非必填 * @param store * 门店信息 非必填 * @return 支付的订单信息 * @see PaymentProxy * @see Order * @see SceneInfoStore * @see MicroPaymentRequest * @see MerchantPaymentRequest#toRequestString() * @see * 提交被扫支付API * @throws WeixinException */ public MerchantPaymentRequest createMicroPayRequest(String authCode, String body, String outTradeNo, double totalFee, String createIp, String attach, SceneInfoStore store) throws WeixinException { return paymentProxy.createMicroPayRequest(authCode, body, outTradeNo, totalFee, createIp, attach, store); } /** * 订单查询 *

* 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知; 调用支付接口后,返回系统错误或未知交易状态情况; * 调用被扫支付API,返回USERPAYING的状态; 调用关单或撤销接口API之前,需确认支付状态; *

* * @param idQuery * 商户系统内部的订单号, transaction_id、out_trade_no 二 选一,如果同时存在优先级: * transaction_id > out_trade_no * @since V3 * @see Order * @see PaymentProxy * @see * 订单查询API * @return 订单详情 */ public Order queryOrder(IdQuery idQuery) throws WeixinException { return paymentProxy.queryOrder(idQuery); } /** * 申请退款 * * @see PaymentProxy#applyRefund(IdQuery, String, double, double, CurrencyType, String, String, RefundAccountType) */ public RefundResult applyRefund(IdQuery idQuery, String outRefundNo, double totalFee, double refundFee, CurrencyType refundFeeType, String opUserId, String refundDesc, RefundAccountType refundAccountType) throws WeixinException { return paymentProxy.applyRefund(idQuery, outRefundNo, totalFee, refundFee, refundFeeType, opUserId, refundDesc, refundAccountType); } /** * 申请退款 * * @see PaymentProxy#applyRefund(IdQuery, String, double) */ public RefundResult applyRefund(IdQuery idQuery, String outRefundNo, double totalFee) throws WeixinException { return paymentProxy.applyRefund(idQuery, outRefundNo, totalFee); } /** * 退款查询 *

* 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。 *

* * @param idQuery * 单号 refund_id、out_refund_no、 out_trade_no 、 transaction_id * 四个参数必填一个,优先级为: * refund_id > out_refund_no > transaction_id > out_trade_no * @return 退款记录 * @see PaymentProxy * @see RefundRecord * @see * 退款查询API * @since V3 * @throws WeixinException */ public RefundRecord queryRefund(IdQuery idQuery) throws WeixinException { return paymentProxy.queryRefund(idQuery); } /** * 下载对账单
* 1.微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账 单中,跟原支付单订单号一致,bill_type 为 * REVOKED;
* 2.微信在次日 9 点启动生成前一天的对账单,建议商户 9 点半后再获取;
* 3.对账单中涉及金额的字段单位为“元”。
* * @param billDate * 下载对账单的日期 * @param billType * 下载对账单的类型 ALL,返回当日所有订单信息, 默认值 SUCCESS,返回当日成功支付的订单 * REFUND,返回当日退款订单 * @param outputStream 输出流 * @param tarType * 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。 * @see PaymentProxy * @see * 下载对账单API * @throws WeixinException */ public void downloadBill(Date billDate, BillType billType, OutputStream outputStream, ZipType tarType) throws WeixinException { paymentProxy.downloadBill(billDate, billType, outputStream, tarType); } /** * 冲正订单(需要证书) 当支付返回失败,或收银系统超时需要取消交易,可以调用该接口 接口逻辑:支 * 付失败的关单,支付成功的撤销支付 7天以内的单可撤销,其他正常支付的单 * 如需实现相同功能请调用退款接口 调用扣款接口后请勿立即调用撤销,需要等待5秒以上。先调用查单接口,如果没有确切的返回,再调用撤销 * * @param idQuery * 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级: * transaction_id > out_trade_no * @return 撤销结果 * @see PaymentProxy * @since V3 */ public MerchantResult reverseOrder(IdQuery idQuery) throws WeixinException { return paymentProxy.reverseOrder(idQuery); } /** * 关闭订单 *

* 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付;系统下单后,用户支付超时,系统退出不再受理,避免用户继续 * ,请调用关单接口,如果关单失败,返回已完 成支付请按正常支付处理。如果出现银行掉单,调用关单成功后,微信后台会主动发起退款。 *

* * @param outTradeNo * 商户系统内部的订单号 * @return 执行结果 * @see PaymentProxy * @since V3 * @throws WeixinException * @see * 关闭订单API */ public MerchantResult closeOrder(String outTradeNo) throws WeixinException { return paymentProxy.closeOrder(outTradeNo); } /** * native支付URL转短链接:用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),减小二维码数据量 * ,提升扫描速度和精确度。 * * @param url * 具有native标识的支付URL * @return 转换后的短链接 * @see PaymentProxy * @see * 转换短链接API * @since V3 * @throws WeixinException */ public String getPayShorturl(String url) throws WeixinException { return paymentProxy.getShorturl(url); } /** * 接口上报 * * @param interfaceUrl * 上报对应的接口的完整 URL, 类似: https://api.mch.weixin.q * q.com/pay/unifiedorder * @param executeTime * 接口耗时情况,单位为毫秒 * @param outTradeNo * 商户系统内部的订单号,商 户可以在上报时提供相关商户订单号方便微信支付更好 的提高服务质量。 * @param ip * 发起接口调用时的机器 IP * @param time * 商户调用该接口时商户自己 系统的时间 * @param returnXml * 调用接口返回的基本数据 * @return 处理结果 * @see PaymentProxy * @see * 接口测试上报API * @throws WeixinException */ public ApiXmlResult reportInterface(String interfaceUrl, int executeTime, String outTradeNo, String ip, Date time, ApiXmlResult returnXml) throws WeixinException { return paymentProxy.reportInterface(interfaceUrl, executeTime, outTradeNo, ip, time, returnXml); } /** * 发放代金券(需要证书) * * @param couponStockId * 代金券批次id * @param partnerTradeNo * 商户发放凭据号(格式:商户id+日期+流水号),商户侧需保持唯一性 * @param openId * 用户的openid * @param opUserId * 操作员帐号, 默认为商户号 可在商户平台配置操作员对应的api权限 可为空 * @return 发放结果 * @see CouponProxy * @see CouponResult * @see * 发放代金券接口 * @throws WeixinException */ public CouponResult sendCoupon(String couponStockId, String partnerTradeNo, String openId, String opUserId) throws WeixinException { return couponProxy.sendCoupon(couponStockId, partnerTradeNo, openId, opUserId); } /** * 查询代金券批次 * * @param couponStockId * 代金券批次ID * @return 代金券批次信息 * @see CouponProxy * @see CouponStock * @see * 查询代金券批次信息接口 * @throws WeixinException */ public CouponStock queryCouponStock(String couponStockId) throws WeixinException { return couponProxy.queryCouponStock(couponStockId); } /** * 查询代金券详细 * * @param openId * 用户ID * @param couponId * 代金券ID * @param stockId * 代金劵对应的批次号 * @return 代金券详细信息 * @see CouponProxy * @see CouponDetail * @see * 查询代金券详细信息接口 * @throws WeixinException */ public CouponDetail queryCouponDetail(String openId, String couponId, String stockId) throws WeixinException { return couponProxy.queryCouponDetail(openId, couponId, stockId); } /** * 发放红包 企业向微信用户个人发现金红包 * * @param redpacket * 红包信息 * @return 发放结果 * @see CashProxy * @see cn.ipokerface.weixin.proxy.redpack.RedPacket * @see cn.ipokerface.weixin.proxy.redpack.RedPacketSendResult * @see * 发放现金红包接口 * @see * 发放裂变红包接口 * @throws WeixinException */ public RedPacketSendResult sendRedpack(RedPacket redpacket) throws WeixinException { return cashProxy.sendRedpack(redpacket); } /** * 批量发放红包 企业向微信用户个人发现金红包 * * @param redpackets * 多个红包信息 * @return 发放结果 * @see CashProxy * @see #sendRedpacks(RedPacket...) */ public List> sendRedpacks( RedPacket... redpackets) { return cashProxy.sendRedpacks(redpackets); } /** * 查询红包记录 * * @param outTradeNo * 商户发放红包的商户订单号 * @return 红包记录 * @see CashProxy * @see cn.ipokerface.weixin.proxy.redpack.RedPacketRecord * @see * 查询现金红包接口 * @see * 查询裂变红包接口 * @throws WeixinException */ public RedPacketRecord queryRedpack(String outTradeNo) throws WeixinException { return cashProxy.queryRedpack(outTradeNo); } /** * 企业付款 * * @see CashProxy#sendCorpPayment(CompanyPayment) */ public CompanyPaymentResult sendCorpPayment(CompanyPayment payment) throws WeixinException { return cashProxy.sendCorpPayment(payment); } /** * 企业付款查询 用于商户的企业付款操作进行结果查询,返回付款操作详细结果 * * @param outTradeNo * 商户调用企业付款API时使用的商户订单号 * @return 付款记录 * @see CashProxy * @see cn.ipokerface.weixin.proxy.company.CompanyPaymentRecord * @see * 企业付款查询接口 * @throws WeixinException */ public CompanyPaymentRecord queryCorpPayment(String outTradeNo) throws WeixinException { return cashProxy.queryCorpPayment(outTradeNo); } /** * 授权码查询OPENID * * @param authCode * 扫码支付授权码,设备读取用户微信中的条码或者二维码信息 * @return 查询结果 * @see CashProxy * @see OpenidResult * @see * 授权码查询OPENID * @throws WeixinException */ public OpenidResult authCode2openId(String authCode) throws WeixinException { return paymentProxy.authCode2openId(authCode); } /** * 查询结算资金 * * @param status * 是否结算 * @param pageable * 分页数据 * @param start * 开始日期 查询未结算记录时,该字段可不传 * @param end * 结束日期 查询未结算记录时,该字段可不传 * @return 结算金额记录 * @throws WeixinException * @see CashProxy * @see SettlementRecord * @see * 查询结算资金接口 */ public SettlementRecord querySettlement(boolean status, Pageable pageable, Date start, Date end) throws WeixinException { return cashProxy.querySettlement(status, pageable, start, end); } /** * 查询汇率 * * @param currencyType * 外币币种 * @param date * 日期 不填则默认当天 * @return 汇率对象 * @throws WeixinException * @see CashProxy * @see * 查询汇率接口 */ public double queryExchageRate(CurrencyType currencyType, Date date) throws WeixinException { return cashProxy.queryExchageRate(currencyType, date); } /** * 订单附加信息提交 * * @param customsOrder * 附加订单信息 * @return 报关结果 * @see OrderProxy * @see cn.ipokerface.weixin.proxy.order.CustomOrder * @see cn.ipokerface.weixin.proxy.order.CustomOrderResult * @see * 附加订单信息提交接口 * @throws WeixinException */ public CustomOrderResult declareCustomsOrder(CustomOrder customsOrder) throws WeixinException { return orderProxy.declareCustomsOrder(customsOrder); } /** * 订单附加信息查询 * * @param idQuery * out_trade_no,transaction_id,sub_order_no,sub_order_id四选一 * @param customsCity * 海关 * @return 报关记录 * @see cn.ipokerface.weixin.proxy.order.CustomOrderRecord * @see OrderProxy * @see * 附加订单信息查询接口 * @throws WeixinException */ public CustomOrderRecord queryCustomsOrder(IdQuery idQuery, CustomCity customsCity) throws WeixinException { return orderProxy.queryCustomsOrder(idQuery, customsCity); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy