From 49bf3d3d507b307c41ea933cb137117bb2f3d485 Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Sat, 23 Jan 2021 11:38:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0V2=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 由于V3没有退款 所以暂时用V2退款代替 --- payment-spring-boot-autoconfigure/pom.xml | 4 +- .../payment/wechat/v2/WechatPayRefundApi.java | 57 +++++++++++++++++++ .../payment/wechat/v2/model/BaseModel.java | 2 +- .../payment/wechat/v2/model/RefundModel.java | 43 ++++++++++++++ .../wechat/v2/model/RefundQueryModel.java | 25 ++++++++ .../payment/wechat/v3/WechatPayClient.java | 2 +- .../payment/wechat/v3/model/Amount.java | 4 +- .../wechat/v3/model/CallbackParams.java | 28 +++++---- .../wechat/v3/model/ConsumeInformation.java | 8 +-- .../wechat/v3/model/CouponConsumeData.java | 36 ++++++------ .../payment/wechat/v3/model/GoodsDetail.java | 8 +-- .../v3/model/NormalCouponInformation.java | 4 +- .../wechat/v3/model/PromotionDetail.java | 44 ++++++++------ .../v3/model/SingleitemDiscountOff.java | 3 + .../v3/model/TransactionConsumeData.java | 48 +++++++++------- payment-spring-boot-starter/pom.xml | 4 +- pom.xml | 2 +- 17 files changed, 235 insertions(+), 87 deletions(-) create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/WechatPayRefundApi.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/RefundModel.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/RefundQueryModel.java diff --git a/payment-spring-boot-autoconfigure/pom.xml b/payment-spring-boot-autoconfigure/pom.xml index 47d2855..3099bbf 100644 --- a/payment-spring-boot-autoconfigure/pom.xml +++ b/payment-spring-boot-autoconfigure/pom.xml @@ -5,11 +5,11 @@ cn.felord payment-spring-boot - 1.0.4.RELEASE + 1.0.5.SNAPSHOT payment-spring-boot-autoconfigure - 1.0.4.RELEASE + 1.0.5.SNAPSHOT jar 4.0.0 diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/WechatPayRefundApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/WechatPayRefundApi.java new file mode 100644 index 0000000..a90a098 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/WechatPayRefundApi.java @@ -0,0 +1,57 @@ +/* + * Copyright 2019-2021 felord.cn + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * Website: + * https://felord.cn + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.felord.payment.wechat.v2; + +import cn.felord.payment.wechat.WechatPayProperties; +import cn.felord.payment.wechat.v2.model.RefundModel; +import com.fasterxml.jackson.databind.JsonNode; +import org.springframework.http.HttpMethod; + +/** + * The type Wechat pay refund api. + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +public class WechatPayRefundApi { + private final WechatV2Client wechatV2Client; + + /** + * Instantiates a new Wechat pay refund api. + * + * @param wechatV2Client the wechat v 2 client + */ + public WechatPayRefundApi(WechatV2Client wechatV2Client) { + this.wechatV2Client = wechatV2Client; + } + + /** + * 退款 + * + * @param refundModel the refund model + * @return json node + */ + public JsonNode transfer(RefundModel refundModel) { + WechatPayProperties.V3 v3 = wechatV2Client.getWechatMetaBean().getV3(); + refundModel.setAppid(v3.getAppId()); + refundModel.setMchId(v3.getMchId()); + return wechatV2Client.wechatPayRequest(refundModel, + HttpMethod.POST, + "https://api.mch.weixin.qq.com/secapi/pay/refund"); + } +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/BaseModel.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/BaseModel.java index 1cf0a47..98b1e36 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/BaseModel.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/BaseModel.java @@ -61,7 +61,7 @@ import java.security.cert.CertificateException; * @since 1.0.5.RELEASE */ @Getter -public class BaseModel { +public abstract class BaseModel { private static final XmlMapper XML_MAPPER = new XmlMapper(); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/RefundModel.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/RefundModel.java new file mode 100644 index 0000000..fe70b8f --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/RefundModel.java @@ -0,0 +1,43 @@ +/* + * Copyright 2019-2021 felord.cn + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * Website: + * https://felord.cn + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.felord.payment.wechat.v2.model; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class RefundModel extends BaseModel { + + private String appid; + private String mchId; + private String signType="MD5"; + private String transactionId; + private String outTradeNo; + private String outRefundNo; + private Integer totalFee; + private Integer refundFee; + private String refundFeeType="CNY"; + private String refundDesc; + private String refundAccount; + private String notifyUrl; + +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/RefundQueryModel.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/RefundQueryModel.java new file mode 100644 index 0000000..fe025b1 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v2/model/RefundQueryModel.java @@ -0,0 +1,25 @@ +/* + * Copyright 2019-2021 felord.cn + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * Website: + * https://felord.cn + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.felord.payment.wechat.v2.model; + +/** + * @author felord.cn + * @since 1.0.4.RELEASE + */ +public class RefundQueryModel { +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayClient.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayClient.java index e2011f0..09fd21f 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayClient.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayClient.java @@ -262,7 +262,7 @@ public class WechatPayClient { responseConsumer.accept(responseEntity); } } else { - throw new PayException("wechat pay signature failed, Request-ID " + requestId); + throw new PayException("wechat pay signature verify failed, Request-ID " + requestId); } } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Amount.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Amount.java index 621b14f..2c865b7 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Amount.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Amount.java @@ -29,11 +29,11 @@ import lombok.Data; @Data public class Amount { /** - * The Total. + * 金额,单位【分】。 */ private int total; /** - * The Currency. + * 货币单位,固定为 CNY 。 */ private String currency = "CNY"; } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CallbackParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CallbackParams.java index 65ec281..955ab54 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CallbackParams.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CallbackParams.java @@ -29,54 +29,58 @@ import lombok.Data; @Data public class CallbackParams { /** - * The Id. + * 通知Id */ private String id; /** - * The Create time. + * 通知创建时间 */ private String createTime; /** - * The Event type. + * 通知类型 + * @see cn.felord.payment.wechat.v3.WechatPayCallback */ private String eventType; /** - * The Resource type. + * 通知数据类型 */ private String resourceType; /** - * The Summary. + * 回调摘要 */ private String summary; /** - * The Resource. + * 通知数据 */ private Resource resource; /** - * The type Resource. + * 通知数据 + * + * @author felord.cn + * @since 1.0.0.RELEASE */ @Data public static class Resource { /** - * The Algorithm. + * 对开启结果数据进行加密的加密算法,目前只支持AEAD_AES_256_GCM。 */ private String algorithm; /** - * The Ciphertext. + * Base64编码后的开启/停用结果数据密文。 */ private String ciphertext; /** - * The Associated data. + * 附加数据。 */ private String associatedData; /** - * The Nonce. + * 加密使用的随机串。 */ private String nonce; /** - * The Original type. + * 原始回调类型。 */ private String originalType; } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/ConsumeInformation.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/ConsumeInformation.java index f172d1b..9df2b50 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/ConsumeInformation.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/ConsumeInformation.java @@ -32,22 +32,22 @@ import java.util.List; public class ConsumeInformation { /** - * The Consume mchid. + * 核销商户号 */ private String consumeMchid; /** - * The Consume time. + * 核销时间 YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE */ private String consumeTime; /** - * The Goods detail. + * 商户下单接口传的单品信息 */ private List goodsDetail; /** - * The Transaction id. + * 核销订单号 */ private String transactionId; diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponConsumeData.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponConsumeData.java index ed11112..4ddc50b 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponConsumeData.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponConsumeData.java @@ -18,6 +18,7 @@ */ package cn.felord.payment.wechat.v3.model; +import cn.felord.payment.wechat.enumeration.CouponStatus; import lombok.Data; /** @@ -30,67 +31,68 @@ import lombok.Data; public class CouponConsumeData { /** - * The Available begin time. + * 可用开始时间 YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE */ private String availableBeginTime; /** - * The Available end time. + * 可用结束时间 YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE */ private String availableEndTime; /** - * The Consume information. + * 实扣代金券信息 */ private ConsumeInformation consumeInformation; /** - * The Coupon id. + * 代金券id */ private String couponId; /** - * The Coupon name. + * 代金券名称 */ private String couponName; /** - * The Coupon type. + * 代金券类型 */ private CouponType couponType; /** - * The Create time. + * 领券时间 */ private String createTime; /** - * The Description. + * 代金券描述 */ private String description; /** - * The Discount to. + * 减至优惠特定信息 */ private DiscountTo discountTo; /** - * The No cash. + * 是否无资金流 */ private Boolean noCash; /** - * The Normal coupon information. + * 普通满减券信息 */ private NormalCouponInformation normalCouponInformation; /** - * The Singleitem. + * 是否单品优惠 */ private Boolean singleitem; /** - * The Singleitem discount off. + * 单品优惠特定信息 */ private SingleitemDiscountOff singleitemDiscountOff; /** - * The Status. + * 代金券状态 + * @see CouponStatus */ - private String status; + private CouponStatus status; /** - * The Stock creator mchid. + * 创建批次的商户号 */ private String stockCreatorMchid; /** - * The Stock id. + * 批次号 */ private String stockId; diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/GoodsDetail.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/GoodsDetail.java index 2093391..c9c246f 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/GoodsDetail.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/GoodsDetail.java @@ -30,19 +30,19 @@ import lombok.Data; public class GoodsDetail { /** - * The Discount amount. + * 优惠金额,单位【分】 */ private Long discountAmount; /** - * The Goods id. + * 单品券创建时录入的单品编码。 */ private String goodsId; /** - * The Price. + * 单品单价 */ private Long price; /** - * The Quantity. + * 单品数量 */ private Long quantity; diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/NormalCouponInformation.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/NormalCouponInformation.java index bb87836..73ab7a2 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/NormalCouponInformation.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/NormalCouponInformation.java @@ -30,11 +30,11 @@ import lombok.Data; public class NormalCouponInformation { /** - * The Coupon amount. + * 面额,单位:分。 */ private Long couponAmount; /** - * The Transaction minimum. + * 使用券金额门槛,单位:分。 */ private Long transactionMinimum; diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/PromotionDetail.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/PromotionDetail.java index a932d47..f8ca929 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/PromotionDetail.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/PromotionDetail.java @@ -24,7 +24,7 @@ import lombok.Data; import java.util.List; /** - * The type Promotion detail. + * 优惠功能 * * @author felord.cn * @since 1.0.0.RELEASE @@ -33,52 +33,60 @@ import java.util.List; public class PromotionDetail { /** - * The Amount. + * 优惠券面额,单位【分】 */ private Long amount; /** - * The Coupon id. + * 券ID */ private String couponId; /** - * The Currency. + * 优惠币种,内商户号仅支持人民币 CNY */ private String currency; /** - * The Goods detail. + * 单品列表信息 */ private List goodsDetail; /** - * The Merchant contribute. + * 商户出资,单位为分 */ private Long merchantContribute; /** - * The Name. + * 优惠名称 */ private String name; /** - * The Other contribute. + * 其他出资,单位为分 */ private Long otherContribute; /** - * The Scope. + * 优惠范围 + *
    + *
  • GLOBAL:全场代金券
  • + *
  • SINGLE:单品优惠
  • + *
*/ private String scope; /** - * The Stock id. + * 活动ID */ private String stockId; /** - * The Type. + * 优惠类型 + *
    + *
  • CASH:充值
  • + *
  • NOCASH:预充值
  • + *
*/ private String type; /** - * The Wechatpay contribute. + * 微信出资,单位为分 */ private Long wechatpayContribute; /** - * The type Goods detail. + * 单品列表信息 * * @author felord.cn * @since 1.0.0.RELEASE @@ -87,23 +95,23 @@ public class PromotionDetail { public static class GoodsDetail { /** - * The Goods id. + * 商品编码 */ private String goodsId; /** - * The Quantity. + * 商品数量 */ private Long quantity; /** - * The Unit price. + * 商品单价 */ private Long unitPrice; /** - * The Discount amount. + * 商品优惠金额,单位【分】 */ private Long discountAmount; /** - * The Goods remark. + * 商品备注 */ private String goodsRemark; diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/SingleitemDiscountOff.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/SingleitemDiscountOff.java index 0f556d4..7bf4a4d 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/SingleitemDiscountOff.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/SingleitemDiscountOff.java @@ -29,6 +29,9 @@ import lombok.Data; @Data public class SingleitemDiscountOff { + /** + * 单品最高优惠价格,单位:分。 + */ private Long singlePriceMax; } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/TransactionConsumeData.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/TransactionConsumeData.java index cf9ee6d..7976f52 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/TransactionConsumeData.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/TransactionConsumeData.java @@ -25,6 +25,8 @@ import lombok.Data; import java.util.List; /** + * 支付成功通知解密 + * * @author felord.cn * @since 1.0.0.RELEASE */ @@ -32,67 +34,71 @@ import java.util.List; public class TransactionConsumeData { /** - * The Amount. + * 订单金额 */ private Amount amount; /** - * The Appid. + * 应用ID */ private String appid; /** - * The Attach. + * 附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用 */ private String attach; /** - * The Bank type. + * 银行类型,采用字符串类型的银行标识。银行标识请参考 《银行类型对照表》 */ private String bankType; /** - * The Mchid. + * 商户号 */ private String mchid; /** - * The Out trade no. + * 商户订单号 */ private String outTradeNo; /** - * The Payer. + * 支付者信息 */ private Payer payer; /** - * The Promotion detail. + * 优惠功能,享受优惠时返回该字段。 */ private List promotionDetail; /** - * The Scene info. + * 支付场景信息描述 */ private SceneInfo sceneInfo; /** - * The Success time. + * 支付完成时间 YYYY-MM-DDTHH:mm:ss+TIMEZONE */ private String successTime; /** * 在 1.0.0.RELEASE 直接返回了枚举字符串,1.0.2.RELEASE 中变更为枚举 + * * @since 1.0.0.RELEASE */ private TradeState tradeState; /** - * The Trade state desc. + * 交易状态描述 */ private String tradeStateDesc; /** + * 交易类型 + *

* 在 1.0.0.RELEASE 直接返回了枚举字符串,1.0.2.RELEASE 中变更为枚举 + * * @since 1.0.0.RELEASE */ private TradeType tradeType; /** - * The Transaction id. + * 微信支付订单号 */ private String transactionId; /** - * The type Payer. + * 支付者信息 * * @author felord.cn * @since 1.0.0.RELEASE @@ -100,13 +106,13 @@ public class TransactionConsumeData { @Data public static class Payer { /** - * The Openid. + * 用户在直连商户appid下的唯一标识。 */ private String openid; } /** - * The type Scene info. + * 支付场景信息描述 * * @author felord.cn * @since 1.0.0.RELEASE @@ -114,13 +120,13 @@ public class TransactionConsumeData { @Data public static class SceneInfo { /** - * The Device id. + * 商户端设备号(门店号或收银设备ID)。 */ private String deviceId; } /** - * The type Amount. + * 订单金额 * * @author felord.cn * @since 1.0.0.RELEASE @@ -128,19 +134,19 @@ public class TransactionConsumeData { @Data public static class Amount { /** - * The Total. + * 订单总金额,单位为分。 */ private Integer total; /** - * The Payer total. + * 用户支付金额,单位为分。 */ private Integer payerTotal; /** - * The Currency. + * CNY:人民币,境内商户号仅支持人民币。 */ private String currency; /** - * The Payer currency. + * 用户支付币种 */ private String payerCurrency; } diff --git a/payment-spring-boot-starter/pom.xml b/payment-spring-boot-starter/pom.xml index 2bf3652..59d2cc1 100644 --- a/payment-spring-boot-starter/pom.xml +++ b/payment-spring-boot-starter/pom.xml @@ -5,11 +5,11 @@ cn.felord payment-spring-boot - 1.0.4.RELEASE + 1.0.5.SNAPSHOT payment-spring-boot-starter - 1.0.4.RELEASE + 1.0.5.SNAPSHOT jar 4.0.0 diff --git a/pom.xml b/pom.xml index 2d7d489..282b7c4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> cn.felord payment-spring-boot - 1.0.4.RELEASE + 1.0.5.SNAPSHOT pom 4.0.0