mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-16 05:16:24 +08:00
🆕 #3720 【微信支付】实现微信押金支付的相关功能接口
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package com.github.binarywang.wxpay.bean.request;
|
||||
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.*;
|
||||
import me.chanjar.weixin.common.annotation.Required;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金消费请求
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=4">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=4</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Builder(builderMethodName = "newBuilder")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class WxDepositConsumeRequest extends BaseWxPayRequest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信押金订单号
|
||||
* transaction_id
|
||||
* 是
|
||||
* String(32)
|
||||
* 1009660380201506130728806387
|
||||
* 微信押金订单号
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户消费单号
|
||||
* out_trade_no
|
||||
* 是
|
||||
* String(32)
|
||||
* 20150806125346
|
||||
* 商户系统内部的消费单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("out_trade_no")
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 消费金额
|
||||
* consume_fee
|
||||
* 是
|
||||
* Int
|
||||
* 88
|
||||
* 消费金额,单位为分,不能大于押金金额
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("consume_fee")
|
||||
private Integer consumeFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 消费描述
|
||||
* consume_desc
|
||||
* 否
|
||||
* String(128)
|
||||
* 单车使用费
|
||||
* 对一笔消费的具体描述信息
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("consume_desc")
|
||||
private String consumeDesc;
|
||||
|
||||
@Override
|
||||
protected void checkConstraints() throws WxPayException {
|
||||
// No additional constraints beyond @Required fields
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void storeMap(Map<String, String> map) {
|
||||
map.put("transaction_id", transactionId);
|
||||
map.put("out_trade_no", outTradeNo);
|
||||
map.put("consume_fee", consumeFee.toString());
|
||||
if (consumeDesc != null) {
|
||||
map.put("consume_desc", consumeDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.github.binarywang.wxpay.bean.request;
|
||||
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.*;
|
||||
import me.chanjar.weixin.common.annotation.Required;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 查询押金订单请求
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=3">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=3</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Builder(builderMethodName = "newBuilder")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class WxDepositOrderQueryRequest extends BaseWxPayRequest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信订单号
|
||||
* transaction_id
|
||||
* 否
|
||||
* String(32)
|
||||
* 1009660380201506130728806387
|
||||
* 微信的订单号,优先使用
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户订单号
|
||||
* out_trade_no
|
||||
* 否
|
||||
* String(32)
|
||||
* 20150806125346
|
||||
* 商户系统内部的订单号,当没提供transaction_id时需要传这个
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("out_trade_no")
|
||||
private String outTradeNo;
|
||||
|
||||
@Override
|
||||
protected void checkConstraints() throws WxPayException {
|
||||
if (transactionId == null && outTradeNo == null) {
|
||||
throw new WxPayException("transaction_id 和 out_trade_no 不能同时为空");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void storeMap(Map<String, String> map) {
|
||||
if (transactionId != null) {
|
||||
map.put("transaction_id", transactionId);
|
||||
}
|
||||
if (outTradeNo != null) {
|
||||
map.put("out_trade_no", outTradeNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.github.binarywang.wxpay.bean.request;
|
||||
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.*;
|
||||
import me.chanjar.weixin.common.annotation.Required;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金退款请求
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=6">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=6</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Builder(builderMethodName = "newBuilder")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class WxDepositRefundRequest extends BaseWxPayRequest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信押金订单号
|
||||
* transaction_id
|
||||
* 否
|
||||
* String(32)
|
||||
* 1009660380201506130728806387
|
||||
* 微信押金订单号,与out_trade_no二选一
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户押金订单号
|
||||
* out_trade_no
|
||||
* 否
|
||||
* String(32)
|
||||
* 20150806125346
|
||||
* 商户系统内部的押金订单号,与transaction_id二选一
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("out_trade_no")
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户退款单号
|
||||
* out_refund_no
|
||||
* 是
|
||||
* String(32)
|
||||
* 1217752501201407033233368018
|
||||
* 商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("out_refund_no")
|
||||
private String outRefundNo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 退款金额
|
||||
* refund_fee
|
||||
* 是
|
||||
* Int
|
||||
* 100
|
||||
* 退款总金额,订单总金额,单位为分,只能为整数
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("refund_fee")
|
||||
private Integer refundFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 退款原因
|
||||
* refund_desc
|
||||
* 否
|
||||
* String(80)
|
||||
* 商品已售完
|
||||
* 若商户传入,会在下发给用户的退款消息中体现退款原因
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("refund_desc")
|
||||
private String refundDesc;
|
||||
|
||||
@Override
|
||||
protected void checkConstraints() throws WxPayException {
|
||||
if (transactionId == null && outTradeNo == null) {
|
||||
throw new WxPayException("transaction_id 和 out_trade_no 不能同时为空");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void storeMap(Map<String, String> map) {
|
||||
if (transactionId != null) {
|
||||
map.put("transaction_id", transactionId);
|
||||
}
|
||||
if (outTradeNo != null) {
|
||||
map.put("out_trade_no", outTradeNo);
|
||||
}
|
||||
map.put("out_refund_no", outRefundNo);
|
||||
map.put("refund_fee", refundFee.toString());
|
||||
if (refundDesc != null) {
|
||||
map.put("refund_desc", refundDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.github.binarywang.wxpay.bean.request;
|
||||
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.*;
|
||||
import me.chanjar.weixin.common.annotation.Required;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金撤销请求
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=5">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=5</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Builder(builderMethodName = "newBuilder")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class WxDepositUnfreezeRequest extends BaseWxPayRequest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信押金订单号
|
||||
* transaction_id
|
||||
* 是
|
||||
* String(32)
|
||||
* 1009660380201506130728806387
|
||||
* 微信押金订单号
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户撤销单号
|
||||
* out_trade_no
|
||||
* 是
|
||||
* String(32)
|
||||
* 20150806125346
|
||||
* 商户系统内部的撤销单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("out_trade_no")
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 撤销金额
|
||||
* unfreeze_fee
|
||||
* 是
|
||||
* Int
|
||||
* 99
|
||||
* 撤销金额,单位为分,不能大于剩余押金金额
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("unfreeze_fee")
|
||||
private Integer unfreezeFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 撤销原因
|
||||
* unfreeze_desc
|
||||
* 否
|
||||
* String(128)
|
||||
* 用户主动取消
|
||||
* 对一笔撤销的具体原因描述
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("unfreeze_desc")
|
||||
private String unfreezeDesc;
|
||||
|
||||
@Override
|
||||
protected void checkConstraints() throws WxPayException {
|
||||
// No additional constraints beyond @Required fields
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void storeMap(Map<String, String> map) {
|
||||
map.put("transaction_id", transactionId);
|
||||
map.put("out_trade_no", outTradeNo);
|
||||
map.put("unfreeze_fee", unfreezeFee.toString());
|
||||
if (unfreezeDesc != null) {
|
||||
map.put("unfreeze_desc", unfreezeDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package com.github.binarywang.wxpay.bean.request;
|
||||
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.*;
|
||||
import me.chanjar.weixin.common.annotation.Required;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金下单请求
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=2">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=2</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Builder(builderMethodName = "newBuilder")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class WxDepositUnifiedOrderRequest extends BaseWxPayRequest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金商品描述
|
||||
* body
|
||||
* 是
|
||||
* String(128)
|
||||
* 共享单车押金
|
||||
* 押金商品描述
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("body")
|
||||
private String body;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户订单号
|
||||
* out_trade_no
|
||||
* 是
|
||||
* String(32)
|
||||
* 20150806125346
|
||||
* 商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("out_trade_no")
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金金额
|
||||
* total_fee
|
||||
* 是
|
||||
* Int
|
||||
* 99
|
||||
* 押金金额,单位为分,只能为整数,详见支付金额
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("total_fee")
|
||||
private Integer totalFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 终端IP
|
||||
* spbill_create_ip
|
||||
* 是
|
||||
* String(16)
|
||||
* 123.12.12.123
|
||||
* 用户端实际ip
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("spbill_create_ip")
|
||||
private String spbillCreateIp;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 通知地址
|
||||
* notify_url
|
||||
* 是
|
||||
* String(256)
|
||||
* http://www.weixin.qq.com/wxpay/pay.php
|
||||
* 接收微信支付异步通知回调地址
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("notify_url")
|
||||
private String notifyUrl;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 交易类型
|
||||
* trade_type
|
||||
* 是
|
||||
* String(16)
|
||||
* JSAPI
|
||||
* 交易类型,取值如下:JSAPI,NATIVE,APP,WAP
|
||||
* </pre>
|
||||
*/
|
||||
@Required
|
||||
@XStreamAlias("trade_type")
|
||||
private String tradeType;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 用户标识
|
||||
* openid
|
||||
* 否
|
||||
* String(128)
|
||||
* oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
|
||||
* trade_type=JSAPI时,此参数必传,用户在商户appid下的唯一标识。
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("openid")
|
||||
private String openid;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商品详情
|
||||
* detail
|
||||
* 否
|
||||
* String(8192)
|
||||
* 详情
|
||||
* 商品名称明细列表
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("detail")
|
||||
private String detail;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 附加数据
|
||||
* attach
|
||||
* 否
|
||||
* String(127)
|
||||
* 深圳分店
|
||||
* 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("attach")
|
||||
private String attach;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 货币类型
|
||||
* fee_type
|
||||
* 否
|
||||
* String(16)
|
||||
* CNY
|
||||
* 符合ISO 4217标准的三位字母代码,默认人民币:CNY
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("fee_type")
|
||||
private String feeType;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 交易起始时间
|
||||
* time_start
|
||||
* 否
|
||||
* String(14)
|
||||
* 20091225091010
|
||||
* 订单生成时间,格式为yyyyMMddHHmmss
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("time_start")
|
||||
private String timeStart;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 交易结束时间
|
||||
* time_expire
|
||||
* 否
|
||||
* String(14)
|
||||
* 20091227091010
|
||||
* 订单失效时间,格式为yyyyMMddHHmmss
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("time_expire")
|
||||
private String timeExpire;
|
||||
|
||||
@Override
|
||||
protected void checkConstraints() throws WxPayException {
|
||||
if ("JSAPI".equals(this.tradeType) && this.openid == null) {
|
||||
throw new WxPayException("当trade_type为JSAPI时,openid为必填参数");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void storeMap(Map<String, String> map) {
|
||||
map.put("body", body);
|
||||
map.put("out_trade_no", outTradeNo);
|
||||
map.put("total_fee", totalFee.toString());
|
||||
map.put("spbill_create_ip", spbillCreateIp);
|
||||
map.put("notify_url", notifyUrl);
|
||||
map.put("trade_type", tradeType);
|
||||
if (openid != null) {
|
||||
map.put("openid", openid);
|
||||
}
|
||||
if (detail != null) {
|
||||
map.put("detail", detail);
|
||||
}
|
||||
if (attach != null) {
|
||||
map.put("attach", attach);
|
||||
}
|
||||
if (feeType != null) {
|
||||
map.put("fee_type", feeType);
|
||||
}
|
||||
if (timeStart != null) {
|
||||
map.put("time_start", timeStart);
|
||||
}
|
||||
if (timeExpire != null) {
|
||||
map.put("time_expire", timeExpire);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.github.binarywang.wxpay.bean.result;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金消费结果
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=4">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=4</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class WxDepositConsumeResult extends BaseWxPayResult implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信订单号
|
||||
* transaction_id
|
||||
* 是
|
||||
* String(32)
|
||||
* 1217752501201407033233368018
|
||||
* 微信支付押金订单号
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户消费单号
|
||||
* out_trade_no
|
||||
* 是
|
||||
* String(32)
|
||||
* 20150806125346
|
||||
* 商户系统内部的消费单号
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("out_trade_no")
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 消费金额
|
||||
* consume_fee
|
||||
* 是
|
||||
* Int
|
||||
* 88
|
||||
* 本次消费的金额,单位为分
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("consume_fee")
|
||||
private Integer consumeFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 剩余押金
|
||||
* remain_fee
|
||||
* 是
|
||||
* Int
|
||||
* 11
|
||||
* 剩余押金金额,单位为分
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("remain_fee")
|
||||
private Integer remainFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 消费时间
|
||||
* time_end
|
||||
* 是
|
||||
* String(14)
|
||||
* 20141030133525
|
||||
* 消费完成时间,格式为yyyyMMddHHmmss
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("time_end")
|
||||
private String timeEnd;
|
||||
|
||||
@Override
|
||||
protected void loadXml(Document d) {
|
||||
transactionId = readXmlString(d, "transaction_id");
|
||||
outTradeNo = readXmlString(d, "out_trade_no");
|
||||
consumeFee = readXmlInteger(d, "consume_fee");
|
||||
remainFee = readXmlInteger(d, "remain_fee");
|
||||
timeEnd = readXmlString(d, "time_end");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.github.binarywang.wxpay.bean.result;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 查询押金订单结果
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=3">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=3</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class WxDepositOrderQueryResult extends BaseWxPayResult implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信订单号
|
||||
* transaction_id
|
||||
* 是
|
||||
* String(32)
|
||||
* 1217752501201407033233368018
|
||||
* 微信支付订单号
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户订单号
|
||||
* out_trade_no
|
||||
* 是
|
||||
* String(32)
|
||||
* 20150806125346
|
||||
* 商户系统内部订单号
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("out_trade_no")
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 交易状态
|
||||
* trade_state
|
||||
* 是
|
||||
* String(32)
|
||||
* SUCCESS
|
||||
* 交易状态:
|
||||
* SUCCESS—支付成功
|
||||
* REFUND—转入退款
|
||||
* NOTPAY—未支付
|
||||
* CLOSED—已关闭
|
||||
* REVOKED—已撤销(付款码支付)
|
||||
* USERPAYING—用户支付中(付款码支付)
|
||||
* PAYERROR—支付失败(其他原因,如银行返回失败)
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("trade_state")
|
||||
private String tradeState;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 交易状态描述
|
||||
* trade_state_desc
|
||||
* 是
|
||||
* String(256)
|
||||
* 支付成功
|
||||
* 对当前查询订单状态的描述和下一步操作的指引
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("trade_state_desc")
|
||||
private String tradeStateDesc;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金金额
|
||||
* total_fee
|
||||
* 否
|
||||
* Int
|
||||
* 99
|
||||
* 订单总金额,单位为分
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("total_fee")
|
||||
private Integer totalFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 现金支付金额
|
||||
* cash_fee
|
||||
* 否
|
||||
* Int
|
||||
* 99
|
||||
* 现金支付金额订单现金支付金额
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("cash_fee")
|
||||
private Integer cashFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 支付完成时间
|
||||
* time_end
|
||||
* 否
|
||||
* String(14)
|
||||
* 20141030133525
|
||||
* 订单支付时间,格式为yyyyMMddHHmmss
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("time_end")
|
||||
private String timeEnd;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 剩余押金
|
||||
* remain_fee
|
||||
* 否
|
||||
* Int
|
||||
* 88
|
||||
* 剩余押金金额,单位为分
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("remain_fee")
|
||||
private Integer remainFee;
|
||||
|
||||
@Override
|
||||
protected void loadXml(Document d) {
|
||||
transactionId = readXmlString(d, "transaction_id");
|
||||
outTradeNo = readXmlString(d, "out_trade_no");
|
||||
tradeState = readXmlString(d, "trade_state");
|
||||
tradeStateDesc = readXmlString(d, "trade_state_desc");
|
||||
totalFee = readXmlInteger(d, "total_fee");
|
||||
cashFee = readXmlInteger(d, "cash_fee");
|
||||
timeEnd = readXmlString(d, "time_end");
|
||||
remainFee = readXmlInteger(d, "remain_fee");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.github.binarywang.wxpay.bean.result;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金退款结果
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=6">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=6</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class WxDepositRefundResult extends BaseWxPayResult implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信订单号
|
||||
* transaction_id
|
||||
* 是
|
||||
* String(32)
|
||||
* 1217752501201407033233368018
|
||||
* 微信支付押金订单号
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户退款单号
|
||||
* out_refund_no
|
||||
* 是
|
||||
* String(32)
|
||||
* 1217752501201407033233368018
|
||||
* 商户系统内部的退款单号
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("out_refund_no")
|
||||
private String outRefundNo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信退款单号
|
||||
* refund_id
|
||||
* 是
|
||||
* String(32)
|
||||
* 1217752501201407033233368018
|
||||
* 微信退款单号
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("refund_id")
|
||||
private String refundId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 退款金额
|
||||
* refund_fee
|
||||
* 是
|
||||
* Int
|
||||
* 100
|
||||
* 退款总金额,单位为分,可以做部分退款
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("refund_fee")
|
||||
private Integer refundFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 现金退款金额
|
||||
* cash_refund_fee
|
||||
* 否
|
||||
* Int
|
||||
* 100
|
||||
* 现金退款金额,单位为分,只能为整数
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("cash_refund_fee")
|
||||
private Integer cashRefundFee;
|
||||
|
||||
@Override
|
||||
protected void loadXml(Document d) {
|
||||
transactionId = readXmlString(d, "transaction_id");
|
||||
outRefundNo = readXmlString(d, "out_refund_no");
|
||||
refundId = readXmlString(d, "refund_id");
|
||||
refundFee = readXmlInteger(d, "refund_fee");
|
||||
cashRefundFee = readXmlInteger(d, "cash_refund_fee");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.github.binarywang.wxpay.bean.result;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金撤销结果
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=5">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=5</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class WxDepositUnfreezeResult extends BaseWxPayResult implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信订单号
|
||||
* transaction_id
|
||||
* 是
|
||||
* String(32)
|
||||
* 1217752501201407033233368018
|
||||
* 微信支付押金订单号
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 商户撤销单号
|
||||
* out_trade_no
|
||||
* 是
|
||||
* String(32)
|
||||
* 20150806125346
|
||||
* 商户系统内部的撤销单号
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("out_trade_no")
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 撤销金额
|
||||
* unfreeze_fee
|
||||
* 是
|
||||
* Int
|
||||
* 99
|
||||
* 撤销的押金金额,单位为分
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("unfreeze_fee")
|
||||
private Integer unfreezeFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 剩余押金
|
||||
* remain_fee
|
||||
* 是
|
||||
* Int
|
||||
* 0
|
||||
* 剩余押金金额,单位为分
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("remain_fee")
|
||||
private Integer remainFee;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 撤销时间
|
||||
* time_end
|
||||
* 是
|
||||
* String(14)
|
||||
* 20141030133525
|
||||
* 撤销完成时间,格式为yyyyMMddHHmmss
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("time_end")
|
||||
private String timeEnd;
|
||||
|
||||
@Override
|
||||
protected void loadXml(Document d) {
|
||||
transactionId = readXmlString(d, "transaction_id");
|
||||
outTradeNo = readXmlString(d, "out_trade_no");
|
||||
unfreezeFee = readXmlInteger(d, "unfreeze_fee");
|
||||
remainFee = readXmlInteger(d, "remain_fee");
|
||||
timeEnd = readXmlString(d, "time_end");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.github.binarywang.wxpay.bean.result;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金下单结果
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=2">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=2</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XStreamAlias("xml")
|
||||
public class WxDepositUnifiedOrderResult extends BaseWxPayResult implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 交易类型
|
||||
* trade_type
|
||||
* 是
|
||||
* String(16)
|
||||
* JSAPI
|
||||
* 交易类型,取值为:JSAPI,NATIVE,APP等
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("trade_type")
|
||||
private String tradeType;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 预支付交易会话标识
|
||||
* prepay_id
|
||||
* 是
|
||||
* String(64)
|
||||
* wx201410272009395522657a690389285100
|
||||
* 微信生成的预支付会话标识,用于后续接口调用中使用,该值有效期为2小时
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("prepay_id")
|
||||
private String prepayId;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 二维码链接
|
||||
* code_url
|
||||
* 否
|
||||
* String(64)
|
||||
* URl:weixin://wxpay/s/An4baqw
|
||||
* trade_type 为 NATIVE 时有返回,可将该参数值生成二维码展示出来进行扫码支付
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("code_url")
|
||||
private String codeUrl;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信订单号
|
||||
* transaction_id
|
||||
* 是
|
||||
* String(32)
|
||||
* 1217752501201407033233368018
|
||||
* 微信支付分配的交易会话标识
|
||||
* </pre>
|
||||
*/
|
||||
@XStreamAlias("transaction_id")
|
||||
private String transactionId;
|
||||
|
||||
@Override
|
||||
protected void loadXml(Document d) {
|
||||
tradeType = readXmlString(d, "trade_type");
|
||||
prepayId = readXmlString(d, "prepay_id");
|
||||
codeUrl = readXmlString(d, "code_url");
|
||||
transactionId = readXmlString(d, "transaction_id");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.github.binarywang.wxpay.service;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.request.WxDepositConsumeRequest;
|
||||
import com.github.binarywang.wxpay.bean.request.WxDepositOrderQueryRequest;
|
||||
import com.github.binarywang.wxpay.bean.request.WxDepositRefundRequest;
|
||||
import com.github.binarywang.wxpay.bean.request.WxDepositUnfreezeRequest;
|
||||
import com.github.binarywang.wxpay.bean.request.WxDepositUnifiedOrderRequest;
|
||||
import com.github.binarywang.wxpay.bean.result.WxDepositConsumeResult;
|
||||
import com.github.binarywang.wxpay.bean.result.WxDepositOrderQueryResult;
|
||||
import com.github.binarywang.wxpay.bean.result.WxDepositRefundResult;
|
||||
import com.github.binarywang.wxpay.bean.result.WxDepositUnfreezeResult;
|
||||
import com.github.binarywang.wxpay.bean.result.WxDepositUnifiedOrderResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信押金支付相关接口.
|
||||
* <a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=1">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=1</a>
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
public interface WxDepositService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金下单
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=2">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=2</a>
|
||||
* 用于商户发起押金支付,支持JSAPI、NATIVE、APP等支付方式
|
||||
* </pre>
|
||||
*
|
||||
* @param request 押金下单请求对象
|
||||
* @return wx deposit unified order result
|
||||
* @throws WxPayException wx pay exception
|
||||
*/
|
||||
WxDepositUnifiedOrderResult unifiedOrder(WxDepositUnifiedOrderRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 查询押金订单
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=3">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=3</a>
|
||||
* 通过商户订单号或微信订单号查询押金订单状态
|
||||
* </pre>
|
||||
*
|
||||
* @param request 查询押金订单请求对象
|
||||
* @return wx deposit order query result
|
||||
* @throws WxPayException wx pay exception
|
||||
*/
|
||||
WxDepositOrderQueryResult queryOrder(WxDepositOrderQueryRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金消费
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=4">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=4</a>
|
||||
* 用于对已支付的押金进行消费扣减
|
||||
* </pre>
|
||||
*
|
||||
* @param request 押金消费请求对象
|
||||
* @return wx deposit consume result
|
||||
* @throws WxPayException wx pay exception
|
||||
*/
|
||||
WxDepositConsumeResult consume(WxDepositConsumeRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金撤销
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=5">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=5</a>
|
||||
* 用于对已支付的押金进行撤销退还
|
||||
* </pre>
|
||||
*
|
||||
* @param request 押金撤销请求对象
|
||||
* @return wx deposit unfreeze result
|
||||
* @throws WxPayException wx pay exception
|
||||
*/
|
||||
WxDepositUnfreezeResult unfreeze(WxDepositUnfreezeRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 押金退款
|
||||
* 详见:<a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=6">https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_7&index=6</a>
|
||||
* 用于对已消费的押金进行退款
|
||||
* </pre>
|
||||
*
|
||||
* @param request 押金退款请求对象
|
||||
* @return wx deposit refund result
|
||||
* @throws WxPayException wx pay exception
|
||||
*/
|
||||
WxDepositRefundResult refund(WxDepositRefundRequest request) throws WxPayException;
|
||||
}
|
||||
@@ -229,6 +229,13 @@ public interface WxPayService {
|
||||
*/
|
||||
WxEntrustPapService getWxEntrustPapService();
|
||||
|
||||
/**
|
||||
* 获取微信押金支付服务类
|
||||
*
|
||||
* @return deposit service
|
||||
*/
|
||||
WxDepositService getWxDepositService();
|
||||
|
||||
/**
|
||||
* 获取批量转账到零钱服务类.
|
||||
*
|
||||
|
||||
@@ -103,6 +103,9 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
|
||||
@Getter
|
||||
private final WxEntrustPapService wxEntrustPapService = new WxEntrustPapServiceImpl(this);
|
||||
|
||||
@Getter
|
||||
private final WxDepositService wxDepositService = new WxDepositServiceImpl(this);
|
||||
|
||||
@Getter
|
||||
private final PartnerTransferService partnerTransferService = new PartnerTransferServiceImpl(this);
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.github.binarywang.wxpay.service.impl;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.request.*;
|
||||
import com.github.binarywang.wxpay.bean.result.*;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.WxDepositService;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信押金支付服务实现
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class WxDepositServiceImpl implements WxDepositService {
|
||||
|
||||
private final WxPayService payService;
|
||||
|
||||
@Override
|
||||
public WxDepositUnifiedOrderResult unifiedOrder(WxDepositUnifiedOrderRequest request) throws WxPayException {
|
||||
request.checkAndSign(payService.getConfig());
|
||||
|
||||
String url = payService.getPayBaseUrl() + "/pay/depositpay";
|
||||
String responseContent = payService.post(url, request.toXML(), false);
|
||||
WxDepositUnifiedOrderResult result = BaseWxPayResult.fromXML(responseContent, WxDepositUnifiedOrderResult.class);
|
||||
result.checkResult(payService, request.getSignType(), true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxDepositOrderQueryResult queryOrder(WxDepositOrderQueryRequest request) throws WxPayException {
|
||||
request.checkAndSign(payService.getConfig());
|
||||
|
||||
String url = payService.getPayBaseUrl() + "/pay/depositorderquery";
|
||||
String responseContent = payService.post(url, request.toXML(), false);
|
||||
WxDepositOrderQueryResult result = BaseWxPayResult.fromXML(responseContent, WxDepositOrderQueryResult.class);
|
||||
result.checkResult(payService, request.getSignType(), true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxDepositConsumeResult consume(WxDepositConsumeRequest request) throws WxPayException {
|
||||
request.checkAndSign(payService.getConfig());
|
||||
|
||||
String url = payService.getPayBaseUrl() + "/pay/depositconsume";
|
||||
String responseContent = payService.post(url, request.toXML(), false);
|
||||
WxDepositConsumeResult result = BaseWxPayResult.fromXML(responseContent, WxDepositConsumeResult.class);
|
||||
result.checkResult(payService, request.getSignType(), true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxDepositUnfreezeResult unfreeze(WxDepositUnfreezeRequest request) throws WxPayException {
|
||||
request.checkAndSign(payService.getConfig());
|
||||
|
||||
String url = payService.getPayBaseUrl() + "/pay/depositreverse";
|
||||
String responseContent = payService.post(url, request.toXML(), false);
|
||||
WxDepositUnfreezeResult result = BaseWxPayResult.fromXML(responseContent, WxDepositUnfreezeResult.class);
|
||||
result.checkResult(payService, request.getSignType(), true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxDepositRefundResult refund(WxDepositRefundRequest request) throws WxPayException {
|
||||
request.checkAndSign(payService.getConfig());
|
||||
|
||||
String url = payService.getPayBaseUrl() + "/pay/depositrefund";
|
||||
String responseContent = payService.post(url, request.toXML(), true);
|
||||
WxDepositRefundResult result = BaseWxPayResult.fromXML(responseContent, WxDepositRefundResult.class);
|
||||
result.checkResult(payService, request.getSignType(), true);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.github.binarywang.wxpay.service.impl;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.request.*;
|
||||
import com.github.binarywang.wxpay.bean.result.*;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.testbase.ApiTestModule;
|
||||
import com.google.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信押金支付测试
|
||||
* </pre>
|
||||
*
|
||||
* @author Binary Wang
|
||||
* created on 2024-09-24
|
||||
*/
|
||||
@Test
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxDepositServiceTest {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Inject
|
||||
private WxPayService payService;
|
||||
|
||||
/**
|
||||
* 测试押金下单
|
||||
*/
|
||||
@Test
|
||||
public void testUnifiedOrder() throws WxPayException {
|
||||
WxDepositUnifiedOrderRequest request = WxDepositUnifiedOrderRequest.newBuilder()
|
||||
.body("共享单车押金")
|
||||
.outTradeNo("D" + System.currentTimeMillis())
|
||||
.totalFee(99)
|
||||
.spbillCreateIp("192.168.1.1")
|
||||
.notifyUrl("https://example.com/wxpay/notify")
|
||||
.tradeType("JSAPI")
|
||||
.openid("test_openid_123")
|
||||
.build();
|
||||
|
||||
try {
|
||||
WxDepositUnifiedOrderResult result = this.payService.getWxDepositService().unifiedOrder(request);
|
||||
logger.info("押金下单结果: {}", result);
|
||||
} catch (WxPayException e) {
|
||||
logger.error("押金下单失败", e);
|
||||
// For demo purposes, just log the error - tests need proper WeChat credentials to run
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试查询押金订单
|
||||
*/
|
||||
@Test
|
||||
public void testQueryOrder() throws WxPayException {
|
||||
WxDepositOrderQueryRequest request = WxDepositOrderQueryRequest.newBuilder()
|
||||
.outTradeNo("D1695559200000")
|
||||
.build();
|
||||
|
||||
try {
|
||||
WxDepositOrderQueryResult result = this.payService.getWxDepositService().queryOrder(request);
|
||||
logger.info("押金订单查询结果: {}", result);
|
||||
} catch (WxPayException e) {
|
||||
logger.error("押金订单查询失败", e);
|
||||
// For demo purposes, just log the error - tests need proper WeChat credentials to run
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试押金消费
|
||||
*/
|
||||
@Test
|
||||
public void testConsume() throws WxPayException {
|
||||
WxDepositConsumeRequest request = WxDepositConsumeRequest.newBuilder()
|
||||
.transactionId("1217752501201407033233368018")
|
||||
.outTradeNo("C" + System.currentTimeMillis())
|
||||
.consumeFee(10)
|
||||
.consumeDesc("单车使用费")
|
||||
.build();
|
||||
|
||||
try {
|
||||
WxDepositConsumeResult result = this.payService.getWxDepositService().consume(request);
|
||||
logger.info("押金消费结果: {}", result);
|
||||
} catch (WxPayException e) {
|
||||
logger.error("押金消费失败", e);
|
||||
// For demo purposes, just log the error - tests need proper WeChat credentials to run
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试押金撤销
|
||||
*/
|
||||
@Test
|
||||
public void testUnfreeze() throws WxPayException {
|
||||
WxDepositUnfreezeRequest request = WxDepositUnfreezeRequest.newBuilder()
|
||||
.transactionId("1217752501201407033233368018")
|
||||
.outTradeNo("U" + System.currentTimeMillis())
|
||||
.unfreezeFee(99)
|
||||
.unfreezeDesc("用户主动取消")
|
||||
.build();
|
||||
|
||||
try {
|
||||
WxDepositUnfreezeResult result = this.payService.getWxDepositService().unfreeze(request);
|
||||
logger.info("押金撤销结果: {}", result);
|
||||
} catch (WxPayException e) {
|
||||
logger.error("押金撤销失败", e);
|
||||
// For demo purposes, just log the error - tests need proper WeChat credentials to run
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试押金退款
|
||||
*/
|
||||
@Test
|
||||
public void testRefund() throws WxPayException {
|
||||
WxDepositRefundRequest request = WxDepositRefundRequest.newBuilder()
|
||||
.transactionId("1217752501201407033233368018")
|
||||
.outRefundNo("R" + System.currentTimeMillis())
|
||||
.refundFee(50)
|
||||
.refundDesc("部分退款")
|
||||
.build();
|
||||
|
||||
try {
|
||||
WxDepositRefundResult result = this.payService.getWxDepositService().refund(request);
|
||||
logger.info("押金退款结果: {}", result);
|
||||
} catch (WxPayException e) {
|
||||
logger.error("押金退款失败", e);
|
||||
// For demo purposes, just log the error - tests need proper WeChat credentials to run
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user