1
0
mirror of synced 2025-11-06 04:20:53 +08:00

🆕 #3681 【小程序】增加企微客服增删查3个接口

This commit is contained in:
tryking123
2025-08-31 21:44:24 +08:00
committed by GitHub
parent 0424d75882
commit 781798345e
5 changed files with 177 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.customservice.WxMaCustomserviceResult;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* <pre>
* 小程序 - 微信客服 相关接口
* 负责处理 https://api.weixin.qq.com/customservice/work/**
* 文档https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/kf-work/getKfWorkBound.html
* 绑定的企业ID需和小程序主体一致。
* 目前仅支持绑定非个人小程序。
* Created by tryking123 on 2025/8/18.
* </pre>
*
* @author <a href="https://github.com/tryking123">tryking123</a>
*/
public interface WxMaCustomserviceWorkService {
/**
* 查询小程序的微信客服绑定情况
*/
String GET_CUSTOMSERVICE_URL = "https://api.weixin.qq.com/customservice/work/get";
/**
* 为小程序绑定微信客服 注:此接口绑定的企业ID需完成企业认证
*/
String BIND_CUSTOMSERVICE_URL = "https://api.weixin.qq.com/customservice/work/bind";
/**
* 为小程序解除绑定微信客服
*/
String UNBIND_CUSTOMSERVICE_URL = "https://api.weixin.qq.com/customservice/work/unbind";
/**
* 查询小程序的微信客服绑定情况
*
* @return 成功示例json { "errcode": 0,"entityName": "XXXXX有限公司","corpid": "wwee11111xxxxxxx","bindTime": 1694611289 }
* @throws WxErrorException
*/
WxMaCustomserviceResult getCustomservice() throws WxErrorException;
/**
* 绑定微信客服
* @param corpid 企业ID获取方式参考:https://developer.work.weixin.qq.com/document/path/90665#corpid
* @return 成功示例json { "errcode": 0 }
* @throws WxErrorException
*/
WxMaCustomserviceResult bindCustomservice(String corpid) throws WxErrorException;
/**
* 解除绑定微信客服
* @param corpid 企业ID获取方式参考:https://developer.work.weixin.qq.com/document/path/90665#corpid
* @return 成功示例json { "errcode": 0 }
* @throws WxErrorException
*/
WxMaCustomserviceResult unbindCustomservice(String corpid) throws WxErrorException;
}

View File

@@ -278,6 +278,13 @@ public interface WxMaService extends WxService {
*/
WxMaCodeService getCodeService();
/**
* 获取小程序 - 微信客服。
*
* @return 微信客服服务对象WxMaCustomserviceWorkService
*/
WxMaCustomserviceWorkService getCustomserviceWorkService();
/**
* 获取jsapi操作相关服务对象。
*

View File

@@ -112,6 +112,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
private final WxMaSchemeService schemeService = new WxMaSchemeServiceImpl(this);
private final WxMaAnalysisService analysisService = new WxMaAnalysisServiceImpl(this);
private final WxMaCodeService codeService = new WxMaCodeServiceImpl(this);
private final WxMaCustomserviceWorkService customserviceWorkService = new WxMaCustomserviceWorkServiceImpl(this);
private final WxMaInternetService internetService = new WxMaInternetServiceImpl(this);
private final WxMaSettingService settingService = new WxMaSettingServiceImpl(this);
private final WxMaJsapiService jsapiService = new WxMaJsapiServiceImpl(this);
@@ -651,6 +652,11 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
return this.codeService;
}
@Override
public WxMaCustomserviceWorkService getCustomserviceWorkService() {
return this.customserviceWorkService;
}
@Override
public WxMaJsapiService getJsapiService() {
return this.jsapiService;

View File

@@ -0,0 +1,51 @@
package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaCustomserviceWorkService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.customservice.WxMaCustomserviceResult;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* <pre>
* 小程序 - 微信客服 相关接口
* 负责处理 https://api.weixin.qq.com/customservice/work/**
* 文档https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/kf-work/getKfWorkBound.html
* 绑定的企业ID需和小程序主体一致。
* 目前仅支持绑定非个人小程序。
* Created by tryking123 on 2025/8/18.
* </pre>
*
* @author <a href="https://github.com/tryking123">tryking123</a>
*/
@RequiredArgsConstructor
public class WxMaCustomserviceWorkServiceImpl implements WxMaCustomserviceWorkService {
private static final String CORPID = "corpid";
private final WxMaService service;
@Override
public WxMaCustomserviceResult getCustomservice() throws WxErrorException {
String responseContent = this.service.get(GET_CUSTOMSERVICE_URL, null);
return WxMaCustomserviceResult.fromJson(responseContent);
}
@Override
public WxMaCustomserviceResult bindCustomservice(String corpid) throws WxErrorException {
JsonObject paramJson = new JsonObject();
paramJson.addProperty(CORPID, corpid);
String response = this.service.post(BIND_CUSTOMSERVICE_URL, paramJson);
return WxMaCustomserviceResult.fromJson(response);
}
@Override
public WxMaCustomserviceResult unbindCustomservice(String corpid) throws WxErrorException {
JsonObject paramJson = new JsonObject();
paramJson.addProperty(CORPID, corpid);
String response = this.service.post(UNBIND_CUSTOMSERVICE_URL, paramJson);
return WxMaCustomserviceResult.fromJson(response);
}
}

View File

@@ -0,0 +1,56 @@
package cn.binarywang.wx.miniapp.bean.customservice;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* 客服绑定结果信息包括错误码、主体名称、企业ID和绑定时间戳。
* <p>
* 字段说明:
* <ul>
* <li>errCode: 错误码</li>
* <li>entityName: 小程序主体名称,未绑定时不返回</li>
* <li>corpid: 企业ID未绑定时不返回</li>
* <li>bindTime: 接受绑定时间戳(毫秒)</li>
* </ul>
* @author <a href="https://github.com/tryking123">tryking123</a>
* @since 2025/8/18 17:40
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaCustomserviceResult implements Serializable {
private static final long serialVersionUID = 8854979405505241314L;
@SerializedName("errcode")
private Integer errCode;
/**
* 该小程序的主体名称,未绑定时不返回
*/
@SerializedName("entityName")
private String entityName;
/**
* 企业ID未绑定时不返回
*/
@SerializedName("corpid")
private String corpid;
/** 接受绑定时间戳ms */
@JsonProperty("bindTime")
private Long bindTime;
public static WxMaCustomserviceResult fromJson(String json) {
return WxMaGsonBuilder.create().fromJson(json, WxMaCustomserviceResult.class);
}
}