Skip to content

Commit 7817983

Browse files
authored
🆕 #3681 【小程序】增加企微客服增删查3个接口
1 parent 0424d75 commit 7817983

File tree

5 files changed

+177
-0
lines changed

5 files changed

+177
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package cn.binarywang.wx.miniapp.api;
2+
3+
import cn.binarywang.wx.miniapp.bean.customservice.WxMaCustomserviceResult;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
6+
7+
/**
8+
* <pre>
9+
* 小程序 - 微信客服 相关接口
10+
* 负责处理 https://api.weixin.qq.com/customservice/work/**
11+
* 文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/kf-work/getKfWorkBound.html
12+
* 绑定的企业ID,需和小程序主体一致。
13+
* 目前仅支持绑定非个人小程序。
14+
* Created by tryking123 on 2025/8/18.
15+
* </pre>
16+
*
17+
* @author <a href="https://github.com/tryking123">tryking123</a>
18+
*/
19+
public interface WxMaCustomserviceWorkService {
20+
21+
/**
22+
* 查询小程序的微信客服绑定情况
23+
*/
24+
String GET_CUSTOMSERVICE_URL = "https://api.weixin.qq.com/customservice/work/get";
25+
/**
26+
* 为小程序绑定微信客服 注:此接口绑定的企业ID需完成企业认证
27+
*/
28+
String BIND_CUSTOMSERVICE_URL = "https://api.weixin.qq.com/customservice/work/bind";
29+
/**
30+
* 为小程序解除绑定微信客服
31+
*/
32+
String UNBIND_CUSTOMSERVICE_URL = "https://api.weixin.qq.com/customservice/work/unbind";
33+
34+
/**
35+
* 查询小程序的微信客服绑定情况
36+
*
37+
* @return 成功示例json { "errcode": 0,"entityName": "XXXXX有限公司","corpid": "wwee11111xxxxxxx","bindTime": 1694611289 }
38+
* @throws WxErrorException
39+
*/
40+
WxMaCustomserviceResult getCustomservice() throws WxErrorException;
41+
42+
/**
43+
* 绑定微信客服
44+
* @param corpid 企业ID,获取方式参考:https://developer.work.weixin.qq.com/document/path/90665#corpid
45+
* @return 成功示例json { "errcode": 0 }
46+
* @throws WxErrorException
47+
*/
48+
WxMaCustomserviceResult bindCustomservice(String corpid) throws WxErrorException;
49+
50+
/**
51+
* 解除绑定微信客服
52+
* @param corpid 企业ID,获取方式参考:https://developer.work.weixin.qq.com/document/path/90665#corpid
53+
* @return 成功示例json { "errcode": 0 }
54+
* @throws WxErrorException
55+
*/
56+
WxMaCustomserviceResult unbindCustomservice(String corpid) throws WxErrorException;
57+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ WxMaApiResponse execute(
278278
*/
279279
WxMaCodeService getCodeService();
280280

281+
/**
282+
* 获取小程序 - 微信客服。
283+
*
284+
* @return 微信客服服务对象WxMaCustomserviceWorkService
285+
*/
286+
WxMaCustomserviceWorkService getCustomserviceWorkService();
287+
281288
/**
282289
* 获取jsapi操作相关服务对象。
283290
*

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
@@ -112,6 +112,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
112112
private final WxMaSchemeService schemeService = new WxMaSchemeServiceImpl(this);
113113
private final WxMaAnalysisService analysisService = new WxMaAnalysisServiceImpl(this);
114114
private final WxMaCodeService codeService = new WxMaCodeServiceImpl(this);
115+
private final WxMaCustomserviceWorkService customserviceWorkService = new WxMaCustomserviceWorkServiceImpl(this);
115116
private final WxMaInternetService internetService = new WxMaInternetServiceImpl(this);
116117
private final WxMaSettingService settingService = new WxMaSettingServiceImpl(this);
117118
private final WxMaJsapiService jsapiService = new WxMaJsapiServiceImpl(this);
@@ -651,6 +652,11 @@ public WxMaCodeService getCodeService() {
651652
return this.codeService;
652653
}
653654

655+
@Override
656+
public WxMaCustomserviceWorkService getCustomserviceWorkService() {
657+
return this.customserviceWorkService;
658+
}
659+
654660
@Override
655661
public WxMaJsapiService getJsapiService() {
656662
return this.jsapiService;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package cn.binarywang.wx.miniapp.api.impl;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaCustomserviceWorkService;
4+
import cn.binarywang.wx.miniapp.api.WxMaService;
5+
import cn.binarywang.wx.miniapp.bean.customservice.WxMaCustomserviceResult;
6+
import com.google.gson.JsonObject;
7+
import lombok.RequiredArgsConstructor;
8+
import me.chanjar.weixin.common.error.WxErrorException;
9+
10+
11+
12+
/**
13+
* <pre>
14+
* 小程序 - 微信客服 相关接口
15+
* 负责处理 https://api.weixin.qq.com/customservice/work/**
16+
* 文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/kf-work/getKfWorkBound.html
17+
* 绑定的企业ID,需和小程序主体一致。
18+
* 目前仅支持绑定非个人小程序。
19+
* Created by tryking123 on 2025/8/18.
20+
* </pre>
21+
*
22+
* @author <a href="https://github.com/tryking123">tryking123</a>
23+
*/
24+
@RequiredArgsConstructor
25+
public class WxMaCustomserviceWorkServiceImpl implements WxMaCustomserviceWorkService {
26+
private static final String CORPID = "corpid";
27+
28+
private final WxMaService service;
29+
30+
@Override
31+
public WxMaCustomserviceResult getCustomservice() throws WxErrorException {
32+
String responseContent = this.service.get(GET_CUSTOMSERVICE_URL, null);
33+
return WxMaCustomserviceResult.fromJson(responseContent);
34+
}
35+
36+
@Override
37+
public WxMaCustomserviceResult bindCustomservice(String corpid) throws WxErrorException {
38+
JsonObject paramJson = new JsonObject();
39+
paramJson.addProperty(CORPID, corpid);
40+
String response = this.service.post(BIND_CUSTOMSERVICE_URL, paramJson);
41+
return WxMaCustomserviceResult.fromJson(response);
42+
}
43+
44+
@Override
45+
public WxMaCustomserviceResult unbindCustomservice(String corpid) throws WxErrorException {
46+
JsonObject paramJson = new JsonObject();
47+
paramJson.addProperty(CORPID, corpid);
48+
String response = this.service.post(UNBIND_CUSTOMSERVICE_URL, paramJson);
49+
return WxMaCustomserviceResult.fromJson(response);
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package cn.binarywang.wx.miniapp.bean.customservice;
2+
3+
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.google.gson.annotations.SerializedName;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Builder;
8+
import lombok.Data;
9+
import lombok.NoArgsConstructor;
10+
11+
import java.io.Serializable;
12+
import java.util.List;
13+
14+
/**
15+
* 客服绑定结果信息,包括错误码、主体名称、企业ID和绑定时间戳。
16+
* <p>
17+
* 字段说明:
18+
* <ul>
19+
* <li>errCode: 错误码</li>
20+
* <li>entityName: 小程序主体名称,未绑定时不返回</li>
21+
* <li>corpid: 企业ID,未绑定时不返回</li>
22+
* <li>bindTime: 接受绑定时间戳(毫秒)</li>
23+
* </ul>
24+
* @author <a href="https://github.com/tryking123">tryking123</a>
25+
* @since 2025/8/18 17:40
26+
*/
27+
@Data
28+
@Builder
29+
@NoArgsConstructor
30+
@AllArgsConstructor
31+
public class WxMaCustomserviceResult implements Serializable {
32+
private static final long serialVersionUID = 8854979405505241314L;
33+
34+
@SerializedName("errcode")
35+
private Integer errCode;
36+
37+
/**
38+
* 该小程序的主体名称,未绑定时不返回
39+
*/
40+
@SerializedName("entityName")
41+
private String entityName;
42+
43+
/**
44+
* 企业ID,未绑定时不返回
45+
*/
46+
@SerializedName("corpid")
47+
private String corpid;
48+
49+
/** 接受绑定时间戳,ms */
50+
@JsonProperty("bindTime")
51+
private Long bindTime;
52+
53+
public static WxMaCustomserviceResult fromJson(String json) {
54+
return WxMaGsonBuilder.create().fromJson(json, WxMaCustomserviceResult.class);
55+
}
56+
}

0 commit comments

Comments
 (0)