-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
增加电商收付通补差SDK #220
Merged
xy-peng
merged 2 commits into
wechatpay-apiv3:main
from
thinkerchi:feat_add_ecommerce-subsidy
Aug 23, 2023
Merged
增加电商收付通补差SDK #220
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...ple/java/com/wechat/pay/java/service/ecommercesubsidy/EcommerceSubsidyServiceExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.wechat.pay.java.service.ecommercesubsidy; | ||
|
||
import com.wechat.pay.java.core.Config; | ||
import com.wechat.pay.java.core.RSAAutoCertificateConfig; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesCancelEntity; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesCancelRequest; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesCreateEntity; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesCreateRequest; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesReturnEntity; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesReturnRequest; | ||
|
||
/** EcommerceSubsidyService使用示例 */ | ||
public class EcommerceSubsidyServiceExample { | ||
|
||
/** 商户号 */ | ||
public static String merchantId = "190000****"; | ||
/** 商户API私钥路径 */ | ||
public static String privateKeyPath = "/Users/yourname/your/path/apiclient_key.pem"; | ||
/** 商户证书序列号 */ | ||
public static String merchantSerialNumber = "5157F09EFDC096DE15EBE81A47057A72********"; | ||
/** 商户APIV3密钥 */ | ||
public static String apiV3Key = "..."; | ||
|
||
public static EcommerceSubsidyService service; | ||
|
||
public static void main(String[] args) { | ||
// 初始化商户配置 | ||
Config config = | ||
new RSAAutoCertificateConfig.Builder() | ||
.merchantId(merchantId) | ||
// 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 | ||
.privateKeyFromPath(privateKeyPath) | ||
.merchantSerialNumber(merchantSerialNumber) | ||
.apiV3Key(apiV3Key) | ||
.build(); | ||
|
||
// 初始化服务 | ||
service = new EcommerceSubsidyService.Builder().config(config).build(); | ||
// ... 调用接口 | ||
} | ||
/** 取消补差 */ | ||
public static SubsidiesCancelEntity cancelSubsidy() { | ||
SubsidiesCancelRequest request = new SubsidiesCancelRequest(); | ||
return service.cancelSubsidy(request); | ||
} | ||
/** 请求补差 */ | ||
public static SubsidiesCreateEntity createSubsidy() { | ||
SubsidiesCreateRequest request = new SubsidiesCreateRequest(); | ||
return service.createSubsidy(request); | ||
} | ||
/** 请求补差回退 */ | ||
public static SubsidiesReturnEntity returnSubsidy() { | ||
SubsidiesReturnRequest request = new SubsidiesReturnRequest(); | ||
return service.returnSubsidy(request); | ||
} | ||
} |
171 changes: 171 additions & 0 deletions
171
...e/src/main/java/com/wechat/pay/java/service/ecommercesubsidy/EcommerceSubsidyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// Copyright 2021 Tencent Inc. All rights reserved. | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// API version: 0.1.3 | ||
|
||
// Code generated by WechatPay APIv3 Generator based on [OpenAPI | ||
// Generator](https://openapi-generator.tech); DO NOT EDIT. | ||
|
||
package com.wechat.pay.java.service.ecommercesubsidy; | ||
|
||
import static com.wechat.pay.java.core.util.GsonUtil.toJson; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import com.wechat.pay.java.core.Config; | ||
import com.wechat.pay.java.core.exception.HttpException; | ||
import com.wechat.pay.java.core.exception.MalformedMessageException; | ||
import com.wechat.pay.java.core.exception.ServiceException; | ||
import com.wechat.pay.java.core.exception.ValidationException; | ||
import com.wechat.pay.java.core.http.Constant; | ||
import com.wechat.pay.java.core.http.DefaultHttpClientBuilder; | ||
import com.wechat.pay.java.core.http.HostName; | ||
import com.wechat.pay.java.core.http.HttpClient; | ||
import com.wechat.pay.java.core.http.HttpHeaders; | ||
import com.wechat.pay.java.core.http.HttpMethod; | ||
import com.wechat.pay.java.core.http.HttpRequest; | ||
import com.wechat.pay.java.core.http.HttpResponse; | ||
import com.wechat.pay.java.core.http.JsonRequestBody; | ||
import com.wechat.pay.java.core.http.MediaType; | ||
import com.wechat.pay.java.core.http.RequestBody; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesCancelEntity; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesCancelRequest; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesCreateEntity; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesCreateRequest; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesReturnEntity; | ||
import com.wechat.pay.java.service.ecommercesubsidy.model.SubsidiesReturnRequest; | ||
|
||
/** EcommerceSubsidyService服务 */ | ||
public class EcommerceSubsidyService { | ||
|
||
private final HttpClient httpClient; | ||
private final HostName hostName; | ||
|
||
private EcommerceSubsidyService(HttpClient httpClient, HostName hostName) { | ||
this.httpClient = requireNonNull(httpClient); | ||
this.hostName = hostName; | ||
} | ||
/** EcommerceSubsidyService构造器 */ | ||
public static class Builder { | ||
|
||
private HttpClient httpClient; | ||
private HostName hostName; | ||
|
||
public Builder config(Config config) { | ||
this.httpClient = new DefaultHttpClientBuilder().config(config).build(); | ||
|
||
return this; | ||
} | ||
|
||
public Builder hostName(HostName hostName) { | ||
this.hostName = hostName; | ||
return this; | ||
} | ||
|
||
public Builder httpClient(HttpClient httpClient) { | ||
this.httpClient = httpClient; | ||
return this; | ||
} | ||
|
||
public EcommerceSubsidyService build() { | ||
return new EcommerceSubsidyService(httpClient, hostName); | ||
} | ||
} | ||
|
||
/** | ||
* 取消补差 | ||
* | ||
* @param request 请求参数 | ||
* @return SubsidiesCancelEntity | ||
* @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 | ||
* @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 | ||
* @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 | ||
* @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 | ||
*/ | ||
public SubsidiesCancelEntity cancelSubsidy(SubsidiesCancelRequest request) { | ||
String requestPath = "https://api.mch.weixin.qq.com/v3/ecommerce/subsidies/cancel"; | ||
SubsidiesCancelRequest realRequest = request; | ||
if (this.hostName != null) { | ||
requestPath = requestPath.replaceFirst(HostName.API.getValue(), hostName.getValue()); | ||
} | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.addHeader(Constant.ACCEPT, MediaType.APPLICATION_JSON.getValue()); | ||
headers.addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()); | ||
HttpRequest httpRequest = | ||
new HttpRequest.Builder() | ||
.httpMethod(HttpMethod.POST) | ||
.url(requestPath) | ||
.headers(headers) | ||
.body(createRequestBody(realRequest)) | ||
.build(); | ||
HttpResponse<SubsidiesCancelEntity> httpResponse = | ||
httpClient.execute(httpRequest, SubsidiesCancelEntity.class); | ||
return httpResponse.getServiceResponse(); | ||
} | ||
/** | ||
* 请求补差 | ||
* | ||
* @param request 请求参数 | ||
* @return SubsidiesCreateEntity | ||
* @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 | ||
* @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 | ||
* @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 | ||
* @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 | ||
*/ | ||
public SubsidiesCreateEntity createSubsidy(SubsidiesCreateRequest request) { | ||
String requestPath = "https://api.mch.weixin.qq.com/v3/ecommerce/subsidies/create"; | ||
SubsidiesCreateRequest realRequest = request; | ||
if (this.hostName != null) { | ||
requestPath = requestPath.replaceFirst(HostName.API.getValue(), hostName.getValue()); | ||
} | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.addHeader(Constant.ACCEPT, MediaType.APPLICATION_JSON.getValue()); | ||
headers.addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()); | ||
HttpRequest httpRequest = | ||
new HttpRequest.Builder() | ||
.httpMethod(HttpMethod.POST) | ||
.url(requestPath) | ||
.headers(headers) | ||
.body(createRequestBody(realRequest)) | ||
.build(); | ||
HttpResponse<SubsidiesCreateEntity> httpResponse = | ||
httpClient.execute(httpRequest, SubsidiesCreateEntity.class); | ||
return httpResponse.getServiceResponse(); | ||
} | ||
/** | ||
* 请求补差回退 | ||
* | ||
* @param request 请求参数 | ||
* @return SubsidiesReturnEntity | ||
* @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 | ||
* @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 | ||
* @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 | ||
* @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 | ||
*/ | ||
public SubsidiesReturnEntity returnSubsidy(SubsidiesReturnRequest request) { | ||
String requestPath = "https://api.mch.weixin.qq.com/v3/ecommerce/subsidies/return"; | ||
SubsidiesReturnRequest realRequest = request; | ||
if (this.hostName != null) { | ||
requestPath = requestPath.replaceFirst(HostName.API.getValue(), hostName.getValue()); | ||
} | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.addHeader(Constant.ACCEPT, MediaType.APPLICATION_JSON.getValue()); | ||
headers.addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()); | ||
HttpRequest httpRequest = | ||
new HttpRequest.Builder() | ||
.httpMethod(HttpMethod.POST) | ||
.url(requestPath) | ||
.headers(headers) | ||
.body(createRequestBody(realRequest)) | ||
.build(); | ||
HttpResponse<SubsidiesReturnEntity> httpResponse = | ||
httpClient.execute(httpRequest, SubsidiesReturnEntity.class); | ||
return httpResponse.getServiceResponse(); | ||
} | ||
|
||
private RequestBody createRequestBody(Object request) { | ||
return new JsonRequestBody.Builder().body(toJson(request)).build(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
service/src/main/java/com/wechat/pay/java/service/ecommercesubsidy/model/CancelStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2021 Tencent Inc. All rights reserved. | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// API version: 0.1.3 | ||
|
||
// Code generated by WechatPay APIv3 Generator based on [OpenAPI | ||
// Generator](https://openapi-generator.tech); DO NOT EDIT. | ||
|
||
package com.wechat.pay.java.service.ecommercesubsidy.model; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** CancelStatus */ | ||
public enum CancelStatus { | ||
@SerializedName("SUCCESS") | ||
SUCCESS, | ||
|
||
@SerializedName("FAIL") | ||
FAIL | ||
} |
26 changes: 26 additions & 0 deletions
26
service/src/main/java/com/wechat/pay/java/service/ecommercesubsidy/model/CreateStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2021 Tencent Inc. All rights reserved. | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// API version: 0.1.3 | ||
|
||
// Code generated by WechatPay APIv3 Generator based on [OpenAPI | ||
// Generator](https://openapi-generator.tech); DO NOT EDIT. | ||
|
||
package com.wechat.pay.java.service.ecommercesubsidy.model; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** CreateStatus */ | ||
public enum CreateStatus { | ||
@SerializedName("SUCCESS") | ||
SUCCESS, | ||
|
||
@SerializedName("FAIL") | ||
FAIL, | ||
|
||
@SerializedName("REFUND") | ||
REFUND | ||
} |
23 changes: 23 additions & 0 deletions
23
service/src/main/java/com/wechat/pay/java/service/ecommercesubsidy/model/ReturnAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2021 Tencent Inc. All rights reserved. | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// API version: 0.1.3 | ||
|
||
// Code generated by WechatPay APIv3 Generator based on [OpenAPI | ||
// Generator](https://openapi-generator.tech); DO NOT EDIT. | ||
|
||
package com.wechat.pay.java.service.ecommercesubsidy.model; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** ReturnAccount */ | ||
public enum ReturnAccount { | ||
@SerializedName("AVAILABLE") | ||
AVAILABLE, | ||
|
||
@SerializedName("UNAVAILABLE") | ||
UNAVAILABLE | ||
} |
52 changes: 52 additions & 0 deletions
52
service/src/main/java/com/wechat/pay/java/service/ecommercesubsidy/model/ReturnFrom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2021 Tencent Inc. All rights reserved. | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// API version: 0.1.3 | ||
|
||
// Code generated by WechatPay APIv3 Generator based on [OpenAPI | ||
// Generator](https://openapi-generator.tech); DO NOT EDIT. | ||
|
||
package com.wechat.pay.java.service.ecommercesubsidy.model; | ||
|
||
import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** ReturnFrom */ | ||
public class ReturnFrom { | ||
/** 出资账户类型 说明:下面枚举值多选一。 枚举值: AVAILABLE : 可用余额 UNAVAILABLE : 不可用余额 */ | ||
@SerializedName("account") | ||
private ReturnAccount account; | ||
/** 出资金额 说明:对应账户出资金额 */ | ||
@SerializedName("amount") | ||
private Long amount; | ||
|
||
public ReturnAccount getAccount() { | ||
return account; | ||
} | ||
|
||
public void setAccount(ReturnAccount account) { | ||
this.account = account; | ||
} | ||
|
||
public Long getAmount() { | ||
return amount; | ||
} | ||
|
||
public void setAmount(Long amount) { | ||
this.amount = amount; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("class ReturnFrom {\n"); | ||
sb.append(" account: ").append(toIndentedString(account)).append("\n"); | ||
sb.append(" amount: ").append(toIndentedString(amount)).append("\n"); | ||
sb.append("}"); | ||
return sb.toString(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
service/src/main/java/com/wechat/pay/java/service/ecommercesubsidy/model/ReturnStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2021 Tencent Inc. All rights reserved. | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// 微信支付平台补差API | ||
// | ||
// API version: 0.1.3 | ||
|
||
// Code generated by WechatPay APIv3 Generator based on [OpenAPI | ||
// Generator](https://openapi-generator.tech); DO NOT EDIT. | ||
|
||
package com.wechat.pay.java.service.ecommercesubsidy.model; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** ReturnStatus */ | ||
public enum ReturnStatus { | ||
@SerializedName("SUCCESS") | ||
SUCCESS, | ||
|
||
@SerializedName("FAIL") | ||
FAIL | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是漏了勾选?