-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Implement WeChat Mini Program complaint handling service with comprehensive API support #3690
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
Draft
Draft
Changes from all commits
Commits
Show all changes
3 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
159 changes: 159 additions & 0 deletions
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaComplaintService.java
This file contains hidden or 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,159 @@ | ||
package cn.binarywang.wx.miniapp.api; | ||
|
||
import cn.binarywang.wx.miniapp.bean.complaint.*; | ||
import me.chanjar.weixin.common.error.WxErrorException; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* 小程序交易投诉接口 | ||
* | ||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | ||
* created on 2025年01月01日 | ||
*/ | ||
public interface WxMaComplaintService { | ||
|
||
/** | ||
* <pre> | ||
* 查询投诉单列表API | ||
* 商户可通过调用此接口,查询指定时间段的所有用户投诉信息,以分页输出查询结果。 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @param request {@link WxMaComplaintRequest} 查询投诉单列表请求数据 | ||
* @return {@link WxMaComplaintResult} 微信返回的投诉单列表 | ||
* @throws WxErrorException the wx error exception | ||
*/ | ||
WxMaComplaintResult queryComplaints(WxMaComplaintRequest request) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* 查询投诉单详情API | ||
* 商户可通过调用此接口,查询指定投诉单的用户投诉详情,包含投诉内容、投诉关联订单、投诉人联系方式等信息,方便商户处理投诉。 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @param request {@link WxMaComplaintDetailRequest} 投诉单详情请求数据 | ||
* @return {@link WxMaComplaintDetailResult} 微信返回的投诉单详情 | ||
* @throws WxErrorException the wx error exception | ||
*/ | ||
WxMaComplaintDetailResult getComplaint(WxMaComplaintDetailRequest request) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* 查询投诉协商历史API | ||
* 商户可通过调用此接口,查询指定投诉的用户商户协商历史,以分页输出查询结果,方便商户根据处理历史来制定后续处理方案。 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @param request {@link WxMaNegotiationHistoryRequest} 请求数据 | ||
* @return {@link WxMaNegotiationHistoryResult} 微信返回结果 | ||
* @throws WxErrorException the wx error exception | ||
*/ | ||
WxMaNegotiationHistoryResult queryNegotiationHistorys(WxMaNegotiationHistoryRequest request) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* 创建投诉通知回调地址API | ||
* 商户通过调用此接口创建投诉通知回调URL,当用户产生新投诉且投诉状态已变更时,微信会通过回调URL通知商户。 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @param request {@link WxMaComplaintNotifyUrlRequest} 请求数据 | ||
* @return {@link WxMaComplaintNotifyUrlResult} 微信返回结果 | ||
* @throws WxErrorException the wx error exception | ||
*/ | ||
WxMaComplaintNotifyUrlResult addComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* 查询投诉通知回调地址API | ||
* 商户通过调用此接口查询投诉通知的回调URL。 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @return {@link WxMaComplaintNotifyUrlResult} 微信返回结果 | ||
* @throws WxErrorException the wx error exception | ||
*/ | ||
WxMaComplaintNotifyUrlResult getComplaintNotifyUrl() throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* 更新投诉通知回调地址API | ||
* 商户通过调用此接口更新投诉通知的回调URL。 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @param request {@link WxMaComplaintNotifyUrlRequest} 请求数据 | ||
* @return {@link WxMaComplaintNotifyUrlResult} 微信返回结果 | ||
* @throws WxErrorException the wx error exception | ||
*/ | ||
WxMaComplaintNotifyUrlResult updateComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* 删除投诉通知回调地址API | ||
* 当商户不再需要推送通知时,可通过调用此接口删除投诉通知的回调URL,取消通知回调。 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @throws WxErrorException the wx error exception | ||
*/ | ||
void deleteComplaintNotifyUrl() throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* 提交回复API | ||
* 商户可通过调用此接口,提交回复内容。其中上传图片凭证需首先调用商户上传反馈图片接口,得到图片id,再将id填入请求。 | ||
* 回复可配置文字链,传入跳转链接文案和跳转链接字段,用户点击即可跳转对应页面 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @param request {@link WxMaResponseRequest} 请求数据 | ||
* @throws WxErrorException the wx error exception | ||
*/ | ||
void submitResponse(WxMaResponseRequest request) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* 反馈处理完成API | ||
* 商户可通过调用此接口,反馈投诉单已处理完成。 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @param request {@link WxMaCompleteRequest} 请求数据 | ||
* @throws WxErrorException the wx error exception | ||
*/ | ||
void complete(WxMaCompleteRequest request) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* 商户上传反馈图片API | ||
* 商户可通过调用此接口上传反馈图片凭证,上传成功后可在提交回复时使用。 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @param imageFile 需要上传的图片文件 | ||
* @return String 微信返回的媒体文件标识Id | ||
* @throws WxErrorException the wx error exception | ||
* @throws IOException IO异常 | ||
*/ | ||
String uploadResponseImage(File imageFile) throws WxErrorException, IOException; | ||
|
||
/** | ||
* <pre> | ||
* 商户上传反馈图片API | ||
* 商户可通过调用此接口上传反馈图片凭证,上传成功后可在提交回复时使用。 | ||
* 文档详见: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html | ||
* </pre> | ||
* | ||
* @param inputStream 需要上传的图片文件流 | ||
* @param fileName 需要上传的图片文件名 | ||
* @return String 微信返回的媒体文件标识Id | ||
* @throws WxErrorException the wx error exception | ||
* @throws IOException IO异常 | ||
*/ | ||
String uploadResponseImage(InputStream inputStream, String fileName) throws WxErrorException, IOException; | ||
} |
This file contains hidden or 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
This file contains hidden or 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
99 changes: 99 additions & 0 deletions
...ava-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaComplaintServiceImpl.java
This file contains hidden or 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,99 @@ | ||
package cn.binarywang.wx.miniapp.api.impl; | ||
|
||
import cn.binarywang.wx.miniapp.api.WxMaComplaintService; | ||
import cn.binarywang.wx.miniapp.api.WxMaService; | ||
import cn.binarywang.wx.miniapp.bean.complaint.*; | ||
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; | ||
import com.google.gson.JsonObject; | ||
import lombok.RequiredArgsConstructor; | ||
import me.chanjar.weixin.common.bean.CommonUploadParam; | ||
import me.chanjar.weixin.common.error.WxError; | ||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.common.util.fs.FileUtils; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.UUID; | ||
|
||
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Complaint.*; | ||
|
||
/** | ||
* 小程序交易投诉接口实现 | ||
* | ||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | ||
* created on 2025年01月01日 | ||
*/ | ||
@RequiredArgsConstructor | ||
public class WxMaComplaintServiceImpl implements WxMaComplaintService { | ||
private static final String JSON_CONTENT_TYPE = "application/json"; | ||
private final WxMaService wxMaService; | ||
|
||
@Override | ||
public WxMaComplaintResult queryComplaints(WxMaComplaintRequest request) throws WxErrorException { | ||
String responseContent = this.wxMaService.post(QUERY_COMPLAINTS_URL, request.toJson()); | ||
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintResult.class); | ||
} | ||
|
||
@Override | ||
public WxMaComplaintDetailResult getComplaint(WxMaComplaintDetailRequest request) throws WxErrorException { | ||
String responseContent = this.wxMaService.post(GET_COMPLAINT_URL, request.toJson()); | ||
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintDetailResult.class); | ||
} | ||
|
||
@Override | ||
public WxMaNegotiationHistoryResult queryNegotiationHistorys(WxMaNegotiationHistoryRequest request) throws WxErrorException { | ||
String responseContent = this.wxMaService.post(QUERY_NEGOTIATION_HISTORY_URL, request.toJson()); | ||
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaNegotiationHistoryResult.class); | ||
} | ||
|
||
@Override | ||
public WxMaComplaintNotifyUrlResult addComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException { | ||
String responseContent = this.wxMaService.post(ADD_COMPLAINT_NOTIFY_URL, request.toJson()); | ||
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintNotifyUrlResult.class); | ||
} | ||
|
||
@Override | ||
public WxMaComplaintNotifyUrlResult getComplaintNotifyUrl() throws WxErrorException { | ||
String responseContent = this.wxMaService.get(GET_COMPLAINT_NOTIFY_URL, null); | ||
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintNotifyUrlResult.class); | ||
} | ||
|
||
@Override | ||
public WxMaComplaintNotifyUrlResult updateComplaintNotifyUrl(WxMaComplaintNotifyUrlRequest request) throws WxErrorException { | ||
String responseContent = this.wxMaService.post(UPDATE_COMPLAINT_NOTIFY_URL, request.toJson()); | ||
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaComplaintNotifyUrlResult.class); | ||
} | ||
|
||
@Override | ||
public void deleteComplaintNotifyUrl() throws WxErrorException { | ||
this.wxMaService.post(DELETE_COMPLAINT_NOTIFY_URL, "{}"); | ||
} | ||
|
||
@Override | ||
public void submitResponse(WxMaResponseRequest request) throws WxErrorException { | ||
this.wxMaService.post(SUBMIT_RESPONSE_URL, request.toJson()); | ||
} | ||
|
||
@Override | ||
public void complete(WxMaCompleteRequest request) throws WxErrorException { | ||
this.wxMaService.post(COMPLETE_COMPLAINT_URL, request.toJson()); | ||
} | ||
|
||
@Override | ||
public String uploadResponseImage(File imageFile) throws WxErrorException, IOException { | ||
String result = this.wxMaService.upload(UPLOAD_RESPONSE_IMAGE_URL, | ||
CommonUploadParam.fromFile("image", imageFile)); | ||
JsonObject jsonResult = WxMaGsonBuilder.create().fromJson(result, JsonObject.class); | ||
return jsonResult.get("media_id").getAsString(); | ||
} | ||
|
||
@Override | ||
public String uploadResponseImage(InputStream inputStream, String fileName) throws WxErrorException, IOException { | ||
try { | ||
return this.uploadResponseImage(FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileName)); | ||
} catch (IOException e) { | ||
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
...app/src/main/java/cn/binarywang/wx/miniapp/bean/complaint/WxMaComplaintDetailRequest.java
This file contains hidden or 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,38 @@ | ||
package cn.binarywang.wx.miniapp.bean.complaint; | ||
|
||
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; | ||
import com.google.gson.annotations.SerializedName; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* 小程序投诉单详情请求实体 | ||
* | ||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | ||
* created on 2025年01月01日 | ||
*/ | ||
@Data | ||
@Builder(builderMethodName = "newBuilder") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class WxMaComplaintDetailRequest implements Serializable { | ||
private static final long serialVersionUID = 3244929701614280806L; | ||
|
||
/** | ||
* <pre> | ||
* 字段名:投诉单号 | ||
* 是否必填:是 | ||
* 描述:投诉单对应的投诉单号 | ||
* </pre> | ||
*/ | ||
@SerializedName("complaint_id") | ||
private String complaintId; | ||
|
||
public String toJson() { | ||
return WxMaGsonBuilder.create().toJson(this); | ||
} | ||
} |
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.