mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-02 20:02:37 +08:00
🎨 优化重构微信小程序订阅消息相关类
This commit is contained in:
parent
232ea7e3c7
commit
2369aa7cb3
@ -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
|
||||
*
|
||||
* @author S
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ -17,7 +19,6 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class WxMaSubscribeMessage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6846729898251286686L;
|
||||
|
||||
/**
|
||||
@ -58,10 +59,9 @@ public class WxMaSubscribeMessage implements Serializable {
|
||||
* 描述: 模板内容,不填则下发空模板
|
||||
* </pre>
|
||||
*/
|
||||
private List<WxMaSubscribeData> data;
|
||||
private List<Data> data;
|
||||
|
||||
|
||||
public WxMaSubscribeMessage addData(WxMaSubscribeData datum) {
|
||||
public WxMaSubscribeMessage addData(Data datum) {
|
||||
if (this.data == null) {
|
||||
this.data = new ArrayList<>();
|
||||
}
|
||||
@ -74,4 +74,12 @@ public class WxMaSubscribeMessage implements Serializable {
|
||||
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;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeData;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@ -9,8 +8,12 @@ import com.google.gson.JsonSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* .
|
||||
*
|
||||
* @author S
|
||||
*/
|
||||
public class WxMaSubscribeMessageGsonAdapter implements JsonSerializer<WxMaSubscribeMessage> {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(WxMaSubscribeMessage message, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject messageJson = new JsonObject();
|
||||
@ -20,7 +23,6 @@ public class WxMaSubscribeMessageGsonAdapter implements JsonSerializer<WxMaSubsc
|
||||
messageJson.addProperty("page", message.getPage());
|
||||
}
|
||||
|
||||
|
||||
JsonObject data = new JsonObject();
|
||||
messageJson.add("data", data);
|
||||
|
||||
@ -28,7 +30,7 @@ public class WxMaSubscribeMessageGsonAdapter implements JsonSerializer<WxMaSubsc
|
||||
return messageJson;
|
||||
}
|
||||
|
||||
for (WxMaSubscribeData datum : message.getData()) {
|
||||
for (WxMaSubscribeMessage.Data datum : message.getData()) {
|
||||
JsonObject dataJson = new JsonObject();
|
||||
dataJson.addProperty("value", datum.getValue());
|
||||
data.add(datum.getName(), dataJson);
|
||||
|
Loading…
Reference in New Issue
Block a user