Skip to content

Commit 93a2fa7

Browse files
authored
🆕 #3519 【小程序】实现交易投诉的相关接口
1 parent 1f4ed68 commit 93a2fa7

15 files changed

+1073
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package cn.binarywang.wx.miniapp.api;
2+
3+
import cn.binarywang.wx.miniapp.bean.complaint.*;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
6+
import java.io.File;
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
10+
/**
11+
* 小程序交易投诉接口
12+
*
13+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
14+
* created on 2025-01-01
15+
*/
16+
public interface WxMaComplaintService {
17+
18+
/**
19+
* <pre>
20+
* 查询投诉单列表API
21+
* 商户可通过调用此接口,查询指定时间段的所有用户投诉信息,以分页输出查询结果。
22+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
23+
* </pre>
24+
*
25+
* @param request {@link WxMaComplaintRequest} 查询投诉单列表请求数据
26+
* @return {@link WxMaComplaintResult} 微信返回的投诉单列表
27+
* @throws WxErrorException the wx error exception
28+
*/
29+
WxMaComplaintResult queryComplaints(WxMaComplaintRequest request) throws WxErrorException;
30+
31+
/**
32+
* <pre>
33+
* 查询投诉单详情API
34+
* 商户可通过调用此接口,查询指定投诉单的用户投诉详情,包含投诉内容、投诉关联订单、投诉人联系方式等信息,方便商户处理投诉。
35+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
36+
* </pre>
37+
*
38+
* @param request {@link WxMaComplaintDetailRequest} 投诉单详情请求数据
39+
* @return {@link WxMaComplaintDetailResult} 微信返回的投诉单详情
40+
* @throws WxErrorException the wx error exception
41+
*/
42+
WxMaComplaintDetailResult getComplaint(WxMaComplaintDetailRequest request) throws WxErrorException;
43+
44+
/**
45+
* <pre>
46+
* 查询投诉协商历史API
47+
* 商户可通过调用此接口,查询指定投诉的用户商户协商历史,以分页输出查询结果,方便商户根据处理历史来制定后续处理方案。
48+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
49+
* </pre>
50+
*
51+
* @param request {@link WxMaNegotiationHistoryRequest} 请求数据
52+
* @return {@link WxMaNegotiationHistoryResult} 微信返回结果
53+
* @throws WxErrorException the wx error exception
54+
*/
55+
WxMaNegotiationHistoryResult queryNegotiationHistorys(WxMaNegotiationHistoryRequest request) throws WxErrorException;
56+
57+
/**
58+
* <pre>
59+
* 创建投诉通知回调地址API
60+
* 商户通过调用此接口创建投诉通知回调URL,当用户产生新投诉且投诉状态已变更时,微信会通过回调URL通知商户。
61+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
62+
* </pre>
63+
*
64+
* @param request {@link WxMaComplaintNotifyUrlRequest} 请求数据
65+
* @return {@link WxMaComplaintNotifyUrlResult} 微信返回结果
66+
* @throws WxErrorException the wx error exception
67+
*/
68+
WxMaComplaintNotifyUrlResult addComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException;
69+
70+
/**
71+
* <pre>
72+
* 查询投诉通知回调地址API
73+
* 商户通过调用此接口查询投诉通知的回调URL。
74+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
75+
* </pre>
76+
*
77+
* @return {@link WxMaComplaintNotifyUrlResult} 微信返回结果
78+
* @throws WxErrorException the wx error exception
79+
*/
80+
WxMaComplaintNotifyUrlResult getComplaintNotifyUrl() throws WxErrorException;
81+
82+
/**
83+
* <pre>
84+
* 更新投诉通知回调地址API
85+
* 商户通过调用此接口更新投诉通知的回调URL。
86+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
87+
* </pre>
88+
*
89+
* @param request {@link WxMaComplaintNotifyUrlRequest} 请求数据
90+
* @return {@link WxMaComplaintNotifyUrlResult} 微信返回结果
91+
* @throws WxErrorException the wx error exception
92+
*/
93+
WxMaComplaintNotifyUrlResult updateComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException;
94+
95+
/**
96+
* <pre>
97+
* 删除投诉通知回调地址API
98+
* 当商户不再需要推送通知时,可通过调用此接口删除投诉通知的回调URL,取消通知回调。
99+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
100+
* </pre>
101+
*
102+
* @throws WxErrorException the wx error exception
103+
*/
104+
void deleteComplaintNotifyUrl() throws WxErrorException;
105+
106+
/**
107+
* <pre>
108+
* 提交回复API
109+
* 商户可通过调用此接口,提交回复内容。其中上传图片凭证需首先调用商户上传反馈图片接口,得到图片id,再将id填入请求。
110+
* 回复可配置文字链,传入跳转链接文案和跳转链接字段,用户点击即可跳转对应页面
111+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
112+
* </pre>
113+
*
114+
* @param request {@link WxMaResponseRequest} 请求数据
115+
* @throws WxErrorException the wx error exception
116+
*/
117+
void submitResponse(WxMaResponseRequest request) throws WxErrorException;
118+
119+
/**
120+
* <pre>
121+
* 反馈处理完成API
122+
* 商户可通过调用此接口,反馈投诉单已处理完成。
123+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
124+
* </pre>
125+
*
126+
* @param request {@link WxMaCompleteRequest} 请求数据
127+
* @throws WxErrorException the wx error exception
128+
*/
129+
void complete(WxMaCompleteRequest request) throws WxErrorException;
130+
131+
/**
132+
* <pre>
133+
* 商户上传反馈图片API
134+
* 商户可通过调用此接口上传反馈图片凭证,上传成功后可在提交回复时使用。
135+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
136+
* </pre>
137+
*
138+
* @param imageFile 需要上传的图片文件
139+
* @return String 微信返回的媒体文件标识Id
140+
* @throws WxErrorException the wx error exception
141+
* @throws IOException IO异常
142+
*/
143+
String uploadResponseImage(File imageFile) throws WxErrorException, IOException;
144+
145+
/**
146+
* <pre>
147+
* 商户上传反馈图片API
148+
* 商户可通过调用此接口上传反馈图片凭证,上传成功后可在提交回复时使用。
149+
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
150+
* </pre>
151+
*
152+
* @param inputStream 需要上传的图片文件流
153+
* @param fileName 需要上传的图片文件名
154+
* @return String 微信返回的媒体文件标识Id
155+
* @throws WxErrorException the wx error exception
156+
* @throws IOException IO异常
157+
*/
158+
String uploadResponseImage(InputStream inputStream, String fileName) throws WxErrorException, IOException;
159+
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,4 +605,13 @@ WxMaApiResponse execute(
605605
* @return 同城配送服务对象WxMaIntracityService
606606
*/
607607
WxMaIntracityService getIntracityService();
608+
609+
/**
610+
* 获取交易投诉服务对象。
611+
* <br>
612+
* 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
613+
*
614+
* @return 交易投诉服务对象WxMaComplaintService
615+
*/
616+
WxMaComplaintService getComplaintService();
608617
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
165165
new WxMaExpressDeliveryReturnServiceImpl(this);
166166
private final WxMaPromotionService wxMaPromotionService = new WxMaPromotionServiceImpl(this);
167167
private final WxMaIntracityService intracityService = new WxMaIntracityServiceImpl(this);
168+
private final WxMaComplaintService complaintService = new WxMaComplaintServiceImpl(this);
168169

169170
private Map<String, WxMaConfig> configMap = new HashMap<>();
170171
private int retrySleepMillis = 1000;
@@ -1030,4 +1031,9 @@ private String aesDecodeResponse(WxMaApiResponse response, String aad, SecretKey
10301031
public WxMaIntracityService getIntracityService() {
10311032
return this.intracityService;
10321033
}
1034+
1035+
@Override
1036+
public WxMaComplaintService getComplaintService() {
1037+
return this.complaintService;
1038+
}
10331039
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package cn.binarywang.wx.miniapp.api.impl;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaComplaintService;
4+
import cn.binarywang.wx.miniapp.api.WxMaService;
5+
import cn.binarywang.wx.miniapp.bean.complaint.*;
6+
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
7+
import com.google.gson.JsonObject;
8+
import lombok.RequiredArgsConstructor;
9+
import me.chanjar.weixin.common.bean.CommonUploadParam;
10+
import me.chanjar.weixin.common.error.WxError;
11+
import me.chanjar.weixin.common.error.WxErrorException;
12+
import me.chanjar.weixin.common.util.fs.FileUtils;
13+
14+
import java.io.File;
15+
import java.io.IOException;
16+
import java.io.InputStream;
17+
import java.util.UUID;
18+
19+
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Complaint.*;
20+
21+
/**
22+
* 小程序交易投诉接口实现
23+
*
24+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
25+
* created on 2025-01-01
26+
*/
27+
@RequiredArgsConstructor
28+
public class WxMaComplaintServiceImpl implements WxMaComplaintService {
29+
private static final String JSON_CONTENT_TYPE = "application/json";
30+
private final WxMaService wxMaService;
31+
32+
@Override
33+
public WxMaComplaintResult queryComplaints(WxMaComplaintRequest request) throws WxErrorException {
34+
String responseContent = this.wxMaService.post(QUERY_COMPLAINTS_URL, request.toJson());
35+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintResult.class);
36+
}
37+
38+
@Override
39+
public WxMaComplaintDetailResult getComplaint(WxMaComplaintDetailRequest request) throws WxErrorException {
40+
String responseContent = this.wxMaService.post(GET_COMPLAINT_URL, request.toJson());
41+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintDetailResult.class);
42+
}
43+
44+
@Override
45+
public WxMaNegotiationHistoryResult queryNegotiationHistorys(WxMaNegotiationHistoryRequest request) throws WxErrorException {
46+
String responseContent = this.wxMaService.post(QUERY_NEGOTIATION_HISTORY_URL, request.toJson());
47+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaNegotiationHistoryResult.class);
48+
}
49+
50+
@Override
51+
public WxMaComplaintNotifyUrlResult addComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException {
52+
String responseContent = this.wxMaService.post(ADD_COMPLAINT_NOTIFY_URL, request.toJson());
53+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintNotifyUrlResult.class);
54+
}
55+
56+
@Override
57+
public WxMaComplaintNotifyUrlResult getComplaintNotifyUrl() throws WxErrorException {
58+
String responseContent = this.wxMaService.get(GET_COMPLAINT_NOTIFY_URL, null);
59+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintNotifyUrlResult.class);
60+
}
61+
62+
@Override
63+
public WxMaComplaintNotifyUrlResult updateComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException {
64+
String responseContent = this.wxMaService.post(UPDATE_COMPLAINT_NOTIFY_URL, request.toJson());
65+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintNotifyUrlResult.class);
66+
}
67+
68+
@Override
69+
public void deleteComplaintNotifyUrl() throws WxErrorException {
70+
this.wxMaService.post(DELETE_COMPLAINT_NOTIFY_URL, "{}");
71+
}
72+
73+
@Override
74+
public void submitResponse(WxMaResponseRequest request) throws WxErrorException {
75+
this.wxMaService.post(SUBMIT_RESPONSE_URL, request.toJson());
76+
}
77+
78+
@Override
79+
public void complete(WxMaCompleteRequest request) throws WxErrorException {
80+
this.wxMaService.post(COMPLETE_COMPLAINT_URL, request.toJson());
81+
}
82+
83+
@Override
84+
public String uploadResponseImage(File imageFile) throws WxErrorException, IOException {
85+
String result = this.wxMaService.upload(UPLOAD_RESPONSE_IMAGE_URL,
86+
CommonUploadParam.fromFile("image", imageFile));
87+
JsonObject jsonResult = WxMaGsonBuilder.create().fromJson(result, JsonObject.class);
88+
return jsonResult.get("media_id").getAsString();
89+
}
90+
91+
@Override
92+
public String uploadResponseImage(InputStream inputStream, String fileName) throws WxErrorException, IOException {
93+
try {
94+
return this.uploadResponseImage(FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileName));
95+
} catch (IOException e) {
96+
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
97+
}
98+
}
99+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cn.binarywang.wx.miniapp.bean.complaint;
2+
3+
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
7+
import lombok.Data;
8+
import lombok.NoArgsConstructor;
9+
10+
import java.io.Serializable;
11+
12+
/**
13+
* 小程序投诉单详情请求实体
14+
*
15+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
16+
* created on 2025-01-01
17+
*/
18+
@Data
19+
@Builder(builderMethodName = "newBuilder")
20+
@NoArgsConstructor
21+
@AllArgsConstructor
22+
public class WxMaComplaintDetailRequest implements Serializable {
23+
private static final long serialVersionUID = 3244929701614280806L;
24+
25+
/**
26+
* <pre>
27+
* 字段名:投诉单号
28+
* 是否必填:是
29+
* 描述:投诉单对应的投诉单号
30+
* </pre>
31+
*/
32+
@SerializedName("complaint_id")
33+
private String complaintId;
34+
35+
public String toJson() {
36+
return WxMaGsonBuilder.create().toJson(this);
37+
}
38+
}

0 commit comments

Comments
 (0)