From edbf4dcbc74c3ff360a6348b8c40b41d85f95761 Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Mon, 11 Jan 2021 14:32:07 +0800 Subject: [PATCH 1/9] =?UTF-8?q?refactor:=20=E7=8E=B0=E5=9C=A8app=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E3=80=81=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=89=80=E6=9C=89=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=E6=94=AF=E4=BB=98=E7=9A=84=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=86=8D=E9=9C=80=E8=A6=81=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=86=8D=E8=BF=9B=E8=A1=8C=E7=AD=BE=E5=90=8D=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/wechat/v3/SignatureProvider.java | 42 +++++++--- .../payment/wechat/v3/WechatDirectPayApi.java | 79 ++++++++++++++++++- 2 files changed, 109 insertions(+), 12 deletions(-) diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java index 7611470..900ec7c 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java @@ -70,7 +70,7 @@ public class SignatureProvider { /** * The constant ID_GENERATOR. */ - private static final IdGenerator ID_GENERATOR = new AlternativeJdkIdGenerator(); + private final IdGenerator nonceStrGenerator = new AlternativeJdkIdGenerator(); /** * The constant SCHEMA. */ @@ -114,18 +114,14 @@ public class SignatureProvider { */ @SneakyThrows public String requestSign(String tenantId, String method, String canonicalUrl, String body) { - Signature signer = Signature.getInstance("SHA256withRSA"); - WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId); - signer.initSign(wechatMetaBean.getKeyPair().getPrivate()); long timestamp = System.currentTimeMillis() / 1000; - String nonceStr = ID_GENERATOR.generateId() + String nonceStr = nonceStrGenerator.generateId() .toString() .replaceAll("-", ""); - final String signatureStr = createSign(method, canonicalUrl, String.valueOf(timestamp), nonceStr, body); - signer.update(signatureStr.getBytes(StandardCharsets.UTF_8)); - String encode = Base64Utils.encodeToString(signer.sign()); - + WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId); + PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate(); + String encode = this.doRequestSign(privateKey, method, canonicalUrl, String.valueOf(timestamp), nonceStr, body); // 序列号 String serialNo = wechatMetaBean.getSerialNumber(); // 生成token @@ -135,6 +131,24 @@ public class SignatureProvider { return SCHEMA.concat(token); } + + /** + * Do request sign. + * + * @param privateKey the private key + * @param orderedComponents the orderedComponents + * @return the string + * @since 1.0.4.RELEASE + */ + @SneakyThrows + public String doRequestSign(PrivateKey privateKey, String... orderedComponents) { + Signature signer = Signature.getInstance("SHA256withRSA"); + signer.initSign(privateKey); + final String signatureStr = createSign(orderedComponents); + signer.update(signatureStr.getBytes(StandardCharsets.UTF_8)); + return Base64Utils.encodeToString(signer.sign()); + } + /** * 我方对响应验签,和应答签名做比较,使用微信平台证书. * @@ -257,6 +271,16 @@ public class SignatureProvider { return wechatMetaContainer; } + /** + * Nonce generator. + * + * @return the id generator + * @since 1.0.4.RELEASE + */ + public IdGenerator nonceStrGenerator() { + return nonceStrGenerator; + } + /** * 请求时设置签名 组件 * diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java index 101264c..64cb11d 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java @@ -18,18 +18,22 @@ */ package cn.felord.payment.wechat.v3; -import cn.felord.payment.wechat.enumeration.WeChatServer; +import cn.felord.payment.PayException; import cn.felord.payment.wechat.WechatPayProperties; +import cn.felord.payment.wechat.enumeration.WeChatServer; import cn.felord.payment.wechat.enumeration.WechatPayV3Type; import cn.felord.payment.wechat.v3.model.PayParams; import cn.felord.payment.wechat.v3.model.TransactionQueryParams; import com.fasterxml.jackson.databind.node.ObjectNode; +import org.springframework.http.HttpStatus; import org.springframework.http.RequestEntity; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.util.UriComponentsBuilder; import java.net.URI; +import java.security.PrivateKey; +import java.util.Objects; /** * 普通支付-直连模式. @@ -59,7 +63,43 @@ public class WechatDirectPayApi extends AbstractApi { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); this.client().withType(WechatPayV3Type.APP, payParams) .function(this::payFunction) - .consumer(wechatResponseEntity::convert) + .consumer(responseEntity -> { + int httpStatus = HttpStatus.BAD_REQUEST.value(); + ObjectNode body = null; + if (Objects.nonNull(responseEntity)) { + httpStatus = responseEntity.getStatusCodeValue(); + body = responseEntity.getBody(); + if (Objects.isNull(body)) { + throw new PayException("response body cannot be resolved"); + } + String timestamp = String.valueOf(System.currentTimeMillis() / 1000); + + SignatureProvider signatureProvider = this.client().signatureProvider(); + String nonceStr = signatureProvider.nonceStrGenerator() + .generateId() + .toString() + .replaceAll("-", ""); + + WechatMetaContainer wechatMetaContainer = signatureProvider.wechatMetaContainer(); + + WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId()); + PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate(); + String appId = wechatMetaBean.getV3().getAppId(); + String prepayId = body.get("prepay_id").asText(); + String paySign = signatureProvider.doRequestSign(privateKey, appId, timestamp, nonceStr, prepayId); + body.put("appid", appId); + String mchId = wechatMetaBean.getV3().getMchId(); + body.put("partnerid", mchId); + body.put("prepayid", prepayId); + body.put("package", "Sign=WXPay"); + body.put("nonceStr", nonceStr); + body.put("timeStamp", timestamp); + body.put("signType", "RSA"); + body.put("paySign", paySign); + } + wechatResponseEntity.setHttpStatus(httpStatus); + wechatResponseEntity.setBody(body); + }) .request(); return wechatResponseEntity; } @@ -74,7 +114,40 @@ public class WechatDirectPayApi extends AbstractApi { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); this.client().withType(WechatPayV3Type.JSAPI, payParams) .function(this::payFunction) - .consumer(wechatResponseEntity::convert) + .consumer(responseEntity -> { + int httpStatus = HttpStatus.BAD_REQUEST.value(); + ObjectNode body = null; + if (Objects.nonNull(responseEntity)) { + httpStatus = responseEntity.getStatusCodeValue(); + body = responseEntity.getBody(); + if (Objects.isNull(body)) { + throw new PayException("response body cannot be resolved"); + } + String timestamp = String.valueOf(System.currentTimeMillis() / 1000); + + SignatureProvider signatureProvider = this.client().signatureProvider(); + String nonceStr = signatureProvider.nonceStrGenerator() + .generateId() + .toString() + .replaceAll("-", ""); + + String packageStr = "prepay_id=" + body.get("prepay_id").asText(); + WechatMetaContainer wechatMetaContainer = signatureProvider.wechatMetaContainer(); + + WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId()); + PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate(); + String appId = wechatMetaBean.getV3().getAppId(); + String paySign = signatureProvider.doRequestSign(privateKey, appId, timestamp, nonceStr, packageStr); + body.put("appId", appId); + body.put("timeStamp", timestamp); + body.put("nonceStr", nonceStr); + body.put("package", packageStr); + body.put("signType", "RSA"); + body.put("paySign", paySign); + } + wechatResponseEntity.setHttpStatus(httpStatus); + wechatResponseEntity.setBody(body); + }) .request(); return wechatResponseEntity; } From ceeba2e3c352d93acb7e181670425abccba19c08 Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Mon, 11 Jan 2021 16:03:50 +0800 Subject: [PATCH 2/9] docs --- README.md | 2 +- docs/README.md | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 411a1e5..53acc52 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 微信支付 Spring Boot 组件 +# 最好用的微信支付V3 Spring Boot 组件 为了满足业务中出现app支付、公众号支付、小程序支付等多appid并存的场景,对原有的进行了增强开发出了多租户版本。 diff --git a/docs/README.md b/docs/README.md index 6a5a65e..762442e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,10 +18,14 @@ - [x] **微信支付V3** 全量支持,并支持多租户以同时满足移动应用App、公众号、小程序等支付场景 - [x] **支付宝** 集成SDK,作简单适配 -## 微信支付V3进度 -- 微信支付营销-代金券 `WechatMarketingFavorApi` 100% -- 微信支付 支付功能-普通支付直连模式 `WechatDirectPayApi` 100% -- 微信合单支付 `WechatCombinePayApi` 100% +## 功能 +- 实现微信支付多商户 +- 集成支付宝SDK、快速接入Spring Boot +- 实现微信支付V3 基础支付 +- 实现微信支付V3 合单支付 +- 实现微信支付V3 代金券 +- 实现微信支付V3 微信支付分 +- 实现微信支付V3 先享卡 ## Maven 中央仓库坐标 > 推荐使用最新版本 From a584a65b25ee78eb5098c8b5d0e83758c66da7f2 Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Tue, 12 Jan 2021 21:40:28 +0800 Subject: [PATCH 3/9] java doc --- README.md | 5 +++++ .../wechat/v3/model/CouponAvailableTime.java | 19 +++++++++++++++---- .../wechat/v3/model/CouponUseRule.java | 8 +------- .../payment/wechat/v3/model/Detail.java | 2 +- .../payment/wechat/v3/model/DiscountTo.java | 6 +++--- .../wechat/v3/model/FixAvailableTime.java | 16 ++++++++++++---- .../v3/model/TransactionQueryParams.java | 12 ++++++++++++ 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 53acc52..3442137 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,11 @@ - 实现微信支付V3 微信支付分 - 实现微信支付V3 先享卡 +## 核心API结构 +![](https://asset.felord.cn/blog/20210112211759.png) + +> 随着版本迭代会增加 + ## 开源协议 **Apache 2.0** diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponAvailableTime.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponAvailableTime.java index dff3444..dea379c 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponAvailableTime.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponAvailableTime.java @@ -21,7 +21,7 @@ package cn.felord.payment.wechat.v3.model; import lombok.Data; /** - * The type Coupon available time. + * 代金券生效时间 * * @author felord.cn * @since 1.0.0.RELEASE @@ -29,15 +29,26 @@ import lombok.Data; @Data public class CouponAvailableTime { /** - * The Available time after receive. + * 领取后有效时间,【单位:分钟】 + *

+ * 领取后,券的结束时间为领取N天后,如设置领取后7天有效,那么7月1日领券,在7月7日23:59:59失效(在可用时间内计算失效时间,若券还未到领取后N天,但是已经到了可用结束时间,那么也会过期) */ private Long availableTimeAfterReceive; /** - * The Fix available time. + * 固定时间段可用 */ private FixAvailableTime fixAvailableTime; /** - * The Second day available. + * 领取后N天有效 + *

+ * 领取后,券的开始时间为领券后第二天,如7月1日领券,那么在7月2日00:00:00开始。 + * 当设置领取后N天有效时,不可设置固定时间段可用。枚举值: + * + *

    + *
  • true:是
  • + *
  • false:否
  • + *
+ * */ private Boolean secondDayAvailable; } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponUseRule.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponUseRule.java index a3f13c5..bc7fba6 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponUseRule.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponUseRule.java @@ -30,32 +30,26 @@ import java.util.List; @Data public class CouponUseRule { - /** * 可核销商品编码 */ private List availableItems; - /** * 可用商户 */ private List availableMerchants; - /** * 是否可以叠加使用 */ private Boolean combineUse; - /** - * 券生效时间 + * 券生效时间(暂时未开放,日期2021-1-12,请以微信官方通知为准) */ private CouponAvailableTime couponAvailableTime; - /** * 固定面额满减券使用规则 */ private FixedNormalCoupon fixedNormalCoupon; - /** * 订单优惠标记 */ diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Detail.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Detail.java index 2c2381f..21cc021 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Detail.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/Detail.java @@ -23,7 +23,7 @@ import lombok.Data; import java.util.List; /** - * The type Detail. + * 支付优惠功能. * * @author felord.cn * @since 1.0.0.RELEASE diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/DiscountTo.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/DiscountTo.java index 2b07faf..7136d0f 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/DiscountTo.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/DiscountTo.java @@ -21,7 +21,7 @@ package cn.felord.payment.wechat.v3.model; import lombok.Data; /** - * 减至优惠限定字段,仅减至优惠场景有返回 + * 微信代金券核销通知参数-减至优惠限定字段,仅减至优惠场景有返回 * * @author felord.cn * @since 1.0.0.RELEASE @@ -30,11 +30,11 @@ import lombok.Data; public class DiscountTo { /** - * The Cut to price. + * 减至后优惠单价,单位:分。 */ private Long cutToPrice; /** - * The Max price. + * 可享受优惠的最高价格,单位:分。 */ private Long maxPrice; diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/FixAvailableTime.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/FixAvailableTime.java index ae6ba94..4e66698 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/FixAvailableTime.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/FixAvailableTime.java @@ -23,7 +23,9 @@ import lombok.Data; import java.util.List; /** - * The type Fix available time. + * 固定时间段可用 + *

+ * 允许指定券在特殊时间段生效。当设置固定时间段可用时不可设置领取后N天有效 * * @author felord.cn * @since 1.0.0.RELEASE @@ -32,15 +34,21 @@ import java.util.List; public class FixAvailableTime { /** - * The Available week day. + * 可用星期数 + * + * 允许指定每周固定星期数生效,0代表周日生效,1代表周一生效,以此类推;不填则代表在可用时间内周一至周日都生效。 */ private List availableWeekDay; /** - * The Begin time. + * 允许指定特殊生效星期数中的具体生效的时间段。 + * + * 当天开始时间,单位:秒。 */ private Long beginTime; /** - * The End time. + * 允许指定特殊生效星期数中的具体生效的时间段。 + * + * 当天结束时间,单位:秒,默认为23点59分59秒。 */ private Long endTime; diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/TransactionQueryParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/TransactionQueryParams.java index 05096c1..14a2dc0 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/TransactionQueryParams.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/TransactionQueryParams.java @@ -18,14 +18,26 @@ */ package cn.felord.payment.wechat.v3.model; +import cn.felord.payment.wechat.v3.WechatDirectPayApi; import lombok.Data; /** + * 微信支付订单号查询API请求参数. + * * @author felord.cn * @since 1.0.0.RELEASE */ @Data public class TransactionQueryParams { + /** + * 商户id + */ private String mchId; + /** + *

    + *
  • 调用 {@link WechatDirectPayApi#queryTransactionByOutTradeNo(TransactionQueryParams)} 传递【商户侧订单号】
  • + *
  • 调用 {@link WechatDirectPayApi#queryTransactionById(TransactionQueryParams)} (TransactionQueryParams)} 传递【微信支付订单号】
  • + *
+ */ private String transactionIdOrOutTradeNo; } From c96e0142732d14b6c56e9437b0e95dcc69502c10 Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Sat, 16 Jan 2021 23:38:29 +0800 Subject: [PATCH 4/9] =?UTF-8?q?refactor:=20=E5=AF=B9=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=B8=80=E4=BA=9B=E9=87=8D=E6=9E=84=E5=92=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20-=20=E8=AF=BB=E5=8F=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=90=8E=E5=AF=B9=E6=B5=81=E8=BF=9B=E8=A1=8C=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=20-=20=E4=BB=A3=E9=87=91=E5=88=B8=E3=80=81?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E6=89=B9=E6=AC=A1=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E6=98=AF=E6=9E=9A=E4=B8=BE=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=20-=20=E6=97=B6=E9=97=B4=E6=88=B3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/alipay/AliPayConfiguration.java | 12 +- .../payment/wechat/enumeration/StockType.java | 44 ++++++ .../wechat/enumeration/UnfinishedReason.java | 2 +- .../payment/wechat/v3/SignatureProvider.java | 6 +- .../payment/wechat/v3/WechatDirectPayApi.java | 125 +++++++++--------- .../wechat/v3/model/StocksCreateParams.java | 5 +- 6 files changed, 120 insertions(+), 74 deletions(-) create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/StockType.java diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/alipay/AliPayConfiguration.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/alipay/AliPayConfiguration.java index 110f64c..564089c 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/alipay/AliPayConfiguration.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/alipay/AliPayConfiguration.java @@ -32,10 +32,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; +import java.io.*; /** * @author felord.cn @@ -78,9 +75,12 @@ public class AliPayConfiguration { private String appRSAPrivateKey(String classPath) { + ClassPathResource resource = new ClassPathResource(classPath); try { - File file = new ClassPathResource(classPath).getFile(); - return new BufferedReader(new FileReader(file)).readLine(); + FileReader in = new FileReader(resource.getFile()); + try(BufferedReader bufferedReader = new BufferedReader(in)){ + return bufferedReader.readLine(); + } } catch (IOException e) { log.error("ali pay app private key is required ,{}", e.getMessage()); throw new PayException("ali pay app private key is required"); diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/StockType.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/StockType.java new file mode 100644 index 0000000..9f9c78f --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/StockType.java @@ -0,0 +1,44 @@ +/* + * 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.enumeration; + +/** + * 代金券、商家券批次类型 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +public enum StockType { + /** + * 固定面额满减券批次 + * + * @since 1.0.4.RELEASE + */ + NORMAL, + /** + * 折扣券批次 + * + * @since 1.0.4.RELEASE + */ + DISCOUNT, + /** + * 换购券批次 + * + * @since 1.0.4.RELEASE + */ + EXCHANGE; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/UnfinishedReason.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/UnfinishedReason.java index f705629..a00692e 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/UnfinishedReason.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/UnfinishedReason.java @@ -21,7 +21,7 @@ package cn.felord.payment.wechat.enumeration; * 未完成约定原因 *

* 当订单守约状态为{@link ContractStatus#UNFINISHED},返回此字段 - * + * @author felord.cn * @since 1.0.3.RELEASE */ public enum UnfinishedReason { diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java index 900ec7c..1397578 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/SignatureProvider.java @@ -19,10 +19,10 @@ package cn.felord.payment.wechat.v3; +import cn.felord.payment.PayException; import cn.felord.payment.wechat.enumeration.WeChatServer; import cn.felord.payment.wechat.enumeration.WechatPayV3Type; import cn.felord.payment.wechat.v3.model.ResponseSignVerifyParams; -import cn.felord.payment.PayException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -46,6 +46,8 @@ import java.security.*; import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.Arrays; import java.util.Collections; import java.util.Map; @@ -115,7 +117,7 @@ public class SignatureProvider { @SneakyThrows public String requestSign(String tenantId, String method, String canonicalUrl, String body) { - long timestamp = System.currentTimeMillis() / 1000; + long timestamp = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")); String nonceStr = nonceStrGenerator.generateId() .toString() .replaceAll("-", ""); diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java index 64cb11d..c537ab4 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatDirectPayApi.java @@ -25,7 +25,6 @@ import cn.felord.payment.wechat.enumeration.WechatPayV3Type; import cn.felord.payment.wechat.v3.model.PayParams; import cn.felord.payment.wechat.v3.model.TransactionQueryParams; import com.fasterxml.jackson.databind.node.ObjectNode; -import org.springframework.http.HttpStatus; import org.springframework.http.RequestEntity; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -33,6 +32,8 @@ import org.springframework.web.util.UriComponentsBuilder; import java.net.URI; import java.security.PrivateKey; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.Objects; /** @@ -64,40 +65,38 @@ public class WechatDirectPayApi extends AbstractApi { this.client().withType(WechatPayV3Type.APP, payParams) .function(this::payFunction) .consumer(responseEntity -> { - int httpStatus = HttpStatus.BAD_REQUEST.value(); - ObjectNode body = null; - if (Objects.nonNull(responseEntity)) { - httpStatus = responseEntity.getStatusCodeValue(); - body = responseEntity.getBody(); - if (Objects.isNull(body)) { - throw new PayException("response body cannot be resolved"); - } - String timestamp = String.valueOf(System.currentTimeMillis() / 1000); - - SignatureProvider signatureProvider = this.client().signatureProvider(); - String nonceStr = signatureProvider.nonceStrGenerator() - .generateId() - .toString() - .replaceAll("-", ""); - - WechatMetaContainer wechatMetaContainer = signatureProvider.wechatMetaContainer(); - - WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId()); - PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate(); - String appId = wechatMetaBean.getV3().getAppId(); - String prepayId = body.get("prepay_id").asText(); - String paySign = signatureProvider.doRequestSign(privateKey, appId, timestamp, nonceStr, prepayId); - body.put("appid", appId); - String mchId = wechatMetaBean.getV3().getMchId(); - body.put("partnerid", mchId); - body.put("prepayid", prepayId); - body.put("package", "Sign=WXPay"); - body.put("nonceStr", nonceStr); - body.put("timeStamp", timestamp); - body.put("signType", "RSA"); - body.put("paySign", paySign); + ObjectNode body = responseEntity.getBody(); + if (Objects.isNull(body)) { + throw new PayException("response body cannot be resolved"); } - wechatResponseEntity.setHttpStatus(httpStatus); + + SignatureProvider signatureProvider = this.client().signatureProvider(); + WechatMetaContainer wechatMetaContainer = signatureProvider.wechatMetaContainer(); + WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId()); + PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate(); + + String appId = wechatMetaBean.getV3().getAppId(); + long epochSecond = LocalDateTime.now() + .toEpochSecond(ZoneOffset.of("+8")); + String timestamp = String.valueOf(epochSecond); + String nonceStr = signatureProvider.nonceStrGenerator() + .generateId() + .toString() + .replaceAll("-", ""); + String prepayId = body.get("prepay_id").asText(); + String paySign = signatureProvider.doRequestSign(privateKey, appId, timestamp, nonceStr, prepayId); + String mchId = wechatMetaBean.getV3().getMchId(); + + body.put("appid", appId); + body.put("partnerid", mchId); + body.put("prepayid", prepayId); + body.put("package", "Sign=WXPay"); + body.put("nonceStr", nonceStr); + body.put("timeStamp", timestamp); + body.put("signType", "RSA"); + body.put("paySign", paySign); + + wechatResponseEntity.setHttpStatus(responseEntity.getStatusCodeValue()); wechatResponseEntity.setBody(body); }) .request(); @@ -115,37 +114,35 @@ public class WechatDirectPayApi extends AbstractApi { this.client().withType(WechatPayV3Type.JSAPI, payParams) .function(this::payFunction) .consumer(responseEntity -> { - int httpStatus = HttpStatus.BAD_REQUEST.value(); - ObjectNode body = null; - if (Objects.nonNull(responseEntity)) { - httpStatus = responseEntity.getStatusCodeValue(); - body = responseEntity.getBody(); - if (Objects.isNull(body)) { - throw new PayException("response body cannot be resolved"); - } - String timestamp = String.valueOf(System.currentTimeMillis() / 1000); - - SignatureProvider signatureProvider = this.client().signatureProvider(); - String nonceStr = signatureProvider.nonceStrGenerator() - .generateId() - .toString() - .replaceAll("-", ""); - - String packageStr = "prepay_id=" + body.get("prepay_id").asText(); - WechatMetaContainer wechatMetaContainer = signatureProvider.wechatMetaContainer(); - - WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId()); - PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate(); - String appId = wechatMetaBean.getV3().getAppId(); - String paySign = signatureProvider.doRequestSign(privateKey, appId, timestamp, nonceStr, packageStr); - body.put("appId", appId); - body.put("timeStamp", timestamp); - body.put("nonceStr", nonceStr); - body.put("package", packageStr); - body.put("signType", "RSA"); - body.put("paySign", paySign); + ObjectNode body = responseEntity.getBody(); + if (Objects.isNull(body)) { + throw new PayException("response body cannot be resolved"); } - wechatResponseEntity.setHttpStatus(httpStatus); + + SignatureProvider signatureProvider = this.client().signatureProvider(); + WechatMetaContainer wechatMetaContainer = signatureProvider.wechatMetaContainer(); + WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId()); + PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate(); + + String appId = wechatMetaBean.getV3().getAppId(); + long epochSecond = LocalDateTime.now() + .toEpochSecond(ZoneOffset.of("+8")); + String timestamp = String.valueOf(epochSecond); + String nonceStr = signatureProvider.nonceStrGenerator() + .generateId() + .toString() + .replaceAll("-", ""); + String packageStr = "prepay_id=" + body.get("prepay_id").asText(); + String paySign = signatureProvider.doRequestSign(privateKey, appId, timestamp, nonceStr, packageStr); + + body.put("appId", appId); + body.put("timeStamp", timestamp); + body.put("nonceStr", nonceStr); + body.put("package", packageStr); + body.put("signType", "RSA"); + body.put("paySign", paySign); + + wechatResponseEntity.setHttpStatus(responseEntity.getStatusCodeValue()); wechatResponseEntity.setBody(body); }) .request(); diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksCreateParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksCreateParams.java index dae859b..6ae6dee 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksCreateParams.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksCreateParams.java @@ -17,6 +17,7 @@ */ package cn.felord.payment.wechat.v3.model; +import cn.felord.payment.wechat.enumeration.StockType; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; @@ -62,8 +63,10 @@ public class StocksCreateParams { private Boolean noCash; /** * 批次类型 + * + * @since 1.0.4.RELEASE */ - private String stockType = "NORMAL"; + private StockType stockType = StockType.NORMAL; /** * 商户单据号 */ From 22bdc4550d1090980fdefcb85a9cb279b7fc2e44 Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Sun, 17 Jan 2021 20:29:45 +0800 Subject: [PATCH 5/9] =?UTF-8?q?feat:=20=E4=BB=A3=E9=87=91=E5=88=B8?= =?UTF-8?q?=E7=94=9F=E6=88=90api=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 代金券核销规则优化 BREAKING CHANGE: 代金券核销规则-支付方式由Sring修改为枚举 --- .../wechat/v3/model/CouponUseRule.java | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponUseRule.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponUseRule.java index bc7fba6..b9566b4 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponUseRule.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponUseRule.java @@ -22,7 +22,7 @@ import lombok.Data; import java.util.List; /** - * 核销规则. + * 代金券核销规则. * * @author felord.cn * @since 1.0.0.RELEASE @@ -74,8 +74,9 @@ public class CouponUseRule { *

  • FACE:人脸支付
  • *
  • OTHER:其他支付
  • * + * 不填则默认“不限” */ - private String tradeType; + private CouponTradeType tradeType; /** @@ -100,4 +101,50 @@ public class CouponUseRule { */ private List bin; } + + /** + * 代金券核销规则-支付方式. + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ + public enum CouponTradeType { + /** + * 小程序支付 + * + * @since 1.0.4.RELEASE + */ + MICROAPP, + /** + * APP支付 + * + * @since 1.0.4.RELEASE + */ + APPPAY, + /** + * 免密支付 + * + * @since 1.0.4.RELEASE + */ + PPAY, + /** + * 刷卡支付 + * + * @since 1.0.4.RELEASE + */ + CARD, + /** + * 人脸支付 + * + * @since 1.0.4.RELEASE + */ + FACE, + /** + * 其他支付 + * + * @since 1.0.4.RELEASE + */ + OTHER, + } + } From 748ab7b4d05b909920c83c906969fcd21b18b2dc Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Mon, 18 Jan 2021 11:37:42 +0800 Subject: [PATCH 6/9] =?UTF-8?q?feat:=20=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=95=86=E5=AE=B6=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加微信支付商家券所有接口的实现 --- .../enumeration/BusiFavorCodeDisplayMode.java | 38 ++ .../enumeration/BusiFavorUseMethod.java | 51 ++ .../wechat/enumeration/CouponStatus.java | 2 +- .../enumeration/FundFlowAccountType.java | 1 + .../payment/wechat/enumeration/StockType.java | 2 +- .../wechat/enumeration/WechatPayV3Type.java | 87 +++- .../v3/ExtensionFormHttpMessageConverter.java | 43 +- .../payment/wechat/v3/WechatApiProvider.java | 11 + .../v3/WechatMarketingBusiFavorApi.java | 438 ++++++++++++++++++ .../wechat/v3/WechatMarketingFavorApi.java | 9 +- .../payment/wechat/v3/WechatPayCallback.java | 50 +- .../wechat/v3/model/StocksCreateParams.java | 4 +- .../model/busifavor/AvailableDayTimeItem.java | 38 ++ .../v3/model/busifavor/AvailableWeek.java | 48 ++ .../busifavor/BusiCouponCodeUploadParams.java | 46 ++ .../busifavor/BusiFavorAssociateInfo.java | 47 ++ .../busifavor/BusiFavorBudgetParams.java | 54 +++ .../BusiFavorCallbackSettingParams.java | 38 ++ .../busifavor/BusiFavorCreateParams.java | 112 +++++ .../busifavor/BusiFavorDeactivateParams.java | 46 ++ .../busifavor/BusiFavorNotifyConfig.java | 37 ++ .../BusiFavorReceiveConsumeData.java | 162 +++++++ .../busifavor/BusiFavorRefundParams.java | 42 ++ .../busifavor/BusiFavorUpdateParams.java | 159 +++++++ .../model/busifavor/BusiFavorUseParams.java | 58 +++ .../model/busifavor/CouponAvailableTime.java | 74 +++ .../v3/model/busifavor/CouponUseRule.java | 71 +++ .../v3/model/busifavor/CustomEntrance.java | 58 +++ .../v3/model/busifavor/DiscountCoupon.java | 25 + .../model/busifavor/DisplayPatternInfo.java | 60 +++ .../v3/model/busifavor/ExchangeCoupon.java | 42 ++ .../v3/model/busifavor/FixedNormalCoupon.java | 26 ++ .../IrregularyAvaliableTimeItem.java | 42 ++ .../v3/model/busifavor/MiniProgramsInfo.java | 48 ++ .../v3/model/busifavor/StockSendRule.java | 51 ++ .../busifavor/UserBusiCouponQueryParams.java | 42 ++ .../busifavor/UserBusiFavorQueryParams.java | 67 +++ 37 files changed, 2195 insertions(+), 34 deletions(-) create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/BusiFavorCodeDisplayMode.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/BusiFavorUseMethod.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingBusiFavorApi.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/AvailableDayTimeItem.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/AvailableWeek.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiCouponCodeUploadParams.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorAssociateInfo.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorBudgetParams.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorCallbackSettingParams.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorCreateParams.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorDeactivateParams.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorNotifyConfig.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorReceiveConsumeData.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorRefundParams.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorUpdateParams.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorUseParams.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CouponAvailableTime.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CouponUseRule.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CustomEntrance.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/DiscountCoupon.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/DisplayPatternInfo.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/ExchangeCoupon.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/FixedNormalCoupon.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/IrregularyAvaliableTimeItem.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/MiniProgramsInfo.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/StockSendRule.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/UserBusiCouponQueryParams.java create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/UserBusiFavorQueryParams.java diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/BusiFavorCodeDisplayMode.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/BusiFavorCodeDisplayMode.java new file mode 100644 index 0000000..afd503c --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/BusiFavorCodeDisplayMode.java @@ -0,0 +1,38 @@ +/* + * 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.enumeration; + +/** + * code展示模式 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +public enum BusiFavorCodeDisplayMode { + /** + * 不展示code + */ + NOT_SHOW, + /** + * 一维码(条形码) + */ + BARCODE, + /** + * 二维码 + */ + QRCODE +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/BusiFavorUseMethod.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/BusiFavorUseMethod.java new file mode 100644 index 0000000..90323a2 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/BusiFavorUseMethod.java @@ -0,0 +1,51 @@ +/* + * 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.enumeration; + +/** + * 商家券核销方式 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +public enum BusiFavorUseMethod { + + /** + * 线下滴码核销,点击券“立即使用”跳转展示券二维码详情。 + * + * @since 1.0.4.RELEASE + */ + OFF_LINE, + /** + * 线上小程序核销,点击券“立即使用”跳转至配置的商家小程序(需要添加小程序appid和path)。 + * + * @since 1.0.4.RELEASE + */ + MINI_PROGRAMS, + /** + * 微信支付付款码核销,点击券“立即使用”跳转至微信支付钱包付款码。 + * + * @since 1.0.4.RELEASE + */ + PAYMENT_CODE, + /** + * 用户自助核销,点击券“立即使用”跳转至用户自助操作核销界面(当前暂不支持用户自助核销)。 + * + * @since 1.0.4.RELEASE + */ + SELF_CONSUME; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/CouponStatus.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/CouponStatus.java index 0c534c0..a52976c 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/CouponStatus.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/CouponStatus.java @@ -19,7 +19,7 @@ package cn.felord.payment.wechat.enumeration; /** - * 代金券状态. + * 代金券、商家券状态. * * @author felord.cn * @since 1.0.0.RELEASE diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/FundFlowAccountType.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/FundFlowAccountType.java index effbbf8..6e94b9c 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/FundFlowAccountType.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/FundFlowAccountType.java @@ -20,6 +20,7 @@ package cn.felord.payment.wechat.enumeration; /** * 申请资金账单账户类型. * + * @author felord.cn * @since 1.0.3.RELEASE */ public enum FundFlowAccountType { diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/StockType.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/StockType.java index 9f9c78f..2eb4804 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/StockType.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/StockType.java @@ -40,5 +40,5 @@ public enum StockType { * * @since 1.0.4.RELEASE */ - EXCHANGE; + EXCHANGE } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java index 59bb9d1..cefb47c 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java @@ -341,8 +341,93 @@ public enum WechatPayV3Type { * * @since 1.0.0.RELEASE */ - MARKETING_FAVOR_CALLBACKS(HttpMethod.POST, "%s/v3/marketing/favor/callbacks"); + MARKETING_FAVOR_CALLBACKS(HttpMethod.POST, "%s/v3/marketing/favor/callbacks"), + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + /** + * 创建商家券API. + * + * @since 1.0.4.RELEASE + */ + MARKETING_BUSI_FAVOR_CREATE_STOCKS(HttpMethod.POST, "%s/v3/marketing/busifavor/stocks"), + /** + * 查询商家券详情API. + * + * @since 1.0.4.RELEASE + */ + MARKETING_BUSI_FAVOR_STOCKS_DETAIL(HttpMethod.GET, "%s/v3/marketing/busifavor/stocks/{stock_id}"), + /** + * 核销用户券API. + * + * @since 1.0.4.RELEASE + */ + MARKETING_BUSI_FAVOR_COUPON_USE(HttpMethod.POST, "%s/v3/marketing/busifavor/coupons/use"), + /** + * 根据过滤条件查询用户券API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_USER_COUPONS(HttpMethod.GET, "%s/v3/marketing/busifavor/users/{openid}/coupons"), + /** + * 查询用户单张券详情API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_USER_COUPON(HttpMethod.GET, "%s/v3/marketing/busifavor/users/{openid}/coupons/{coupon_code}/appids/{appid}"), + /** + * 商家券上传预存Code API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_UPLOAD_COUPON_CODES(HttpMethod.POST, "%s/v3/marketing/busifavor/stocks/{stock_id}/couponcodes"), + /** + * 设置商家券事件通知地址API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_SETTING_CALLBACKS(HttpMethod.POST, "%s/v3/marketing/busifavor/callbacks"), + /** + * 查询商家券事件通知地址API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_GET_CALLBACKS(HttpMethod.GET, "%s/v3/marketing/busifavor/callbacks"), + /** + * 关联订单信息API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_ASSOCIATE(HttpMethod.POST, "%s/v3/marketing/busifavor/coupons/associate"), + /** + * 取消关联订单信息API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_DISASSOCIATE(HttpMethod.POST, "%s/v3/marketing/busifavor/coupons/disassociate"), + /** + * 取消关联订单信息API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_BUDGET(HttpMethod.POST, "%s/v3/marketing/busifavor/stocks/{stock_id}/budget"), + /** + * 修改商家券基本信息API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_UPDATE(HttpMethod.POST, "%s/v3/marketing/busifavor/stocks/{stock_id}"), + /** + * 申请退券API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_RETURN(HttpMethod.POST, "%s/v3/marketing/busifavor/coupons/return"), + /** + * 使券失效API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_BUSI_FAVOR_DEACTIVATE(HttpMethod.POST, "%s/v3/marketing/busifavor/coupons/deactivate"); /** * The Pattern. diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/ExtensionFormHttpMessageConverter.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/ExtensionFormHttpMessageConverter.java index 930d435..74413b1 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/ExtensionFormHttpMessageConverter.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/ExtensionFormHttpMessageConverter.java @@ -55,36 +55,35 @@ final class ExtensionFormHttpMessageConverter extends FormHttpMessageConverter { */ private static final String BOUNDARY = "boundary"; - /** * The constant jaxb2Present. */ - private static final boolean jaxb2Present; + private static final boolean JAXB_2_PRESENT; /** * The constant jackson2Present. */ - private static final boolean jackson2Present; + private static final boolean JACKSON_2_PRESENT; /** * The constant jackson2XmlPresent. */ - private static final boolean jackson2XmlPresent; + private static final boolean JACKSON_2_XML_PRESENT; /** * The constant jackson2SmilePresent. */ - private static final boolean jackson2SmilePresent; + private static final boolean JACKSON_2_SMILE_PRESENT; /** * The constant gsonPresent. */ - private static final boolean gsonPresent; + private static final boolean GSON_PRESENT; /** * The constant jsonbPresent. */ - private static final boolean jsonbPresent; + private static final boolean JSONB_PRESENT; /** * The Part converters. @@ -93,13 +92,13 @@ final class ExtensionFormHttpMessageConverter extends FormHttpMessageConverter { static { ClassLoader classLoader = AllEncompassingFormHttpMessageConverter.class.getClassLoader(); - jaxb2Present = ClassUtils.isPresent("javax.xml.bind.Binder", classLoader); - jackson2Present = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) && + JAXB_2_PRESENT = ClassUtils.isPresent("javax.xml.bind.Binder", classLoader); + JACKSON_2_PRESENT = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) && ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader); - jackson2XmlPresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper", classLoader); - jackson2SmilePresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.smile.SmileFactory", classLoader); - gsonPresent = ClassUtils.isPresent("com.google.gson.Gson", classLoader); - jsonbPresent = ClassUtils.isPresent("javax.json.bind.Jsonb", classLoader); + JACKSON_2_XML_PRESENT = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper", classLoader); + JACKSON_2_SMILE_PRESENT = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.smile.SmileFactory", classLoader); + GSON_PRESENT = ClassUtils.isPresent("com.google.gson.Gson", classLoader); + JSONB_PRESENT = ClassUtils.isPresent("javax.json.bind.Jsonb", classLoader); } /** @@ -107,7 +106,8 @@ final class ExtensionFormHttpMessageConverter extends FormHttpMessageConverter { */ public ExtensionFormHttpMessageConverter() { StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(); - stringHttpMessageConverter.setWriteAcceptCharset(false); // see SPR-7316 + // see SPR-7316 + stringHttpMessageConverter.setWriteAcceptCharset(false); this.partConverters.add(new ByteArrayHttpMessageConverter()); this.partConverters.add(stringHttpMessageConverter); @@ -118,23 +118,23 @@ final class ExtensionFormHttpMessageConverter extends FormHttpMessageConverter { // Ignore when no TransformerFactory implementation is available } - if (jaxb2Present && !jackson2XmlPresent) { + if (JAXB_2_PRESENT && !JACKSON_2_XML_PRESENT) { this.partConverters.add(new Jaxb2RootElementHttpMessageConverter()); } - if (jackson2Present) { + if (JACKSON_2_PRESENT) { this.partConverters.add(new MappingJackson2HttpMessageConverter()); - } else if (gsonPresent) { + } else if (GSON_PRESENT) { this.partConverters.add(new GsonHttpMessageConverter()); - } else if (jsonbPresent) { + } else if (JSONB_PRESENT) { this.partConverters.add(new JsonbHttpMessageConverter()); } - if (jackson2XmlPresent) { + if (JACKSON_2_XML_PRESENT) { this.partConverters.add(new MappingJackson2XmlHttpMessageConverter()); } - if (jackson2SmilePresent) { + if (JACKSON_2_SMILE_PRESENT) { this.partConverters.add(new MappingJackson2SmileHttpMessageConverter()); } this.setPartConverters(this.partConverters); @@ -205,7 +205,8 @@ final class ExtensionFormHttpMessageConverter extends FormHttpMessageConverter { outputMessage.getHeaders().setContentType(contentType); Charset charset = contentType.getCharset(); - Assert.notNull(charset, "No charset"); // should never occur + // should never occur + Assert.notNull(charset, "No charset"); final byte[] bytes = serializeForm(formData, charset).getBytes(charset); outputMessage.getHeaders().setContentLength(bytes.length); diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatApiProvider.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatApiProvider.java index b245a96..0d3073b 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatApiProvider.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatApiProvider.java @@ -94,6 +94,17 @@ public class WechatApiProvider { return new WechatDiscountCardApi(wechatPayClient, tenantId); } + /** + * 微信支付商家券. + * + * @param tenantId the tenant id + * @return the wechat discount card api + * @since 1.0.4.RELEASE + */ + public WechatMarketingBusiFavorApi busiFavorApi(String tenantId) { + return new WechatMarketingBusiFavorApi(wechatPayClient, tenantId); + } + /** * 回调. *

    diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingBusiFavorApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingBusiFavorApi.java new file mode 100644 index 0000000..239ffa1 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingBusiFavorApi.java @@ -0,0 +1,438 @@ +/* + * 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.v3; + +import cn.felord.payment.wechat.WechatPayProperties; +import cn.felord.payment.wechat.enumeration.CouponStatus; +import cn.felord.payment.wechat.enumeration.WeChatServer; +import cn.felord.payment.wechat.enumeration.WechatPayV3Type; +import cn.felord.payment.wechat.v3.model.busifavor.*; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.springframework.http.RequestEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.util.StringUtils; +import org.springframework.web.util.UriComponentsBuilder; + +import java.net.URI; + +/** + * 微信支付商家券. + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +public class WechatMarketingBusiFavorApi extends AbstractApi { + /** + * Instantiates a new Abstract api. + * + * @param wechatPayClient the wechat pay client + * @param tenantId the tenant id + */ + public WechatMarketingBusiFavorApi(WechatPayClient wechatPayClient, String tenantId) { + super(wechatPayClient, tenantId); + } + + /** + * 创建商家券券批次API + *

    + * 商家券介绍详见 微信支付商家券 + * + * @param params the params + * @return the wechat response entity + */ + public WechatResponseEntity createStock(BusiFavorCreateParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_CREATE_STOCKS, params) + .function(this::createStocksFunction) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + private RequestEntity createStocksFunction(WechatPayV3Type type, BusiFavorCreateParams busiFavorCreateParams) { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .toUri(); + if (!StringUtils.hasText(busiFavorCreateParams.getBelongMerchant())) { + WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); + String mchId = v3.getMchId(); + busiFavorCreateParams.setBelongMerchant(mchId); + } + return Post(uri, busiFavorCreateParams); + } + + /** + * 查询商家券详情API + *

    + * 商户可通过该接口查询已创建的商家券批次详情信息。 + * + * @param stockId the stock id + * @return the wechat response entity + */ + public WechatResponseEntity queryStockDetail(String stockId) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_STOCKS_DETAIL, stockId) + .function((type, id) -> { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .expand(id) + .toUri(); + return Get(uri); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 核销用户券API,暂时appid需要手工在参数中传递 + *

    + * 在用户满足优惠门槛后,服务商可通过该接口核销用户微信卡包中具体某一张商家券。 + * + * @param params the params + * @return the wechat response entity + */ + public WechatResponseEntity use(BusiFavorUseParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_COUPON_USE, params) + .function((type, useParams) -> { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .toUri(); + if (!StringUtils.hasText(params.getAppid())) { + WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); + String appId = v3.getAppId(); + useParams.setAppid(appId); + } + return Post(uri, useParams); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 根据过滤条件查询用户券API + *

    + * 商户自定义筛选条件(如创建商户号、归属商户号、发放商户号等),查询指定微信用户卡包中满足对应条件的所有商家券信息。 + * + * @param params the params + * @return the wechat response entity + */ + public WechatResponseEntity queryUserStocks(UserBusiFavorQueryParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_USER_COUPONS, params) + .function((type, userBusiFavorQueryParams) -> { + MultiValueMap queryParams = new LinkedMultiValueMap<>(); + + String appid = userBusiFavorQueryParams.getAppid(); + if (StringUtils.hasText(appid)) { + queryParams.add("appid", appid); + } + queryParams.add("stock_id", userBusiFavorQueryParams.getStockId()); + queryParams.add("coupon_state", userBusiFavorQueryParams.getCouponState().name()); + queryParams.add("creator_merchant", userBusiFavorQueryParams.getCreatorMerchant()); + queryParams.add("belong_merchant", userBusiFavorQueryParams.getBelongMerchant()); + queryParams.add("sender_merchant", userBusiFavorQueryParams.getSenderMerchant()); + queryParams.add("offset", String.valueOf(params.getOffset())); + queryParams.add("limit", String.valueOf(params.getLimit())); + + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .queryParams(queryParams) + .build() + .expand(userBusiFavorQueryParams.getOpenid()) + .toUri(); + return Get(uri); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 查询用户单张券详情API + *

    + * 服务商可通过该接口查询微信用户卡包中某一张商家券的详情信息。 + * + * @param params the params + * @return the wechat response entity + */ + public WechatResponseEntity queryUserCoupon(UserBusiCouponQueryParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_USER_COUPON, params) + .function((type, queryParams) -> { + if (!StringUtils.hasText(params.getAppid())) { + WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); + String appId = v3.getAppId(); + queryParams.setAppid(appId); + } + + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .expand(queryParams.getOpenid(), queryParams.getCouponCode(), queryParams.getAppid()) + .toUri(); + return Get(uri); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 上传预存code API + *

    + * 商家券的Code码可由微信后台随机分配,同时支持商户自定义。 + * 如商家已有自己的优惠券系统,可直接使用自定义模式。 + * 即商家预先向微信支付上传券Code,当券在发放时,微信支付自动从已导入的Code中随机取值(不能指定),派发给用户。 + * + * @param params the params + * @return wechat response entity + */ + public WechatResponseEntity uploadCouponCodes(BusiCouponCodeUploadParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_UPLOAD_COUPON_CODES, params) + .function((type, queryParams) -> { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .expand(queryParams.getStockId()) + .toUri(); + queryParams.setStockId(null); + return Post(uri, queryParams); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 设置商家券事件通知地址API + *

    + * 用于设置接收商家券相关事件通知的URL,可接收商家券相关的事件通知、包括发放通知等。 + * 需要设置接收通知的URL,并在商户平台开通 营销事件推送 的能力,即可接收到相关通知。 + *

    + * 营销事件推送:点击开通产品权限。由商家券批次创建方登录Pay平台,操作开通 + *

    + * 注意: + *

      + *
    • 仅可以收到由商户自己创建的批次相关的通知
    • + *
    • 需要设置apiv3秘钥,否则无法收到回调。
    • + *
    • 如果需要领券回调中的参数openid。需要创券时候传入 notify_appid参数。
    • + *
    + * + * @param params the params + * @return callbacks callbacks + */ + public WechatResponseEntity setCallbacks(BusiFavorCallbackSettingParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_SETTING_CALLBACKS, params) + .function((type, queryParams) -> { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .toUri(); + return Post(uri, queryParams); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 查询商家券事件通知地址API + *

    + * 通过调用此接口可查询设置的通知URL。 + *

    + * 注意: + *

      + *
    • 仅可以查询由请求商户号设置的商家券通知url
    • + *
    + * + * @param mchId the mch id + * @return callbacks callbacks + */ + public WechatResponseEntity getCallbacks(String mchId) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_GET_CALLBACKS, mchId) + .function((type, id) -> { + + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)); + + if (StringUtils.hasText(id)) { + MultiValueMap queryParams = new LinkedMultiValueMap<>(); + queryParams.add("mchid", id); + uriComponentsBuilder.queryParams(queryParams); + } + + URI uri = uriComponentsBuilder + .build() + .toUri(); + return Get(uri); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 商家券关联订单信息API + *

    + * 将有效态(未核销)的商家券与订单信息关联,用于后续参与摇奖&返佣激励等操作的统计。 + *

    + * 注意: + * 仅对有关联订单需求的券进行该操作 + * + * @param associateInfo the associate info + * @return wechat response entity + */ + public WechatResponseEntity associate(BusiFavorAssociateInfo associateInfo) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_ASSOCIATE, associateInfo) + .function(this::associateFunction) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 商家券取消关联订单信息API + *

    + * 取消商家券与订单信息的关联关系。 + *

    + * 注意: + * 建议取消前调用查询接口,查到当前关联的商户单号并确认后,再进行取消操作 + * + * @param associateInfo the associate info + * @return wechat response entity + */ + public WechatResponseEntity disassociate(BusiFavorAssociateInfo associateInfo) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_DISASSOCIATE, associateInfo) + .function(this::associateFunction) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * associate and disassociate function + * + * @param type WechatPayV3Type + * @param associateInfo the associateInfo + * @return RequestEntity + */ + private RequestEntity associateFunction(WechatPayV3Type type, BusiFavorAssociateInfo associateInfo) { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .toUri(); + return Post(uri, associateInfo); + } + + /** + * 修改批次预算API + *

    + * 商户可以通过该接口修改批次单天发放上限数量或者批次最大发放数量 + * + * @param params the params + * @return wechat response entity + */ + public WechatResponseEntity budget(BusiFavorBudgetParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_BUDGET, params) + .function((type, budgetParams) -> { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .expand(budgetParams.getStockId()) + .toUri(); + budgetParams.setStockId(null); + return Post(uri, budgetParams); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 修改商家券基本信息API + *

    + * 商户可以通过该接口修改商家券基本信息 + * + * @param params the params + * @return wechat response entity + */ + public WechatResponseEntity updateStock(BusiFavorUpdateParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_UPDATE, params) + .function((type, updateParams) -> { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .expand(updateParams.getStockId()) + .toUri(); + updateParams.setStockId(null); + return Post(uri, updateParams); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 申请退券API + *

    + * 商户可以通过该接口为已核销的券申请退券 + * + * @param params the params + * @return wechat response entity + */ + public WechatResponseEntity refund(BusiFavorRefundParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_RETURN, params) + .function((type, refundParams) -> { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .toUri(); + return Post(uri, refundParams); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } + + /** + * 使券失效API + *

    + * 前置条件:券的状态为{@link CouponStatus#SENDED} + *

    + * 商户可以通过该接口将可用券进行失效处理,券被失效后无法再被核销 + * + * @param params the params + * @return wechat response entity + */ + public WechatResponseEntity deactivate(BusiFavorDeactivateParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_BUSI_FAVOR_DEACTIVATE, params) + .function((type, deactivateParams) -> { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .toUri(); + return Post(uri, deactivateParams); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java index 2209320..be88ff5 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java @@ -92,10 +92,11 @@ public class WechatMarketingFavorApi extends AbstractApi { URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) .build() .toUri(); - - WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); - String mchId = v3.getMchId(); - params.setBelongMerchant(mchId); + if (!StringUtils.hasText(params.getBelongMerchant())){ + WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); + String mchId = v3.getMchId(); + params.setBelongMerchant(mchId); + } return Post(uri, params); } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayCallback.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayCallback.java index 9a0ae13..a86bf33 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayCallback.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatPayCallback.java @@ -22,8 +22,12 @@ import cn.felord.payment.wechat.v3.model.CallbackParams; import cn.felord.payment.wechat.v3.model.CouponConsumeData; import cn.felord.payment.wechat.v3.model.ResponseSignVerifyParams; import cn.felord.payment.wechat.v3.model.TransactionConsumeData; +import cn.felord.payment.wechat.v3.model.busifavor.BusiFavorReceiveConsumeData; import cn.felord.payment.wechat.v3.model.combine.CombineTransactionConsumeData; -import cn.felord.payment.wechat.v3.model.discountcard.*; +import cn.felord.payment.wechat.v3.model.discountcard.DiscountCardAcceptedConsumeData; +import cn.felord.payment.wechat.v3.model.discountcard.DiscountCardAgreementEndConsumeData; +import cn.felord.payment.wechat.v3.model.discountcard.DiscountCardConsumer; +import cn.felord.payment.wechat.v3.model.discountcard.DiscountCardUserPaidConsumeData; import cn.felord.payment.wechat.v3.model.payscore.PayScoreConsumer; import cn.felord.payment.wechat.v3.model.payscore.PayScoreUserConfirmConsumeData; import cn.felord.payment.wechat.v3.model.payscore.PayScoreUserPaidConsumeData; @@ -95,7 +99,7 @@ public class WechatPayCallback { */ @SneakyThrows public Map couponCallback(ResponseSignVerifyParams params, Consumer consumeDataConsumer) { - String data = this.callback(params, EventType.COUPON); + String data = this.callback(params, EventType.COUPON_USE); CouponConsumeData consumeData = MAPPER.readValue(data, CouponConsumeData.class); consumeDataConsumer.accept(consumeData); Map responseBody = new HashMap<>(2); @@ -230,7 +234,7 @@ public class WechatPayCallback { String data = this.decrypt(callbackParams); DiscountCardAcceptedConsumeData acceptedConsumeData = MAPPER.readValue(data, DiscountCardAcceptedConsumeData.class); discountCardConsumer.getAcceptedConsumeDataConsumer().accept(acceptedConsumeData); - } else if (Objects.equals(eventType, EventType.DISCOUNT_CARD_USER_PAID.event)) { + } else if (Objects.equals(eventType, EventType.DISCOUNT_CARD_USER_PAID.event)) { String data = this.decrypt(callbackParams); DiscountCardUserPaidConsumeData paidConsumeData = MAPPER.readValue(data, DiscountCardUserPaidConsumeData.class); discountCardConsumer.getCardUserPaidConsumeDataConsumer().accept(paidConsumeData); @@ -241,6 +245,32 @@ public class WechatPayCallback { return Collections.singletonMap("code", "SUCCESS"); } + /** + * 商家券领券事件回调通知API + *

    + * 领券完成后,微信会把相关支付结果和用户信息发送给商户,商户需要接收处理,并按照文档规范返回应答。出于安全的考虑,我们对支付结果数据进行了加密,商户需要先对通知数据进行解密,才能得到支付结果数据。 + *

    + * 该链接是通过商户设置商家券事件通知地址API中提交notify_url参数,必须为https协议。如果链接无法访问,商户将无法接收到微信通知。 通知url必须为直接可访问的url,不能携带参数。示例: “https://pay.weixin.qq.com/wxpay/pay.action” + * + * @param params the params + * @param consumeDataConsumer the consume data consumer + * @return the map + */ + @SneakyThrows + public Map busiFavorReceiveCallback(ResponseSignVerifyParams params, Consumer consumeDataConsumer) { + CallbackParams callbackParams = resolve(params); + String eventType = callbackParams.getEventType(); + + if (!Objects.equals(eventType, EventType.COUPON_SEND.event)) { + log.error("wechat pay event type is not matched, callbackParams {}", callbackParams); + throw new PayException(" wechat pay event type is not matched"); + } + String data = this.decrypt(callbackParams); + BusiFavorReceiveConsumeData consumeData = MAPPER.readValue(data, BusiFavorReceiveConsumeData.class); + + consumeDataConsumer.accept(consumeData); + return Collections.singletonMap("code", "SUCCESS"); + } /** * Callback. @@ -352,10 +382,22 @@ public class WechatPayCallback { /** * 优惠券核销事件. + *

    + * 代金券 * * @since 1.0.0.RELEASE */ - COUPON("COUPON.USE"), + COUPON_USE("COUPON.USE"), + + /** + * 优惠券领券事件. + *

    + * 商家券 + * + * @since 1.0.0.RELEASE + */ + COUPON_SEND("COUPON.SEND"), + /** * 支付成功事件. * diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksCreateParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksCreateParams.java index 6ae6dee..2774e93 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksCreateParams.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/StocksCreateParams.java @@ -44,12 +44,12 @@ public class StocksCreateParams { */ private String belongMerchant; /** - * 批次开始时间 rfc 3339 yyyy-mm-ddthh:mm:ss.sss+timezone + * 批次开始时间 rfc 3339 yyyy-MM-ddTHH:mm:ss+TIMEZONE */ @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "GMT+8") private OffsetDateTime availableBeginTime; /** - * 批次结束时间 rfc 3339 YYYY-MM-DDTHH:mm:ss.sss+TIMEZONE + * 批次结束时间 rfc 3339 yyyy-MM-ddTHH:mm:ss+TIMEZONE */ @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "GMT+8") private OffsetDateTime availableEndTime; diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/AvailableDayTimeItem.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/AvailableDayTimeItem.java new file mode 100644 index 0000000..de5e0c8 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/AvailableDayTimeItem.java @@ -0,0 +1,38 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +/** + * 商家券当天可用时间段 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class AvailableDayTimeItem { + + /** + * 当天可用开始时间,单位:秒,1代表当天0点0分1秒。 + */ + private Integer endTime; + /** + * 当天可用结束时间,单位:秒,86399代表当天23点59分59秒。 + */ + private Integer beginTime; +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/AvailableWeek.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/AvailableWeek.java new file mode 100644 index 0000000..62ce136 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/AvailableWeek.java @@ -0,0 +1,48 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +import java.util.List; + +/** + * 固定周期有效时间段 + *

    + * 可以设置多个星期下的多个可用时间段,比如每周二10点到18点,用户自定义字段。 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class AvailableWeek { + + /** + * 当天可用时间段 + *

    + * 可以填写多个时间段,最多不超过2个。 + */ + private List availableDayTime; + /** + * 可用星期数 + *

    + * 0代表周日,1代表周一,以此类推 + *

    + * 当填写{@link #availableDayTime}时,{@code weekDay}必填 + */ + private List weekDay; +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiCouponCodeUploadParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiCouponCodeUploadParams.java new file mode 100644 index 0000000..0c7dc6e --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiCouponCodeUploadParams.java @@ -0,0 +1,46 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +import java.util.Set; + +/** + * 商家券上传预存code API请求参数 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiCouponCodeUploadParams { + + /** + * 批次号 + */ + private String stockId; + /** + * 券code列表 + *

    + * 特殊规则:单个券code长度为【1,32】,条目个数限制为【1,200】。 + */ + private Set couponCodeList; + /** + * 请求业务单据号 + */ + private String uploadRequestNo; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorAssociateInfo.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorAssociateInfo.java new file mode 100644 index 0000000..47a0120 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorAssociateInfo.java @@ -0,0 +1,47 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +/** + * 商家券关联订单信息API请求参数 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiFavorAssociateInfo { + + /** + * 批次号 + */ + private String stockId; + /** + * 券code + */ + private String couponCode; + /** + * 关联的商户订单号 + */ + private String outTradeNo; + /** + * 商户请求单号 + * @see BusiFavorCreateParams#getOutRequestNo() + */ + private String outRequestNo; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorBudgetParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorBudgetParams.java new file mode 100644 index 0000000..8b46067 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorBudgetParams.java @@ -0,0 +1,54 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +/** + * 修改商家券批次预算API请求参数 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiFavorBudgetParams { + + /** + * 批次号 + */ + private String stockId; + /** + * 目标批次最大发放个数,同{@link #targetMaxCouponsByDay}二选一 + */ + private Integer targetMaxCoupons; + /** + * 目标单天发放上限个数,同{@link #targetMaxCoupons}二选一 + */ + private Integer targetMaxCouponsByDay; + /** + * 当前批次最大发放个数,当传入{@link #targetMaxCoupons}大于0时,必传 + */ + private Integer currentMaxCoupons; + /** + * 当前单天发放上限个数 ,当传入{@link #targetMaxCouponsByDay}大于0时,必填 + */ + private Integer currentMaxCouponsByDay; + /** + * 修改预算请求单据号 + */ + private String modifyBudgetRequestNo; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorCallbackSettingParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorCallbackSettingParams.java new file mode 100644 index 0000000..c76f4b0 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorCallbackSettingParams.java @@ -0,0 +1,38 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +/** + * 设置商家券事件通知地址API请求参数 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiFavorCallbackSettingParams { + + /** + * 微信支付商户的商户号,由微信支付生成并下发,不填默认查询调用方商户的通知URL。 + */ + private String mchid; + /** + * 商户提供的用于接收商家券事件通知的url地址,必须支持https。 + */ + private String notifyUrl; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorCreateParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorCreateParams.java new file mode 100644 index 0000000..e781f23 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorCreateParams.java @@ -0,0 +1,112 @@ +/* + * 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.v3.model.busifavor; + +import cn.felord.payment.wechat.enumeration.StockType; +import lombok.Data; + +/** + * 创建商家券请求参数. + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiFavorCreateParams { + + /** + * 商家券批次名称,[1,21],必填 + */ + private String stockName; + /** + * 批次归属商户号,必填 + */ + private String belongMerchant; + /** + * 批次备注,[1,20],选填 + */ + private String comment; + /** + * 适用商品范围,必填 + *

    + * 用来描述批次在哪些商品可用,会显示在微信卡包中。字数上限为15个,一个中文汉字/英文字母/数字均占用一个字数。 + */ + private String goodsName; + /** + * 批次类型 + */ + private StockType stockType; + /** + * 核销规则 + */ + private CouponUseRule couponUseRule; + /** + * 自定义入口 + */ + private CustomEntrance customEntrance; + /** + * 商家券code模式枚举 + */ + private CouponCodeMode couponCodeMode; + /** + * 样式信息 + */ + private DisplayPatternInfo displayPatternInfo; + /** + * 券发放规则 + */ + private StockSendRule stockSendRule; + /** + * 商户请求单号 + *

    + * 商户创建批次凭据号(格式:商户id+日期+流水号),商户侧需保持唯一性。 + */ + private String outRequestNo; + /** + * 事件通知配置 + */ + private BusiFavorNotifyConfig notifyConfig; + + + /** + * 商家券code模式枚举 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ + public enum CouponCodeMode { + + /** + * 系统分配券code。(固定22位纯数字) + * + * @since 1.0.4.RELEASE + */ + WECHATPAY_MODE, + /** + * 商户发放时接口指定券code。 + * + * @since 1.0.4.RELEASE + */ + MERCHANT_API, + /** + * 商户上传自定义code,发券时系统随机选取上传的券code。 + * + * @since 1.0.4.RELEASE + */ + MERCHANT_UPLOAD + } +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorDeactivateParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorDeactivateParams.java new file mode 100644 index 0000000..4d4b96a --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorDeactivateParams.java @@ -0,0 +1,46 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +/** + * 使券失效API请求参数 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiFavorDeactivateParams { + + /** + * 券code + */ + private String couponCode; + /** + * 批次号 + */ + private String stockId; + /** + * 失效请求单据号 + */ + private String deactivateRequestNo; + /** + * 失效原因 + */ + private String deactivateReason; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorNotifyConfig.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorNotifyConfig.java new file mode 100644 index 0000000..f156629 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorNotifyConfig.java @@ -0,0 +1,37 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +/** + * 事件通知配置 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiFavorNotifyConfig { + + /** + * 事件通知appid + *

    + * 用于回调通知时,计算返回操作用户的openid(诸如领券用户),支持小程序or公众号的APPID; + * 如该字段不填写,则回调通知中涉及到用户身份信息的openid与unionid都将为空。 + */ + private String notifyAppid; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorReceiveConsumeData.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorReceiveConsumeData.java new file mode 100644 index 0000000..2560165 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorReceiveConsumeData.java @@ -0,0 +1,162 @@ +/* + * 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.v3.model.busifavor; + + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.time.OffsetDateTime; + +/** + * 商家券领券事件回调通知解密 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiFavorReceiveConsumeData { + + /** + * 业务细分事件类型 + *

    + * 枚举值: + * EVENT_TYPE_BUSICOUPON_SEND:商家券用户领券通知 + */ + private String eventType; + /** + * 券code + */ + private String couponCode; + /** + * 批次号 + */ + private String stockId; + /** + * 发放时间 rfc 3339 yyyy-MM-ddTHH:mm:ss+TIMEZONE + */ + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX", timezone = "GMT+8") + private OffsetDateTime sendTime; + /** + * 微信用户在appid下的唯一标识。 + */ + private String openid; + /** + * 微信用户在同一个微信开放平台账号下的唯一用户标识, + * unionid获取方式请参见 《UnionID机制说明》 文档。 + */ + private String unionid; + /** + * 发券商户号 + */ + private String sendMerchant; + /** + * 发放渠道 + */ + private SendChannel sendChannel; + /** + * 发券附加信息,仅在支付有礼、扫码领券(营销馆)、会员有礼发放渠道,才有该信息 + */ + private AttachInfo attachInfo; + + + /** + * 发放渠道 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ + public enum SendChannel { + + /** + * 小程序 + */ + BUSICOUPON_SEND_CHANNEL_MINIAPP, + /** + * API + */ + BUSICOUPON_SEND_CHANNEL_API, + /** + * 支付有礼 + */ + BUSICOUPON_SEND_CHANNEL_PAYGIFT, + /** + * H5 + */ + BUSICOUPON_SEND_CHANNEL_H5, + + /** + * 面对面 + */ + BUSICOUPON_SEND_CHANNEL_FTOF, + /** + * 会员卡活动 + */ + BUSICOUPON_SEND_CHANNEL_MEMBER_CARD_ACT, + /** + * 扫码领券(营销馆) + */ + BUSICOUPON_SEND_CHANNEL_HALL + } + + /** + * 商家券领券事件回调通知解密-发券附加信息 + *

    + * 仅在支付有礼、扫码领券(营销馆)、会员有礼发放渠道,才有该信息 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ + @Data + public static class AttachInfo { + + /** + * 交易订单编号 + *

    + * 仅在支付有礼渠道,才有该信息,对应支付有礼曝光支付订单编号信息 + */ + private String transactionId; + /** + * 支付有礼活动编号对应{@link SendChannel#BUSICOUPON_SEND_CHANNEL_PAYGIFT} + *

    + * 营销馆活动ID对应{@link SendChannel#BUSICOUPON_SEND_CHANNEL_HALL} + *

    + * 二选一,且只在对应场景下出现 + */ + private String actCode; + /** + * 仅在扫码领券(营销馆)渠道,才有该信息,对应领券的营销馆 馆ID信息 + */ + private String hallCode; + /** + * 仅在扫码领券(营销馆)渠道,才有该信息,对应领券的营销馆所属商户号信息 + */ + private Integer hallBelongMchId; + /** + * 仅在会员卡活动渠道,才有该信息,对应会员卡Card_ID信息 + */ + private String cardId; + /** + * 仅在会员卡活动渠道,才有该信息,对应用户卡包会员卡卡Code信息 + */ + private String code; + /** + * 仅在会员卡活动渠道,才有该信息,对应会员有礼活动ID信息 + */ + private String activityId; + } +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorRefundParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorRefundParams.java new file mode 100644 index 0000000..8e6b5aa --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorRefundParams.java @@ -0,0 +1,42 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +/** + * 修改商家券基本信息API请求参数 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiFavorRefundParams { + + /** + * 券code + */ + private String couponCode; + /** + * 批次号 + */ + private String stockId; + /** + * 退券请求单据号 + */ + private String returnRequestNo; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorUpdateParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorUpdateParams.java new file mode 100644 index 0000000..db0432e --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorUpdateParams.java @@ -0,0 +1,159 @@ +/* + * 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.v3.model.busifavor; + +import cn.felord.payment.wechat.enumeration.BusiFavorCodeDisplayMode; +import cn.felord.payment.wechat.enumeration.BusiFavorUseMethod; +import lombok.Data; + +/** + * 修改商家券基本信息API请求参数. + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiFavorUpdateParams { + + /** + * 商家券批次号,必传 + */ + private String stockId; + /** + * 自定义入口 + */ + private UpdateCustomEntrance customEntrance; + /** + * 商家券批次名称,[1,21] + */ + private String stockName; + /** + * 批次备注,[1,20] + */ + private String comment; + /** + * 适用商品范围 + *

    + * 用来描述批次在哪些商品可用,会显示在微信卡包中。字数上限为15个,一个中文汉字/英文字母/数字均占用一个字数。 + */ + private String goodsName; + /** + * 商户请求单号 + *

    + * 商户创建批次凭据号(格式:商户id+日期+流水号),商户侧需保持唯一性。 + */ + private String outRequestNo; + /** + * 样式信息 + */ + private DisplayPatternInfo displayPatternInfo; + /** + * 核销规则 + */ + private UpdateCouponUseRule couponUseRule; + /** + * 券发放规则 + */ + private UpdateStockSendRule stockSendRule; + /** + * 事件通知配置 + */ + private BusiFavorNotifyConfig notifyConfig; + + + /** + * 商家券核销规则-自定义入口修改参数 + *

    + * 卡详情页面,可选择多种入口引导用户。 + * + * @author felord.cn + * @see CustomEntrance + * @since 1.0.4.RELEASE + */ + @Data + public static class UpdateCustomEntrance { + + /** + * 营销馆id + */ + private String hallId; + /** + * 小程序入口 + */ + private MiniProgramsInfo miniProgramsInfo; + /** + * 商户公众号appid + *

    + * 从券详情可跳转至公众号 + */ + private String appid; + /** + * code展示模式 + */ + private BusiFavorCodeDisplayMode codeDisplayMode; + + } + + /** + * 商家券核销规则修改参数 + * + * @author felord.cn + * @see CouponUseRule + * @since 1.0.4.RELEASE + */ + @Data + public static class UpdateCouponUseRule { + + /** + * 核销方式 + */ + private BusiFavorUseMethod useMethod; + /** + * 核销小程序appid + * + * @see BusiFavorUseMethod#MINI_PROGRAMS + */ + private String miniProgramsAppid; + /** + * 核销小程序path + * + * @see #miniProgramsAppid + */ + private String miniProgramsPath; + } + + + /** + * 商家券发放规则修改参数 + * + * @author felord.cn + * @see StockSendRule + * @since 1.0.4.RELEASE + */ + @Data + public static class UpdateStockSendRule { + + /** + * 是否开启自然人限制 + */ + private Boolean naturalPersonLimit; + /** + * 可疑账号拦截 + */ + private Boolean preventApiAbuse; + } +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorUseParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorUseParams.java new file mode 100644 index 0000000..b3e24d1 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/BusiFavorUseParams.java @@ -0,0 +1,58 @@ +/* + * 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.v3.model.busifavor; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.time.OffsetDateTime; + +/** + * 核销用户券请求参数 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class BusiFavorUseParams { + /** + * 券code + */ + private String couponCode; + /** + * 批次号 + */ + private String stockId; + /** + * 公众账号ID + */ + private String appid; + /** + * 请求核销时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX", timezone = "GMT+8") + private OffsetDateTime useTime; + /** + * 核销请求单据号,商户侧保证唯一 + */ + private String useRequestNo; + /** + * 用户标识,用户的唯一标识,做安全校验使用 + */ + private String openid; + +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CouponAvailableTime.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CouponAvailableTime.java new file mode 100644 index 0000000..ac5b7ae --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CouponAvailableTime.java @@ -0,0 +1,74 @@ +/* + * 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.v3.model.busifavor; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.time.OffsetDateTime; +import java.util.List; + +/** + * 商家券核销规则-券可核销时间 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class CouponAvailableTime { + + /** + * 领取后N天开始生效 + *

    + * 日期区间内,用户领券后需等待x天开始生效。例如领券后当天开始生效则无需填写,领券后第2天开始生效填1,以此类推…… + *

    + * 用户在有效期开始前领取商家券,则从有效期第1天开始计算天数,用户在有效期内领取商家券,则从领取当天开始计算天数。无论用户何时领取商家券,商家券在活动有效期结束后均不可用。 + *

    + * 需配合{@link #availableDayAfterReceive} 一同填写,不可单独填写。 + */ + private int waitDaysAfterReceive; + /** + * 生效后N天内有效 + *

    + * 日期区间内,券生效后x天内有效。例如生效当天内有效填1,生效后2天内有效填2,以此类推…… + *

    + * 注意,用户在有效期开始前领取商家券,则从有效期第1天开始计算天数,用户在有效期内领取商家券,则从领取当天开始计算天数,无论用户何时领取商家券,商家券在活动有效期结束后均不可用。 + *

    + * 可配合{@link #waitDaysAfterReceive}一同填写,也可单独填写。单独填写时,有效期内领券后立即生效,生效后x天内有效。 + */ + private int availableDayAfterReceive; + /** + * 批次开始时间 rfc 3339 yyyy-MM-ddTHH:mm:ss+TIMEZONE + */ + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX", timezone = "GMT+8") + private OffsetDateTime availableBeginTime; + /** + * 批次结束时间 rfc 3339 yyyy-MM-ddTHH:mm:ss+TIMEZONE + */ + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX", timezone = "GMT+8") + private OffsetDateTime availableEndTime; + /** + * 固定周期有效时间段 + */ + private AvailableWeek availableWeek; + /** + * 无规律的有效时间段 + */ + private List irregularyAvaliableTime; + + +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CouponUseRule.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CouponUseRule.java new file mode 100644 index 0000000..8abef7a --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CouponUseRule.java @@ -0,0 +1,71 @@ +/* + * 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.v3.model.busifavor; + +import cn.felord.payment.wechat.enumeration.BusiFavorUseMethod; +import cn.felord.payment.wechat.enumeration.StockType; +import lombok.Data; + +/** + * 商家券核销规则 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class CouponUseRule { + + /** + * 核销方式 + */ + private BusiFavorUseMethod useMethod; + /** + * 换购券使用规则 + * + * @see StockType#EXCHANGE + */ + private ExchangeCoupon exchangeCoupon; + /** + * 券可核销时间 + */ + private CouponAvailableTime couponAvailableTime; + /** + * 核销小程序appid + * + * @see BusiFavorUseMethod#MINI_PROGRAMS + */ + private String miniProgramsAppid; + /** + * 核销小程序path + * + * @see #miniProgramsAppid + */ + private String miniProgramsPath; + /** + * 固定面额满减券使用规则 + * + * @see StockType#NORMAL + */ + private FixedNormalCoupon fixedNormalCoupon; + /** + * 折扣券使用规则 + * + * @see StockType#DISCOUNT + */ + private DiscountCoupon discountCoupon; + +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CustomEntrance.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CustomEntrance.java new file mode 100644 index 0000000..559a526 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/CustomEntrance.java @@ -0,0 +1,58 @@ +/* + * 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.v3.model.busifavor; + +import cn.felord.payment.wechat.enumeration.BusiFavorCodeDisplayMode; +import lombok.Data; + +/** + * 商家券核销规则-自定义入口 + *

    + * 卡详情页面,可选择多种入口引导用户。 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class CustomEntrance { + + /** + * 可用门店id + *

    + * 不可修改项 + */ + private String storeId; + /** + * 营销馆id + */ + private String hallId; + /** + * 小程序入口 + */ + private MiniProgramsInfo miniProgramsInfo; + /** + * 商户公众号appid + *

    + * 从券详情可跳转至公众号 + */ + private String appid; + /** + * code展示模式 + */ + private BusiFavorCodeDisplayMode codeDisplayMode; + +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/DiscountCoupon.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/DiscountCoupon.java new file mode 100644 index 0000000..d17901d --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/DiscountCoupon.java @@ -0,0 +1,25 @@ +package cn.felord.payment.wechat.v3.model.busifavor; + +import lombok.Data; + +/** + * 商家券核销规则-折扣券使用规则 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class DiscountCoupon { + + /** + * 折扣百分比,例如:88为八八折 + */ + private Integer discountPercent; + /** + * 消费门槛,单位:分。 + *

    + * 特殊规则:取值范围 1 ≤ transactionMinimum ≤ 10000000 + */ + private Integer transactionMinimum; + +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/DisplayPatternInfo.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/DisplayPatternInfo.java new file mode 100644 index 0000000..a61759e --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/DisplayPatternInfo.java @@ -0,0 +1,60 @@ +package cn.felord.payment.wechat.v3.model.busifavor; + +import cn.felord.payment.wechat.enumeration.CouponBgColor; +import cn.felord.payment.wechat.v3.WechatMarketingFavorApi; +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; + +/** + * 商家券样式信息. + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class DisplayPatternInfo { + + /** + * 背景颜色 + */ + private CouponBgColor backgroundColor; + /** + * 商户logo + *

    + *

      + *
    1. 商户logo大小需为120像素*120像素
    2. + *
    3. 支持JPG/JPEG/PNG格式,且图片小于1M
    4. + *
    + *

    + * 仅支持通过 图片上传API 接口获取的图片URL地址。 + * + * @see WechatMarketingFavorApi#marketingImageUpload(MultipartFile) + */ + private String merchantLogoUrl; + /** + * 券详情图片 + *

    + *

      + *
    1. 需为850像素*350像素
    2. + *
    3. 图片大小不超过2M
    4. + *
    5. 支持JPG/PNG格式
    6. + *
    + *

    + * 仅支持通过 图片上传API 接口获取的图片URL地址。 + * + * @see WechatMarketingFavorApi#marketingImageUpload(MultipartFile) + */ + private String couponImageUrl; + /** + * 使用须知 + *

    + * 用于说明详细的活动规则,会展示在代金券详情页。 + *

    + * 示例值:xxx门店可用 + */ + private String description; + /** + * 商户名称,字数上限为16个 + */ + private String merchantName; +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/ExchangeCoupon.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/ExchangeCoupon.java new file mode 100644 index 0000000..390a6a6 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/ExchangeCoupon.java @@ -0,0 +1,42 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +/** + * 商家券核销规则-换购券使用规则 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class ExchangeCoupon { + + /** + * 单品换购价,单位:分。 + *

    + * 特殊规则:取值范围 1 ≤ exchangePrice ≤ 10000000 + */ + private Integer exchangePrice; + /** + * 消费门槛,单位:分。 + *

    + * 特殊规则:取值范围 1 ≤ transactionMinimum ≤ 10000000 + */ + private Integer transactionMinimum; +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/FixedNormalCoupon.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/FixedNormalCoupon.java new file mode 100644 index 0000000..c4e1643 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/FixedNormalCoupon.java @@ -0,0 +1,26 @@ +package cn.felord.payment.wechat.v3.model.busifavor; + +import lombok.Data; + +/** + * 商家券核销规则-固定面额满减券使用规则 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class FixedNormalCoupon { + + /** + * 优惠金额,单位:分。 + *

    + * 特殊规则:取值范围 1 ≤ transactionMinimum ≤ 10000000 + */ + private Integer discountAmount; + /** + * 消费门槛,单位:分。 + *

    + * 特殊规则:取值范围 1 ≤ transactionMinimum ≤ 10000000 + */ + private Integer transactionMinimum; +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/IrregularyAvaliableTimeItem.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/IrregularyAvaliableTimeItem.java new file mode 100644 index 0000000..2fe24f7 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/IrregularyAvaliableTimeItem.java @@ -0,0 +1,42 @@ +/* + * 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.v3.model.busifavor; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.time.OffsetDateTime; +/** + * 商家券核销规则-券可核销时间-无规律的有效时间段 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class IrregularyAvaliableTimeItem{ + + /** + * 开始时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX", timezone = "GMT+8") + private OffsetDateTime beginTime; + /** + * 结束时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX", timezone = "GMT+8") + private OffsetDateTime endTime; +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/MiniProgramsInfo.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/MiniProgramsInfo.java new file mode 100644 index 0000000..0af2758 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/MiniProgramsInfo.java @@ -0,0 +1,48 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +/** + * 商家券核销规则-自定义入口-小程序入口 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class MiniProgramsInfo{ + + /** + * 商家小程序appid + *

    + * 商家小程序appid要与归属商户号有M-A or M-m-suba关系。 + */ + private String miniProgramsAppid; + /** + * 商家小程序path + */ + private String miniProgramsPath; + /** + * 入口文案,字数上限为5个,一个中文汉字/英文字母/数字均占用一个字数。 + */ + private String guidingWords; + /** + * 小程序入口引导文案,用户自定义字段。字数上限为6个,一个中文汉字/英文字母/数字均占用一个字数。 + */ + private String entranceWords; +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/StockSendRule.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/StockSendRule.java new file mode 100644 index 0000000..4fe3c76 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/StockSendRule.java @@ -0,0 +1,51 @@ +package cn.felord.payment.wechat.v3.model.busifavor; + +import cn.felord.payment.wechat.enumeration.StockType; +import lombok.Data; + +/** + * 商家券发放规则. + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class StockSendRule { + + /** + * 批次最大发放个数 + *

    + * 特殊规则:取值范围 1 ≤ maxCoupons ≤ 1000000000 + */ + private Integer maxCoupons; + /** + * 用户最大可领个数 + *

    + * 每个用户最多100张券 。 + */ + private Integer maxCouponsPerUser; + /** + * 单天发放上限个数 + *

    + * {@link StockType#DISCOUNT}或者{@link StockType#DISCOUNT}时可传入此字段控制单天发放上限 + *

    + * 特殊规则:取值范围 1 ≤ maxCouponsByDay ≤ 1000000000 + */ + private Integer maxCouponsByDay; + /** + * 是否开启自然人限制 + */ + private Boolean naturalPersonLimit; + /** + * 可疑账号拦截 + */ + private Boolean preventApiAbuse; + /** + * 是否允许转赠 + */ + private Boolean transferable; + /** + * 是否允许分享链接 + */ + private Boolean shareable; +} \ No newline at end of file diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/UserBusiCouponQueryParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/UserBusiCouponQueryParams.java new file mode 100644 index 0000000..50afdcb --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/UserBusiCouponQueryParams.java @@ -0,0 +1,42 @@ +/* + * 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.v3.model.busifavor; + +import lombok.Data; + +/** + * 查询用户单张券详情请求参数 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class UserBusiCouponQueryParams { + + /** + * 券code + */ + private String couponCode; + /** + * 与当前调用接口商户号有绑定关系的appid。支持小程序appid与公众号appid。 + */ + private String appid; + /** + * Openid信息,用户在appid下的唯一标识。 + */ + private String openid; +} diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/UserBusiFavorQueryParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/UserBusiFavorQueryParams.java new file mode 100644 index 0000000..15cd15c --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/busifavor/UserBusiFavorQueryParams.java @@ -0,0 +1,67 @@ +/* + * 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.v3.model.busifavor; + +import cn.felord.payment.wechat.enumeration.CouponStatus; +import lombok.Data; + +/** + * 根据过滤条件查询用户券API查询参数 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class UserBusiFavorQueryParams { + + /** + * 用户标识,用户在appid下的唯一标识。 + */ + private String openid; + /** + * 与当前调用接口商户号有绑定关系的appid。支持小程序appid与公众号appid。 + */ + private String appid; + /** + * 商户券批次号 + */ + private String stockId; + /** + * 券状态 + */ + private CouponStatus couponState; + /** + * 创建批次的商户号 + */ + private String creatorMerchant; + /** + * 批次归属商户号 + */ + private String belongMerchant; + /** + * 批次发放商户号 + */ + private String senderMerchant; + /** + * 分页页码 + */ + private String offset; + /** + * 分页大小 + */ + private String limit; +} From 72c505939b6e1bcb5669b70cd6a199f81b13304c Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Mon, 18 Jan 2021 11:45:03 +0800 Subject: [PATCH 7/9] =?UTF-8?q?feat:=20=E4=BB=A3=E9=87=91=E5=88=B8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=91=E6=94=BE=E6=B6=88=E8=B4=B9=E5=8D=A1?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 代金券功能增加发放消费卡接口支持 --- .../wechat/enumeration/WechatPayV3Type.java | 6 ++ .../wechat/v3/WechatMarketingFavorApi.java | 42 ++++++++++++-- .../v3/model/CouponsCardSendParams.java | 58 +++++++++++++++++++ 3 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponsCardSendParams.java diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java index cefb47c..9c91773 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/enumeration/WechatPayV3Type.java @@ -342,6 +342,12 @@ public enum WechatPayV3Type { * @since 1.0.0.RELEASE */ MARKETING_FAVOR_CALLBACKS(HttpMethod.POST, "%s/v3/marketing/favor/callbacks"), + /** + * 发放代金券消费卡API. + * + * @since 1.0.4.RELEASES + */ + MARKETING_FAVOR_COUPONS_SEND(HttpMethod.POST, "%s/v3/marketing/busifavor/coupons/{card_id}/send"), //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /** diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java index be88ff5..c602b31 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/WechatMarketingFavorApi.java @@ -92,7 +92,7 @@ public class WechatMarketingFavorApi extends AbstractApi { URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) .build() .toUri(); - if (!StringUtils.hasText(params.getBelongMerchant())){ + if (!StringUtils.hasText(params.getBelongMerchant())) { WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); String mchId = v3.getMchId(); params.setBelongMerchant(mchId); @@ -491,7 +491,7 @@ public class WechatMarketingFavorApi extends AbstractApi { * * @param stockId the stock id * @return the wechat response entity - * @see AbstractApi#billDownload(String) 对账单下载api + * @see AbstractApi#billDownload(String) AbstractApi#billDownload(String)对账单下载api */ public WechatResponseEntity downloadStockUseFlow(String stockId) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); @@ -513,7 +513,7 @@ public class WechatMarketingFavorApi extends AbstractApi { * * @param stockId the stock id * @return the wechat response entity - * @see AbstractApi#billDownload(String) 对账单下载api + * @see AbstractApi#billDownload(String) AbstractApi#billDownload(String)对账单下载api */ public WechatResponseEntity downloadStockRefundFlow(String stockId) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); @@ -602,7 +602,7 @@ public class WechatMarketingFavorApi extends AbstractApi { * * @param notifyUrl the notify url * @return the wechat response entity - * @see WechatPayCallback#couponCallback(ResponseSignVerifyParams, Consumer) 核销回调 + * @see WechatPayCallback#couponCallback(ResponseSignVerifyParams, Consumer) WechatPayCallback#couponCallback(ResponseSignVerifyParams, Consumer)核销回调 */ public WechatResponseEntity setMarketingFavorCallback(String notifyUrl) { WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); @@ -632,6 +632,40 @@ public class WechatMarketingFavorApi extends AbstractApi { .toUri(); return Post(uri, body); } + + /** + * 发放消费卡API + *

    + * 商户通过调用本接口向用户发放消费卡,用户领到卡的同时会领取到一批代金券,消费卡会自动放入卡包中。 + *

    + * 注意: + *

      + *
    • 调用该接口前,需要在微信支付商户平台创建“消费卡”,获得card_id。
    • + *
    • 此功能仅向指定邀约商户开放,如有需要请联系微信支付运营经理。
    • + *
    + * + * @param params the params + * @return wechat response entity + */ + public WechatResponseEntity sendCouponsCard(CouponsCardSendParams params) { + WechatResponseEntity wechatResponseEntity = new WechatResponseEntity<>(); + this.client().withType(WechatPayV3Type.MARKETING_FAVOR_COUPONS_SEND, params) + .function((type, sendParams) -> { + URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA)) + .build() + .expand(sendParams.getCardId()) + .toUri(); + sendParams.setCardId(null); + if (!StringUtils.hasText(sendParams.getAppid())) { + WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3(); + sendParams.setAppid(v3.getAppId()); + } + return Post(uri, sendParams); + }) + .consumer(wechatResponseEntity::convert) + .request(); + return wechatResponseEntity; + } } diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponsCardSendParams.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponsCardSendParams.java new file mode 100644 index 0000000..ca07115 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/v3/model/CouponsCardSendParams.java @@ -0,0 +1,58 @@ +/* + * 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.v3.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.time.OffsetDateTime; + +/** + * 发放代金券消费卡API请求参数 + * + * @author felord.cn + * @since 1.0.4.RELEASE + */ +@Data +public class CouponsCardSendParams { + + /** + * 消费卡ID + *

    + * 获取方法请参见《接入流程》中的创建消费卡。 + */ + private String cardId; + /** + * 消费卡归属appid + */ + private String appid; + /** + * 需为消费卡归属appid生成的openid。 + */ + private String openid; + /** + * 商户此次发放凭据号。 + *

    + * 推荐使用大小写字母和数字,不同添加请求发放凭据号不同,商户侧需保证同一发券请求的out_request_no和send_time的唯一性。 + */ + private String outRequestNo; + /** + * 请求发卡时间,由于系统限制,暂不支持传入早于当前时间24小时以上的时间进行发券请求。 + */ + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "GMT+8") + private OffsetDateTime sendTime; +} From e93fb5e4ed61ad3908788e4b1f3cbd866c533e97 Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Mon, 18 Jan 2021 11:51:32 +0800 Subject: [PATCH 8/9] =?UTF-8?q?build:=20=E6=9E=84=E5=BB=BA=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upgrade to Spring Boot 2.4.2 --- payment-spring-boot-autoconfigure/pom.xml | 4 ++-- payment-spring-boot-starter/pom.xml | 4 ++-- pom.xml | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/payment-spring-boot-autoconfigure/pom.xml b/payment-spring-boot-autoconfigure/pom.xml index 6c96d52..fec1754 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.3.RELEASE + 1.0.4.RELEASE payment-spring-boot-autoconfigure - 1.0.3.RELEASE + 1.0.4.RELEASE jar 4.0.0 diff --git a/payment-spring-boot-starter/pom.xml b/payment-spring-boot-starter/pom.xml index 116f47e..b290966 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.3.RELEASE + 1.0.4.RELEASE payment-spring-boot-starter - 1.0.3.RELEASE + 1.0.4.RELEASE jar 4.0.0 diff --git a/pom.xml b/pom.xml index 31ddea9..8829664 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.3.RELEASE + 1.0.4.RELEASE pom 4.0.0 @@ -30,7 +30,7 @@ - payment-spring-boot-1.0.0.RELEASE + payment-spring-boot-1.0.4.RELEASE https://github.com/NotFound403/payment-spring-boot scm:git:https://github.com/NotFound403/payment-spring-boot.git scm:git:https://github.com/NotFound403/payment-spring-boot.git @@ -48,7 +48,7 @@ UTF-8 UTF-8 1.8 - 2.4.1 + 2.4.2 4.10.167.ALL 1.0.0.RELEASE 1.18.12 From d919ec460031a40da59dba3b51bd441970b64aea Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Mon, 18 Jan 2021 12:00:24 +0800 Subject: [PATCH 9/9] docs: docs docs --- README.md | 2 +- docs/README.md | 2 +- docs/changelog.md | 8 ++++++++ docs/quick_start.md | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3442137..f9353e2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ cn.felord payment-spring-boot-starter - 1.0.3.RELEASE + 1.0.4.RELEASE ``` diff --git a/docs/README.md b/docs/README.md index 762442e..91c7927 100644 --- a/docs/README.md +++ b/docs/README.md @@ -33,7 +33,7 @@ cn.felord payment-spring-boot-starter - 1.0.3.RELEASE + 1.0.4.RELEASE ``` ## 采用技术 diff --git a/docs/changelog.md b/docs/changelog.md index 95f9bcc..98ec434 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,4 +1,12 @@ ## 1.0.3.RELEASE +- 微信支付 + - feat: 支持微信支付商家券 + - feat: 代金券功能增加发放消费卡接口`WechatMarketingBusiFavorApi` + - refactor: 一些代码优化 + - refactor: 现在app支付、小程序支付返回所有客户端拉起支付的参数,不再需要用户再进行签名操作了 + - build: SDK开发环境 Spring Boot 版本升级到2.4.2 + - fix: 支付分RiskFund下枚举无法使用的问题(#2) +## 1.0.3.RELEASE - 微信支付 - feat: 完善合单支付账单 1. 增加合单支付-申请交易账单API。 diff --git a/docs/quick_start.md b/docs/quick_start.md index cd2d15e..12ab160 100644 --- a/docs/quick_start.md +++ b/docs/quick_start.md @@ -4,7 +4,7 @@ cn.felord payment-spring-boot-starter - 1.0.3.RELEASE + 1.0.4.RELEASE ``` > 基于 **Spring Boot 2.4.1**