-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: sysong <[email protected]>
- Loading branch information
Showing
10 changed files
with
421 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentWorkBenchService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...in-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentWorkBenchServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpAgentWorkBench.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/workbench/WorkBenchKeyData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
26 changes: 26 additions & 0 deletions
26
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/workbench/WorkBenchList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.