| @@ -48,3 +48,5 @@ Icon | |||
| Network Trash Folder | |||
| Temporary Items | |||
| .apdisk | |||
| /.sonar/ | |||
| sonar-project.properties | |||
| @@ -26,7 +26,7 @@ Weixin Java Tools 微信公众号/企业号开发Java SDK | |||
| ## 版本说明 | |||
| 1. 本项目定为每两个月发布一次正式版,版本号格式为X.X.0(如2.1.0,2.2.0等),月底发布新版本,遇到重大问题需修复会及时提交新版本,欢迎大家随时提交Pull Request; | |||
| 1. BUG修复和新特性一般会先发布成小版本作为临时版本(如2.0.1,2.0.2等,即尾号不为0,以区别于正式版); | |||
| 1. BUG修复和新特性一般会先发布成小版本作为临时测试版本(如2.0.1-beta,2.0.2-beta等,即尾号不为0,并添加beta字样,以区别于正式版); | |||
| 1. 目前最新版本号为 [](https://maven-badges.herokuapp.com/maven-central/com.github.binarywang/weixin-java-parent) ,也可以通过访问链接 [【公众号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-mp%22) 、[【企业号】](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.binarywang%22%20AND%20a%3A%22weixin-java-cp%22) | |||
| 分别查看所有最新的版本。 | |||
| @@ -5,7 +5,7 @@ | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <groupId>com.github.binarywang</groupId> | |||
| <artifactId>weixin-java-parent</artifactId> | |||
| <version>2.5.0-SNAPSHOT</version> | |||
| <version>2.4.4-beta</version> | |||
| <packaging>pom</packaging> | |||
| <name>WeiXin Java Tools - Parent</name> | |||
| <description>微信公众号、企业号上级POM</description> | |||
| @@ -69,6 +69,11 @@ | |||
| <email>dongfuqiang1988@163.com</email> | |||
| <url>https://github.com/johnnytung</url> | |||
| </developer> | |||
| <developer> | |||
| <name>Jonk</name> | |||
| <email>aimilin@yeah.net</email> | |||
| <url>https://github.com/aimilin6688</url> | |||
| </developer> | |||
| </developers> | |||
| <scm> | |||
| @@ -6,7 +6,7 @@ | |||
| <parent> | |||
| <groupId>com.github.binarywang</groupId> | |||
| <artifactId>weixin-java-parent</artifactId> | |||
| <version>2.5.0-SNAPSHOT</version> | |||
| <version>2.4.4-beta</version> | |||
| </parent> | |||
| <artifactId>weixin-java-common</artifactId> | |||
| @@ -6,7 +6,7 @@ | |||
| <parent> | |||
| <groupId>com.github.binarywang</groupId> | |||
| <artifactId>weixin-java-parent</artifactId> | |||
| <version>2.5.0-SNAPSHOT</version> | |||
| <version>2.4.4-beta</version> | |||
| </parent> | |||
| <artifactId>weixin-java-cp</artifactId> | |||
| @@ -6,7 +6,7 @@ | |||
| <parent> | |||
| <groupId>com.github.binarywang</groupId> | |||
| <artifactId>weixin-java-parent</artifactId> | |||
| <version>2.5.0-SNAPSHOT</version> | |||
| <version>2.4.4-beta</version> | |||
| </parent> | |||
| <artifactId>weixin-java-mp</artifactId> | |||
| <name>WeiXin Java Tools - MP</name> | |||
| @@ -422,8 +422,7 @@ public class WxMpServiceImpl implements WxMpService { | |||
| } | |||
| if (error.getErrorCode() != 0) { | |||
| this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data, | |||
| error); | |||
| this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data, error); | |||
| throw new WxErrorException(error); | |||
| } | |||
| return null; | |||
| @@ -1,28 +1,29 @@ | |||
| package me.chanjar.weixin.mp.bean; | |||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
| import java.io.Serializable; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
| /** | |||
| * openid列表群发的消息 | |||
| * | |||
| * | |||
| * @author chanjarster | |||
| */ | |||
| public class WxMpMassOpenIdsMessage implements Serializable { | |||
| private static final long serialVersionUID = -8022910911104788999L; | |||
| private List<String> toUsers = new ArrayList<>(); | |||
| private String msgType; | |||
| private String content; | |||
| private String mediaId; | |||
| private boolean sendIgnoreReprint = false; | |||
| public WxMpMassOpenIdsMessage() { | |||
| super(); | |||
| } | |||
| public String getMsgType() { | |||
| return this.msgType; | |||
| } | |||
| @@ -86,4 +87,15 @@ public class WxMpMassOpenIdsMessage implements Serializable { | |||
| this.toUsers = toUsers; | |||
| } | |||
| public boolean isSendIgnoreReprint() { | |||
| return sendIgnoreReprint; | |||
| } | |||
| /** | |||
| * | |||
| * @param sendIgnoreReprint 文章被判定为转载时,是否继续进行群发操作。 | |||
| */ | |||
| public void setSendIgnoreReprint(boolean sendIgnoreReprint) { | |||
| this.sendIgnoreReprint = sendIgnoreReprint; | |||
| } | |||
| } | |||
| @@ -1,28 +1,29 @@ | |||
| package me.chanjar.weixin.mp.bean; | |||
| import java.io.Serializable; | |||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
| import java.io.Serializable; | |||
| /** | |||
| * 按标签群发的消息 | |||
| * | |||
| * | |||
| * @author chanjarster | |||
| */ | |||
| public class WxMpMassTagMessage implements Serializable { | |||
| private static final long serialVersionUID = -6625914040986749286L; | |||
| private Long tagId; | |||
| private String msgtype; | |||
| private String msgType; | |||
| private String content; | |||
| private String mediaId; | |||
| private boolean sendIgnoreReprint = false; | |||
| public WxMpMassTagMessage() { | |||
| super(); | |||
| } | |||
| public String getMsgtype() { | |||
| return this.msgtype; | |||
| public String getMsgType() { | |||
| return this.msgType; | |||
| } | |||
| /** | |||
| @@ -35,10 +36,11 @@ public class WxMpMassTagMessage implements Serializable { | |||
| * {@link me.chanjar.weixin.common.api.WxConsts#MASS_MSG_VOICE} | |||
| * 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误 | |||
| * </pre> | |||
| * @param msgtype | |||
| * | |||
| * @param msgType 消息类型 | |||
| */ | |||
| public void setMsgtype(String msgtype) { | |||
| this.msgtype = msgtype; | |||
| public void setMsgType(String msgType) { | |||
| this.msgType = msgType; | |||
| } | |||
| public String getContent() { | |||
| @@ -67,10 +69,23 @@ public class WxMpMassTagMessage implements Serializable { | |||
| /** | |||
| * 如果不设置则就意味着发给所有用户 | |||
| * @param tagId | |||
| * | |||
| * @param tagId 标签id | |||
| */ | |||
| public void setTagId(Long tagId) { | |||
| this.tagId = tagId; | |||
| } | |||
| public boolean isSendIgnoreReprint() { | |||
| return sendIgnoreReprint; | |||
| } | |||
| /** | |||
| * | |||
| * @param sendIgnoreReprint 文章被判定为转载时,是否继续进行群发操作。 | |||
| */ | |||
| public void setSendIgnoreReprint(boolean sendIgnoreReprint) { | |||
| this.sendIgnoreReprint = sendIgnoreReprint; | |||
| } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package me.chanjar.weixin.mp.bean.result; | |||
| import me.chanjar.weixin.common.util.ToStringUtils; | |||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
| import java.io.Serializable; | |||
| @@ -7,19 +8,15 @@ import java.io.Serializable; | |||
| /** | |||
| * <pre> | |||
| * 群发消息一发送就返回的结果 | |||
| * | |||
| * | |||
| * 真正的群发消息是否发送成功要看 | |||
| * http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口#.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81.E7.BE.A4.E5.8F.91.E7.BB.93.E6.9E.9C | |||
| * | |||
| * | |||
| * </pre> | |||
| * @author chanjarster | |||
| * | |||
| */ | |||
| public class WxMpMassSendResult implements Serializable { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = -4816336807575562818L; | |||
| private String errorCode; | |||
| private String errorMsg; | |||
| @@ -64,7 +61,7 @@ public class WxMpMassSendResult implements Serializable { | |||
| @Override | |||
| public String toString() { | |||
| return "WxMassSendResult [errcode=" + this.errorCode + ", errmsg=" + this.errorMsg + ", msg_id=" + this.msgId + "]"; | |||
| return ToStringUtils.toSimpleString(this); | |||
| } | |||
| } | |||
| @@ -1,16 +1,11 @@ | |||
| package me.chanjar.weixin.mp.util.json; | |||
| import java.lang.reflect.Type; | |||
| import com.google.gson.JsonDeserializationContext; | |||
| import com.google.gson.JsonDeserializer; | |||
| import com.google.gson.JsonElement; | |||
| import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonParseException; | |||
| import com.google.gson.*; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import me.chanjar.weixin.mp.bean.WxMpCard; | |||
| import java.lang.reflect.Type; | |||
| /** | |||
| * Created by YuJian on 15/11/11. | |||
| * | |||
| @@ -21,7 +16,7 @@ public class WxMpCardGsonAdapter implements JsonDeserializer<WxMpCard> { | |||
| @Override | |||
| public WxMpCard deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext | |||
| jsonDeserializationContext) throws JsonParseException { | |||
| jsonDeserializationContext) throws JsonParseException { | |||
| WxMpCard card = new WxMpCard(); | |||
| JsonObject jsonObject = jsonElement.getAsJsonObject(); | |||
| @@ -1,18 +1,13 @@ | |||
| package me.chanjar.weixin.mp.util.json; | |||
| import java.lang.reflect.Type; | |||
| import com.google.gson.JsonDeserializationContext; | |||
| import com.google.gson.JsonDeserializer; | |||
| import com.google.gson.JsonElement; | |||
| import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonParseException; | |||
| import com.google.gson.*; | |||
| import com.google.gson.reflect.TypeToken; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import me.chanjar.weixin.mp.bean.WxMpCard; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | |||
| import java.lang.reflect.Type; | |||
| /** | |||
| * Created by YuJian on 15/11/11. | |||
| * | |||
| @@ -32,8 +27,8 @@ public class WxMpCardResultGsonAdapter implements JsonDeserializer<WxMpCardResul | |||
| cardResult.setUserCardStatus(GsonHelper.getString(jsonObject, "user_card_status")); | |||
| WxMpCard card = WxMpGsonBuilder.INSTANCE.create().fromJson(jsonObject.get("card"), | |||
| new TypeToken<WxMpCard>() { | |||
| }.getType()); | |||
| new TypeToken<WxMpCard>() { | |||
| }.getType()); | |||
| cardResult.setCard(card); | |||
| @@ -2,33 +2,12 @@ package me.chanjar.weixin.mp.util.json; | |||
| import com.google.gson.Gson; | |||
| import com.google.gson.GsonBuilder; | |||
| import me.chanjar.weixin.mp.bean.WxMpCard; | |||
| import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassNews; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassVideo; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | |||
| import me.chanjar.weixin.mp.bean.*; | |||
| import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; | |||
| import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; | |||
| import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialCountResult; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialFileBatchGetResult; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialNewsBatchGetResult; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult; | |||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpUserList; | |||
| import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
| import me.chanjar.weixin.mp.bean.material.*; | |||
| import me.chanjar.weixin.mp.bean.result.*; | |||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; | |||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | |||
| @@ -10,10 +10,17 @@ import java.lang.reflect.Type; | |||
| * @author miller | |||
| */ | |||
| public class WxMpIndustryGsonAdapter | |||
| implements JsonSerializer<WxMpTemplateIndustry>, JsonDeserializer<WxMpTemplateIndustry> { | |||
| implements JsonSerializer<WxMpTemplateIndustry>, JsonDeserializer<WxMpTemplateIndustry> { | |||
| private static WxMpTemplateIndustry.Industry convertFromJson(JsonObject json) { | |||
| WxMpTemplateIndustry.Industry industry = new WxMpTemplateIndustry.Industry(); | |||
| industry.setFirstClass(GsonHelper.getString(json, "first_class")); | |||
| industry.setSecondClass(GsonHelper.getString(json, "second_class")); | |||
| return industry; | |||
| } | |||
| @Override | |||
| public JsonElement serialize(WxMpTemplateIndustry wxMpIndustry, Type type, | |||
| JsonSerializationContext jsonSerializationContext) { | |||
| JsonSerializationContext jsonSerializationContext) { | |||
| JsonObject json = new JsonObject(); | |||
| json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId()); | |||
| json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId()); | |||
| @@ -22,22 +29,15 @@ public class WxMpIndustryGsonAdapter | |||
| @Override | |||
| public WxMpTemplateIndustry deserialize(JsonElement jsonElement, Type type, | |||
| JsonDeserializationContext jsonDeserializationContext) | |||
| throws JsonParseException { | |||
| JsonDeserializationContext jsonDeserializationContext) | |||
| throws JsonParseException { | |||
| WxMpTemplateIndustry wxMpIndustry = new WxMpTemplateIndustry(); | |||
| JsonObject primaryIndustry = jsonElement.getAsJsonObject() | |||
| .get("primary_industry").getAsJsonObject(); | |||
| .get("primary_industry").getAsJsonObject(); | |||
| wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry)); | |||
| JsonObject secondaryIndustry = jsonElement.getAsJsonObject() | |||
| .get("secondary_industry").getAsJsonObject(); | |||
| .get("secondary_industry").getAsJsonObject(); | |||
| wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry)); | |||
| return wxMpIndustry; | |||
| } | |||
| private static WxMpTemplateIndustry.Industry convertFromJson(JsonObject json) { | |||
| WxMpTemplateIndustry.Industry industry = new WxMpTemplateIndustry.Industry(); | |||
| industry.setFirstClass(GsonHelper.getString(json, "first_class")); | |||
| industry.setSecondClass(GsonHelper.getString(json, "second_class")); | |||
| return industry; | |||
| } | |||
| } | |||
| @@ -87,7 +87,7 @@ public class WxMpKefuMessageGsonAdapter implements JsonSerializer<WxMpKefuMessag | |||
| messageJson.add("wxcard", wxcard); | |||
| } | |||
| if (StringUtils.isNotBlank(message.getKfAccount())){ | |||
| if (StringUtils.isNotBlank(message.getKfAccount())) { | |||
| JsonObject newsJsonObject = new JsonObject(); | |||
| newsJsonObject.addProperty("kf_account", message.getKfAccount()); | |||
| messageJson.add("customservice", newsJsonObject); | |||
| @@ -19,13 +19,13 @@ public class WxMpMassOpenIdsMessageGsonAdapter implements JsonSerializer<WxMpMas | |||
| @Override | |||
| public JsonElement serialize(WxMpMassOpenIdsMessage message, Type typeOfSrc, JsonSerializationContext context) { | |||
| JsonObject messageJson = new JsonObject(); | |||
| JsonArray toUsers = new JsonArray(); | |||
| for (String openId : message.getToUsers()) { | |||
| toUsers.add(new JsonPrimitive(openId)); | |||
| } | |||
| messageJson.add("touser", toUsers); | |||
| if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) { | |||
| JsonObject sub = new JsonObject(); | |||
| sub.addProperty("media_id", message.getMediaId()); | |||
| @@ -52,6 +52,7 @@ public class WxMpMassOpenIdsMessageGsonAdapter implements JsonSerializer<WxMpMas | |||
| messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); | |||
| } | |||
| messageJson.addProperty("msgtype", message.getMsgType()); | |||
| messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1); | |||
| return messageJson; | |||
| } | |||
| @@ -15,9 +15,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | |||
| import java.lang.reflect.Type; | |||
| /** | |||
| * | |||
| * @author Daniel Qian | |||
| * | |||
| */ | |||
| public class WxMpMassSendResultAdapter implements JsonDeserializer<WxMpMassSendResult> { | |||
| @@ -40,5 +38,5 @@ public class WxMpMassSendResultAdapter implements JsonDeserializer<WxMpMassSendR | |||
| } | |||
| return sendResult; | |||
| } | |||
| } | |||
| @@ -8,57 +8,57 @@ | |||
| */ | |||
| package me.chanjar.weixin.mp.util.json; | |||
| import java.lang.reflect.Type; | |||
| import com.google.gson.JsonElement; | |||
| import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonSerializationContext; | |||
| import com.google.gson.JsonSerializer; | |||
| import me.chanjar.weixin.common.api.WxConsts; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; | |||
| import java.lang.reflect.Type; | |||
| public class WxMpMassTagMessageGsonAdapter implements JsonSerializer<WxMpMassTagMessage> { | |||
| @Override | |||
| public JsonElement serialize(WxMpMassTagMessage message, Type typeOfSrc, JsonSerializationContext context) { | |||
| JsonObject messageJson = new JsonObject(); | |||
| JsonObject filter = new JsonObject(); | |||
| if(null == message.getTagId()) { | |||
| if (null == message.getTagId()) { | |||
| filter.addProperty("is_to_all", true); | |||
| } else { | |||
| filter.addProperty("is_to_all", false); | |||
| filter.addProperty("tag_id", message.getTagId()); | |||
| } | |||
| messageJson.add("filter", filter); | |||
| if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgtype())) { | |||
| if (WxConsts.MASS_MSG_NEWS.equals(message.getMsgType())) { | |||
| JsonObject sub = new JsonObject(); | |||
| sub.addProperty("media_id", message.getMediaId()); | |||
| messageJson.add(WxConsts.MASS_MSG_NEWS, sub); | |||
| } | |||
| if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgtype())) { | |||
| if (WxConsts.MASS_MSG_TEXT.equals(message.getMsgType())) { | |||
| JsonObject sub = new JsonObject(); | |||
| sub.addProperty("content", message.getContent()); | |||
| messageJson.add(WxConsts.MASS_MSG_TEXT, sub); | |||
| } | |||
| if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgtype())) { | |||
| if (WxConsts.MASS_MSG_VOICE.equals(message.getMsgType())) { | |||
| JsonObject sub = new JsonObject(); | |||
| sub.addProperty("media_id", message.getMediaId()); | |||
| messageJson.add(WxConsts.MASS_MSG_VOICE, sub); | |||
| } | |||
| if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgtype())) { | |||
| if (WxConsts.MASS_MSG_IMAGE.equals(message.getMsgType())) { | |||
| JsonObject sub = new JsonObject(); | |||
| sub.addProperty("media_id", message.getMediaId()); | |||
| messageJson.add(WxConsts.MASS_MSG_IMAGE, sub); | |||
| } | |||
| if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgtype())) { | |||
| if (WxConsts.MASS_MSG_VIDEO.equals(message.getMsgType())) { | |||
| JsonObject sub = new JsonObject(); | |||
| sub.addProperty("media_id", message.getMediaId()); | |||
| messageJson.add(WxConsts.MASS_MSG_VIDEO, sub); | |||
| } | |||
| messageJson.addProperty("msgtype", message.getMsgtype()); | |||
| messageJson.addProperty("msgtype", message.getMsgType()); | |||
| messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1); | |||
| return messageJson; | |||
| } | |||
| @@ -15,9 +15,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | |||
| import java.lang.reflect.Type; | |||
| /** | |||
| * | |||
| * @author Daniel Qian | |||
| * | |||
| */ | |||
| public class WxMpMassUploadResultAdapter implements JsonDeserializer<WxMpMassUploadResult> { | |||
| @@ -37,5 +35,5 @@ public class WxMpMassUploadResultAdapter implements JsonDeserializer<WxMpMassUpl | |||
| } | |||
| return uploadResult; | |||
| } | |||
| } | |||
| @@ -17,9 +17,7 @@ import me.chanjar.weixin.mp.bean.WxMpMassVideo; | |||
| import java.lang.reflect.Type; | |||
| /** | |||
| * | |||
| * @author Daniel Qian | |||
| * | |||
| */ | |||
| public class WxMpMassVideoAdapter implements JsonSerializer<WxMpMassVideo> { | |||
| @@ -21,7 +21,7 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMa | |||
| JsonObject articleJson = new JsonObject(); | |||
| articleJson.addProperty("thumb_media_id", article.getThumbMediaId()); | |||
| articleJson.addProperty("thumb_url",article.getThumbUrl()); | |||
| articleJson.addProperty("thumb_url", article.getThumbUrl()); | |||
| articleJson.addProperty("title", article.getTitle()); | |||
| articleJson.addProperty("content", article.getContent()); | |||
| if (null != article.getAuthor()) { | |||
| @@ -70,7 +70,7 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMa | |||
| article.setThumbMediaId(GsonHelper.getAsString(thumbMediaId)); | |||
| } | |||
| JsonElement thumbUrl = articleInfo.get("thumb_url"); | |||
| if(thumbUrl != null && !thumbUrl.isJsonNull()) { | |||
| if (thumbUrl != null && !thumbUrl.isJsonNull()) { | |||
| article.setThumbUrl(GsonHelper.getAsString(thumbUrl)); | |||
| } | |||
| JsonElement showCoverPic = articleInfo.get("show_cover_pic"); | |||
| @@ -1,21 +1,16 @@ | |||
| package me.chanjar.weixin.mp.util.json; | |||
| import java.lang.reflect.Type; | |||
| import com.google.gson.JsonDeserializationContext; | |||
| import com.google.gson.JsonDeserializer; | |||
| import com.google.gson.JsonElement; | |||
| import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonParseException; | |||
| import com.google.gson.*; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||
| import java.lang.reflect.Type; | |||
| public class WxMpOAuth2AccessTokenAdapter implements JsonDeserializer<WxMpOAuth2AccessToken> { | |||
| @Override | |||
| public WxMpOAuth2AccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws | |||
| JsonParseException { | |||
| JsonParseException { | |||
| WxMpOAuth2AccessToken accessToken = new WxMpOAuth2AccessToken(); | |||
| JsonObject accessTokenJsonObject = json.getAsJsonObject(); | |||
| @@ -15,9 +15,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; | |||
| import java.lang.reflect.Type; | |||
| /** | |||
| * | |||
| * @author Daniel Qian | |||
| * | |||
| */ | |||
| public class WxMpSemanticQueryResultAdapter implements JsonDeserializer<WxMpSemanticQueryResult> { | |||
| @@ -46,5 +44,5 @@ public class WxMpSemanticQueryResultAdapter implements JsonDeserializer<WxMpSema | |||
| } | |||
| return result; | |||
| } | |||
| } | |||
| @@ -12,7 +12,6 @@ import com.google.gson.JsonElement; | |||
| import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonSerializationContext; | |||
| import com.google.gson.JsonSerializer; | |||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; | |||
| import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | |||
| @@ -8,29 +8,21 @@ | |||
| */ | |||
| package me.chanjar.weixin.mp.util.json; | |||
| import java.lang.reflect.Type; | |||
| import java.text.ParseException; | |||
| import org.apache.commons.lang3.time.FastDateFormat; | |||
| import com.google.gson.JsonDeserializationContext; | |||
| import com.google.gson.JsonDeserializer; | |||
| import com.google.gson.JsonElement; | |||
| import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonParseException; | |||
| import com.google.gson.*; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; | |||
| import org.apache.commons.lang3.time.FastDateFormat; | |||
| import java.lang.reflect.Type; | |||
| import java.text.ParseException; | |||
| /** | |||
| * | |||
| * @author Daniel Qian | |||
| * | |||
| */ | |||
| public class WxMpUserCumulateGsonAdapter implements JsonDeserializer<WxDataCubeUserCumulate> { | |||
| private static final FastDateFormat DATE_FORMAT = FastDateFormat | |||
| .getInstance("yyyy-MM-dd"); | |||
| .getInstance("yyyy-MM-dd"); | |||
| @Override | |||
| public WxDataCubeUserCumulate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
| @@ -49,5 +41,5 @@ public class WxMpUserCumulateGsonAdapter implements JsonDeserializer<WxDataCubeU | |||
| return cumulate; | |||
| } | |||
| } | |||
| @@ -8,17 +8,12 @@ | |||
| */ | |||
| package me.chanjar.weixin.mp.util.json; | |||
| import java.lang.reflect.Type; | |||
| import com.google.gson.JsonDeserializationContext; | |||
| import com.google.gson.JsonDeserializer; | |||
| import com.google.gson.JsonElement; | |||
| import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonParseException; | |||
| import com.google.gson.*; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||
| import java.lang.reflect.Type; | |||
| public class WxMpUserGsonAdapter implements JsonDeserializer<WxMpUser> { | |||
| @Override | |||
| @@ -43,7 +38,7 @@ public class WxMpUserGsonAdapter implements JsonDeserializer<WxMpUser> { | |||
| wxMpUser.setGroupId(GsonHelper.getInteger(o, "groupid")); | |||
| wxMpUser.setTagIds(GsonHelper.getIntArray(o, "tagid_list")); | |||
| wxMpUser.setSexId(sexId); | |||
| if(new Integer(1).equals(sexId)) { | |||
| if (new Integer(1).equals(sexId)) { | |||
| wxMpUser.setSex("男"); | |||
| } else if (new Integer(2).equals(sexId)) { | |||
| wxMpUser.setSex("女"); | |||
| @@ -8,19 +8,13 @@ | |||
| */ | |||
| package me.chanjar.weixin.mp.util.json; | |||
| import java.lang.reflect.Type; | |||
| import java.text.ParseException; | |||
| import org.apache.commons.lang3.time.FastDateFormat; | |||
| import com.google.gson.JsonDeserializationContext; | |||
| import com.google.gson.JsonDeserializer; | |||
| import com.google.gson.JsonElement; | |||
| import com.google.gson.JsonObject; | |||
| import com.google.gson.JsonParseException; | |||
| import com.google.gson.*; | |||
| import me.chanjar.weixin.common.util.json.GsonHelper; | |||
| import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; | |||
| import org.apache.commons.lang3.time.FastDateFormat; | |||
| import java.lang.reflect.Type; | |||
| import java.text.ParseException; | |||
| /** | |||
| * @author Daniel Qian | |||
| @@ -28,11 +22,11 @@ import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; | |||
| public class WxMpUserSummaryGsonAdapter implements JsonDeserializer<WxDataCubeUserSummary> { | |||
| private static final FastDateFormat DATE_FORMAT = FastDateFormat | |||
| .getInstance("yyyy-MM-dd"); | |||
| .getInstance("yyyy-MM-dd"); | |||
| @Override | |||
| public WxDataCubeUserSummary deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) | |||
| throws JsonParseException { | |||
| throws JsonParseException { | |||
| WxDataCubeUserSummary summary = new WxDataCubeUserSummary(); | |||
| JsonObject summaryJsonObject = json.getAsJsonObject(); | |||
| @@ -15,9 +15,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | |||
| import java.lang.reflect.Type; | |||
| /** | |||
| * | |||
| * @author Daniel Qian | |||
| * | |||
| */ | |||
| public class WxQrCodeTicketAdapter implements JsonDeserializer<WxMpQrCodeTicket> { | |||
| @@ -37,5 +35,5 @@ public class WxQrCodeTicketAdapter implements JsonDeserializer<WxMpQrCodeTicket> | |||
| } | |||
| return ticket; | |||
| } | |||
| } | |||
| @@ -1,15 +1,6 @@ | |||
| package me.chanjar.weixin.mp.api; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import org.testng.Assert; | |||
| import org.testng.annotations.DataProvider; | |||
| import org.testng.annotations.Guice; | |||
| import org.testng.annotations.Test; | |||
| import com.google.inject.Inject; | |||
| import me.chanjar.weixin.common.api.WxConsts; | |||
| import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | |||
| import me.chanjar.weixin.common.exception.WxErrorException; | |||
| @@ -19,13 +10,20 @@ import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; | |||
| import me.chanjar.weixin.mp.bean.WxMpMassVideo; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | |||
| import org.testng.Assert; | |||
| import org.testng.annotations.DataProvider; | |||
| import org.testng.annotations.Guice; | |||
| import org.testng.annotations.Test; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| /** | |||
| * 测试群发消息 | |||
| * @author chanjarster | |||
| * | |||
| * @author chanjarster | |||
| */ | |||
| @Test(groups = "massAPI", dependsOnGroups = { "baseAPI", "mediaAPI", "groupAPI"}) | |||
| @Test(groups = "massAPI", dependsOnGroups = {"baseAPI", "mediaAPI", "groupAPI"}) | |||
| @Guice(modules = ApiTestModule.class) | |||
| public class WxMpMassMessageAPITest { | |||
| @@ -36,31 +34,31 @@ public class WxMpMassMessageAPITest { | |||
| public void testTextMassOpenIdsMessageSend() throws WxErrorException { | |||
| // 发送群发消息 | |||
| WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService | |||
| .getWxMpConfigStorage(); | |||
| .getWxMpConfigStorage(); | |||
| WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); | |||
| massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); | |||
| massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | |||
| massMessage.getToUsers().add(configProvider.getOpenid()); | |||
| WxMpMassSendResult massResult = this.wxService | |||
| .massOpenIdsMessageSend(massMessage); | |||
| .massOpenIdsMessageSend(massMessage); | |||
| Assert.assertNotNull(massResult); | |||
| Assert.assertNotNull(massResult.getMsgId()); | |||
| } | |||
| @Test(dataProvider="massMessages") | |||
| @Test(dataProvider = "massMessages") | |||
| public void testMediaMassOpenIdsMessageSend(String massMsgType, | |||
| String mediaId) throws WxErrorException { | |||
| String mediaId) throws WxErrorException { | |||
| // 发送群发消息 | |||
| WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService | |||
| .getWxMpConfigStorage(); | |||
| .getWxMpConfigStorage(); | |||
| WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); | |||
| massMessage.setMsgType(massMsgType); | |||
| massMessage.setMediaId(mediaId); | |||
| massMessage.getToUsers().add(configProvider.getOpenid()); | |||
| WxMpMassSendResult massResult = this.wxService | |||
| .massOpenIdsMessageSend(massMessage); | |||
| .massOpenIdsMessageSend(massMessage); | |||
| Assert.assertNotNull(massResult); | |||
| Assert.assertNotNull(massResult.getMsgId()); | |||
| } | |||
| @@ -68,28 +66,28 @@ public class WxMpMassMessageAPITest { | |||
| @Test | |||
| public void testTextMassGroupMessageSend() throws WxErrorException { | |||
| WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); | |||
| massMessage.setMsgtype(WxConsts.MASS_MSG_TEXT); | |||
| massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); | |||
| massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | |||
| massMessage | |||
| .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); | |||
| .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); | |||
| WxMpMassSendResult massResult = this.wxService | |||
| .massGroupMessageSend(massMessage); | |||
| .massGroupMessageSend(massMessage); | |||
| Assert.assertNotNull(massResult); | |||
| Assert.assertNotNull(massResult.getMsgId()); | |||
| } | |||
| @Test(dataProvider="massMessages") | |||
| @Test(dataProvider = "massMessages") | |||
| public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) | |||
| throws WxErrorException { | |||
| throws WxErrorException { | |||
| WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); | |||
| massMessage.setMsgtype(massMsgType); | |||
| massMessage.setMsgType(massMsgType); | |||
| massMessage.setMediaId(mediaId); | |||
| massMessage | |||
| .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); | |||
| .setTagId(this.wxService.getUserTagService().tagGet().get(0).getId()); | |||
| WxMpMassSendResult massResult = this.wxService | |||
| .massGroupMessageSend(massMessage); | |||
| .massGroupMessageSend(massMessage); | |||
| Assert.assertNotNull(massResult); | |||
| Assert.assertNotNull(massResult.getMsgId()); | |||
| } | |||
| @@ -102,10 +100,10 @@ public class WxMpMassMessageAPITest { | |||
| * 视频素材 | |||
| */ | |||
| try (InputStream inputStream = ClassLoader | |||
| .getSystemResourceAsStream("mm.mp4")) { | |||
| .getSystemResourceAsStream("mm.mp4")) { | |||
| // 上传视频到媒体库 | |||
| WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() | |||
| .mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream); | |||
| .mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream); | |||
| Assert.assertNotNull(uploadMediaRes); | |||
| Assert.assertNotNull(uploadMediaRes.getMediaId()); | |||
| @@ -117,41 +115,41 @@ public class WxMpMassMessageAPITest { | |||
| WxMpMassUploadResult uploadResult = this.wxService.massVideoUpload(video); | |||
| Assert.assertNotNull(uploadResult); | |||
| Assert.assertNotNull(uploadResult.getMediaId()); | |||
| messages[0] = new Object[] { WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId() }; | |||
| messages[0] = new Object[]{WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId()}; | |||
| } | |||
| /** | |||
| * 图片素材 | |||
| */ | |||
| try (InputStream inputStream = ClassLoader | |||
| .getSystemResourceAsStream("mm.jpeg")) { | |||
| .getSystemResourceAsStream("mm.jpeg")) { | |||
| WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() | |||
| .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); | |||
| .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); | |||
| Assert.assertNotNull(uploadMediaRes); | |||
| Assert.assertNotNull(uploadMediaRes.getMediaId()); | |||
| messages[1] = new Object[] { WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId() }; | |||
| messages[1] = new Object[]{WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId()}; | |||
| } | |||
| /** | |||
| * 语音素材 | |||
| */ | |||
| try (InputStream inputStream = ClassLoader | |||
| .getSystemResourceAsStream("mm.mp3")) { | |||
| .getSystemResourceAsStream("mm.mp3")) { | |||
| WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() | |||
| .mediaUpload(WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, inputStream); | |||
| .mediaUpload(WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, inputStream); | |||
| Assert.assertNotNull(uploadMediaRes); | |||
| Assert.assertNotNull(uploadMediaRes.getMediaId()); | |||
| messages[2] = new Object[] { WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId() }; | |||
| messages[2] = new Object[]{WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId()}; | |||
| } | |||
| /** | |||
| * 图文素材 | |||
| */ | |||
| try (InputStream inputStream = ClassLoader | |||
| .getSystemResourceAsStream("mm.jpeg")) { | |||
| .getSystemResourceAsStream("mm.jpeg")) { | |||
| // 上传照片到媒体库 | |||
| WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService() | |||
| .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); | |||
| .mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream); | |||
| Assert.assertNotNull(uploadMediaRes); | |||
| Assert.assertNotNull(uploadMediaRes.getMediaId()); | |||
| @@ -174,10 +172,10 @@ public class WxMpMassMessageAPITest { | |||
| news.addArticle(article2); | |||
| WxMpMassUploadResult massUploadResult = this.wxService | |||
| .massNewsUpload(news); | |||
| .massNewsUpload(news); | |||
| Assert.assertNotNull(massUploadResult); | |||
| Assert.assertNotNull(uploadMediaRes.getMediaId()); | |||
| messages[3] = new Object[] { WxConsts.MASS_MSG_NEWS, massUploadResult.getMediaId() }; | |||
| messages[3] = new Object[]{WxConsts.MASS_MSG_NEWS, massUploadResult.getMediaId()}; | |||
| } | |||
| return messages; | |||
| @@ -6,7 +6,7 @@ | |||
| <parent> | |||
| <groupId>com.github.binarywang</groupId> | |||
| <artifactId>weixin-java-parent</artifactId> | |||
| <version>2.5.0-SNAPSHOT</version> | |||
| <version>2.4.4-beta</version> | |||
| </parent> | |||
| <artifactId>weixin-java-osgi</artifactId> | |||