mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-15 06:23:42 +08:00
refactor: 下载交易账单API和下载资金账单现在是公共接口
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.felord</groupId>
|
<groupId>cn.felord</groupId>
|
||||||
<artifactId>payment-spring-boot-starter</artifactId>
|
<artifactId>payment-spring-boot-starter</artifactId>
|
||||||
<version>1.0.2.RELEASE</version>
|
<version>1.0.3.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,12 @@
|
|||||||
- 微信合单支付 `WechatCombinePayApi` 100%
|
- 微信合单支付 `WechatCombinePayApi` 100%
|
||||||
|
|
||||||
## Maven 中央仓库坐标
|
## Maven 中央仓库坐标
|
||||||
|
> 推荐使用最新版本
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.felord</groupId>
|
<groupId>cn.felord</groupId>
|
||||||
<artifactId>payment-spring-boot-starter</artifactId>
|
<artifactId>payment-spring-boot-starter</artifactId>
|
||||||
<version>1.0.1.RELEASE</version>
|
<version>1.0.3.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
## 采用技术
|
## 采用技术
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
## 1.0.2.RELEASE
|
||||||
|
- 微信支付
|
||||||
|
- feat: 接入微信支付分
|
||||||
|
- feat: 接入微信支付先享卡
|
||||||
|
- fix: 支付回调参数不全的问题
|
||||||
|
|
||||||
## 1.0.1.RELEASE
|
## 1.0.1.RELEASE
|
||||||
|
|
||||||
- 微信支付
|
- 微信支付
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.felord</groupId>
|
<groupId>cn.felord</groupId>
|
||||||
<artifactId>payment-spring-boot-starter</artifactId>
|
<artifactId>payment-spring-boot-starter</artifactId>
|
||||||
<version>1.0.1.RELEASE</version>
|
<version>1.0.3.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
> 基于 **Spring Boot 2.4.1**
|
> 基于 **Spring Boot 2.4.1**
|
||||||
|
|||||||
@@ -44,6 +44,18 @@ public enum WechatPayV3Type {
|
|||||||
* @since 1.0.0.RELEASE
|
* @since 1.0.0.RELEASE
|
||||||
*/
|
*/
|
||||||
FILE_DOWNLOAD(HttpMethod.GET, "%s/v3/billdownload/file"),
|
FILE_DOWNLOAD(HttpMethod.GET, "%s/v3/billdownload/file"),
|
||||||
|
/**
|
||||||
|
* 申请交易账单API.
|
||||||
|
*
|
||||||
|
* @since 1.0.3.RELEASE
|
||||||
|
*/
|
||||||
|
TRADEBILL(HttpMethod.GET, "%s/v3/bill/tradebill"),
|
||||||
|
/**
|
||||||
|
* 申请资金账单API.
|
||||||
|
*
|
||||||
|
* @since 1.0.3.RELEASE
|
||||||
|
*/
|
||||||
|
FUNDFLOWBILL(HttpMethod.GET, "%s/v3/bill/fundflowbill"),
|
||||||
|
|
||||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
@@ -133,18 +145,6 @@ public enum WechatPayV3Type {
|
|||||||
* @since 1.0.0.RELEASE
|
* @since 1.0.0.RELEASE
|
||||||
*/
|
*/
|
||||||
COMBINE_CLOSE(HttpMethod.POST, "%s/v3/combine-transactions/out-trade-no/{combine_out_trade_no}/close"),
|
COMBINE_CLOSE(HttpMethod.POST, "%s/v3/combine-transactions/out-trade-no/{combine_out_trade_no}/close"),
|
||||||
/**
|
|
||||||
* 申请交易账单API.
|
|
||||||
*
|
|
||||||
* @since 1.0.3.RELEASE
|
|
||||||
*/
|
|
||||||
COMBINE_TRADEBILL(HttpMethod.POST, "%s/v3/bill/tradebill"),
|
|
||||||
/**
|
|
||||||
* 申请资金账单API.
|
|
||||||
*
|
|
||||||
* @since 1.0.3.RELEASE
|
|
||||||
*/
|
|
||||||
COMBINE_FUNDFLOWBILL(HttpMethod.POST, "%s/v3/bill/fundflowbill"),
|
|
||||||
|
|
||||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,9 @@
|
|||||||
package cn.felord.payment.wechat.v3;
|
package cn.felord.payment.wechat.v3;
|
||||||
|
|
||||||
import cn.felord.payment.PayException;
|
import cn.felord.payment.PayException;
|
||||||
import cn.felord.payment.wechat.enumeration.WechatPayV3Type;
|
import cn.felord.payment.wechat.enumeration.*;
|
||||||
|
import cn.felord.payment.wechat.v3.model.FundFlowBillParams;
|
||||||
|
import cn.felord.payment.wechat.v3.model.TradeBillParams;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -28,9 +30,16 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
|
|||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import org.springframework.http.RequestEntity;
|
import org.springframework.http.RequestEntity;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Abstract api.
|
* The type Abstract api.
|
||||||
@@ -172,4 +181,86 @@ public abstract class AbstractApi {
|
|||||||
})
|
})
|
||||||
.download();
|
.download();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请交易账单API
|
||||||
|
* <p>
|
||||||
|
* 微信支付按天提供交易账单文件,商户可以通过该接口获取账单文件的下载地址。文件内包含交易相关的金额、时间、营销等信息,供商户核对订单、退款、银行到账等情况。
|
||||||
|
* <p>
|
||||||
|
* 注意:
|
||||||
|
* <ul>
|
||||||
|
* <li>微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账单中,跟原支付单订单号一致;</li>
|
||||||
|
* <li>对账单中涉及金额的字段单位为“元”;</li>
|
||||||
|
* <li>对账单接口只能下载三个月以内的账单。</li>
|
||||||
|
* <li>小微商户不单独提供对账单下载,如有需要,可在调取“下载对账单”API接口时不传sub_mch_id,获取服务商下全量电商二级商户(包括小微商户和非小微商户)的对账单。</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param tradeBillParams tradeBillParams
|
||||||
|
* @since 1.0.3.RELEASE
|
||||||
|
*/
|
||||||
|
public final void downloadTradeBill(TradeBillParams tradeBillParams) {
|
||||||
|
this.client().withType(WechatPayV3Type.TRADEBILL, tradeBillParams)
|
||||||
|
.function((wechatPayV3Type, params) -> {
|
||||||
|
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
|
||||||
|
LocalDate billDate = params.getBillDate();
|
||||||
|
queryParams.add("bill_date", billDate.format(DateTimeFormatter.ISO_DATE));
|
||||||
|
String subMchid = params.getSubMchid();
|
||||||
|
|
||||||
|
if (StringUtils.hasText(subMchid)) {
|
||||||
|
queryParams.add("sub_mchid", subMchid);
|
||||||
|
}
|
||||||
|
|
||||||
|
TradeBillType tradeBillType = Optional.ofNullable(params.getBillType())
|
||||||
|
.orElse(TradeBillType.ALL);
|
||||||
|
queryParams.add("bill_type", tradeBillType.name());
|
||||||
|
TarType tarType = params.getTarType();
|
||||||
|
if (Objects.nonNull(tarType)) {
|
||||||
|
queryParams.add("tar_type", tarType.name());
|
||||||
|
}
|
||||||
|
URI uri = UriComponentsBuilder.fromHttpUrl(wechatPayV3Type.uri(WeChatServer.CHINA))
|
||||||
|
.queryParams(queryParams)
|
||||||
|
.build().toUri();
|
||||||
|
return Get(uri);
|
||||||
|
})
|
||||||
|
.consumer(response -> this.billDownload(Objects.requireNonNull(response.getBody()).get("download_url").asText()))
|
||||||
|
.request();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请资金账单API
|
||||||
|
* <p>
|
||||||
|
* 微信支付按天提供微信支付账户的资金流水账单文件,商户可以通过该接口获取账单文件的下载地址。文件内包含该账户资金操作相关的业务单号、收支金额、记账时间等信息,供商户进行核对。
|
||||||
|
* <p>
|
||||||
|
* 注意:
|
||||||
|
* <ul>
|
||||||
|
* <li>资金账单中的数据反映的是商户微信支付账户资金变动情况;</li>
|
||||||
|
* <li>对账单中涉及金额的字段单位为“元”。</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param fundFlowBillParams fundFlowBillParams
|
||||||
|
* @since 1.0.3.RELEASE
|
||||||
|
*/
|
||||||
|
public final void downloadFundFlowBill(FundFlowBillParams fundFlowBillParams) {
|
||||||
|
this.client().withType(WechatPayV3Type.FUNDFLOWBILL, fundFlowBillParams)
|
||||||
|
.function((wechatPayV3Type, params) -> {
|
||||||
|
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
|
||||||
|
LocalDate billDate = params.getBillDate();
|
||||||
|
queryParams.add("bill_date", billDate.format(DateTimeFormatter.ISO_DATE));
|
||||||
|
|
||||||
|
FundFlowAccountType accountType = Optional.ofNullable(params.getAccountType())
|
||||||
|
.orElse(FundFlowAccountType.BASIC);
|
||||||
|
queryParams.add("account_type", accountType.name());
|
||||||
|
TarType tarType = params.getTarType();
|
||||||
|
if (Objects.nonNull(tarType)) {
|
||||||
|
queryParams.add("tar_type", tarType.name());
|
||||||
|
}
|
||||||
|
URI uri = UriComponentsBuilder.fromHttpUrl(wechatPayV3Type.uri(WeChatServer.CHINA))
|
||||||
|
.queryParams(queryParams)
|
||||||
|
.build().toUri();
|
||||||
|
return Get(uri);
|
||||||
|
})
|
||||||
|
.consumer(response -> this.billDownload(Objects.requireNonNull(response.getBody()).get("download_url").asText()))
|
||||||
|
.request();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,20 +19,16 @@
|
|||||||
package cn.felord.payment.wechat.v3;
|
package cn.felord.payment.wechat.v3;
|
||||||
|
|
||||||
import cn.felord.payment.wechat.WechatPayProperties;
|
import cn.felord.payment.wechat.WechatPayProperties;
|
||||||
import cn.felord.payment.wechat.enumeration.*;
|
import cn.felord.payment.wechat.enumeration.WeChatServer;
|
||||||
import cn.felord.payment.wechat.v3.model.combine.*;
|
import cn.felord.payment.wechat.enumeration.WechatPayV3Type;
|
||||||
|
import cn.felord.payment.wechat.v3.model.combine.CombineCloseParams;
|
||||||
|
import cn.felord.payment.wechat.v3.model.combine.CombineH5PayParams;
|
||||||
|
import cn.felord.payment.wechat.v3.model.combine.CombinePayParams;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.springframework.http.RequestEntity;
|
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 org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信合单支付.
|
* 微信合单支付.
|
||||||
@@ -215,85 +211,4 @@ public class WechatCombinePayApi extends AbstractApi {
|
|||||||
.request();
|
.request();
|
||||||
return wechatResponseEntity;
|
return wechatResponseEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 申请交易账单API
|
|
||||||
* <p>
|
|
||||||
* 微信支付按天提供交易账单文件,商户可以通过该接口获取账单文件的下载地址。文件内包含交易相关的金额、时间、营销等信息,供商户核对订单、退款、银行到账等情况。
|
|
||||||
* <p>
|
|
||||||
* 注意:
|
|
||||||
* <ul>
|
|
||||||
* <li>微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账单中,跟原支付单订单号一致;</li>
|
|
||||||
* <li>对账单中涉及金额的字段单位为“元”;</li>
|
|
||||||
* <li>对账单接口只能下载三个月以内的账单。</li>
|
|
||||||
* <li>小微商户不单独提供对账单下载,如有需要,可在调取“下载对账单”API接口时不传sub_mch_id,获取服务商下全量电商二级商户(包括小微商户和非小微商户)的对账单。</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @param tradeBillParams tradeBillParams
|
|
||||||
* @since 1.0.3.RELEASE
|
|
||||||
*/
|
|
||||||
public void downloadTradeBill(TradeBillParams tradeBillParams) {
|
|
||||||
this.client().withType(WechatPayV3Type.COMBINE_TRADEBILL, tradeBillParams)
|
|
||||||
.function((wechatPayV3Type, params) -> {
|
|
||||||
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
|
|
||||||
LocalDate billDate = params.getBillDate();
|
|
||||||
queryParams.add("bill_date", billDate.format(DateTimeFormatter.ISO_DATE));
|
|
||||||
String subMchid = params.getSubMchid();
|
|
||||||
|
|
||||||
if (StringUtils.hasText(subMchid)) {
|
|
||||||
queryParams.add("sub_mchid", subMchid);
|
|
||||||
}
|
|
||||||
|
|
||||||
TradeBillType tradeBillType = Optional.ofNullable(params.getBillType())
|
|
||||||
.orElse(TradeBillType.ALL);
|
|
||||||
queryParams.add("bill_type", tradeBillType.name());
|
|
||||||
TarType tarType = params.getTarType();
|
|
||||||
if (Objects.nonNull(tarType)) {
|
|
||||||
queryParams.add("tar_type", tarType.name());
|
|
||||||
}
|
|
||||||
URI uri = UriComponentsBuilder.fromHttpUrl(wechatPayV3Type.uri(WeChatServer.CHINA))
|
|
||||||
.queryParams(queryParams)
|
|
||||||
.build().toUri();
|
|
||||||
return Get(uri);
|
|
||||||
})
|
|
||||||
.consumer(response -> this.billDownload(Objects.requireNonNull(response.getBody()).get("download_url").asText()))
|
|
||||||
.request();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 申请资金账单API
|
|
||||||
* <p>
|
|
||||||
* 微信支付按天提供微信支付账户的资金流水账单文件,商户可以通过该接口获取账单文件的下载地址。文件内包含该账户资金操作相关的业务单号、收支金额、记账时间等信息,供商户进行核对。
|
|
||||||
* <p>
|
|
||||||
* 注意:
|
|
||||||
* <ul>
|
|
||||||
* <li>资金账单中的数据反映的是商户微信支付账户资金变动情况;</li>
|
|
||||||
* <li>对账单中涉及金额的字段单位为“元”。</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @param fundFlowBillParams fundFlowBillParams
|
|
||||||
* @since 1.0.3.RELEASE
|
|
||||||
*/
|
|
||||||
public void downloadFundFlowBill(FundFlowBillParams fundFlowBillParams) {
|
|
||||||
this.client().withType(WechatPayV3Type.COMBINE_FUNDFLOWBILL, fundFlowBillParams)
|
|
||||||
.function((wechatPayV3Type, params) -> {
|
|
||||||
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
|
|
||||||
LocalDate billDate = params.getBillDate();
|
|
||||||
queryParams.add("bill_date", billDate.format(DateTimeFormatter.ISO_DATE));
|
|
||||||
|
|
||||||
FundFlowAccountType accountType = Optional.ofNullable(params.getAccountType())
|
|
||||||
.orElse(FundFlowAccountType.BASIC);
|
|
||||||
queryParams.add("account_type", accountType.name());
|
|
||||||
TarType tarType = params.getTarType();
|
|
||||||
if (Objects.nonNull(tarType)) {
|
|
||||||
queryParams.add("tar_type", tarType.name());
|
|
||||||
}
|
|
||||||
URI uri = UriComponentsBuilder.fromHttpUrl(wechatPayV3Type.uri(WeChatServer.CHINA))
|
|
||||||
.queryParams(queryParams)
|
|
||||||
.build().toUri();
|
|
||||||
return Get(uri);
|
|
||||||
})
|
|
||||||
.consumer(response -> this.billDownload(Objects.requireNonNull(response.getBody()).get("download_url").asText()))
|
|
||||||
.request();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package cn.felord.payment.wechat.v3.model.combine;
|
package cn.felord.payment.wechat.v3.model;
|
||||||
|
|
||||||
import cn.felord.payment.wechat.enumeration.FundFlowAccountType;
|
import cn.felord.payment.wechat.enumeration.FundFlowAccountType;
|
||||||
import cn.felord.payment.wechat.enumeration.TarType;
|
import cn.felord.payment.wechat.enumeration.TarType;
|
||||||
@@ -24,7 +24,7 @@ import lombok.Data;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合单支付申请资金账单请求参数
|
* 申请资金账单请求参数
|
||||||
*
|
*
|
||||||
* @author felord.cn
|
* @author felord.cn
|
||||||
* @since 1.0.3.RELEASE
|
* @since 1.0.3.RELEASE
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package cn.felord.payment.wechat.v3.model.combine;
|
package cn.felord.payment.wechat.v3.model;
|
||||||
|
|
||||||
import cn.felord.payment.wechat.enumeration.TarType;
|
import cn.felord.payment.wechat.enumeration.TarType;
|
||||||
import cn.felord.payment.wechat.enumeration.TradeBillType;
|
import cn.felord.payment.wechat.enumeration.TradeBillType;
|
||||||
@@ -24,7 +24,7 @@ import lombok.Data;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合单支付申请交易账单请求参数
|
* 申请交易账单请求参数
|
||||||
*
|
*
|
||||||
* @author felord.cn
|
* @author felord.cn
|
||||||
* @since 1.0.3.RELEASE
|
* @since 1.0.3.RELEASE
|
||||||
Reference in New Issue
Block a user