Blame view

src/main/java/com/jfinal/weixin/sdk/api/TemplateData.java 2.51 KB
e80df919   atao   init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  package com.jfinal.weixin.sdk.api;
  
  import com.jfinal.weixin.sdk.utils.JsonUtils;
  
  import java.io.Serializable;
  import java.util.HashMap;
  
  /**
   * 模板消息数据对象
   *
   * @author L.cm
   * #date 2014-11-10 下午3:32:30
   * #description 模板消息数据对象
   */
  public class TemplateData implements Serializable {
      private static final long serialVersionUID = 8038149984818112449L;
  
      private String touser;
      private String template_id;
      private String url;
      private TemplateItem data;
  
      public static TemplateData New() {
          return new TemplateData();
      }
  
      private TemplateData() {
          this.data = new TemplateItem();
      }
  
      public String getTouser() {
          return touser;
      }
  
      public TemplateData setTouser(String touser) {
          this.touser = touser;
          return this;
      }
  
      public String getTemplate_id() {
          return template_id;
      }
  
      public TemplateData setTemplate_id(String template_id) {
          this.template_id = template_id;
          return this;
      }
  
      public String getUrl() {
          return url;
      }
  
      public TemplateData setUrl(String url) {
          this.url = url;
          return this;
      }
  
      public TemplateItem getData() {
          return data;
      }
  
      public TemplateData add(String key, String value, String color){
          data.put(key, new Item(value, color));
          return this;
      }
      
      public TemplateData add(String key, String value){
          data.put(key, new Item(value));
          return this;
      }
  
      /**
       * 直接转化成jsonString
       * @return {String}
       */
      public String build() {
          return JsonUtils.toJson(this);
      }
  
      public class TemplateItem extends HashMap<String, Item> {
  
          private static final long serialVersionUID = -3728490424738325020L;
  
          public TemplateItem() {}
  
          public TemplateItem(String key, Item item) {
              this.put(key, item);
          }
      }
  
      public class Item {
          private Object value;
          private String color;
  
          public Object getValue() {
              return value;
          }
          public void setValue(Object value) {
              this.value = value;
          }
          public String getColor() {
              return color;
          }
          public void setColor(String color) {
              this.color = color;
          }
          
          public Item(Object value) {
              this(value, "#999");
          }
          public Item(Object value, String color) {
              this.value = value;
              this.color = color;
          }
      }
  }