🆕 #3681 【小程序】增加企微客服增删查3个接口
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -278,6 +278,13 @@ public interface WxMaService extends WxService {
|
||||
*/
|
||||
WxMaCodeService getCodeService();
|
||||
|
||||
/**
|
||||
* 获取小程序 - 微信客服。
|
||||
*
|
||||
* @return 微信客服服务对象WxMaCustomserviceWorkService
|
||||
*/
|
||||
WxMaCustomserviceWorkService getCustomserviceWorkService();
|
||||
|
||||
/**
|
||||
* 获取jsapi操作相关服务对象。
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user