Skip to content

Commit

Permalink
🆕 #1793 企业微信添加应用管理的设置工作台自定义展示模块
Browse files Browse the repository at this point in the history
Co-authored-by: sysong <[email protected]>
  • Loading branch information
youflint and sysong authored Sep 30, 2020
1 parent cd0c63f commit 8428270
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.chanjar.weixin.cp.api;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpAgentWorkBench;

/**
* @author songshiyu
* @date : create in 16:16 2020/9/27
* @description: 工作台自定义展示:https://work.weixin.qq.com/api/doc/90000/90135/92535
*/
public interface WxCpAgentWorkBenchService {

void setWorkBenchTemplate(WxCpAgentWorkBench wxCpAgentWorkBench) throws WxErrorException;

String getWorkBenchTemplate(Long agentid) throws WxErrorException;

void setWorkBenchData(WxCpAgentWorkBench wxCpAgentWorkBench) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ public interface WxCpService {
* @return 群机器人消息推送服务 group robot service
*/
WxCpGroupRobotService getGroupRobotService();
/*
* 获取工作台服务
*
* @return the workbench service
* */
WxCpAgentWorkBenchService getWorkBenchService();

/**
* http请求对象
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
private WxCpGroupRobotService groupRobotService = new WxCpGroupRobotServiceImpl(this);
private WxCpMessageService messageService = new WxCpMessageServiceImpl(this);
private WxCpOaCalendarService oaCalendarService = new WxCpOaCalendarServiceImpl(this);
private WxCpAgentWorkBenchService workBenchService = new WxCpAgentWorkBenchServiceImpl(this);

/**
* 全局的是否正在刷新access token的锁.
Expand Down Expand Up @@ -437,6 +438,11 @@ public WxCpGroupRobotService getGroupRobotService() {
return groupRobotService;
}

@Override
public WxCpAgentWorkBenchService getWorkBenchService() {
return workBenchService;
}

@Override
public WxCpTaskCardService getTaskCardService() {
return taskCardService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package me.chanjar.weixin.cp.api.impl;

import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpAgentWorkBenchService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpAgentWorkBench;

import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.WorkBench.WORKBENCH_DATA_SET;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.WorkBench.WORKBENCH_TEMPLATE_GET;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.WorkBench.WORKBENCH_TEMPLATE_SET;

/**
* @author songshiyu
* @date : create in 11:24 2020/9/28
* @description: 工作台自定义展示实现
*/
@RequiredArgsConstructor
public class WxCpAgentWorkBenchServiceImpl implements WxCpAgentWorkBenchService {
private final WxCpService mainService;

@Override
public void setWorkBenchTemplate(WxCpAgentWorkBench wxCpAgentWorkBench) throws WxErrorException {
final String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WORKBENCH_TEMPLATE_SET));
this.mainService.post(url, wxCpAgentWorkBench.toTemplateString());
}

@Override
public String getWorkBenchTemplate(Long agentId) throws WxErrorException {
final String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WORKBENCH_TEMPLATE_GET));
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("agentid", agentId);
return this.mainService.post(url, jsonObject.toString());
}

