| @@ -1,30 +0,0 @@ | |||||
| package cn.binarywang.wx.miniapp.bean; | |||||
| import lombok.Data; | |||||
| import lombok.NoArgsConstructor; | |||||
| /** | |||||
| * <pre> | |||||
| * 参考文档 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html | |||||
| * </pre> | |||||
| */ | |||||
| @Data | |||||
| @NoArgsConstructor | |||||
| public class WxMaSubscribeData { | |||||
| private String name; | |||||
| private String value; | |||||
| private String color; | |||||
| public WxMaSubscribeData(String name, String value) { | |||||
| this.name = name; | |||||
| this.value = value; | |||||
| } | |||||
| public WxMaSubscribeData(String name, String value, String color) { | |||||
| this.name = name; | |||||
| this.value = value; | |||||
| this.color = color; | |||||
| } | |||||
| } | |||||
| @@ -10,6 +10,8 @@ import java.util.List; | |||||
| /** | /** | ||||
| * 订阅消息. | * 订阅消息. | ||||
| * https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html | * https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html | ||||
| * | |||||
| * @author S | |||||
| */ | */ | ||||
| @Getter | @Getter | ||||
| @Setter | @Setter | ||||
| @@ -17,7 +19,6 @@ import java.util.List; | |||||
| @AllArgsConstructor | @AllArgsConstructor | ||||
| @Builder | @Builder | ||||
| public class WxMaSubscribeMessage implements Serializable { | public class WxMaSubscribeMessage implements Serializable { | ||||
| private static final long serialVersionUID = 6846729898251286686L; | private static final long serialVersionUID = 6846729898251286686L; | ||||
| /** | /** | ||||
| @@ -58,10 +59,9 @@ public class WxMaSubscribeMessage implements Serializable { | |||||
| * 描述: 模板内容,不填则下发空模板 | * 描述: 模板内容,不填则下发空模板 | ||||
| * </pre> | * </pre> | ||||
| */ | */ | ||||
| private List<WxMaSubscribeData> data; | |||||
| private List<Data> data; | |||||
| public WxMaSubscribeMessage addData(WxMaSubscribeData datum) { | |||||
| public WxMaSubscribeMessage addData(Data datum) { | |||||
| if (this.data == null) { | if (this.data == null) { | ||||
| this.data = new ArrayList<>(); | this.data = new ArrayList<>(); | ||||
| } | } | ||||
| @@ -74,4 +74,12 @@ public class WxMaSubscribeMessage implements Serializable { | |||||
| return WxMaGsonBuilder.create().toJson(this); | return WxMaGsonBuilder.create().toJson(this); | ||||
| } | } | ||||
| @lombok.Data | |||||
| @NoArgsConstructor | |||||
| @AllArgsConstructor | |||||
| public static class Data { | |||||
| private String name; | |||||
| private String value; | |||||
| } | |||||
| } | } | ||||
| @@ -1,6 +1,5 @@ | |||||
| package cn.binarywang.wx.miniapp.util.json; | package cn.binarywang.wx.miniapp.util.json; | ||||
| import cn.binarywang.wx.miniapp.bean.WxMaSubscribeData; | |||||
| import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; | import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; | ||||
| import com.google.gson.JsonElement; | import com.google.gson.JsonElement; | ||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||
| @@ -9,8 +8,12 @@ import com.google.gson.JsonSerializer; | |||||
| import java.lang.reflect.Type; | import java.lang.reflect.Type; | ||||
| /** | |||||
| * . | |||||
| * | |||||
| * @author S | |||||
| */ | |||||
| public class WxMaSubscribeMessageGsonAdapter implements JsonSerializer<WxMaSubscribeMessage> { | public class WxMaSubscribeMessageGsonAdapter implements JsonSerializer<WxMaSubscribeMessage> { | ||||
| @Override | @Override | ||||
| public JsonElement serialize(WxMaSubscribeMessage message, Type typeOfSrc, JsonSerializationContext context) { | public JsonElement serialize(WxMaSubscribeMessage message, Type typeOfSrc, JsonSerializationContext context) { | ||||
| JsonObject messageJson = new JsonObject(); | JsonObject messageJson = new JsonObject(); | ||||
| @@ -20,7 +23,6 @@ public class WxMaSubscribeMessageGsonAdapter implements JsonSerializer<WxMaSubsc | |||||
| messageJson.addProperty("page", message.getPage()); | messageJson.addProperty("page", message.getPage()); | ||||
| } | } | ||||
| JsonObject data = new JsonObject(); | JsonObject data = new JsonObject(); | ||||
| messageJson.add("data", data); | messageJson.add("data", data); | ||||
| @@ -28,7 +30,7 @@ public class WxMaSubscribeMessageGsonAdapter implements JsonSerializer<WxMaSubsc | |||||
| return messageJson; | return messageJson; | ||||
| } | } | ||||
| for (WxMaSubscribeData datum : message.getData()) { | |||||
| for (WxMaSubscribeMessage.Data datum : message.getData()) { | |||||
| JsonObject dataJson = new JsonObject(); | JsonObject dataJson = new JsonObject(); | ||||
| dataJson.addProperty("value", datum.getValue()); | dataJson.addProperty("value", datum.getValue()); | ||||
| data.add(datum.getName(), dataJson); | data.add(datum.getName(), dataJson); | ||||