| @@ -5,6 +5,7 @@ import java.util.ArrayList; | |||
| import java.util.List; | |||
| import lombok.Data; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpNewsArticle; | |||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
| /** | |||
| @@ -16,9 +17,9 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
| public class WxMpMassNews implements Serializable { | |||
| private static final long serialVersionUID = 565937155013581016L; | |||
| private List<WxMpMassNewsArticle> articles = new ArrayList<>(); | |||
| private List<WxMpNewsArticle> articles = new ArrayList<>(); | |||
| public void addArticle(WxMpMassNewsArticle article) { | |||
| public void addArticle(WxMpNewsArticle article) { | |||
| this.articles.add(article); | |||
| } | |||
| @@ -35,54 +36,4 @@ public class WxMpMassNews implements Serializable { | |||
| return WxMpGsonBuilder.create().toJson(this); | |||
| } | |||
| /** | |||
| * <pre> | |||
| * 群发图文消息article. | |||
| * 1. thumbMediaId (必填) 图文消息缩略图的media_id,可以在基础支持-上传多媒体文件接口中获得 | |||
| * 2. author 图文消息的作者 | |||
| * 3. title (必填) 图文消息的标题 | |||
| * 4. contentSourceUrl 在图文消息页面点击“阅读原文”后的页面链接 | |||
| * 5. content (必填) 图文消息页面的内容,支持HTML标签 | |||
| * 6. digest 图文消息的描述 | |||
| * 7, showCoverPic 是否显示封面,true为显示,false为不显示 | |||
| * </pre> | |||
| * | |||
| * @author chanjarster | |||
| */ | |||
| @Data | |||
| public static class WxMpMassNewsArticle { | |||
| /** | |||
| * (必填) 图文消息缩略图的media_id,可以在基础支持-上传多媒体文件接口中获得. | |||
| */ | |||
| private String thumbMediaId; | |||
| /** | |||
| * 图文消息的作者. | |||
| */ | |||
| private String author; | |||
| /** | |||
| * (必填) 图文消息的标题. | |||
| */ | |||
| private String title; | |||
| /** | |||
| * 在图文消息页面点击“阅读原文”后的页面链接. | |||
| */ | |||
| private String contentSourceUrl; | |||
| /** | |||
| * (必填) 图文消息页面的内容,支持HTML标签. | |||
| */ | |||
| private String content; | |||
| /** | |||
| * 图文消息的描述. | |||
| */ | |||
| private String digest; | |||
| /** | |||
| * 是否显示封面,true为显示,false为不显示. | |||
| */ | |||
| private boolean showCoverPic; | |||
| @Override | |||
| public String toString() { | |||
| return WxMpGsonBuilder.create().toJson(this); | |||
| } | |||
| } | |||
| } | |||
| @@ -11,7 +11,7 @@ public class WxMpMaterialArticleUpdate implements Serializable { | |||
| private String mediaId; | |||
| private int index; | |||
| private WxMpMaterialNews.WxMpMaterialNewsArticle articles; | |||
| private WxMpNewsArticle articles; | |||
| public String toJson() { | |||
| return WxMpGsonBuilder.create().toJson(this); | |||
| @@ -20,13 +20,13 @@ public class WxMpMaterialNews implements Serializable { | |||
| private Date createTime; | |||
| private Date updateTime; | |||
| private List<WxMpMaterialNewsArticle> articles = new ArrayList<>(); | |||
| private List<WxMpNewsArticle> articles = new ArrayList<>(); | |||
| public List<WxMpMaterialNewsArticle> getArticles() { | |||
| public List<WxMpNewsArticle> getArticles() { | |||
| return this.articles; | |||
| } | |||
| public void addArticle(WxMpMaterialNewsArticle article) { | |||
| public void addArticle(WxMpNewsArticle article) { | |||
| this.articles.add(article); | |||
| } | |||
| @@ -43,80 +43,4 @@ public class WxMpMaterialNews implements Serializable { | |||
| return this.toJson(); | |||
| } | |||
| /** | |||
| * <pre> | |||
| * 群发图文消息article. | |||
| * 1. thumbMediaId (必填) 图文消息的封面图片素材id(必须是永久mediaID) | |||
| * 2. author 图文消息的作者 | |||
| * 3. title (必填) 图文消息的标题 | |||
| * 4. contentSourceUrl 在图文消息页面点击“阅读原文”后的页面链接 | |||
| * 5. content (必填) 图文消息页面的内容,支持HTML标签 | |||
| * 6. digest 图文消息的描述 | |||
| * 7. showCoverPic 是否显示封面,true为显示,false为不显示 | |||
| * 8. url 点击图文消息跳转链接 | |||
| * 9. need_open_comment(新增字段) 否 Uint32 是否打开评论,0不打开,1打开 | |||
| * 10. only_fans_can_comment(新增字段) 否 Uint32 是否粉丝才可评论,0所有人可评论,1粉丝才可评论 | |||
| * </pre> | |||
| * | |||
| * @author chanjarster | |||
| */ | |||
| @Data | |||
| public static class WxMpMaterialNewsArticle implements Serializable{ | |||
| private static final long serialVersionUID = -635384661692321171L; | |||
| /** | |||
| * (必填) 图文消息缩略图的media_id,可以在基础支持-上传多媒体文件接口中获得. | |||
| */ | |||
| private String thumbMediaId; | |||
| /** | |||
| * 图文消息的封面url. | |||
| */ | |||
| private String thumbUrl; | |||
| /** | |||
| * 图文消息的作者. | |||
| */ | |||
| private String author; | |||
| /** | |||
| * (必填) 图文消息的标题. | |||
| */ | |||
| private String title; | |||
| /** | |||
| * 在图文消息页面点击“阅读原文”后的页面链接. | |||
| */ | |||
| private String contentSourceUrl; | |||
| /** | |||
| * (必填) 图文消息页面的内容,支持HTML标签. | |||
| */ | |||
| private String content; | |||
| /** | |||
| * 图文消息的描述. | |||
| */ | |||
| private String digest; | |||
| /** | |||
| * 是否显示封面,true为显示,false为不显示. | |||
| */ | |||
| private boolean showCoverPic; | |||
| /** | |||
| * 点击图文消息跳转链接. | |||
| */ | |||
| private String url; | |||
| /** | |||
| * need_open_comment | |||
| * 是否打开评论,0不打开,1打开. | |||
| */ | |||
| private Boolean needOpenComment; | |||
| /** | |||
| * only_fans_can_comment | |||
| * 是否粉丝才可评论,0所有人可评论,1粉丝才可评论. | |||
| */ | |||
| private Boolean onlyFansCanComment; | |||
| @Override | |||
| public String toString() { | |||
| return WxMpGsonBuilder.create().toJson(this); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,82 @@ | |||
| package me.chanjar.weixin.mp.bean.material; | |||
| import lombok.Data; | |||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
| import java.io.Serializable; | |||
| /** | |||
| * <pre> | |||
| * 图文消息article. | |||
| * 1. thumbMediaId (必填) 图文消息的封面图片素材id(必须是永久mediaID) | |||
| * 2. author 图文消息的作者 | |||
| * 3. title (必填) 图文消息的标题 | |||
| * 4. contentSourceUrl 在图文消息页面点击“阅读原文”后的页面链接 | |||
| * 5. content (必填) 图文消息页面的内容,支持HTML标签 | |||
| * 6. digest 图文消息的描述 | |||
| * 7. showCoverPic 是否显示封面,true为显示,false为不显示 | |||
| * 8. url 点击图文消息跳转链接 | |||
| * 9. need_open_comment(新增字段) 否 Uint32 是否打开评论,0不打开,1打开 | |||
| * 10. only_fans_can_comment(新增字段) 否 Uint32 是否粉丝才可评论,0所有人可评论,1粉丝才可评论 | |||
| * </pre> | |||
| * | |||
| * @author chanjarster | |||
| */ | |||
| @Data | |||
| public class WxMpNewsArticle implements Serializable { | |||
| private static final long serialVersionUID = -635384661692321171L; | |||
| /** | |||
| * (必填) 图文消息缩略图的media_id,可以在基础支持-上传多媒体文件接口中获得. | |||
| */ | |||
| private String thumbMediaId; | |||
| /** | |||
| * 图文消息的封面url. | |||
| */ | |||
| private String thumbUrl; | |||
| /** | |||
| * 图文消息的作者. | |||
| */ | |||
| private String author; | |||
| /** | |||
| * (必填) 图文消息的标题. | |||
| */ | |||
| private String title; | |||
| /** | |||
| * 在图文消息页面点击“阅读原文”后的页面链接. | |||
| */ | |||
| private String contentSourceUrl; | |||
| /** | |||
| * (必填) 图文消息页面的内容,支持HTML标签. | |||
| */ | |||
| private String content; | |||
| /** | |||
| * 图文消息的描述. | |||
| */ | |||
| private String digest; | |||
| /** | |||
| * 是否显示封面,true为显示,false为不显示. | |||
| */ | |||
| private boolean showCoverPic; | |||
| /** | |||
| * 点击图文消息跳转链接. | |||
| */ | |||
| private String url; | |||
| /** | |||
| * need_open_comment | |||
| * 是否打开评论,0不打开,1打开. | |||
| */ | |||
| private Boolean needOpenComment; | |||
| /** | |||
| * only_fans_can_comment | |||
| * 是否粉丝才可评论,0所有人可评论,1粉丝才可评论. | |||
| */ | |||
| private Boolean onlyFansCanComment; | |||
| @Override | |||
| public String toString() { | |||
| return WxMpGsonBuilder.create().toJson(this); | |||
| } | |||
| } | |||
| @@ -8,10 +8,10 @@ import me.chanjar.weixin.mp.bean.card.WxMpCardResult; | |||
| import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; | |||
| import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; | |||
| import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
| import me.chanjar.weixin.mp.bean.material.*; | |||
| import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivateTempInfoResult; | |||
| import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateResult; | |||
| import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUserInfoResult; | |||
| import me.chanjar.weixin.mp.bean.material.*; | |||
| import me.chanjar.weixin.mp.bean.result.*; | |||
| import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage; | |||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; | |||
| @@ -45,11 +45,10 @@ public class WxMpGsonBuilder { | |||
| INSTANCE.registerTypeAdapter(WxDataCubeUserCumulate.class, new WxMpUserCumulateGsonAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpMaterialUploadResult.class, new WxMpMaterialUploadResultAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpMaterialVideoInfoResult.class, new WxMpMaterialVideoInfoResultAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpMassNews.WxMpMassNewsArticle.class, new WxMpMassNewsArticleGsonAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpMaterialArticleUpdate.class, new WxMpMaterialArticleUpdateGsonAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpMaterialCountResult.class, new WxMpMaterialCountResultAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpMaterialNews.class, new WxMpMaterialNewsGsonAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpMaterialNews.WxMpMaterialNewsArticle.class, new WxMpMaterialNewsArticleGsonAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpNewsArticle.class, new WxMpNewsArticleGsonAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpMaterialNewsBatchGetResult.class, new WxMpMaterialNewsBatchGetGsonAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem.class, new WxMpMaterialNewsBatchGetGsonItemAdapter()); | |||
| INSTANCE.registerTypeAdapter(WxMpMaterialFileBatchGetResult.class, new WxMpMaterialFileBatchGetGsonAdapter()); | |||
| @@ -1,70 +0,0 @@ | |||
| package me.chanjar.weixin.mp.util.json; | |||
| import com.google.gson.*; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassNews; | |||
| import org.apache.commons.lang3.BooleanUtils; | |||
| import java.lang.reflect.Type; | |||
| /** | |||
| * @author codepiano | |||
| */ | |||
| public class WxMpMassNewsArticleGsonAdapter implements JsonSerializer<WxMpMassNews.WxMpMassNewsArticle>, JsonDeserializer<WxMpMassNews.WxMpMassNewsArticle> { | |||
| @Override | |||
| public JsonElement serialize(WxMpMassNews.WxMpMassNewsArticle article, Type typeOfSrc, JsonSerializationContext context) { | |||
| JsonObject articleJson = new JsonObject(); | |||
| articleJson.addProperty("thumb_media_id", article.getThumbMediaId()); | |||
| articleJson.addProperty("title", article.getTitle()); | |||
| articleJson.addProperty("content", article.getContent()); | |||
| if (null != article.getAuthor()) { | |||
| articleJson.addProperty("author", article.getAuthor()); | |||
| } | |||
| if (null != article.getContentSourceUrl()) { | |||
| articleJson.addProperty("content_source_url", article.getContentSourceUrl()); | |||
| } | |||
| if (null != article.getDigest()) { | |||
| articleJson.addProperty("digest", article.getDigest()); | |||
| } | |||
| articleJson.addProperty("show_cover_pic", article.isShowCoverPic() ? "1" : "0"); | |||
| return articleJson; | |||
| } | |||
| @Override | |||
| public WxMpMassNews.WxMpMassNewsArticle deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { | |||
| JsonObject articleInfo = jsonElement.getAsJsonObject(); | |||
| WxMpMassNews.WxMpMassNewsArticle article = new WxMpMassNews.WxMpMassNewsArticle(); | |||
| JsonElement title = articleInfo.get("title"); | |||
| if (title != null && !title.isJsonNull()) { | |||
| article.setTitle(GsonHelper.getAsString(title)); | |||
| } | |||
| JsonElement content = articleInfo.get("content"); | |||
| if (content != null && !content.isJsonNull()) { | |||
| article.setContent(GsonHelper.getAsString(content)); | |||
| } | |||
| JsonElement contentSourceUrl = articleInfo.get("content_source_url"); | |||
| if (contentSourceUrl != null && !contentSourceUrl.isJsonNull()) { | |||
| article.setContentSourceUrl(GsonHelper.getAsString(contentSourceUrl)); | |||
| } | |||
| JsonElement author = articleInfo.get("author"); | |||
| if (author != null && !author.isJsonNull()) { | |||
| article.setAuthor(GsonHelper.getAsString(author)); | |||
| } | |||
| JsonElement digest = articleInfo.get("digest"); | |||
| if (digest != null && !digest.isJsonNull()) { | |||
| article.setDigest(GsonHelper.getAsString(digest)); | |||
| } | |||
| JsonElement thumbMediaId = articleInfo.get("thumb_media_id"); | |||
| if (thumbMediaId != null && !thumbMediaId.isJsonNull()) { | |||
| article.setThumbMediaId(GsonHelper.getAsString(thumbMediaId)); | |||
| } | |||
| JsonElement showCoverPic = articleInfo.get("show_cover_pic"); | |||
| if (showCoverPic != null && !showCoverPic.isJsonNull()) { | |||
| article.setShowCoverPic(BooleanUtils.toBoolean(showCoverPic.getAsInt())); | |||
| } | |||
| return article; | |||
| } | |||
| } | |||
| @@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.util.json; | |||
| import com.google.gson.*; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassNews; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpNewsArticle; | |||
| import java.lang.reflect.Type; | |||
| @@ -12,8 +13,8 @@ public class WxMpMassNewsGsonAdapter implements JsonSerializer<WxMpMassNews>, Js | |||
| JsonObject newsJson = new JsonObject(); | |||
| JsonArray articleJsonArray = new JsonArray(); | |||
| for (WxMpMassNews.WxMpMassNewsArticle article : message.getArticles()) { | |||
| JsonObject articleJson = WxMpGsonBuilder.create().toJsonTree(article, WxMpMassNews.WxMpMassNewsArticle.class).getAsJsonObject(); | |||
| for (WxMpNewsArticle article : message.getArticles()) { | |||
| JsonObject articleJson = WxMpGsonBuilder.create().toJsonTree(article, WxMpNewsArticle.class).getAsJsonObject(); | |||
| articleJsonArray.add(articleJson); | |||
| } | |||
| newsJson.add("articles", articleJsonArray); | |||
| @@ -29,7 +30,7 @@ public class WxMpMassNewsGsonAdapter implements JsonSerializer<WxMpMassNews>, Js | |||
| JsonArray articles = json.getAsJsonArray("articles"); | |||
| for (JsonElement article1 : articles) { | |||
| JsonObject articleInfo = article1.getAsJsonObject(); | |||
| WxMpMassNews.WxMpMassNewsArticle article = WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMassNews.WxMpMassNewsArticle.class); | |||
| WxMpNewsArticle article = WxMpGsonBuilder.create().fromJson(articleInfo, WxMpNewsArticle.class); | |||
| wxMpMassNews.addArticle(article); | |||
| } | |||
| } | |||
| @@ -5,7 +5,7 @@ import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonSerializationContext; | |||
| import com.google.gson.JsonSerializer; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpNewsArticle; | |||
| import java.lang.reflect.Type; | |||
| @@ -16,7 +16,7 @@ public class WxMpMaterialArticleUpdateGsonAdapter implements JsonSerializer<WxMp | |||
| JsonObject articleUpdateJson = new JsonObject(); | |||
| articleUpdateJson.addProperty("media_id", wxMpMaterialArticleUpdate.getMediaId()); | |||
| articleUpdateJson.addProperty("index", wxMpMaterialArticleUpdate.getIndex()); | |||
| articleUpdateJson.add("articles", WxMpGsonBuilder.create().toJsonTree(wxMpMaterialArticleUpdate.getArticles(), WxMpMaterialNews.WxMpMaterialNewsArticle.class)); | |||
| articleUpdateJson.add("articles", WxMpGsonBuilder.create().toJsonTree(wxMpMaterialArticleUpdate.getArticles(), WxMpNewsArticle.class)); | |||
| return articleUpdateJson; | |||
| } | |||
| @@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.util.json; | |||
| import com.google.gson.*; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpNewsArticle; | |||
| import java.lang.reflect.Type; | |||
| import java.text.SimpleDateFormat; | |||
| @@ -15,8 +16,8 @@ public class WxMpMaterialNewsGsonAdapter implements JsonSerializer<WxMpMaterialN | |||
| JsonObject newsJson = new JsonObject(); | |||
| JsonArray articleJsonArray = new JsonArray(); | |||
| for (WxMpMaterialNews.WxMpMaterialNewsArticle article : wxMpMaterialNews.getArticles()) { | |||
| JsonObject articleJson = WxMpGsonBuilder.create().toJsonTree(article, WxMpMaterialNews.WxMpMaterialNewsArticle.class).getAsJsonObject(); | |||
| for (WxMpNewsArticle article : wxMpMaterialNews.getArticles()) { | |||
| JsonObject articleJson = WxMpGsonBuilder.create().toJsonTree(article, WxMpNewsArticle.class).getAsJsonObject(); | |||
| articleJsonArray.add(articleJson); | |||
| } | |||
| newsJson.add("articles", articleJsonArray); | |||
| @@ -42,7 +43,7 @@ public class WxMpMaterialNewsGsonAdapter implements JsonSerializer<WxMpMaterialN | |||
| JsonArray articles = json.getAsJsonArray("news_item"); | |||
| for (JsonElement article1 : articles) { | |||
| JsonObject articleInfo = article1.getAsJsonObject(); | |||
| WxMpMaterialNews.WxMpMaterialNewsArticle article = WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialNews.WxMpMaterialNewsArticle.class); | |||
| WxMpNewsArticle article = WxMpGsonBuilder.create().fromJson(articleInfo, WxMpNewsArticle.class); | |||
| wxMpMaterialNews.addArticle(article); | |||
| } | |||
| } | |||
| @@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.util.json; | |||
| import com.google.gson.*; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpNewsArticle; | |||
| import org.apache.commons.lang3.BooleanUtils; | |||
| import java.lang.reflect.Type; | |||
| @@ -10,10 +10,9 @@ import java.lang.reflect.Type; | |||
| /** | |||
| * @author codepiano | |||
| */ | |||
| public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMaterialNews.WxMpMaterialNewsArticle>, JsonDeserializer<WxMpMaterialNews.WxMpMaterialNewsArticle> { | |||
| public class WxMpNewsArticleGsonAdapter implements JsonSerializer<WxMpNewsArticle>, JsonDeserializer<WxMpNewsArticle> { | |||
| @Override | |||
| public JsonElement serialize(WxMpMaterialNews.WxMpMaterialNewsArticle article, Type typeOfSrc, JsonSerializationContext context) { | |||
| public JsonElement serialize(WxMpNewsArticle article, Type typeOfSrc, JsonSerializationContext context) { | |||
| JsonObject articleJson = new JsonObject(); | |||
| articleJson.addProperty("thumb_media_id", article.getThumbMediaId()); | |||
| @@ -47,9 +46,9 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMa | |||
| } | |||
| @Override | |||
| public WxMpMaterialNews.WxMpMaterialNewsArticle deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { | |||
| public WxMpNewsArticle deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { | |||
| JsonObject articleInfo = jsonElement.getAsJsonObject(); | |||
| WxMpMaterialNews.WxMpMaterialNewsArticle article = new WxMpMaterialNews.WxMpMaterialNewsArticle(); | |||
| WxMpNewsArticle article = new WxMpNewsArticle(); | |||
| JsonElement title = articleInfo.get("title"); | |||
| if (title != null && !title.isJsonNull()) { | |||
| @@ -12,14 +12,17 @@ import me.chanjar.weixin.mp.bean.WxMpMassNews; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassVideo; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpNewsArticle; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | |||
| import org.testng.annotations.*; | |||
| import org.testng.annotations.DataProvider; | |||
| import org.testng.annotations.Guice; | |||
| import org.testng.annotations.Test; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import static org.testng.Assert.*; | |||
| import static org.testng.Assert.assertNotNull; | |||
| /** | |||
| * 测试群发消息 | |||
| @@ -35,15 +38,13 @@ public class WxMpMassMessageServiceImplTest { | |||
| @Test | |||
| public void testTextMassOpenIdsMessageSend() throws WxErrorException { | |||
| // 发送群发消息 | |||
| TestConfigStorage configProvider = (TestConfigStorage) this.wxService | |||
| .getWxMpConfigStorage(); | |||
| TestConfigStorage configProvider = (TestConfigStorage) this.wxService .getWxMpConfigStorage(); | |||
| WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); | |||
| massMessage.setMsgType(WxConsts.MassMsgType.TEXT); | |||
| massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | |||
| massMessage.setContent("测试群发消息\n欢迎欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | |||
| massMessage.getToUsers().add(configProvider.getOpenid()); | |||
| WxMpMassSendResult massResult = this.wxService.getMassMessageService() | |||
| .massOpenIdsMessageSend(massMessage); | |||
| WxMpMassSendResult massResult = this.wxService.getMassMessageService().massOpenIdsMessageSend(massMessage); | |||
| assertNotNull(massResult); | |||
| assertNotNull(massResult.getMsgId()); | |||
| } | |||
| @@ -51,15 +52,13 @@ public class WxMpMassMessageServiceImplTest { | |||
| @Test(dataProvider = "massMessages") | |||
| public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException { | |||
| // 发送群发消息 | |||
| TestConfigStorage configProvider = (TestConfigStorage) this.wxService | |||
| .getWxMpConfigStorage(); | |||
| TestConfigStorage configProvider = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); | |||
| WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); | |||
| massMessage.setMsgType(massMsgType); | |||
| massMessage.setMediaId(mediaId); | |||
| massMessage.getToUsers().add(configProvider.getOpenid()); | |||
| WxMpMassSendResult massResult = this.wxService.getMassMessageService() | |||
| .massOpenIdsMessageSend(massMessage); | |||
| WxMpMassSendResult massResult = this.wxService.getMassMessageService().massOpenIdsMessageSend(massMessage); | |||
| assertNotNull(massResult); | |||
| assertNotNull(massResult.getMsgId()); | |||
| } | |||
| @@ -68,26 +67,23 @@ public class WxMpMassMessageServiceImplTest { | |||
| public void testTextMassGroupMessageSend() throws WxErrorException { | |||
| WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); | |||
| massMessage.setMsgType(WxConsts.MassMsgType.TEXT); | |||
| massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | |||
| massMessage.setContent("测试群发消息\n欢迎欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | |||
| massMessage | |||
| .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); | |||
| WxMpMassSendResult massResult = this.wxService.getMassMessageService() | |||
| .massGroupMessageSend(massMessage); | |||
| WxMpMassSendResult massResult = this.wxService.getMassMessageService().massGroupMessageSend(massMessage); | |||
| assertNotNull(massResult); | |||
| assertNotNull(massResult.getMsgId()); | |||
| } | |||
| @Test(dataProvider = "massMessages") | |||
| public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) | |||
| throws WxErrorException { | |||
| public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException { | |||
| WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); | |||
| massMessage.setMsgType(massMsgType); | |||
| massMessage.setMediaId(mediaId); | |||
| massMessage.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); | |||
| WxMpMassSendResult massResult = this.wxService.getMassMessageService() | |||
| .massGroupMessageSend(massMessage); | |||
| WxMpMassSendResult massResult = this.wxService.getMassMessageService().massGroupMessageSend(massMessage); | |||
| assertNotNull(massResult); | |||
| assertNotNull(massResult.getMsgId()); | |||
| } | |||
| @@ -155,15 +151,15 @@ public class WxMpMassMessageServiceImplTest { | |||
| // 上传图文消息 | |||
| WxMpMassNews news = new WxMpMassNews(); | |||
| WxMpMassNews.WxMpMassNewsArticle article1 = new WxMpMassNews.WxMpMassNewsArticle(); | |||
| WxMpNewsArticle article1 = new WxMpNewsArticle(); | |||
| article1.setTitle("标题1"); | |||
| article1.setContent("内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1"); | |||
| article1.setContent("内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1"); | |||
| article1.setThumbMediaId(uploadMediaRes.getMediaId()); | |||
| news.addArticle(article1); | |||
| WxMpMassNews.WxMpMassNewsArticle article2 = new WxMpMassNews.WxMpMassNewsArticle(); | |||
| WxMpNewsArticle article2 = new WxMpNewsArticle(); | |||
| article2.setTitle("标题2"); | |||
| article2.setContent("内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2"); | |||
| article2.setContent("内容2内容2内容2内容2内容2内容2内容2内容2内2内容2内容2内容2内容2内容2内容2内容2内容2内容2"); | |||
| article2.setThumbMediaId(uploadMediaRes.getMediaId()); | |||
| article2.setShowCoverPic(true); | |||
| article2.setAuthor("作者2"); | |||
| @@ -183,7 +179,7 @@ public class WxMpMassMessageServiceImplTest { | |||
| @Test | |||
| public void testMassDelete() throws Exception { | |||
| this.wxService.getMassMessageService().delete(1L,2); | |||
| this.wxService.getMassMessageService().delete(1L, 2); | |||
| } | |||
| } | |||
| @@ -103,7 +103,7 @@ public class WxMpMaterialServiceImplTest { | |||
| public void testAddNews() throws WxErrorException { | |||
| // 单图文消息 | |||
| WxMpMaterialNews wxMpMaterialNewsSingle = new WxMpMaterialNews(); | |||
| WxMpMaterialNews.WxMpMaterialNewsArticle article = new WxMpMaterialNews.WxMpMaterialNewsArticle(); | |||
| WxMpNewsArticle article = new WxMpNewsArticle(); | |||
| article.setAuthor("author"); | |||
| article.setThumbMediaId(this.thumbMediaId); | |||
| article.setTitle("single title"); | |||
| @@ -115,7 +115,7 @@ public class WxMpMaterialServiceImplTest { | |||
| // 多图文消息 | |||
| WxMpMaterialNews wxMpMaterialNewsMultiple = new WxMpMaterialNews(); | |||
| WxMpMaterialNews.WxMpMaterialNewsArticle article1 = new WxMpMaterialNews.WxMpMaterialNewsArticle(); | |||
| WxMpNewsArticle article1 = new WxMpNewsArticle(); | |||
| article1.setAuthor("author1"); | |||
| article1.setThumbMediaId(this.thumbMediaId); | |||
| article1.setTitle("multi title1"); | |||
| @@ -124,7 +124,7 @@ public class WxMpMaterialServiceImplTest { | |||
| article1.setShowCoverPic(true); | |||
| article1.setDigest(""); | |||
| WxMpMaterialNews.WxMpMaterialNewsArticle article2 = new WxMpMaterialNews.WxMpMaterialNewsArticle(); | |||
| WxMpNewsArticle article2 = new WxMpNewsArticle(); | |||
| article2.setAuthor("author2"); | |||
| article2.setThumbMediaId(this.thumbMediaId); | |||
| article2.setTitle("multi title2"); | |||
| @@ -196,7 +196,7 @@ public class WxMpMaterialServiceImplTest { | |||
| .getMaterialService().materialNewsInfo(this.singleNewsMediaId); | |||
| assertNotNull(wxMpMaterialNewsSingle); | |||
| WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateSingle = new WxMpMaterialArticleUpdate(); | |||
| WxMpMaterialNews.WxMpMaterialNewsArticle articleSingle = wxMpMaterialNewsSingle.getArticles().get(0); | |||
| WxMpNewsArticle articleSingle = wxMpMaterialNewsSingle.getArticles().get(0); | |||
| articleSingle.setContent("content single update"); | |||
| wxMpMaterialArticleUpdateSingle.setMediaId(this.singleNewsMediaId); | |||
| wxMpMaterialArticleUpdateSingle.setArticles(articleSingle); | |||
| @@ -213,7 +213,7 @@ public class WxMpMaterialServiceImplTest { | |||
| .getMaterialService().materialNewsInfo(this.multiNewsMediaId); | |||
| assertNotNull(wxMpMaterialNewsMultiple); | |||
| WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateMulti = new WxMpMaterialArticleUpdate(); | |||
| WxMpMaterialNews.WxMpMaterialNewsArticle articleMulti = wxMpMaterialNewsMultiple.getArticles().get(1); | |||
| WxMpNewsArticle articleMulti = wxMpMaterialNewsMultiple.getArticles().get(1); | |||
| articleMulti.setContent("content 2 update"); | |||
| wxMpMaterialArticleUpdateMulti.setMediaId(this.multiNewsMediaId); | |||
| wxMpMaterialArticleUpdateMulti.setArticles(articleMulti); | |||