@Override
public void setWorkBenchData(WxCpAgentWorkBench wxCpAgentWorkBench) throws WxErrorException {
final String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WORKBENCH_DATA_SET));
this.mainService.post(url, wxCpAgentWorkBench.toUserDataString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package me.chanjar.weixin.cp.bean;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.cp.bean.workbench.WorkBenchKeyData;
import me.chanjar.weixin.cp.bean.workbench.WorkBenchList;
import me.chanjar.weixin.cp.constant.WxCpConsts;

import java.io.Serializable;
import java.util.List;

/**
* @author songshiyu
* @date : create in 16:09 2020/9/27
* @description: 工作台自定义展示
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxCpAgentWorkBench implements Serializable {
private static final long serialVersionUid = 1L;

/*
* 展示类型,目前支持 “keydata”、 “image”、 “list” 、”webview”
* */
private String type;
/*
* 用户的userid
* */
private String userId;
/*
* 应用id
* */
private Long agentId;
/*
* 点击跳转url,若不填且应用设置了主页url,则跳转到主页url,否则跳到应用会话窗口
* */
private String jumpUrl;
/*
* 若应用为小程序类型,该字段填小程序pagepath,若未设置,跳到小程序主页
* */
private String pagePath;
/*
* 图片url:图片的最佳比例为3.35:1;webview:渲染展示的url
* */
private String url;
/*
* 是否覆盖用户工作台的数据。设置为true的时候,会覆盖企业所有用户当前设置的数据。若设置为false,则不会覆盖用户当前设置的所有数据
* */
private Boolean replaceUserData;

private List<WorkBenchKeyData> keyDataList;

private List<WorkBenchList> lists;

// 生成模板Json字符串
public String toTemplateString() {
JsonObject templateObject = new JsonObject();
templateObject.addProperty("agentid", this.agentId);
templateObject.addProperty("type", this.type);
if (this.replaceUserData != null) {
templateObject.addProperty("replace_user_data", this.replaceUserData);
}
this.handle(templateObject);
return templateObject.toString();
}

// 生成用户数据Json字符串
public String toUserDataString() {
JsonObject userDataObject = new JsonObject();
userDataObject.addProperty("agentid", this.agentId);
userDataObject.addProperty("userid", this.userId);
userDataObject.addProperty("type", this.type);
this.handle(userDataObject);
return userDataObject.toString();
}

// 处理不用类型的工作台数据
private void handle(JsonObject templateObject) {
switch (this.getType()) {
case WxCpConsts.WorkBenchType.KEYDATA: {
JsonArray keyDataArray = new JsonArray();
JsonObject itemsObject = new JsonObject();
for (WorkBenchKeyData keyDataItem : this.keyDataList) {
JsonObject keyDataObject = new JsonObject();
keyDataObject.addProperty("key", keyDataItem.getKey());
keyDataObject.addProperty("data", keyDataItem.getData());
keyDataObject.addProperty("jump_url", keyDataItem.getJumpUrl());
keyDataObject.addProperty("pagepath", keyDataItem.getPagePath());
keyDataArray.add(keyDataObject);
}
itemsObject.add("items", keyDataArray);
templateObject.add("keydata", itemsObject);
break;
}
case WxCpConsts.WorkBenchType.IMAGE: {
JsonObject image = new JsonObject();
image.addProperty("url", this.url);
image.addProperty("jump_url", this.jumpUrl);
image.addProperty("pagepath", this.pagePath);
templateObject.add("image", image);
break;
}
case WxCpConsts.WorkBenchType.LIST: {
JsonArray listArray = new JsonArray();
JsonObject itemsObject = new JsonObject();
for (WorkBenchList listItem : this.lists) {
JsonObject listObject = new JsonObject();
listObject.addProperty("title", listItem.getTitle());
listObject.addProperty("jump_url", listItem.getJumpUrl());
listObject.addProperty("pagepath", listItem.getPagePath());
listArray.add(listObject);
}
itemsObject.add("items",listArray);
templateObject.add("list", itemsObject);
break;
}
case WxCpConsts.WorkBenchType.WEBVIEW: {
JsonObject webview = new JsonObject();
webview.addProperty("url", this.url);
webview.addProperty("jump_url", this.jumpUrl);
webview.addProperty("pagepath", this.pagePath);
templateObject.add("webview", webview);
break;
}
default: {
//do nothing
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.chanjar.weixin.cp.bean.workbench;

import lombok.Data;

import java.io.Serializable;

/**
* @author songshiyu
* @date : create in 10:21 2020/9/28
* @description: 关键数据型模板类型
*/
@Data
public class WorkBenchKeyData implements Serializable {
/*
* 关键数据名称
* */
private String key;
/*
* 关键数据
* */
private String data;
/*
* 点击跳转url,若不填且应用设置了主页url,则跳转到主页url,否则跳到应用会话窗口
* */
private String jumpUrl;
/*
* 若应用为小程序类型,该字段填小程序pagepath,若未设置,跳到小程序主页
* */
private String pagePath;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.chanjar.weixin.cp.bean.workbench;

import lombok.Data;

import java.io.Serializable;

/**
* @author songshiyu
* @date : create in 10:21 2020/9/28
* @description: 列表模板类型
*/
@Data
public class WorkBenchList implements Serializable {
/*
* 列表显示文字,不超过128个字节
* */
private String title;
/*
* 点击跳转url,若不填且应用设置了主页url,则跳转到主页url,否则跳到应用会话窗口
* */
private String jumpUrl;
/*
* 若应用为小程序类型,该字段填小程序pagepath,若未设置,跳到小程序主页
* */
private String pagePath;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public static class Agent {
public static final String AGENT_LIST = "/cgi-bin/agent/list";
}

@UtilityClass
public static class WorkBench {
public static final String WORKBENCH_TEMPLATE_SET = "/cgi-bin/agent/set_workbench_template";
public static final String WORKBENCH_TEMPLATE_GET = "/cgi-bin/agent/get_workbench_template";
public static final String WORKBENCH_DATA_SET = "/cgi-bin/agent/set_workbench_data";
}

@UtilityClass
public static class OAuth2 {
public static final String GET_USER_INFO = "/cgi-bin/user/getuserinfo?code=%s&agentid=%d";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,23 @@ public static class AppChatMsgType {
*/
public static final String MARKDOWN = "markdown";
}

public static class WorkBenchType {
/*
* 关键数据型
* */
public static final String KEYDATA = "keydata";
/*
* 图片型
* */
public static final String IMAGE = "image";
/*
* 列表型
* */
public static final String LIST = "list";
/*
* webview型
* */
public static final String WEBVIEW = "webview";
}
}
Loading

0 comments on commit 8428270

Please sign in to comment.