8000 :new: #3327【微信支付】增加平台收付通(注销申请)相关接口 · Goforit000/WxJava@5821710 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5821710

Browse files
authored
🆕 binarywang#3327【微信支付】增加平台收付通(注销申请)相关接口
1 parent 2226693 commit 5821710

File tree

7 files changed

+269
-7
lines changed

7 files changed

+269
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.binarywang.wxpay.bean.ecommerce;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.io.Serializable;
8+
9+
/**
10+
* 图片上传API
11+
* <pre>
12+
* https://pay.weixin.qq.com/docs/partner/apis/ecommerce-cancel/media/upload-media.html
13+
* </pre>
14+
*/
15+
@Data
16+
@NoArgsConstructor
17+
public class AccountCancelApplicationsMediaResult implements Serializable {
18+
19+
/**
20+
* 微信返回的媒体文件标识ID。
21+
*/
22+
@SerializedName(value = "media_id")
23+
private String mediaId;
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.github.binarywang.wxpay.bean.ecommerce;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* 提交注销申请单
14+
* <pre>
15+
* https://pay.weixin.qq.com/docs/partner/apis/ecommerce-cancel/cancel-applications/create-cancel-application.html
16+
* </pre>
17+
*/
18+
@Data
19+
@NoArgsConstructor
20+
public class AccountCancelApplicationsRequest implements Serializable {
21+
22+
/**
23+
* 【申请注销的二级商户号】 电商平台二级商户号,由微信支付生成并下发
24+
*/
25+
@SerializedName(value = "sub_mchid")
26+
private String subMchid;
27+
28+
/**
29+
* 【商户注销申请单号】 商户注销申请单号,由商户自定义生成,要求在服务商维度下是唯一的,必须仅包含大小写字母与数字
30+
*/
31+
@SerializedName(value = "out_apply_no")
32+
private String outApplyNo;
33+
34+
/**
35+
* 【注销申请材料】 注销申请材料,详见文档:注销申请材料
36+
*/
37+
@SerializedName(value = "application_info")
38+
private List<CancelApplicationInfo> applicationInfo;
39+
40+
@Data
41+
@Builder
42+
@AllArgsConstructor
43+
@NoArgsConstructor
44+
public static class CancelApplicationInfo implements Serializable {
45+
46+
/**
47+
*【注销申请材料类型】 注销申请材料类型,详见文档:注销申请材料
48+
* 可选取值:
49+
* SP_MERCHANT_APPLICATION: 此枚举值已废弃,请使用新字段 SP_CANCEL_ACCOUNT_APPLICATION 以及新版本材料
50+
* SUB_MERCHANT_APPLICATION: 此枚举值已废弃,请使用新字段 SUB_CANCEL_ACCOUNT_APPLICATION 以及新版本材料
51+
* MISSING_OFFICIAL_SEAL_LETTER: 此材料已废弃,无需上传
52+
* SP_CANCEL_ACCOUNT_APPLICATION: 电商服务商注销电商子申请书,请下载模板打印纸质版、填写盖章后拍照。模板文档详见:微信支付商户号注销申请书-服务商(纸质版)
53+
* SUB_CANCEL_ACCOUNT_APPLICATION: 电商服务商子商户注销申请书,详见文档:微信支付商户号注销申请书-电商平台子商户适用(纸质版)
54+
*/
55+
@SerializedName("application_type")
56+
private String applicationType;
57+
58+
/**
59+
* 【注销申请材料照片ID】 注销申请材料照片ID,请填写通过上传图片接口预先上传图片生成好的media_id
60+
*/
61+
@SerializedName("application_media_id")
62+
private String applicationMediaId;
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.github.binarywang.wxpay.bean.ecommerce;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.io.Serializable;
8+
9+
/**
10+
* 提交注销申请单
11+
* <pre>
12+
* https://pay.weixin.qq.com/docs/partner/apis/ecommerce-cancel/cancel-applications/create-cancel-application.html
13+
* </pre>
14+
*/
15+
@Data
16+
@NoArgsConstructor
17+
public class AccountCancelApplicationsResult implements Serializable {
18+
19+
/**
20+
* 【商户注销申请单号】 商户注销申请单号,原样返回请求参数里的内容
21+
*/
22+
@SerializedName(value = "out_apply_no")
23+
private String outApplyNo;
24+
25+
/**
26+
* 【二级商户号】 二级商户号
27+
*/
28+
@SerializedName(value = "sub_mchid")
29+
private String subMchid;
30+
31+
/**
32+
* 【驳回原因】 受理失败原因
33+
*/
34+
@SerializedName(value = "reject_reason")
35+
private String rejectReason;
36+
37+
/**
38+
* 【注销状态】 注销状态
39+
* 可选取值:
40+
* REVIEWING: 审核中
41+
* REJECTED: 审核驳回,驳回原因详见reject_reason
42+
* CANCEL_SUCCESS: 注销成功
43+
*/
44+
@SerializedName(value = "cancel_state")
45+
private String cancelState;
46+
47+
/**
48+
* 【最后更新时间】 最后更新时间。遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
49+
*/
50+
@SerializedName(value = "update_time")
51+
private String updateTime;
52+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum;
77
import com.github.binarywang.wxpay.exception.WxPayException;
88

9+
import java.io.File;
10+
import java.io.IOException;
911
import java.io.InputStream;
1012

1113
/**
@@ -535,4 +537,39 @@ public interface EcommerceService {
535537
*/
536538
SubsidiesCancelResult subsidiesCancel(SubsidiesCancelRequest subsidiesCancelRequest) throws WxPayException;
537539

540+
/**
541+
* <pre>
542+
* 提交注销申请单
543+
* 文档地址: https://pay.weixin.qq.com/docs/partner/apis/ecommerce-cancel/cancel-applications/create-cancel-application.html
544+
* </pre>
545+
*
546+
* @param accountCancelApplicationsRequest 提交注销申请单
547+
* @return 返回数据 return AccountCancelApplicationsResult
548+
* @throws WxPayException the wx pay exception
549+
*/
550+
AccountCancelApplicationsResult createdAccountCancelApplication(AccountCancelApplicationsRequest accountCancelApplicationsRequest) throws WxPayException;
551+
552+
/**
553+
* <pre>
554+
* 查询注销单状态
555+
* 文档地址: https://pay.weixin.qq.com/docs/partner/apis/ecommerce-cancel/cancel-applications/get-cancel-application.html
556+
* </pre>
557+
*
558+
* @param outApplyNo 注销申请单号
559+
* @return 返回数据 return AccountCancelApplicationsResult
560+
* @throws WxPayException the wx pay exception
561+
*/
562+
AccountCancelApplicationsResult getAccountCancelApplication(String outApplyNo) throws WxPayException;
563+
564+
/**
565+
* <pre>
566+
* 注销单资料图片上传
567+
* 文档地址: https://pay.weixin.qq.com/docs/partner/apis/ecommerce-cancel/media/upload-media.html
568+
* </pre>
569+
*
570+
* @param imageFile 图片
571+
* @return 返回数据 return AccountCancelApplicationsResult
572+
* @throws WxPayException the wx pay exception
573+
*/
574+
AccountCancelApplicationsMediaResult uploadMediaAccountCancelApplication(File imageFile) throws WxPayException, IOException;;
538575
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,27 @@
77
import com.github.binarywang.wxpay.exception.WxPayException;
88
import com.github.binarywang.wxpay.service.EcommerceService;
99
import com.github.binarywang.wxpay.service.WxPayService;
10+
import com.github.binarywang.wxpay.v3.WechatPayUploadHttpPost;
1011
import com.github.binarywang.wxpay.v3.util.AesUtils;
1112
import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil;
1213
import com.google.common.base.CaseFormat;
1314
import com.google.gson.Gson;
1415
import com.google.gson.GsonBuilder;
1516
import lombok.RequiredArgsConstructor;
17+
import org.apache.commons.codec.digest.DigestUtils;
1618
import org.apache.commons.lang3.StringUtils;
1719

1820
import java.beans.BeanInfo;
1921
import java.beans.IntrospectionException;
2022
import java.beans.Introspector;
2123
import java.beans.PropertyDescriptor;
24+
import java.io.File;
25+
import java.io.FileInputStream;
2226
import java.io.IOException;
2327
import java.io.InputStream;
2428
import java.lang.reflect.InvocationTargetException;
2529
import java.lang.reflect.Method;
30+
import java.net.URI;
2631
import java.nio.charset.StandardCharsets;
2732
import java.security.GeneralSecurityException;
2833
import java.text.DateFormat;
@@ -395,6 +400,36 @@ public SubsidiesCancelResult subsidiesCancel(SubsidiesCancelRequest subsidiesCan
395400
String response = this.payService.postV3(url, GSON.toJson(subsidiesCancelRequest));
396401
return GSON.fromJson(response, SubsidiesCancelResult.class);
397402
}
403+
404+
@Override
405+
public AccountCancelApplicationsResult createdAccountCancelApplication(AccountCancelApplicationsRequest accountCancelApplicationsRequest) throws WxPayException {
406+
String url = String.format("%s/v3/ecommerce/account/cancel-applications", this.payService.getPayBaseUrl());
407+
String response = this.payService.postV3(url, GSON.toJson(accountCancelApplicationsRequest));
408+
return GSON.fromJson(response, AccountCancelApplicationsResult.class);
409+
}
410+
411+
@Override
412+
public AccountCancelApplicationsResult getAccountCancelApplication(String outApplyNo) throws WxPayException {
413+
String url = String.format("%s/v3/ecommerce/account/cancel-applications/out-apply-no/%s", this.payService.getPayBaseUrl(), outApplyNo);
414+
String result = this.payService.getV3(url);
415+
return GSON.fromJson(result, AccountCancelApplicationsResult.class);
416+
}
417+
418+
@Override
419+
public AccountCancelApplicationsMediaResult uploadMediaAccountCancelApplication(File imageFile) throws WxPayException, IOException {
420+
String url = String.format("%s/v3/ecommerce/account/cancel-applications/media", this.payService.getPayBaseUrl());
421+
try (FileInputStream s1 = new FileInputStream(imageFile)) {
422+
String sha256 = DigestUtils.sha256Hex(s1);
423+
try (InputStream s2 = new FileInputStream(imageFile)) {
424+
WechatPayUploadHttpPost request = new WechatPayUploadHttpPost.Builder(URI.create(url))
425+
.withImage(imageFile.getName(), sha256, s2)
426+
.buildEcommerceAccount();
427+
String result = this.payService.postV3(url, request);
428+
return GSON.fromJson(result, AccountCancelApplicationsMediaResult.class);
429+
}
430+
}
431+
}
432+
398433
/**
399434
* 校验通知签名
400435
*

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/WechatPayUploadHttpPost.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,33 @@ public WechatPayUploadHttpPost build() {
7272

7373
return request;
7474
}
75+
76+
/**
77+
* 平台收付通(注销申请)-图片上传-图片上传
78+
* https://pay.weixin.qq.com/docs/partner/apis/ecommerce-cancel/media/upload-media.html
79+
* @return WechatPayUploadHttpPost
80+
*/
81+
public WechatPayUploadHttpPost buildEcommerceAccount() {
82+
if (fileName == null || fileSha256 == null || fileInputStream == null) {
83+
throw new IllegalArgumentException("缺少待上传图片文件信息");
84+
}
85+
86+
if (uri == null) {
87+
throw new IllegalArgumentException("缺少上传图片接口URL");
88+
}
89+
90+
String meta = String.format("{\"file_name\":\"%s\",\"file_digest\":\"%s\"}", fileName, fileSha256);
91+
WechatPayUploadHttpPost request = new WechatPayUploadHttpPost(uri, meta);
92+
93+
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
94+
entityBuilder.setMode(HttpMultipartMode.RFC6532)
95+
.addBinaryBody("file", fileInputStream, fileContentType, fileName)
96+
.addTextBody("meta", meta, ContentType.APPLICATION_JSON);
97+
98+
request.setEntity(entityBuilder.build());
99+
request.addHeader("Accept", ContentType.APPLICATION_JSON.toString());
100+
101+
return request;
102+
}
75103
}
76104
}

weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package com.github.binarywang.wxpay.service.impl;
2+
import com.google.common.collect.Lists;
23

3-
import com.github.binarywang.wxpay.bean.ecommerce.CombineTransactionsRequest;
4-
import com.github.binarywang.wxpay.bean.ecommerce.PartnerTransactionsQueryRequest;
5-
import com.github.binarywang.wxpay.bean.ecommerce.PartnerTransactionsResult;
6-
import com.github.binarywang.wxpay.bean.ecommerce.ProfitSharingReceiverRequest;
7-
import com.github.binarywang.wxpay.bean.ecommerce.ProfitSharingReceiverResult;
8-
import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader;
9-
import com.github.binarywang.wxpay.bean.ecommerce.TransactionsResult;
4+
import com.github.binarywang.wxpay.bean.ecommerce.*;
105
import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum;
116
import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum;
127
import com.github.binarywang.wxpay.exception.WxPayException;
@@ -19,6 +14,8 @@
1914
import org.testng.annotations.Guice;
2015
import org.testng.annotations.Test;
2116

17+
import java.io.File;
18+
import java.io.IOException;
2219
import java.nio.charset.StandardCharsets;
2320
import java.util.Arrays;
2421

@@ -151,4 +148,29 @@ public void testSubDayEndBalance() throws WxPayException {
151148
String date = "";
152149
wxPayService.getEcommerceService().subDayEndBalance(subMchid, date);
153150
}
151+
152+
@Test
153+
public void testCreatedAccountCancelApplication() throws WxPayException {
154+
AccountCancelApplicationsRequest request = new AccountCancelApplicationsRequest();
155+
request.setSubMchid("");
156+
request.setOutApplyNo("");
157+
request.setApplicationInfo(Lists.newArrayList());
158+
159+
AccountCancelApplicationsResult result = wxPayService.getEcommerceService().createdAccountCancelApplication(request);
160+
log.info("请求参数:{} 响应结果:{}", request, result);
161+
}
162+
163+
@Test
164+
public void testGetAccountCancelApplication() throws WxPayException {
165+
String request = "申请单号";
166+
AccountCancelApplicationsResult result = wxPayService.getEcommerceService().getAccountCancelApplication(request);
167+
log.info("请求参数:{} 响应结果:{}", request, result);
168+
}
169+
170+
@Test
171+
public void testUploadMediaAccountCancelApplication() throws WxPayException, IOException {
172+
AccountCancelApplicationsMediaResult result = wxPayService.getEcommerceService()
173+
.uploadMediaAccountCancelApplication(new File("src\\test\\resources\\mm.jpeg"));
174+
log.info("响应结果:{}", result);
175+
}
154176
}

0 commit comments

Comments
 (0)
0