From 7c0a38e1a0c17d7a9729cb927859e60e272151c9 Mon Sep 17 00:00:00 2001 From: Dean Wong Date: Wed, 15 Jul 2020 09:36:00 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#1668=20=E4=BC=81=E4=B8=9A=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E5=A2=9E=E5=8A=A0=E5=A4=96=E9=83=A8=E8=81=94=E7=B3=BB?= =?UTF-8?q?=E4=BA=BA=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cp/api/WxCpExternalContactService.java | 27 ++++--- .../impl/WxCpExternalContactServiceImpl.java | 7 ++ .../weixin/cp/bean/WxCpMsgTemplate.java | 81 +++++++++++++++++++ .../cp/bean/WxCpMsgTemplateAddResult.java | 36 +++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 1 + 5 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMsgTemplate.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMsgTemplateAddResult.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java index 94de03e555..2b3a17b87d 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java @@ -88,6 +88,7 @@ public interface WxCpExternalContactService { /** * 企业和第三方可通过此接口,获取所有离职成员的客户列表,并可进一步调用离职成员的外部联系人再分配接口将这些客户重新分配给其他企业成员。 + * * @param page * @param pageSize * @return @@ -97,22 +98,24 @@ public interface WxCpExternalContactService { /** * 企业可通过此接口,将已离职成员的外部联系人分配给另一个成员接替联系。 + * * @param externalUserid * @param handOverUserid * @param takeOverUserid * @return * @throws WxErrorException */ - WxCpBaseResp transferExternalContact(String externalUserid,String handOverUserid,String takeOverUserid)throws WxErrorException; + WxCpBaseResp transferExternalContact(String externalUserid, String handOverUserid, String takeOverUserid) throws WxErrorException; - /**
-    * 该接口用于获取配置过客户群管理的客户群列表。
-    * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
-    * 暂不支持第三方调用。
-    * 微信文档:https://work.weixin.qq.com/api/doc/90000/90135/92119
-    * 
- */ - WxCpUserExternalGroupChatList listGroupChat(Integer pageIndex,Integer pageSize,int status,String[] userIds,String[] partyIds) throws WxErrorException; + /** + *
+   * 该接口用于获取配置过客户群管理的客户群列表。
+   * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
+   * 暂不支持第三方调用。
+   * 微信文档:https://work.weixin.qq.com/api/doc/90000/90135/92119
+   * 
+ */ + WxCpUserExternalGroupChatList listGroupChat(Integer pageIndex, Integer pageSize, int status, String[] userIds, String[] partyIds) throws WxErrorException; /** *
@@ -135,6 +138,7 @@ public interface WxCpExternalContactService {
    * 第三方应用需拥有“企业客户”权限。
    * 第三方/自建应用调用时传入的userid和partyid要在应用的可见范围内;
    * 
+ * * @param startTime * @param endTime * @param userIds @@ -150,6 +154,7 @@ public interface WxCpExternalContactService { * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。 * 暂不支持第三方调用。 * + * * @param startTime * @param orderBy * @param orderAsc @@ -160,5 +165,7 @@ public interface WxCpExternalContactService { * @return * @throws WxErrorException */ - WxCpUserExternalGroupChatStatistic getGroupChatStatistic(Date startTime,Integer orderBy,Integer orderAsc,Integer pageIndex,Integer pageSize, String[] userIds, String[] partyIds) throws WxErrorException; + WxCpUserExternalGroupChatStatistic getGroupChatStatistic(Date startTime, Integer orderBy, Integer orderAsc, Integer pageIndex, Integer pageSize, String[] userIds, String[] partyIds) throws WxErrorException; + + WxCpMsgTemplateAddResult addMsgTemplate(WxCpMsgTemplate wxCpMsgTemplate) throws WxErrorException; } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java index 961b21d522..982c115502 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java @@ -150,4 +150,11 @@ public WxCpUserExternalGroupChatStatistic getGroupChatStatistic(Date startTime, final String result = this.mainService.post(url, json.toString()); return WxCpUserExternalGroupChatStatistic.fromJson(result); } + + @Override + public WxCpMsgTemplateAddResult addMsgTemplate(WxCpMsgTemplate wxCpMsgTemplate) throws WxErrorException { + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_MSG_TEMPLATE); + final String result = this.mainService.post(url, wxCpMsgTemplate.toJson()); + return WxCpMsgTemplateAddResult.fromJson(result); + } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMsgTemplate.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMsgTemplate.java new file mode 100644 index 0000000000..a4abb87821 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMsgTemplate.java @@ -0,0 +1,81 @@ +package me.chanjar.weixin.cp.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 企业群发消息任务 + *

+ * Created by songfan on 2020/7/14. + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpMsgTemplate implements Serializable { + private static final long serialVersionUID = 3172331565173474358L; + + @SerializedName("chat_type") + private String chatType; + + @SerializedName("external_userid") + private List externalUserid; + + private String sender; + + private Text text; + + private Image image; + + private Link link; + + private Miniprogram miniprogram; + + public static WxCpMsgTemplate fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpMsgTemplate.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + @Data + public class Text { + private String content; + } + + @Data + public class Image { + + @SerializedName("media_id") + private String mediaId; + + @SerializedName("pic_url") + private String picUrl; + } + + @Data + public class Link { + private String title; + @SerializedName("picurl") + private String picUrl; + private String desc; + private String url; + } + + @Data + public class Miniprogram { + private String title; + @SerializedName("pic_media_id") + private String picMediaId; + private String appid; + private String page; + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMsgTemplateAddResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMsgTemplateAddResult.java new file mode 100644 index 0000000000..2e91ec0671 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMsgTemplateAddResult.java @@ -0,0 +1,36 @@ +package me.chanjar.weixin.cp.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * Created by songfan on 2020/7/14. + */ +@Data +public class WxCpMsgTemplateAddResult implements Serializable { + private static final long serialVersionUID = -5166048319463473188L; + + @SerializedName("errcode") + private Integer errCode; + + @SerializedName("errmsg") + private String errMsg; + + @SerializedName("fail_list") + private List failList; + + @SerializedName("msgid") + private String msgId; + + public static WxCpMsgTemplateAddResult fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpMsgTemplateAddResult.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index 9b465fd0c5..24debae397 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -126,5 +126,6 @@ public static class ExternalContact { public static final String GROUP_CHAT_INFO = "/cgi-bin/externalcontact/groupchat/get"; public static final String LIST_USER_BEHAVIOR_DATA = "/cgi-bin/externalcontact/get_user_behavior_data"; public static final String LIST_GROUP_CHAT_DATA = "/cgi-bin/externalcontact/groupchat/statistic"; + public static final String ADD_MSG_TEMPLATE = "/cgi-bin/externalcontact/add_msg_template"; } }