Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Copilot wants to merge 3 commits into develop
base: develop
Choose a base branch
Loading
from copilot/fix-3519
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file Open in desktop
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;
}
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -605,4 +605,13 @@ WxMaApiResponse execute(
* @return 同城配送服务对象WxMaIntracityService
*/
WxMaIntracityService getIntracityService();

/**
* 获取交易投诉服务对象。
* <br>
* 文档:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/guarantee/complaint.html
*
* @return 交易投诉服务对象WxMaComplaintService
*/
WxMaComplaintService getComplaintService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
new WxMaExpressDeliveryReturnServiceImpl(this);
private final WxMaPromotionService wxMaPromotionService = new WxMaPromotionServiceImpl(this);
private final WxMaIntracityService intracityService = new WxMaIntracityServiceImpl(this);
private final WxMaComplaintService complaintService = new WxMaComplaintServiceImpl(this);

private Map<String, WxMaConfig> configMap = new HashMap<>();
private int retrySleepMillis = 1000;
Expand Down Expand Up @@ -1030,4 +1031,9 @@ private String aesDecodeResponse(WxMaApiResponse response, String aad, SecretKey
public WxMaIntracityService getIntracityService() {
return this.intracityService;
}

@Override
public WxMaComplaintService getComplaintService() {
return this.complaintService;
}
}
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);
}
}
}
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);
}
}
Loading

AltStyle によって変換されたページ (->オリジナル) /