context, IService iService)
11 | throws WxErrorException;
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/api/WxMessageMatcher.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.api;
2 |
3 | import com.soecode.wxtools.bean.WxXmlMessage;
4 |
5 | public interface WxMessageMatcher {
6 |
7 | boolean match(WxXmlMessage message);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/api/WxMessageRouter.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.api;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.soecode.wxtools.bean.WxXmlMessage;
7 | import com.soecode.wxtools.bean.WxXmlOutMessage;
8 |
9 | /**
10 | *
11 | * WxMessageRouter router = new WxMessageRouter(wxService);
12 | * router
13 | * .rule()
14 | * .msgType("MSG_TYPE").event("EVENT").eventKey("EVENT_KEY").content("CONTENT")
15 | * .interceptor(interceptor, ...).handler(handler, ...)
16 | * .end()
17 | * .rule()
18 | * ...
19 | * .end()
20 | * ;
21 | *
22 | * router.route(message);
23 | *
24 | *
25 | *
26 | * @author antgan
27 | *
28 | */
29 | public class WxMessageRouter {
30 |
31 | private final List rules = new ArrayList();
32 | private final IService iService;
33 | private WxErrorExceptionHandler exceptionHandler;
34 | public WxMessageRouter(IService iService) {
35 | this.iService = iService;
36 | }
37 |
38 | public void setExceptionHandler(WxErrorExceptionHandler exceptionHandler) {
39 | this.exceptionHandler = exceptionHandler;
40 | }
41 |
42 | List getRules() {
43 | return this.rules;
44 | }
45 |
46 | public WxMessageRouterRule rule() {
47 | return new WxMessageRouterRule(this);
48 | }
49 |
50 | public WxXmlOutMessage route(final WxXmlMessage wxMessage) {
51 |
52 | final List matchRules = new ArrayList();
53 | for (final WxMessageRouterRule rule : rules) {
54 | if (rule.test(wxMessage)) {
55 | matchRules.add(rule);
56 | if (!rule.isReEnter()) {
57 | break;
58 | }
59 | }
60 | }
61 |
62 | if (matchRules.size() == 0) {
63 | return null;
64 | }
65 |
66 | WxXmlOutMessage res = null;
67 | for (final WxMessageRouterRule rule : matchRules) {
68 | res = rule.service(wxMessage, iService, exceptionHandler);
69 | }
70 | return res;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/api/WxMessageRouterRule.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.api;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 | import java.util.regex.Pattern;
8 |
9 | import com.soecode.wxtools.bean.WxXmlMessage;
10 | import com.soecode.wxtools.bean.WxXmlOutMessage;
11 | import com.soecode.wxtools.exception.WxErrorException;
12 |
13 | public class WxMessageRouterRule {
14 |
15 | private final WxMessageRouter routerBuilder;
16 |
17 | private String fromUser;
18 |
19 | private String msgType;
20 |
21 | private String event;
22 |
23 | private String eventKey;
24 |
25 | private String content;
26 |
27 | private String rContent;
28 |
29 | private WxMessageMatcher matcher;
30 |
31 | private boolean reEnter = false;
32 |
33 | private List handlers = new ArrayList();
34 |
35 | private List interceptors = new ArrayList();
36 |
37 | protected WxMessageRouterRule(WxMessageRouter routerBuilder) {
38 | this.routerBuilder = routerBuilder;
39 | }
40 |
41 | public WxMessageRouterRule msgType(String msgType) {
42 | this.msgType = msgType;
43 | return this;
44 | }
45 |
46 | public WxMessageRouterRule event(String event) {
47 | this.event = event;
48 | return this;
49 | }
50 |
51 | public WxMessageRouterRule eventKey(String eventKey) {
52 | this.eventKey = eventKey;
53 | return this;
54 | }
55 |
56 | public WxMessageRouterRule content(String content) {
57 | this.content = content;
58 | return this;
59 | }
60 |
61 | public WxMessageRouterRule rContent(String regex) {
62 | this.rContent = regex;
63 | return this;
64 | }
65 |
66 | public WxMessageRouterRule fromUser(String fromUser) {
67 | this.fromUser = fromUser;
68 | return this;
69 | }
70 |
71 | public WxMessageRouterRule matcher(WxMessageMatcher matcher) {
72 | this.matcher = matcher;
73 | return this;
74 | }
75 |
76 | public WxMessageRouterRule interceptor(WxMessageInterceptor interceptor) {
77 | return interceptor(interceptor, (WxMessageInterceptor[]) null);
78 | }
79 |
80 | public WxMessageRouterRule interceptor(WxMessageInterceptor interceptor,
81 | WxMessageInterceptor... otherInterceptors) {
82 | this.interceptors.add(interceptor);
83 | if (otherInterceptors != null && otherInterceptors.length > 0) {
84 | for (WxMessageInterceptor i : otherInterceptors) {
85 | this.interceptors.add(i);
86 | }
87 | }
88 | return this;
89 | }
90 |
91 | public WxMessageRouterRule handler(WxMessageHandler handler) {
92 | return handler(handler, (WxMessageHandler[]) null);
93 | }
94 |
95 | public WxMessageRouterRule handler(WxMessageHandler handler, WxMessageHandler... otherHandlers) {
96 | this.handlers.add(handler);
97 | if (otherHandlers != null && otherHandlers.length > 0) {
98 | for (WxMessageHandler i : otherHandlers) {
99 | this.handlers.add(i);
100 | }
101 | }
102 | return this;
103 | }
104 |
105 | public WxMessageRouter end() {
106 | this.routerBuilder.getRules().add(this);
107 | return this.routerBuilder;
108 | }
109 |
110 | public WxMessageRouter next() {
111 | this.reEnter = true;
112 | return end();
113 | }
114 |
115 | protected boolean test(WxXmlMessage wxMessage) {
116 | return (this.fromUser == null || this.fromUser.equals(wxMessage.getFromUserName()))
117 | && (this.msgType == null || this.msgType.equals(wxMessage.getMsgType()))
118 | && (this.event == null || this.event.equals(wxMessage.getEvent()))
119 | && (this.eventKey == null || this.eventKey.equals(wxMessage.getEventKey()))
120 | && (this.content == null
121 | || this.content
122 | .equals(wxMessage.getContent() == null ? null : wxMessage.getContent().trim()))
123 | && (this.rContent == null || Pattern.matches(this.rContent,
124 | wxMessage.getContent() == null ? "" : wxMessage.getContent().trim()))
125 | && (this.matcher == null || this.matcher.match(wxMessage));
126 | }
127 |
128 | protected WxXmlOutMessage service(WxXmlMessage wxMessage, IService iService,
129 | WxErrorExceptionHandler exceptionHandler) {
130 | try {
131 | Map context = new HashMap();
132 | // 如果拦截器不通过,返回null
133 | for (WxMessageInterceptor interceptor : this.interceptors) {
134 | if (!interceptor.intercept(wxMessage, context, iService)) {
135 | return null;
136 | }
137 | }
138 | // 交给handler处理
139 | WxXmlOutMessage res = null;
140 | for (WxMessageHandler handler : this.handlers) {
141 | // 返回最后handler的结果
142 | res = handler.handle(wxMessage, context, iService);
143 | }
144 | return res;
145 | } catch (WxErrorException e) {
146 | e.printStackTrace();
147 | exceptionHandler.handle(e);
148 | }
149 | return null;
150 | }
151 |
152 | public void setFromUser(String fromUser) {
153 | this.fromUser = fromUser;
154 | }
155 |
156 | public void setMsgType(String msgType) {
157 | this.msgType = msgType;
158 | }
159 |
160 | public void setEvent(String event) {
161 | this.event = event;
162 | }
163 |
164 | public void setEventKey(String eventKey) {
165 | this.eventKey = eventKey;
166 | }
167 |
168 | public void setContent(String content) {
169 | this.content = content;
170 | }
171 |
172 | public void setrContent(String rContent) {
173 | this.rContent = rContent;
174 | }
175 |
176 | public void setMatcher(WxMessageMatcher matcher) {
177 | this.matcher = matcher;
178 | }
179 |
180 | public void setHandlers(List handlers) {
181 | this.handlers = handlers;
182 | }
183 |
184 | public void setInterceptors(List interceptors) {
185 | this.interceptors = interceptors;
186 | }
187 |
188 | public boolean isReEnter() {
189 | return reEnter;
190 | }
191 |
192 | public void setReEnter(boolean reEnter) {
193 | this.reEnter = reEnter;
194 | }
195 |
196 | }
197 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/InvokePay.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonGenerationException;
6 | import org.codehaus.jackson.map.JsonMappingException;
7 | import org.codehaus.jackson.map.ObjectMapper;
8 |
9 | public class InvokePay {
10 | private String appId;
11 | private String timeStamp;
12 | private String nonceStr;
13 | private String prepayId;
14 | private String signType;
15 | private String paySign;
16 | public String getAppId() {
17 | return appId;
18 | }
19 | public void setAppId(String appId) {
20 | this.appId = appId;
21 | }
22 | public String getTimeStamp() {
23 | return timeStamp;
24 | }
25 | public void setTimeStamp(String timeStamp) {
26 | this.timeStamp = timeStamp;
27 | }
28 | public String getNonceStr() {
29 | return nonceStr;
30 | }
31 | public void setNonceStr(String nonceStr) {
32 | this.nonceStr = nonceStr;
33 | }
34 |
35 | public String getPrepayId() {
36 | return prepayId;
37 | }
38 | public void setPrepayId(String prepayId) {
39 | this.prepayId = prepayId;
40 | }
41 | public String getSignType() {
42 | return signType;
43 | }
44 | public void setSignType(String signType) {
45 | this.signType = signType;
46 | }
47 | public String getPaySign() {
48 | return paySign;
49 | }
50 | public void setPaySign(String paySign) {
51 | this.paySign = paySign;
52 | }
53 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException{
54 | ObjectMapper mapper = new ObjectMapper();
55 | return mapper.writeValueAsString(this);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/JSJDKEntity.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.util.List;
4 |
5 | public class JSJDKEntity {
6 | private String appId;
7 | private String timestamp;
8 | private String nonceStr;
9 | private String signature;
10 | private List jsApiList;
11 |
12 | public String getAppId() {
13 | return appId;
14 | }
15 | public void setAppId(String appId) {
16 | this.appId = appId;
17 | }
18 | public String getTimestamp() {
19 | return timestamp;
20 | }
21 | public void setTimestamp(String timestamp) {
22 | this.timestamp = timestamp;
23 | }
24 | public String getNonceStr() {
25 | return nonceStr;
26 | }
27 | public void setNonceStr(String nonceStr) {
28 | this.nonceStr = nonceStr;
29 | }
30 | public String getSignature() {
31 | return signature;
32 | }
33 | public void setSignature(String signature) {
34 | this.signature = signature;
35 | }
36 | public List getJsApiList() {
37 | return jsApiList;
38 | }
39 | public void setJsApiList(List jsApiList) {
40 | this.jsApiList = jsApiList;
41 | }
42 |
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/KfAccount.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 | import org.codehaus.jackson.map.ObjectMapper;
6 |
7 | public class KfAccount {
8 |
9 | @JsonProperty("kf_account")
10 | private String kfAccount;
11 | private String nickname;
12 | private String password;
13 |
14 | public KfAccount() {
15 | }
16 |
17 | public KfAccount(String kfAccount, String nickname, String password) {
18 | this.kfAccount = kfAccount;
19 | this.nickname = nickname;
20 | this.password = password;
21 | }
22 |
23 | public String getKfAccount() {
24 | return kfAccount;
25 | }
26 |
27 | public void setKfAccount(String kfAccount) {
28 | this.kfAccount = kfAccount;
29 | }
30 |
31 | public String getNickname() {
32 | return nickname;
33 | }
34 |
35 | public void setNickname(String nickname) {
36 | this.nickname = nickname;
37 | }
38 |
39 | public String getPassword() {
40 | return password;
41 | }
42 |
43 | public void setPassword(String password) {
44 | this.password = password;
45 | }
46 |
47 | public String toJson() throws IOException {
48 | ObjectMapper mapper = new ObjectMapper();
49 | return mapper.writeValueAsString(this);
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return "KfAccount{" +
55 | "kfAccount='" + kfAccount + '\'' +
56 | ", nickname='" + nickname + '\'' +
57 | ", password='" + password + '\'' +
58 | '}';
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/KfSender.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 | import org.codehaus.jackson.map.ObjectMapper;
5 | import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
6 |
7 | public class KfSender extends SenderContent {
8 | private String touser;
9 | private String msgtype;
10 |
11 | public String getTouser() {
12 | return touser;
13 | }
14 |
15 | public void setTouser(String touser) {
16 | this.touser = touser;
17 | }
18 |
19 | public String getMsgtype() {
20 | return msgtype;
21 | }
22 |
23 | public void setMsgtype(String msgtype) {
24 | this.msgtype = msgtype;
25 | }
26 |
27 |
28 | public String toJson() throws IOException {
29 | ObjectMapper mapper = new ObjectMapper();
30 | mapper.setSerializationInclusion(Inclusion.NON_NULL);
31 | return mapper.writeValueAsString(this);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/PayOrderInfo.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | public class PayOrderInfo {
4 | private String orderId;
5 | private String orderName;
6 | private String detail;
7 | private String totalFee;
8 | private String attach;
9 | private String productId;
10 | private String tradeType = "JSAPI";
11 |
12 | public String getTradeType() {
13 | return tradeType;
14 | }
15 | public void setTradeType(String tradeType) {
16 | this.tradeType = tradeType;
17 | }
18 | public String getAttach() {
19 | return attach;
20 | }
21 | public void setAttach(String attach) {
22 | this.attach = attach;
23 | }
24 | public String getProductId() {
25 | return productId;
26 | }
27 | public void setProductId(String productId) {
28 | this.productId = productId;
29 | }
30 | public String getOrderId() {
31 | return orderId;
32 | }
33 | public void setOrderId(String orderId) {
34 | this.orderId = orderId;
35 | }
36 | public String getOrderName() {
37 | return orderName;
38 | }
39 | public void setOrderName(String orderName) {
40 | this.orderName = orderName;
41 | }
42 | public String getDetail() {
43 | return detail;
44 | }
45 | public void setDetail(String detail) {
46 | this.detail = detail;
47 | }
48 | public String getTotalFee() {
49 | return totalFee;
50 | }
51 | public void setTotalFee(String totalFee) {
52 | this.totalFee = totalFee;
53 | }
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/PreviewSender.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonGenerationException;
6 | import org.codehaus.jackson.map.JsonMappingException;
7 | import org.codehaus.jackson.map.ObjectMapper;
8 | import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
9 |
10 | public class PreviewSender extends SenderContent {
11 |
12 | private String touser;
13 | private String towxname;
14 | private String msgtype;
15 |
16 | public String getTouser() {
17 | return touser;
18 | }
19 |
20 | public void setTouser(String touser) {
21 | this.touser = touser;
22 | }
23 |
24 | public String getTowxname() {
25 | return towxname;
26 | }
27 |
28 | public void setTowxname(String towxname) {
29 | this.towxname = towxname;
30 | }
31 |
32 | public String getMsgtype() {
33 | return msgtype;
34 | }
35 |
36 | public void setMsgtype(String msgtype) {
37 | this.msgtype = msgtype;
38 | }
39 |
40 | public String toJson() throws IOException {
41 | ObjectMapper mapper = new ObjectMapper();
42 | mapper.setSerializationInclusion(Inclusion.NON_NULL);
43 | return mapper.writeValueAsString(this);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/SenderContent.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.util.List;
4 |
5 | public class SenderContent {
6 | private Media mpnews;
7 | private NewsList news;
8 | private Text text;
9 | private Media voice;
10 | private Media image;
11 | private Media mpvideo;
12 | private Media video;
13 | private Media music;
14 |
15 | public Media getMpnews() {
16 | return mpnews;
17 | }
18 |
19 | public void setMpnews(Media mpnews) {
20 | this.mpnews = mpnews;
21 | }
22 |
23 | public NewsList getNews() {
24 | return news;
25 | }
26 |
27 | public void setNews(NewsList news) {
28 | this.news = news;
29 | }
30 |
31 | public Text getText() {
32 | return text;
33 | }
34 |
35 | public void setText(Text text) {
36 | this.text = text;
37 | }
38 |
39 | public Media getVoice() {
40 | return voice;
41 | }
42 |
43 | public void setVoice(Media voice) {
44 | this.voice = voice;
45 | }
46 |
47 | public Media getImage() {
48 | return image;
49 | }
50 |
51 | public void setImage(Media image) {
52 | this.image = image;
53 | }
54 |
55 | public Media getMpvideo() {
56 | return mpvideo;
57 | }
58 |
59 | public void setMpvideo(Media mpvideo) {
60 | this.mpvideo = mpvideo;
61 | }
62 |
63 | public Media getVideo() {
64 | return video;
65 | }
66 |
67 | public void setVideo(Media video) {
68 | this.video = video;
69 | }
70 |
71 | public Media getMusic() {
72 | return music;
73 | }
74 |
75 | public void setMusic(Media music) {
76 | this.music = music;
77 | }
78 |
79 | /**
80 | * 媒体包括图文语音视频图片
81 | * @author antgan
82 | *
83 | */
84 | public static class Media{
85 | private String media_id;
86 | private String thumb_media_id;
87 | private String title;
88 | private String description;
89 | private String musicurl;
90 | private String hqmusicurl;
91 | public Media() {
92 | }
93 | public Media(String media_id) {
94 | this.media_id = media_id;
95 | }
96 |
97 | public Media(String media_id, String thumb_media_id, String title, String description) {
98 | this.media_id = media_id;
99 | this.thumb_media_id = thumb_media_id;
100 | this.title = title;
101 | this.description = description;
102 | }
103 |
104 | public Media(String thumb_media_id, String title, String description, String musicurl,
105 | String hqmusicurl) {
106 | this.thumb_media_id = thumb_media_id;
107 | this.title = title;
108 | this.description = description;
109 | this.musicurl = musicurl;
110 | this.hqmusicurl = hqmusicurl;
111 | }
112 |
113 | public String getMedia_id() {
114 | return media_id;
115 | }
116 |
117 | public void setMedia_id(String media_id) {
118 | this.media_id = media_id;
119 | }
120 |
121 | public String getThumb_media_id() {
122 | return thumb_media_id;
123 | }
124 |
125 | public void setThumb_media_id(String thumb_media_id) {
126 | this.thumb_media_id = thumb_media_id;
127 | }
128 |
129 | public String getTitle() {
130 | return title;
131 | }
132 |
133 | public void setTitle(String title) {
134 | this.title = title;
135 | }
136 |
137 | public String getDescription() {
138 | return description;
139 | }
140 |
141 | public void setDescription(String description) {
142 | this.description = description;
143 | }
144 |
145 | public String getMusicurl() {
146 | return musicurl;
147 | }
148 |
149 | public void setMusicurl(String musicurl) {
150 | this.musicurl = musicurl;
151 | }
152 |
153 | public String getHqmusicurl() {
154 | return hqmusicurl;
155 | }
156 |
157 | public void setHqmusicurl(String hqmusicurl) {
158 | this.hqmusicurl = hqmusicurl;
159 | }
160 | }
161 |
162 | public static class Text{
163 | private String content;
164 | public Text() {
165 | }
166 | public Text(String content){
167 | this.content = content;
168 | }
169 | public String getContent() {
170 | return content;
171 | }
172 |
173 | public void setContent(String content) {
174 | this.content = content;
175 | }
176 |
177 | }
178 |
179 | public static class NewsList{
180 | private List articles;
181 |
182 | public NewsList(List articles) {
183 | this.articles = articles;
184 | }
185 |
186 | public List getArticles() {
187 | return articles;
188 | }
189 |
190 | public void setArticles(List articles) {
191 | this.articles = articles;
192 | }
193 |
194 | public static class News{
195 | private String title;
196 | private String description;
197 | private String url;
198 | private String picurl;
199 |
200 | public News() {
201 | }
202 |
203 | public News(String title, String description, String url, String picurl) {
204 | this.title = title;
205 | this.description = description;
206 | this.url = url;
207 | this.picurl = picurl;
208 | }
209 |
210 | public String getTitle() {
211 | return title;
212 | }
213 |
214 | public void setTitle(String title) {
215 | this.title = title;
216 | }
217 |
218 | public String getDescription() {
219 | return description;
220 | }
221 |
222 | public void setDescription(String description) {
223 | this.description = description;
224 | }
225 |
226 | public String getUrl() {
227 | return url;
228 | }
229 |
230 | public void setUrl(String url) {
231 | this.url = url;
232 | }
233 |
234 | public String getPicurl() {
235 | return picurl;
236 | }
237 |
238 | public void setPicurl(String picurl) {
239 | this.picurl = picurl;
240 | }
241 | }
242 | }
243 | }
244 |
245 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/SenderFilter.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | public class SenderFilter {
4 |
5 | private boolean is_to_all;
6 | private int tag_id;
7 |
8 | public SenderFilter() {}
9 |
10 | public SenderFilter(boolean is_to_all, int tag_id) {
11 | this.is_to_all = is_to_all;
12 | this.tag_id = tag_id;
13 | }
14 |
15 | public Boolean getIs_to_all() {
16 | return is_to_all;
17 | }
18 |
19 | public void setIs_to_all(Boolean is_to_all) {
20 | this.is_to_all = is_to_all;
21 | }
22 |
23 | public int getTag_id() {
24 | return tag_id;
25 | }
26 |
27 | public void setTag_id(int tag_id) {
28 | this.tag_id = tag_id;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/TemplateSender.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonGenerationException;
6 | import org.codehaus.jackson.map.JsonMappingException;
7 | import org.codehaus.jackson.map.ObjectMapper;
8 |
9 | public class TemplateSender {
10 |
11 | private String touser;
12 | private String template_id;
13 | private String url;
14 | private Object data;
15 | public String getTouser() {
16 | return touser;
17 | }
18 | public void setTouser(String touser) {
19 | this.touser = touser;
20 | }
21 | public String getTemplate_id() {
22 | return template_id;
23 | }
24 | public void setTemplate_id(String template_id) {
25 | this.template_id = template_id;
26 | }
27 | public String getUrl() {
28 | return url;
29 | }
30 | public void setUrl(String url) {
31 | this.url = url;
32 | }
33 | public Object getData() {
34 | return data;
35 | }
36 | public void setData(Object data) {
37 | this.data = data;
38 | }
39 | @Override
40 | public String toString() {
41 | return "TemplateSender [touser=" + touser + ", template_id=" + template_id + ", url=" + url + ", data=" + data
42 | + "]";
43 | }
44 |
45 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException {
46 | ObjectMapper mapper = new ObjectMapper();
47 | return mapper.writeValueAsString(this);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxAccessToken.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 | import org.codehaus.jackson.JsonParseException;
5 | import org.codehaus.jackson.map.JsonMappingException;
6 | import org.codehaus.jackson.map.ObjectMapper;
7 |
8 | public class WxAccessToken {
9 | private String access_token;
10 | private int expires_in = -1;
11 | public String getAccess_token() {
12 | return access_token;
13 | }
14 |
15 | public void setAccess_token(String access_token) {
16 | this.access_token = access_token;
17 | }
18 |
19 | public int getExpires_in() {
20 | return expires_in;
21 | }
22 |
23 | public void setExpires_in(int expires_in) {
24 | this.expires_in = expires_in;
25 | }
26 |
27 | public static WxAccessToken fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
28 | ObjectMapper mapper = new ObjectMapper();
29 | return mapper.readValue(json, WxAccessToken.class);
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return "WxAccessToken [access_token=" + access_token + ", expires_in=" + expires_in + "]";
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxJsapiConfig.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 |
6 | import org.codehaus.jackson.JsonGenerationException;
7 | import org.codehaus.jackson.map.JsonMappingException;
8 | import org.codehaus.jackson.map.ObjectMapper;
9 |
10 | public class WxJsapiConfig {
11 | private String appid;
12 |
13 | private String noncestr;
14 |
15 | private long timestamp;
16 |
17 | private String url;
18 |
19 | private String signature;
20 |
21 | private List jsApiList;
22 |
23 | public List getJsApiList() {
24 | return jsApiList;
25 | }
26 |
27 | public void setJsApiList(List jsApiList) {
28 | this.jsApiList = jsApiList;
29 | }
30 |
31 | public String getSignature() {
32 | return signature;
33 | }
34 |
35 | public void setSignature(String signature) {
36 | this.signature = signature;
37 | }
38 |
39 | public String getNoncestr() {
40 | return noncestr;
41 | }
42 |
43 | public void setNoncestr(String noncestr) {
44 | this.noncestr = noncestr;
45 | }
46 |
47 | public long getTimestamp() {
48 | return timestamp;
49 | }
50 |
51 | public void setTimestamp(long timestamp) {
52 | this.timestamp = timestamp;
53 | }
54 |
55 | public String getUrl() {
56 | return url;
57 | }
58 |
59 | public void setUrl(String url) {
60 | this.url = url;
61 | }
62 |
63 | public String getAppid() {
64 | return appid;
65 | }
66 |
67 | public void setAppid(String appid) {
68 | this.appid = appid;
69 | }
70 |
71 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException{
72 | ObjectMapper mapper = new ObjectMapper();
73 | return mapper.writeValueAsString(this);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxJsapiSignature.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | public class WxJsapiSignature {
4 | private String appid;
5 |
6 | private String noncestr;
7 |
8 | private long timestamp;
9 |
10 | private String url;
11 |
12 | private String signature;
13 |
14 | public String getSignature() {
15 | return signature;
16 | }
17 |
18 | public void setSignature(String signature) {
19 | this.signature = signature;
20 | }
21 |
22 | public String getNoncestr() {
23 | return noncestr;
24 | }
25 |
26 | public void setNoncestr(String noncestr) {
27 | this.noncestr = noncestr;
28 | }
29 |
30 | public long getTimestamp() {
31 | return timestamp;
32 | }
33 |
34 | public void setTimestamp(long timestamp) {
35 | this.timestamp = timestamp;
36 | }
37 |
38 | public String getUrl() {
39 | return url;
40 | }
41 |
42 | public void setUrl(String url) {
43 | this.url = url;
44 | }
45 |
46 | public String getAppid() {
47 | return appid;
48 | }
49 |
50 | public void setAppid(String appid) {
51 | this.appid = appid;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxMenu.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import org.codehaus.jackson.JsonGenerationException;
8 | import org.codehaus.jackson.JsonParseException;
9 | import org.codehaus.jackson.map.JsonMappingException;
10 | import org.codehaus.jackson.map.ObjectMapper;
11 |
12 | public class WxMenu {
13 |
14 | private List button = new ArrayList();
15 |
16 | private WxMenuRule matchrule;
17 |
18 | private String menuid;
19 |
20 | public List getButton() {
21 | return button;
22 | }
23 |
24 | public void setButton(List button) {
25 | this.button = button;
26 | }
27 |
28 | public WxMenuRule getMatchrule() {
29 | return matchrule;
30 | }
31 |
32 | public void setMatchrule(WxMenuRule matchrule) {
33 | this.matchrule = matchrule;
34 | }
35 |
36 | public String getMenuid() {
37 | return menuid;
38 | }
39 |
40 | public void setMenuid(String menuid) {
41 | this.menuid = menuid;
42 | }
43 |
44 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException {
45 | ObjectMapper mapper = new ObjectMapper();
46 | return mapper.writeValueAsString(this);
47 | }
48 |
49 | public static WxMenu fromJson(String json)
50 | throws JsonParseException, JsonMappingException, IOException {
51 | ObjectMapper mapper = new ObjectMapper();
52 | return mapper.readValue(json, WxMenu.class);
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return "WxMenu [button=" + button + ", matchrule=" + matchrule + ", menuid=" + menuid + "]";
58 | }
59 |
60 | public static class WxMenuButton {
61 |
62 | private String type;
63 | private String name;
64 | private String key;
65 | private String url;
66 | private String appid;
67 | private String pagepath;
68 |
69 | private List sub_button = new ArrayList();
70 |
71 | public String getAppid() {
72 | return appid;
73 | }
74 |
75 | public void setAppid(String appid) {
76 | this.appid = appid;
77 | }
78 |
79 | public String getPagepath() {
80 | return pagepath;
81 | }
82 |
83 | public void setPagepath(String pagepath) {
84 | this.pagepath = pagepath;
85 | }
86 |
87 | public String getType() {
88 | return type;
89 | }
90 |
91 | public void setType(String type) {
92 | this.type = type;
93 | }
94 |
95 | public String getName() {
96 | return name;
97 | }
98 |
99 | public void setName(String name) {
100 | this.name = name;
101 | }
102 |
103 | public String getKey() {
104 | return key;
105 | }
106 |
107 | public void setKey(String key) {
108 | this.key = key;
109 | }
110 |
111 | public String getUrl() {
112 | return url;
113 | }
114 |
115 | public void setUrl(String url) {
116 | this.url = url;
117 | }
118 |
119 | public List getSub_button() {
120 | return sub_button;
121 | }
122 |
123 | public void setSub_button(List sub_button) {
124 | this.sub_button = sub_button;
125 | }
126 |
127 | @Override
128 | public String toString() {
129 | return "WxMenuButton{" +
130 | "type='" + type + '\'' +
131 | ", name='" + name + '\'' +
132 | ", key='" + key + '\'' +
133 | ", url='" + url + '\'' +
134 | ", appid='" + appid + '\'' +
135 | ", pagepath='" + pagepath + '\'' +
136 | ", sub_button=" + sub_button +
137 | '}';
138 | }
139 | }
140 |
141 | public static class WxMenuRule {
142 |
143 | private String tag_id;
144 | private String sex;
145 | private String country;
146 | private String province;
147 | private String city;
148 | private String client_platform_type;
149 | private String language;
150 |
151 | public String getLanguage() {
152 | return language;
153 | }
154 |
155 | public void setLanguage(String language) {
156 | this.language = language;
157 | }
158 |
159 | public String getTag_id() {
160 | return tag_id;
161 | }
162 |
163 | public void setTag_id(String tag_id) {
164 | this.tag_id = tag_id;
165 | }
166 |
167 | public String getSex() {
168 | return sex;
169 | }
170 |
171 | public void setSex(String sex) {
172 | this.sex = sex;
173 | }
174 |
175 | public String getCountry() {
176 | return country;
177 | }
178 |
179 | public void setCountry(String country) {
180 | this.country = country;
181 | }
182 |
183 | public String getProvince() {
184 | return province;
185 | }
186 |
187 | public void setProvince(String province) {
188 | this.province = province;
189 | }
190 |
191 | public String getCity() {
192 | return city;
193 | }
194 |
195 | public void setCity(String city) {
196 | this.city = city;
197 | }
198 |
199 | public String getClient_platform_type() {
200 | return client_platform_type;
201 | }
202 |
203 | public void setClient_platform_type(String client_platform_type) {
204 | this.client_platform_type = client_platform_type;
205 | }
206 |
207 | @Override
208 | public String toString() {
209 | return "WxMenuRule{" +
210 | "tag_id='" + tag_id + '\'' +
211 | ", sex='" + sex + '\'' +
212 | ", country='" + country + '\'' +
213 | ", province='" + province + '\'' +
214 | ", city='" + city + '\'' +
215 | ", client_platform_type='" + client_platform_type + '\'' +
216 | ", language='" + language + '\'' +
217 | '}';
218 | }
219 | }
220 |
221 | }
222 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxMessage.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import org.codehaus.jackson.JsonGenerationException;
8 | import org.codehaus.jackson.map.JsonMappingException;
9 | import org.codehaus.jackson.map.ObjectMapper;
10 |
11 | import com.soecode.wxtools.bean.msgbuilder.FileBuilder;
12 | import com.soecode.wxtools.bean.msgbuilder.ImageBuilder;
13 | import com.soecode.wxtools.bean.msgbuilder.NewsBuilder;
14 | import com.soecode.wxtools.bean.msgbuilder.TextBuilder;
15 | import com.soecode.wxtools.bean.msgbuilder.VideoBuilder;
16 | import com.soecode.wxtools.bean.msgbuilder.VoiceBuilder;
17 |
18 | public class WxMessage {
19 |
20 | private String toUser;
21 | private String toParty;
22 | private String toTag;
23 | private String agentId;
24 | private String msgType;
25 | private String content;
26 | private String mediaId;
27 | private String thumbMediaId;
28 | private String title;
29 | private String description;
30 | private String musicUrl;
31 | private String hqMusicUrl;
32 | private String safe;
33 | private List articles = new ArrayList();
34 |
35 | public String getToUser() {
36 | return toUser;
37 | }
38 |
39 | public void setToUser(String toUser) {
40 | this.toUser = toUser;
41 | }
42 |
43 | public String getToParty() {
44 | return toParty;
45 | }
46 |
47 | public void setToParty(String toParty) {
48 | this.toParty = toParty;
49 | }
50 |
51 | public String getToTag() {
52 | return toTag;
53 | }
54 |
55 | public void setToTag(String toTag) {
56 | this.toTag = toTag;
57 | }
58 |
59 | public String getAgentId() {
60 | return agentId;
61 | }
62 |
63 | public void setAgentId(String agentId) {
64 | this.agentId = agentId;
65 | }
66 |
67 | public String getMsgType() {
68 | return msgType;
69 | }
70 |
71 | public String getSafe() {
72 | return safe;
73 | }
74 |
75 | public void setSafe(String safe) {
76 | this.safe = safe;
77 | }
78 |
79 | public void setMsgType(String msgType) {
80 | this.msgType = msgType;
81 | }
82 |
83 | public String getContent() {
84 | return content;
85 | }
86 |
87 | public void setContent(String content) {
88 | this.content = content;
89 | }
90 |
91 | public String getMediaId() {
92 | return mediaId;
93 | }
94 |
95 | public void setMediaId(String mediaId) {
96 | this.mediaId = mediaId;
97 | }
98 |
99 | public String getThumbMediaId() {
100 | return thumbMediaId;
101 | }
102 |
103 | public void setThumbMediaId(String thumbMediaId) {
104 | this.thumbMediaId = thumbMediaId;
105 | }
106 |
107 | public String getTitle() {
108 | return title;
109 | }
110 |
111 | public void setTitle(String title) {
112 | this.title = title;
113 | }
114 |
115 | public String getDescription() {
116 | return description;
117 | }
118 |
119 | public void setDescription(String description) {
120 | this.description = description;
121 | }
122 |
123 | public String getMusicUrl() {
124 | return musicUrl;
125 | }
126 |
127 | public void setMusicUrl(String musicUrl) {
128 | this.musicUrl = musicUrl;
129 | }
130 |
131 | public String getHqMusicUrl() {
132 | return hqMusicUrl;
133 | }
134 |
135 | public void setHqMusicUrl(String hqMusicUrl) {
136 | this.hqMusicUrl = hqMusicUrl;
137 | }
138 |
139 | public List getArticles() {
140 | return articles;
141 | }
142 |
143 | public void setArticles(List articles) {
144 | this.articles = articles;
145 | }
146 |
147 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException {
148 | ObjectMapper mapper = new ObjectMapper();
149 | return mapper.writeValueAsString(this);
150 | }
151 |
152 | public static class WxArticle {
153 |
154 | private String title;
155 | private String description;
156 | private String url;
157 | private String picUrl;
158 |
159 | public String getTitle() {
160 | return title;
161 | }
162 |
163 | public void setTitle(String title) {
164 | this.title = title;
165 | }
166 |
167 | public String getDescription() {
168 | return description;
169 | }
170 |
171 | public void setDescription(String description) {
172 | this.description = description;
173 | }
174 |
175 | public String getUrl() {
176 | return url;
177 | }
178 |
179 | public void setUrl(String url) {
180 | this.url = url;
181 | }
182 |
183 | public String getPicUrl() {
184 | return picUrl;
185 | }
186 |
187 | public void setPicUrl(String picUrl) {
188 | this.picUrl = picUrl;
189 | }
190 |
191 | }
192 |
193 | public static TextBuilder TEXT() {
194 | return new TextBuilder();
195 | }
196 |
197 | public static ImageBuilder IMAGE() {
198 | return new ImageBuilder();
199 | }
200 |
201 | public static VoiceBuilder VOICE() {
202 | return new VoiceBuilder();
203 | }
204 |
205 | public static VideoBuilder VIDEO() {
206 | return new VideoBuilder();
207 | }
208 |
209 | public static NewsBuilder NEWS() {
210 | return new NewsBuilder();
211 | }
212 |
213 | public static FileBuilder FILE() {
214 | return new FileBuilder();
215 | }
216 |
217 | }
218 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxNewsInfo.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonGenerationException;
6 | import org.codehaus.jackson.map.JsonMappingException;
7 | import org.codehaus.jackson.map.ObjectMapper;
8 |
9 | public class WxNewsInfo {
10 | private String title;
11 | private String thumb_media_id;
12 | private String thumb_url;
13 | private int show_cover_pic;
14 | private String author;
15 | private String digest;
16 | private String content;
17 | private String url;
18 | private String content_source_url;
19 | private int need_open_comment;
20 | private int only_fans_can_comment;
21 |
22 | public String getTitle() {
23 | return title;
24 | }
25 |
26 | public void setTitle(String title) {
27 | this.title = title;
28 | }
29 |
30 | public String getThumb_media_id() {
31 | return thumb_media_id;
32 | }
33 |
34 | public void setThumb_media_id(String thumb_media_id) {
35 | this.thumb_media_id = thumb_media_id;
36 | }
37 |
38 | public String getThumb_url() {
39 | return thumb_url;
40 | }
41 |
42 | public void setThumb_url(String thumb_url) {
43 | this.thumb_url = thumb_url;
44 | }
45 |
46 | public int getShow_cover_pic() {
47 | return show_cover_pic;
48 | }
49 |
50 | public void setShow_cover_pic(int show_cover_pic) {
51 | this.show_cover_pic = show_cover_pic;
52 | }
53 |
54 | public String getAuthor() {
55 | return author;
56 | }
57 |
58 | public void setAuthor(String author) {
59 | this.author = author;
60 | }
61 |
62 | public String getDigest() {
63 | return digest;
64 | }
65 |
66 | public void setDigest(String digest) {
67 | this.digest = digest;
68 | }
69 |
70 | public String getContent() {
71 | return content;
72 | }
73 |
74 | public void setContent(String content) {
75 | this.content = content;
76 | }
77 |
78 | public String getUrl() {
79 | return url;
80 | }
81 |
82 | public void setUrl(String url) {
83 | this.url = url;
84 | }
85 |
86 | public String getContent_source_url() {
87 | return content_source_url;
88 | }
89 |
90 | public void setContent_source_url(String content_source_url) {
91 | this.content_source_url = content_source_url;
92 | }
93 |
94 | public int getNeed_open_comment() {
95 | return need_open_comment;
96 | }
97 |
98 | public void setNeed_open_comment(int need_open_comment) {
99 | this.need_open_comment = need_open_comment;
100 | }
101 |
102 | public int getOnly_fans_can_comment() {
103 | return only_fans_can_comment;
104 | }
105 |
106 | public void setOnly_fans_can_comment(int only_fans_can_comment) {
107 | this.only_fans_can_comment = only_fans_can_comment;
108 | }
109 |
110 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException{
111 | ObjectMapper mapper = new ObjectMapper();
112 | return mapper.writeValueAsString(this);
113 | }
114 |
115 | @Override
116 | public String toString() {
117 | return "WxNewsInfo{" +
118 | "title='" + title + '\'' +
119 | ", thumb_media_id='" + thumb_media_id + '\'' +
120 | ", thumb_url='" + thumb_url + '\'' +
121 | ", show_cover_pic=" + show_cover_pic +
122 | ", author='" + author + '\'' +
123 | ", digest='" + digest + '\'' +
124 | ", content='" + content + '\'' +
125 | ", url='" + url + '\'' +
126 | ", content_source_url='" + content_source_url + '\'' +
127 | ", need_open_comment=" + need_open_comment +
128 | ", only_fans_can_comment=" + only_fans_can_comment +
129 | '}';
130 | }
131 | }
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxOpenidSender.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 |
6 | import org.codehaus.jackson.JsonGenerationException;
7 | import org.codehaus.jackson.map.JsonMappingException;
8 | import org.codehaus.jackson.map.ObjectMapper;
9 |
10 | public class WxOpenidSender extends SenderContent{
11 | List touser;
12 | private String msgtype;
13 | public List getTouser() {
14 | return touser;
15 | }
16 | public void setTouser(List touser) {
17 | this.touser = touser;
18 | }
19 | public String getMsgtype() {
20 | return msgtype;
21 | }
22 | public void setMsgtype(String msgtype) {
23 | this.msgtype = msgtype;
24 | }
25 |
26 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException{
27 | ObjectMapper mapper = new ObjectMapper();
28 | return mapper.writeValueAsString(this);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxQrcode.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonGenerationException;
6 | import org.codehaus.jackson.map.JsonMappingException;
7 | import org.codehaus.jackson.map.ObjectMapper;
8 |
9 | public class WxQrcode {
10 | private int expire_seconds;
11 | private String action_name;
12 | private WxQrActionInfo action_info;
13 |
14 | public int getExpire_seconds() {
15 | return expire_seconds;
16 | }
17 |
18 | public void setExpire_seconds(int expire_seconds) {
19 | this.expire_seconds = expire_seconds;
20 | }
21 |
22 | public String getAction_name() {
23 | return action_name;
24 | }
25 |
26 | public void setAction_name(String action_name) {
27 | this.action_name = action_name;
28 | }
29 |
30 | public WxQrActionInfo getAction_info() {
31 | return action_info;
32 | }
33 |
34 | public void setAction_info(WxQrActionInfo action_info) {
35 | this.action_info = action_info;
36 | }
37 |
38 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException{
39 | ObjectMapper mapper = new ObjectMapper();
40 | return mapper.writeValueAsString(this);
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "WxQrcode [expire_seconds=" + expire_seconds + ", action_name=" + action_name + ", action_info="
46 | + action_info + "]";
47 | }
48 |
49 | public static class WxQrActionInfo{
50 | private WxScene scene;
51 |
52 |
53 | public WxQrActionInfo(WxScene scene) {
54 | this.scene = scene;
55 | }
56 |
57 | public WxScene getScene() {
58 | return scene;
59 | }
60 |
61 | public void setScene(WxScene scene) {
62 | this.scene = scene;
63 | }
64 |
65 | @Override
66 | public String toString() {
67 | return "WxQrActionInfo [scene=" + scene + "]";
68 | }
69 |
70 | public static class WxScene{
71 | private int scene_id;
72 | private String scene_str;
73 |
74 | public WxScene(int scene_id) {
75 | this.scene_id = scene_id;
76 | }
77 |
78 | public WxScene(String scene_str) {
79 | this.scene_str = scene_str;
80 | }
81 |
82 | public int getScene_id() {
83 | return scene_id;
84 | }
85 | public void setScene_id(int scene_id) {
86 | this.scene_id = scene_id;
87 | }
88 | public String getScene_str() {
89 | return scene_str;
90 | }
91 | public void setScene_str(String scene_str) {
92 | this.scene_str = scene_str;
93 | }
94 | @Override
95 | public String toString() {
96 | return "WxScene [scene_id=" + scene_id + ", scene_str=" + scene_str + "]";
97 | }
98 | }
99 | }
100 |
101 |
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxTagSender.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 | import org.codehaus.jackson.map.ObjectMapper;
5 |
6 | public class WxTagSender extends SenderContent{
7 | private SenderFilter filter;
8 | private String msgtype;
9 | public SenderFilter getFilter() {
10 | return filter;
11 | }
12 | public void setFilter(SenderFilter filter) {
13 | this.filter = filter;
14 | }
15 | public String getMsgtype() {
16 | return msgtype;
17 | }
18 | public void setMsgtype(String msgtype) {
19 | this.msgtype = msgtype;
20 | }
21 |
22 | public String toJson() throws IOException{
23 | ObjectMapper mapper = new ObjectMapper();
24 | return mapper.writeValueAsString(this);
25 | }
26 |
27 | }
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxUnifiedOrder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonGenerationException;
6 | import org.codehaus.jackson.map.JsonMappingException;
7 | import org.codehaus.jackson.map.ObjectMapper;
8 |
9 | import com.soecode.wxtools.util.xml.XStreamTransformer;
10 | import com.thoughtworks.xstream.annotations.XStreamAlias;
11 |
12 | @XStreamAlias("xml")
13 | public class WxUnifiedOrder {
14 |
15 | @XStreamAlias("appid")
16 | private String appid;
17 |
18 | @XStreamAlias("mch_id")
19 | private String mchId;
20 |
21 | @XStreamAlias("device_info")
22 | private String deviceInfo;
23 |
24 | @XStreamAlias("nonce_str")
25 | private String nonceStr;
26 |
27 | @XStreamAlias("sign")
28 | private String sign;
29 |
30 | @XStreamAlias("body")
31 | private String body;
32 |
33 | @XStreamAlias("detail")
34 | private String detail;
35 |
36 | @XStreamAlias("attach")
37 | private String attach;
38 |
39 | @XStreamAlias("out_trade_no")
40 | private String outTradeNo;
41 |
42 | @XStreamAlias("fee_type")
43 | private String feeType;
44 |
45 | @XStreamAlias("total_fee")
46 | private String totalFee;
47 |
48 | @XStreamAlias("spbill_create_ip")
49 | private String spbillCreateIp;
50 |
51 | @XStreamAlias("time_start")
52 | private String timeStart;
53 |
54 | @XStreamAlias("time_expire")
55 | private String timeExpire;
56 |
57 | @XStreamAlias("goods_tag")
58 | private String goodsTag;
59 |
60 | @XStreamAlias("notify_url")
61 | private String notifyUrl;
62 |
63 | @XStreamAlias("trade_type")
64 | private String tradeType;
65 |
66 | @XStreamAlias("product_id")
67 | private String productId;
68 |
69 | @XStreamAlias("limit_pay")
70 | private String limitPay;
71 |
72 | @XStreamAlias("openid")
73 | private String openid;
74 |
75 |
76 | public String getAppid() {
77 | return appid;
78 | }
79 |
80 |
81 | public void setAppid(String appid) {
82 | this.appid = appid;
83 | }
84 |
85 |
86 | public String getMchId() {
87 | return mchId;
88 | }
89 |
90 |
91 | public void setMchId(String mchId) {
92 | this.mchId = mchId;
93 | }
94 |
95 |
96 | public String getDeviceInfo() {
97 | return deviceInfo;
98 | }
99 |
100 |
101 | public void setDeviceInfo(String deviceInfo) {
102 | this.deviceInfo = deviceInfo;
103 | }
104 |
105 |
106 | public String getNonceStr() {
107 | return nonceStr;
108 | }
109 |
110 |
111 | public void setNonceStr(String nonceStr) {
112 | this.nonceStr = nonceStr;
113 | }
114 |
115 |
116 | public String getSign() {
117 | return sign;
118 | }
119 |
120 |
121 | public void setSign(String sign) {
122 | this.sign = sign;
123 | }
124 |
125 |
126 | public String getBody() {
127 | return body;
128 | }
129 |
130 |
131 | public void setBody(String body) {
132 | this.body = body;
133 | }
134 |
135 |
136 | public String getDetail() {
137 | return detail;
138 | }
139 |
140 |
141 | public void setDetail(String detail) {
142 | this.detail = detail;
143 | }
144 |
145 |
146 | public String getAttach() {
147 | return attach;
148 | }
149 |
150 |
151 | public void setAttach(String attach) {
152 | this.attach = attach;
153 | }
154 |
155 |
156 | public String getOutTradeNo() {
157 | return outTradeNo;
158 | }
159 |
160 |
161 | public void setOutTradeNo(String outTradeNo) {
162 | this.outTradeNo = outTradeNo;
163 | }
164 |
165 |
166 | public String getFeeType() {
167 | return feeType;
168 | }
169 |
170 |
171 | public void setFeeType(String feeType) {
172 | this.feeType = feeType;
173 | }
174 |
175 |
176 | public String getTotalFee() {
177 | return totalFee;
178 | }
179 |
180 |
181 | public void setTotalFee(String totalFee) {
182 | this.totalFee = totalFee;
183 | }
184 |
185 |
186 | public String getSpbillCreateIp() {
187 | return spbillCreateIp;
188 | }
189 |
190 |
191 | public void setSpbillCreateIp(String spbillCreateIp) {
192 | this.spbillCreateIp = spbillCreateIp;
193 | }
194 |
195 |
196 | public String getTimeStart() {
197 | return timeStart;
198 | }
199 |
200 |
201 | public void setTimeStart(String timeStart) {
202 | this.timeStart = timeStart;
203 | }
204 |
205 |
206 | public String getTimeExpire() {
207 | return timeExpire;
208 | }
209 |
210 |
211 | public void setTimeExpire(String timeExpire) {
212 | this.timeExpire = timeExpire;
213 | }
214 |
215 |
216 | public String getGoodsTag() {
217 | return goodsTag;
218 | }
219 |
220 |
221 | public void setGoodsTag(String goodsTag) {
222 | this.goodsTag = goodsTag;
223 | }
224 |
225 |
226 | public String getNotifyUrl() {
227 | return notifyUrl;
228 | }
229 |
230 |
231 | public void setNotifyUrl(String notifyUrl) {
232 | this.notifyUrl = notifyUrl;
233 | }
234 |
235 |
236 | public String getTradeType() {
237 | return tradeType;
238 | }
239 |
240 |
241 | public void setTradeType(String tradeType) {
242 | this.tradeType = tradeType;
243 | }
244 |
245 |
246 | public String getProductId() {
247 | return productId;
248 | }
249 |
250 |
251 | public void setProductId(String productId) {
252 | this.productId = productId;
253 | }
254 |
255 |
256 | public String getLimitPay() {
257 | return limitPay;
258 | }
259 |
260 |
261 | public void setLimitPay(String limitPay) {
262 | this.limitPay = limitPay;
263 | }
264 |
265 |
266 | public String getOpenid() {
267 | return openid;
268 | }
269 |
270 |
271 | public void setOpenid(String openid) {
272 | this.openid = openid;
273 | }
274 |
275 |
276 | public String toXml() {
277 | return XStreamTransformer.toXml((Class) this.getClass(), this);
278 | }
279 |
280 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException {
281 | ObjectMapper mapper = new ObjectMapper();
282 | return mapper.writeValueAsString(this);
283 | }
284 | }
285 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxVideoIntroduction.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonGenerationException;
6 | import org.codehaus.jackson.map.JsonMappingException;
7 | import org.codehaus.jackson.map.ObjectMapper;
8 |
9 | public class WxVideoIntroduction {
10 | private String title;
11 | private String introduction;
12 | public String getTitle() {
13 | return title;
14 | }
15 | public void setTitle(String title) {
16 | this.title = title;
17 | }
18 | public String getIntroduction() {
19 | return introduction;
20 | }
21 | public void setIntroduction(String introduction) {
22 | this.introduction = introduction;
23 | }
24 |
25 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException{
26 | ObjectMapper mapper = new ObjectMapper();
27 | return mapper.writeValueAsString(this);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxXmlOutImageMessage.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.util.xml.XStreamMediaIdConverter;
5 | import com.thoughtworks.xstream.annotations.XStreamAlias;
6 | import com.thoughtworks.xstream.annotations.XStreamConverter;
7 |
8 | @XStreamAlias("xml")
9 | public class WxXmlOutImageMessage extends WxXmlOutMessage {
10 |
11 | @XStreamAlias("Image")
12 | @XStreamConverter(value = XStreamMediaIdConverter.class)
13 | private String mediaId;
14 |
15 | public WxXmlOutImageMessage() {
16 | this.msgType = WxConsts.XML_MSG_IMAGE;
17 | }
18 |
19 | public String getMediaId() {
20 | return mediaId;
21 | }
22 |
23 | public void setMediaId(String mediaId) {
24 | this.mediaId = mediaId;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxXmlOutMessage.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import com.soecode.wxtools.api.WxConfig;
4 | import com.soecode.wxtools.bean.outxmlbuilder.ImageBuilder;
5 | import com.soecode.wxtools.bean.outxmlbuilder.MusicBuilder;
6 | import com.soecode.wxtools.bean.outxmlbuilder.NewsBuilder;
7 | import com.soecode.wxtools.bean.outxmlbuilder.TextBuilder;
8 | import com.soecode.wxtools.bean.outxmlbuilder.VideoBuilder;
9 | import com.soecode.wxtools.bean.outxmlbuilder.VoiceBuilder;
10 | import com.soecode.wxtools.exception.AesException;
11 | import com.soecode.wxtools.util.crypto.WXBizMsgCrypt;
12 | import com.soecode.wxtools.util.xml.XStreamCDataConverter;
13 | import com.soecode.wxtools.util.xml.XStreamTransformer;
14 | import com.thoughtworks.xstream.annotations.XStreamAlias;
15 | import com.thoughtworks.xstream.annotations.XStreamConverter;
16 |
17 | @XStreamAlias("xml")
18 | public abstract class WxXmlOutMessage {
19 |
20 | @XStreamAlias("ToUserName")
21 | @XStreamConverter(value = XStreamCDataConverter.class)
22 | protected String toUserName;
23 |
24 | @XStreamAlias("FromUserName")
25 | @XStreamConverter(value = XStreamCDataConverter.class)
26 | protected String fromUserName;
27 |
28 | @XStreamAlias("CreateTime")
29 | protected Long createTime;
30 |
31 | @XStreamAlias("MsgType")
32 | @XStreamConverter(value = XStreamCDataConverter.class)
33 | protected String msgType;
34 |
35 | public String getToUserName() {
36 | return toUserName;
37 | }
38 |
39 | public void setToUserName(String toUserName) {
40 | this.toUserName = toUserName;
41 | }
42 |
43 | public String getFromUserName() {
44 | return fromUserName;
45 | }
46 |
47 | public void setFromUserName(String fromUserName) {
48 | this.fromUserName = fromUserName;
49 | }
50 |
51 | public Long getCreateTime() {
52 | return createTime;
53 | }
54 |
55 | public void setCreateTime(Long createTime) {
56 | this.createTime = createTime;
57 | }
58 |
59 | public String getMsgType() {
60 | return msgType;
61 | }
62 |
63 | public void setMsgType(String msgType) {
64 | this.msgType = msgType;
65 | }
66 |
67 | public String toXml() {
68 | return XStreamTransformer.toXml((Class) this.getClass(), this);
69 | }
70 |
71 | public static String encryptMsg(WxConfig wxconfig, String replyMsg, String timeStamp, String nonce) throws AesException {
72 | WXBizMsgCrypt pc = new WXBizMsgCrypt(WxConfig.getInstance().getToken(), WxConfig.getInstance().getAesKey(), WxConfig.getInstance().getAppId());
73 | return pc.encryptMsg(replyMsg, timeStamp, nonce);
74 | }
75 |
76 | public static TextBuilder TEXT() {
77 | return new TextBuilder();
78 | }
79 |
80 | public static ImageBuilder IMAGE() {
81 | return new ImageBuilder();
82 | }
83 |
84 | public static VoiceBuilder VOICE() {
85 | return new VoiceBuilder();
86 | }
87 |
88 | public static VideoBuilder VIDEO() {
89 | return new VideoBuilder();
90 | }
91 |
92 | public static NewsBuilder NEWS() {
93 | return new NewsBuilder();
94 | }
95 |
96 | public static MusicBuilder MUSIC(){
97 | return new MusicBuilder();
98 | }
99 |
100 | @Override
101 | public String toString() {
102 | return "WxXmlOutMessage [toUserName=" + toUserName + ", fromUserName=" + fromUserName + ", createTime="
103 | + createTime + ", msgType=" + msgType + "]";
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxXmlOutMusicMessage.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.util.xml.XStreamCDataConverter;
5 | import com.thoughtworks.xstream.annotations.XStreamAlias;
6 | import com.thoughtworks.xstream.annotations.XStreamConverter;
7 |
8 | public class WxXmlOutMusicMessage extends WxXmlOutMessage {
9 |
10 | @XStreamAlias("Music")
11 | protected final Music music = new Music();
12 |
13 | public WxXmlOutMusicMessage() {
14 | this.msgType = WxConsts.XML_MSG_MUSIC;
15 | }
16 |
17 | public String getTitle() {
18 | return music.title;
19 | }
20 |
21 | public void setTitle(String title) {
22 | music.title = title;
23 | }
24 |
25 | public String getDescription() {
26 | return music.description;
27 | }
28 |
29 | public void setDescription(String description) {
30 | music.description = description;
31 | }
32 |
33 | public String getMusicUrl() {
34 | return music.musicUrl;
35 | }
36 |
37 | public void setMusicUrl(String musicUrl) {
38 | music.musicUrl = musicUrl;
39 | }
40 |
41 | public String gethQMusicUrl() {
42 | return music.hQMusicUrl;
43 | }
44 |
45 | public void sethQMusicUrl(String hQMusicUrl) {
46 | music.hQMusicUrl = hQMusicUrl;
47 | }
48 |
49 | public String getThumbMediaId() {
50 | return music.thumbMediaId;
51 | }
52 |
53 | public void setThumbMediaId(String thumbMediaId) {
54 | music.thumbMediaId = thumbMediaId;
55 | }
56 |
57 | @XStreamAlias("Music")
58 | public static class Music{
59 | @XStreamAlias("Title")
60 | @XStreamConverter(value = XStreamCDataConverter.class)
61 | private String title;
62 |
63 | @XStreamAlias("Description")
64 | @XStreamConverter(value = XStreamCDataConverter.class)
65 | private String description;
66 |
67 | @XStreamAlias("MusicUrl")
68 | @XStreamConverter(value = XStreamCDataConverter.class)
69 | private String musicUrl;
70 |
71 | @XStreamAlias("HQMusicUrl")
72 | @XStreamConverter(value = XStreamCDataConverter.class)
73 | private String hQMusicUrl;
74 |
75 | @XStreamAlias("ThumbMediaId")
76 | @XStreamConverter(value = XStreamCDataConverter.class)
77 | private String thumbMediaId;
78 |
79 | public String getTitle() {
80 | return title;
81 | }
82 |
83 | public void setTitle(String title) {
84 | this.title = title;
85 | }
86 |
87 | public String getDescription() {
88 | return description;
89 | }
90 |
91 | public void setDescription(String description) {
92 | this.description = description;
93 | }
94 |
95 | public String getMusicUrl() {
96 | return musicUrl;
97 | }
98 |
99 | public void setMusicUrl(String musicUrl) {
100 | this.musicUrl = musicUrl;
101 | }
102 |
103 | public String gethQMusicUrl() {
104 | return hQMusicUrl;
105 | }
106 |
107 | public void sethQMusicUrl(String hQMusicUrl) {
108 | this.hQMusicUrl = hQMusicUrl;
109 | }
110 |
111 | public String getThumbMediaId() {
112 | return thumbMediaId;
113 | }
114 |
115 | public void setThumbMediaId(String thumbMediaId) {
116 | this.thumbMediaId = thumbMediaId;
117 | }
118 |
119 |
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxXmlOutNewsMessage.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.soecode.wxtools.api.WxConsts;
7 | import com.soecode.wxtools.util.xml.XStreamCDataConverter;
8 | import com.thoughtworks.xstream.annotations.XStreamAlias;
9 | import com.thoughtworks.xstream.annotations.XStreamConverter;
10 |
11 | @XStreamAlias("xml")
12 | public class WxXmlOutNewsMessage extends WxXmlOutMessage {
13 |
14 | @XStreamAlias("ArticleCount")
15 | protected int articleCount;
16 |
17 | @XStreamAlias("Articles")
18 | protected final List- articles = new ArrayList
- ();
19 |
20 | public WxXmlOutNewsMessage() {
21 | this.msgType = WxConsts.XML_MSG_NEWS;
22 | }
23 |
24 | public int getArticleCount() {
25 | return articleCount;
26 | }
27 |
28 | public void addArticle(Item item) {
29 | this.articles.add(item);
30 | this.articleCount = this.articles.size();
31 | }
32 |
33 | public List
- getArticles() {
34 | return articles;
35 | }
36 |
37 | @XStreamAlias("item")
38 | public static class Item {
39 |
40 | @XStreamAlias("Title")
41 | @XStreamConverter(value = XStreamCDataConverter.class)
42 | private String Title;
43 |
44 | @XStreamAlias("Description")
45 | @XStreamConverter(value = XStreamCDataConverter.class)
46 | private String Description;
47 |
48 | @XStreamAlias("PicUrl")
49 | @XStreamConverter(value = XStreamCDataConverter.class)
50 | private String PicUrl;
51 |
52 | @XStreamAlias("Url")
53 | @XStreamConverter(value = XStreamCDataConverter.class)
54 | private String Url;
55 |
56 | public String getTitle() {
57 | return Title;
58 | }
59 |
60 | public void setTitle(String title) {
61 | Title = title;
62 | }
63 |
64 | public String getDescription() {
65 | return Description;
66 | }
67 |
68 | public void setDescription(String description) {
69 | Description = description;
70 | }
71 |
72 | public String getPicUrl() {
73 | return PicUrl;
74 | }
75 |
76 | public void setPicUrl(String picUrl) {
77 | PicUrl = picUrl;
78 | }
79 |
80 | public String getUrl() {
81 | return Url;
82 | }
83 |
84 | public void setUrl(String url) {
85 | Url = url;
86 | }
87 |
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxXmlOutTextMessage.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.util.xml.XStreamCDataConverter;
5 | import com.thoughtworks.xstream.annotations.XStreamAlias;
6 | import com.thoughtworks.xstream.annotations.XStreamConverter;
7 |
8 | @XStreamAlias("xml")
9 | public class WxXmlOutTextMessage extends WxXmlOutMessage {
10 |
11 | @XStreamAlias("Content")
12 | @XStreamConverter(value = XStreamCDataConverter.class)
13 | private String content;
14 |
15 | public WxXmlOutTextMessage() {
16 | this.msgType = WxConsts.XML_MSG_TEXT;
17 | }
18 |
19 | public String getContent() {
20 | return content;
21 | }
22 |
23 | public void setContent(String content) {
24 | this.content = content;
25 | }
26 |
27 | @Override
28 | public String toString() {
29 | return "WxXmlOutTextMessage [content=" + content + "]";
30 | }
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxXmlOutVideoMessage.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.util.xml.XStreamCDataConverter;
5 | import com.thoughtworks.xstream.annotations.XStreamAlias;
6 | import com.thoughtworks.xstream.annotations.XStreamConverter;
7 |
8 | @XStreamAlias("xml")
9 | public class WxXmlOutVideoMessage extends WxXmlOutMessage {
10 |
11 | @XStreamAlias("Video")
12 | protected final Video video = new Video();
13 |
14 | public WxXmlOutVideoMessage() {
15 | this.msgType = WxConsts.XML_MSG_VIDEO;
16 | }
17 |
18 | public String getMediaId() {
19 | return video.getMediaId();
20 | }
21 |
22 | public void setMediaId(String mediaId) {
23 | video.setMediaId(mediaId);
24 | }
25 |
26 | public String getTitle() {
27 | return video.getTitle();
28 | }
29 |
30 | public void setTitle(String title) {
31 | video.setTitle(title);
32 | }
33 |
34 | public String getDescription() {
35 | return video.getDescription();
36 | }
37 |
38 | public void setDescription(String description) {
39 | video.setDescription(description);
40 | }
41 |
42 | @XStreamAlias("Video")
43 | public static class Video {
44 |
45 | @XStreamAlias("MediaId")
46 | @XStreamConverter(value = XStreamCDataConverter.class)
47 | private String mediaId;
48 |
49 | @XStreamAlias("Title")
50 | @XStreamConverter(value = XStreamCDataConverter.class)
51 | private String title;
52 |
53 | @XStreamAlias("Description")
54 | @XStreamConverter(value = XStreamCDataConverter.class)
55 | private String description;
56 |
57 | public String getMediaId() {
58 | return mediaId;
59 | }
60 |
61 | public void setMediaId(String mediaId) {
62 | this.mediaId = mediaId;
63 | }
64 |
65 | public String getTitle() {
66 | return title;
67 | }
68 |
69 | public void setTitle(String title) {
70 | this.title = title;
71 | }
72 |
73 | public String getDescription() {
74 | return description;
75 | }
76 |
77 | public void setDescription(String description) {
78 | this.description = description;
79 | }
80 |
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/WxXmlOutVoiceMessage.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.util.xml.XStreamMediaIdConverter;
5 | import com.thoughtworks.xstream.annotations.XStreamAlias;
6 | import com.thoughtworks.xstream.annotations.XStreamConverter;
7 |
8 | @XStreamAlias("xml")
9 | public class WxXmlOutVoiceMessage extends WxXmlOutMessage {
10 |
11 | @XStreamAlias("Voice")
12 | @XStreamConverter(value = XStreamMediaIdConverter.class)
13 | private String mediaId;
14 |
15 | public WxXmlOutVoiceMessage() {
16 | this.msgType = WxConsts.XML_MSG_VOICE;
17 | }
18 |
19 | public String getMediaId() {
20 | return mediaId;
21 | }
22 |
23 | public void setMediaId(String mediaId) {
24 | this.mediaId = mediaId;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/msgbuilder/BaseBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.msgbuilder;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.bean.WxMessage;
5 |
6 | public class BaseBuilder {
7 | protected String msgType;
8 | protected String agentId;
9 | protected String toUser;
10 | protected String toParty;
11 | protected String toTag;
12 | protected String safe;
13 |
14 | public T agentId(String agentId) {
15 | this.agentId = agentId;
16 | return (T) this;
17 | }
18 |
19 | public T toUser(String toUser) {
20 | this.toUser = toUser;
21 | return (T) this;
22 | }
23 |
24 | public T toParty(String toParty) {
25 | this.toParty = toParty;
26 | return (T) this;
27 | }
28 |
29 | public T toTag(String toTag) {
30 | this.toTag = toTag;
31 | return (T) this;
32 | }
33 |
34 | public T safe(String safe) {
35 | this.safe = safe;
36 | return (T) this;
37 | }
38 |
39 | public WxMessage build() {
40 | WxMessage m = new WxMessage();
41 | m.setAgentId(this.agentId);
42 | m.setMsgType(this.msgType);
43 | m.setToUser(this.toUser);
44 | m.setToParty(this.toParty);
45 | m.setToTag(this.toTag);
46 | m.setSafe((this.safe == null || "".equals(this.safe)) ? WxConsts.CUSTOM_MSG_SAFE_NO : this.safe);
47 | return m;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/msgbuilder/FileBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.msgbuilder;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.bean.WxMessage;
5 |
6 | /**
7 | * 获得消息builder
8 | *
9 | *
10 | * 用法: WxCustomMessage m = WxCustomMessage.FILE().mediaId(...).toUser(...).build();
11 | *
12 | *
13 | * @author antgan
14 | *
15 | */
16 | public final class FileBuilder extends BaseBuilder {
17 | private String mediaId;
18 |
19 | public FileBuilder() {
20 | this.msgType = WxConsts.CUSTOM_MSG_FILE;
21 | }
22 |
23 | public FileBuilder mediaId(String media_id) {
24 | this.mediaId = media_id;
25 | return this;
26 | }
27 |
28 | public WxMessage build() {
29 | WxMessage m = super.build();
30 | m.setMediaId(this.mediaId);
31 | return m;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/msgbuilder/ImageBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.msgbuilder;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.bean.WxMessage;
5 |
6 | /**
7 | * 图片消息builder
8 | *
9 | * 用法: WxCustomMessage m = WxCustomMessage.IMAGE().mediaId(...).toUser(...).build();
10 | *
11 | *
12 | * @author antgan
13 | *
14 | */
15 | public final class ImageBuilder extends BaseBuilder {
16 | private String mediaId;
17 |
18 | public ImageBuilder() {
19 | this.msgType = WxConsts.CUSTOM_MSG_IMAGE;
20 | }
21 |
22 | public ImageBuilder mediaId(String media_id) {
23 | this.mediaId = media_id;
24 | return this;
25 | }
26 |
27 | public WxMessage build() {
28 | WxMessage m = super.build();
29 | m.setMediaId(this.mediaId);
30 | return m;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/msgbuilder/NewsBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.msgbuilder;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.soecode.wxtools.api.WxConsts;
7 | import com.soecode.wxtools.bean.WxMessage;
8 |
9 | /**
10 | * 图文消息builder
11 | *
12 | *
13 | * 用法:
14 | * WxCustomMessage m = WxCustomMessage.NEWS().addArticle(article).toUser(...).build();
15 | *
16 | *
17 | * @author antgan
18 | *
19 | */
20 | public final class NewsBuilder extends BaseBuilder {
21 |
22 | private List articles = new ArrayList();
23 |
24 | public NewsBuilder() {
25 | this.msgType = WxConsts.CUSTOM_MSG_NEWS;
26 | }
27 |
28 | public NewsBuilder addArticle(WxMessage.WxArticle article) {
29 | this.articles.add(article);
30 | return this;
31 | }
32 |
33 | public WxMessage build() {
34 | WxMessage m = super.build();
35 | m.setArticles(this.articles);
36 | return m;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/msgbuilder/TextBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.msgbuilder;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.bean.WxMessage;
5 |
6 | /**
7 | * 文本消息builder
8 | *
9 | *
10 | * 用法: WxCustomMessage m = WxCustomMessage.TEXT().content(...).toUser(...).build();
11 | *
12 | *
13 | * @author antgan
14 | *
15 | */
16 | public final class TextBuilder extends BaseBuilder {
17 | private String content;
18 |
19 | public TextBuilder() {
20 | this.msgType = WxConsts.CUSTOM_MSG_TEXT;
21 | }
22 |
23 | public TextBuilder content(String content) {
24 | this.content = content;
25 | return this;
26 | }
27 |
28 | public WxMessage build() {
29 | WxMessage m = super.build();
30 | m.setContent(this.content);
31 | return m;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/msgbuilder/VideoBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.msgbuilder;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.bean.WxMessage;
5 |
6 | /**
7 | * 视频消息builder
8 | *
9 | * 用法: WxCustomMessage m = WxCustomMessage.VIDEO()
10 | * .mediaId(...)
11 | * .title(...)
12 | * .thumbMediaId(..)
13 | * .description(..)
14 | * .toUser(...)
15 | * .build();
16 | *
17 | * @author antgan
18 | *
19 | */
20 | public final class VideoBuilder extends BaseBuilder {
21 | private String mediaId;
22 | private String title;
23 | private String description;
24 | private String thumbMediaId;
25 |
26 | public VideoBuilder() {
27 | this.msgType = WxConsts.CUSTOM_MSG_VIDEO;
28 | }
29 |
30 | public VideoBuilder mediaId(String mediaId) {
31 | this.mediaId = mediaId;
32 | return this;
33 | }
34 |
35 | public VideoBuilder title(String title) {
36 | this.title = title;
37 | return this;
38 | }
39 |
40 | public VideoBuilder description(String description) {
41 | this.description = description;
42 | return this;
43 | }
44 |
45 | public VideoBuilder thumbMediaId(String thumb_media_id) {
46 | this.thumbMediaId = thumb_media_id;
47 | return this;
48 | }
49 |
50 | public WxMessage build() {
51 | WxMessage m = super.build();
52 | m.setMediaId(this.mediaId);
53 | m.setTitle(title);
54 | m.setDescription(description);
55 | m.setThumbMediaId(thumbMediaId);
56 | return m;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/msgbuilder/VoiceBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.msgbuilder;
2 |
3 | import com.soecode.wxtools.api.WxConsts;
4 | import com.soecode.wxtools.bean.WxMessage;
5 |
6 | /**
7 | * 语音消息builder
8 | *
9 | * 用法: WxCustomMessage m = WxCustomMessage.VOICE().mediaId(...).toUser(...).build();
10 | *
11 | * @author antgan
12 | *
13 | */
14 | public final class VoiceBuilder extends BaseBuilder {
15 | private String mediaId;
16 |
17 | public VoiceBuilder() {
18 | this.msgType = WxConsts.CUSTOM_MSG_VOICE;
19 | }
20 |
21 | public VoiceBuilder mediaId(String media_id) {
22 | this.mediaId = media_id;
23 | return this;
24 | }
25 |
26 | public WxMessage build() {
27 | WxMessage m = super.build();
28 | m.setMediaId(this.mediaId);
29 | return m;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/outxmlbuilder/BaseBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.outxmlbuilder;
2 |
3 | import com.soecode.wxtools.bean.WxXmlOutMessage;
4 |
5 | public abstract class BaseBuilder {
6 |
7 | protected String toUserName;
8 |
9 | protected String fromUserName;
10 |
11 | public BuilderType toUser(String touser) {
12 | this.toUserName = touser;
13 | return (BuilderType) this;
14 | }
15 |
16 | public BuilderType fromUser(String fromusername) {
17 | this.fromUserName = fromusername;
18 | return (BuilderType) this;
19 | }
20 |
21 | public abstract ValueType build();
22 |
23 | public void setCommon(WxXmlOutMessage m) {
24 | m.setToUserName(this.toUserName);
25 | m.setFromUserName(this.fromUserName);
26 | m.setCreateTime(System.currentTimeMillis() / 1000l);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/outxmlbuilder/ImageBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.outxmlbuilder;
2 |
3 | import com.soecode.wxtools.bean.WxXmlOutImageMessage;
4 |
5 | /**
6 | * 图片消息builder
7 | *
8 | * @author antgan
9 | */
10 | public final class ImageBuilder extends BaseBuilder {
11 |
12 | private String mediaId;
13 |
14 | public ImageBuilder mediaId(String media_id) {
15 | this.mediaId = media_id;
16 | return this;
17 | }
18 |
19 | public WxXmlOutImageMessage build() {
20 | WxXmlOutImageMessage m = new WxXmlOutImageMessage();
21 | setCommon(m);
22 | m.setMediaId(this.mediaId);
23 | return m;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/outxmlbuilder/MusicBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.outxmlbuilder;
2 |
3 | import com.soecode.wxtools.bean.WxXmlOutMusicMessage;
4 |
5 | /**
6 | * 音乐消息builder
7 | *
8 | * @author antgan
9 | *
10 | */
11 | public final class MusicBuilder extends BaseBuilder {
12 | private String title;
13 | private String description;
14 | private String musicUrl;
15 | private String hQMusicUrl;
16 | private String thumbMediaId;
17 |
18 | public MusicBuilder title(String title) {
19 | this.title = title;
20 | return this;
21 | }
22 |
23 | public MusicBuilder description(String description) {
24 | this.description = description;
25 | return this;
26 | }
27 |
28 | public MusicBuilder musicUri(String musicUrl){
29 | this.musicUrl = musicUrl;
30 | return this;
31 | }
32 |
33 | public MusicBuilder hQMusicUrl(String hQMusicUrl){
34 | this.hQMusicUrl = hQMusicUrl;
35 | return this;
36 | }
37 |
38 | public MusicBuilder thumbMediaId(String thumbMediaId){
39 | this.thumbMediaId = thumbMediaId;
40 | return this;
41 | }
42 |
43 |
44 | public WxXmlOutMusicMessage build() {
45 | WxXmlOutMusicMessage m = new WxXmlOutMusicMessage();
46 | setCommon(m);
47 | m.setTitle(title);
48 | m.setDescription(description);
49 | m.setMusicUrl(musicUrl);
50 | m.sethQMusicUrl(hQMusicUrl);
51 | m.setThumbMediaId(thumbMediaId);
52 | return m;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/outxmlbuilder/NewsBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.outxmlbuilder;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.soecode.wxtools.bean.WxXmlOutNewsMessage;
7 | import com.soecode.wxtools.bean.WxXmlOutNewsMessage.Item;
8 |
9 | /**
10 | * 图文消息builder
11 | *
12 | * @author antgan
13 | */
14 | public final class NewsBuilder extends BaseBuilder {
15 |
16 | protected final List- articles = new ArrayList
- ();
17 |
18 | public NewsBuilder addArticle(Item item) {
19 | this.articles.add(item);
20 | return this;
21 | }
22 |
23 | public WxXmlOutNewsMessage build() {
24 | WxXmlOutNewsMessage m = new WxXmlOutNewsMessage();
25 | for (Item item : articles) {
26 | m.addArticle(item);
27 | }
28 | setCommon(m);
29 | return m;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/outxmlbuilder/TextBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.outxmlbuilder;
2 |
3 | import com.soecode.wxtools.bean.WxXmlOutTextMessage;
4 |
5 | /**
6 | * 文本消息builder
7 | *
8 | * @author antgan
9 | *
10 | */
11 | public final class TextBuilder extends BaseBuilder {
12 | private String content;
13 |
14 | public TextBuilder content(String content) {
15 | this.content = content;
16 | return this;
17 | }
18 |
19 | public WxXmlOutTextMessage build() {
20 | WxXmlOutTextMessage m = new WxXmlOutTextMessage();
21 | setCommon(m);
22 | m.setContent(this.content);
23 | return m;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/outxmlbuilder/VideoBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.outxmlbuilder;
2 |
3 | import com.soecode.wxtools.bean.WxXmlOutVideoMessage;
4 |
5 | /**
6 | * 视频消息builder
7 | *
8 | * @author antgan
9 | *
10 | */
11 | public final class VideoBuilder extends BaseBuilder {
12 |
13 | private String mediaId;
14 | private String title;
15 | private String description;
16 |
17 | public VideoBuilder title(String title) {
18 | this.title = title;
19 | return this;
20 | }
21 |
22 | public VideoBuilder description(String description) {
23 | this.description = description;
24 | return this;
25 | }
26 |
27 | public VideoBuilder mediaId(String mediaId) {
28 | this.mediaId = mediaId;
29 | return this;
30 | }
31 |
32 | public WxXmlOutVideoMessage build() {
33 | WxXmlOutVideoMessage m = new WxXmlOutVideoMessage();
34 | setCommon(m);
35 | m.setTitle(title);
36 | m.setDescription(description);
37 | m.setMediaId(mediaId);
38 | return m;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/outxmlbuilder/VoiceBuilder.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.outxmlbuilder;
2 |
3 | import com.soecode.wxtools.bean.WxXmlOutVoiceMessage;
4 |
5 | /**
6 | * 语音消息builder
7 | *
8 | * @author antgan
9 | */
10 | public final class VoiceBuilder extends BaseBuilder {
11 |
12 | private String mediaId;
13 |
14 | public VoiceBuilder mediaId(String mediaId) {
15 | this.mediaId = mediaId;
16 | return this;
17 | }
18 |
19 | public WxXmlOutVoiceMessage build() {
20 | WxXmlOutVoiceMessage m = new WxXmlOutVoiceMessage();
21 | setCommon(m);
22 | m.setMediaId(mediaId);
23 | return m;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/IndustryResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonParseException;
6 | import org.codehaus.jackson.map.DeserializationConfig;
7 | import org.codehaus.jackson.map.JsonMappingException;
8 | import org.codehaus.jackson.map.ObjectMapper;
9 |
10 | public class IndustryResult {
11 | private Industry primary_industry;
12 | private Industry secondary_industry;
13 |
14 | public Industry getPrimary_industry() {
15 | return primary_industry;
16 | }
17 |
18 | public void setPrimary_industry(Industry primary_industry) {
19 | this.primary_industry = primary_industry;
20 | }
21 |
22 | public Industry getSecondary_industry() {
23 | return secondary_industry;
24 | }
25 |
26 | public void setSecondary_industry(Industry secondary_industry) {
27 | this.secondary_industry = secondary_industry;
28 | }
29 |
30 | public static IndustryResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
31 | ObjectMapper mapper = new ObjectMapper();
32 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
33 | return mapper.readValue(json, IndustryResult.class);
34 | }
35 |
36 |
37 |
38 | @Override
39 | public String toString() {
40 | return "IndustryResult [primary_industry=" + primary_industry + ", secondary_industry=" + secondary_industry
41 | + "]";
42 | }
43 |
44 |
45 |
46 | public static class Industry{
47 | private String first_class;
48 | private String second_class;
49 | public String getFirst_class() {
50 | return first_class;
51 | }
52 | public void setFirst_class(String first_class) {
53 | this.first_class = first_class;
54 | }
55 | public String getSecond_class() {
56 | return second_class;
57 | }
58 | public void setSecond_class(String second_class) {
59 | this.second_class = second_class;
60 | }
61 | @Override
62 | public String toString() {
63 | return "Industry [first_class=" + first_class + ", second_class=" + second_class + "]";
64 | }
65 |
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/KfAccountListResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 | import org.codehaus.jackson.annotate.JsonProperty;
6 | import org.codehaus.jackson.map.DeserializationConfig;
7 | import org.codehaus.jackson.map.ObjectMapper;
8 |
9 | public class KfAccountListResult {
10 | @JsonProperty("kf_list")
11 | private List kfList;
12 |
13 | public List getKfList() {
14 | return kfList;
15 | }
16 |
17 | public void setKfList(
18 | List kfList) {
19 | this.kfList = kfList;
20 | }
21 |
22 | @Override
23 | public String toString() {
24 | return "KfAccountListResult{" +
25 | "kfList=" + kfList +
26 | '}';
27 | }
28 |
29 | public static KfAccountListResult fromJson(String json) throws IOException {
30 | ObjectMapper mapper = new ObjectMapper();
31 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
32 | return mapper.readValue(json, KfAccountListResult.class);
33 | }
34 |
35 | class KfAccountResult{
36 | @JsonProperty("kf_account")
37 | private String kfAccount;
38 | @JsonProperty("kf_nick")
39 | private String kfNick;
40 | @JsonProperty("kf_id")
41 | private String kfId;
42 | @JsonProperty("kf_headimgurl")
43 | private String kfHeadImgUrl;
44 |
45 | public String getKfAccount() {
46 | return kfAccount;
47 | }
48 |
49 | public void setKfAccount(String kfAccount) {
50 | this.kfAccount = kfAccount;
51 | }
52 |
53 | public String getKfNick() {
54 | return kfNick;
55 | }
56 |
57 | public void setKfNick(String kfNick) {
58 | this.kfNick = kfNick;
59 | }
60 |
61 | public String getKfId() {
62 | return kfId;
63 | }
64 |
65 | public void setKfId(String kfId) {
66 | this.kfId = kfId;
67 | }
68 |
69 | public String getKfHeadImgUrl() {
70 | return kfHeadImgUrl;
71 | }
72 |
73 | public void setKfHeadImgUrl(String kfHeadImgUrl) {
74 | this.kfHeadImgUrl = kfHeadImgUrl;
75 | }
76 |
77 | @Override
78 | public String toString() {
79 | return "KfAccountResult{" +
80 | "kfAccount='" + kfAccount + '\'' +
81 | ", kfNick='" + kfNick + '\'' +
82 | ", kfId='" + kfId + '\'' +
83 | ", kfHeadImgUrl='" + kfHeadImgUrl + '\'' +
84 | '}';
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/QrCodeResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonParseException;
6 | import org.codehaus.jackson.map.DeserializationConfig;
7 | import org.codehaus.jackson.map.JsonMappingException;
8 | import org.codehaus.jackson.map.ObjectMapper;
9 |
10 | public class QrCodeResult {
11 | private String ticket;
12 | private int expire_seconds;
13 | private String url;
14 | public String getTicket() {
15 | return ticket;
16 | }
17 | public void setTicket(String ticket) {
18 | this.ticket = ticket;
19 | }
20 | public int getExpire_seconds() {
21 | return expire_seconds;
22 | }
23 | public void setExpire_seconds(int expire_seconds) {
24 | this.expire_seconds = expire_seconds;
25 | }
26 | public String getUrl() {
27 | return url;
28 | }
29 | public void setUrl(String url) {
30 | this.url = url;
31 | }
32 |
33 | public static QrCodeResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
34 | ObjectMapper mapper = new ObjectMapper();
35 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
36 | return mapper.readValue(json, QrCodeResult.class);
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "QrCodeResult [ticket=" + ticket + ", expire_seconds=" + expire_seconds + ", url=" + url + "]";
42 | }
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/SenderResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonParseException;
6 | import org.codehaus.jackson.annotate.JsonIgnore;
7 | import org.codehaus.jackson.map.DeserializationConfig;
8 | import org.codehaus.jackson.map.JsonMappingException;
9 | import org.codehaus.jackson.map.ObjectMapper;
10 |
11 | public class SenderResult extends WxError{
12 |
13 | private long msg_id;
14 | private long msg_data_id;
15 | private String msg_status;
16 | public long getMsg_id() {
17 | return msg_id;
18 | }
19 | public void setMsg_id(long msg_id) {
20 | this.msg_id = msg_id;
21 | }
22 | public long getMsg_data_id() {
23 | return msg_data_id;
24 | }
25 | public void setMsg_data_id(long msg_data_id) {
26 | this.msg_data_id = msg_data_id;
27 | }
28 | public String getMsg_status() {
29 | return msg_status;
30 | }
31 | public void setMsg_status(String msg_status) {
32 | this.msg_status = msg_status;
33 | }
34 |
35 | public static SenderResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
36 | ObjectMapper mapper = new ObjectMapper();
37 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
38 | return mapper.readValue(json, SenderResult.class);
39 | }
40 | @Override
41 | public String toString() {
42 | return "SenderResult [msg_id=" + msg_id + ", msg_data_id=" + msg_data_id + ", msg_status=" + msg_status
43 | + " errcode= "+ getErrcode()+
44 | " errmsg= " + getErrmsg()+"]";
45 | }
46 |
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/TemplateListResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 |
6 | import org.codehaus.jackson.JsonParseException;
7 | import org.codehaus.jackson.map.DeserializationConfig;
8 | import org.codehaus.jackson.map.JsonMappingException;
9 | import org.codehaus.jackson.map.ObjectMapper;
10 |
11 | public class TemplateListResult {
12 |
13 | private List template_list;
14 |
15 | public List getTemplate_list() {
16 | return template_list;
17 | }
18 |
19 | public void setTemplate_list(List template_list) {
20 | this.template_list = template_list;
21 | }
22 |
23 | public static TemplateListResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
24 | ObjectMapper mapper = new ObjectMapper();
25 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
26 | return mapper.readValue(json, TemplateListResult.class);
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return "TemplateListResult [template_list=" + template_list + "]";
32 | }
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/TemplateResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonParseException;
6 | import org.codehaus.jackson.map.DeserializationConfig;
7 | import org.codehaus.jackson.map.JsonMappingException;
8 | import org.codehaus.jackson.map.ObjectMapper;
9 |
10 | public class TemplateResult extends WxError{
11 |
12 | private String template_id;
13 |
14 | private String title;
15 | private String primary_industry;
16 | private String deputy_industry;
17 | private String content;
18 | private String example;
19 |
20 | public String getTitle() {
21 | return title;
22 | }
23 |
24 | public void setTitle(String title) {
25 | this.title = title;
26 | }
27 |
28 | public String getPrimary_industry() {
29 | return primary_industry;
30 | }
31 |
32 | public void setPrimary_industry(String primary_industry) {
33 | this.primary_industry = primary_industry;
34 | }
35 |
36 | public String getDeputy_industry() {
37 | return deputy_industry;
38 | }
39 |
40 | public void setDeputy_industry(String deputy_industry) {
41 | this.deputy_industry = deputy_industry;
42 | }
43 |
44 | public String getContent() {
45 | return content;
46 | }
47 |
48 | public void setContent(String content) {
49 | this.content = content;
50 | }
51 |
52 | public String getExample() {
53 | return example;
54 | }
55 |
56 | public void setExample(String example) {
57 | this.example = example;
58 | }
59 |
60 | public String getTemplate_id() {
61 | return template_id;
62 | }
63 |
64 | public void setTemplate_id(String template_id) {
65 | this.template_id = template_id;
66 | }
67 |
68 | @Override
69 | public String toString() {
70 | return "TemplateResult [template_id=" + template_id + ", title=" + title + ", primary_industry="
71 | + primary_industry + ", deputy_industry=" + deputy_industry + ", content=" + content + ", example="
72 | + example + "]";
73 | }
74 |
75 | public static TemplateResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
76 | ObjectMapper mapper = new ObjectMapper();
77 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
78 | return mapper.readValue(json, TemplateResult.class);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/TemplateSenderResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 | import org.codehaus.jackson.map.DeserializationConfig;
5 | import org.codehaus.jackson.map.ObjectMapper;
6 |
7 | public class TemplateSenderResult extends WxError{
8 |
9 | private long msgid;
10 |
11 | public long getMsgid() {
12 | return msgid;
13 | }
14 |
15 | public void setMsgid(long msgid) {
16 | this.msgid = msgid;
17 | }
18 |
19 | @Override
20 | public String toString() {
21 | return "TemplateSenderResult [msgid=" + msgid + "]";
22 | }
23 |
24 | public static TemplateSenderResult fromJson(String json) throws IOException {
25 | ObjectMapper mapper = new ObjectMapper();
26 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
27 | return mapper.readValue(json, TemplateSenderResult.class);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/UnifiedOrderResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import com.soecode.wxtools.util.xml.XStreamCDataConverter;
4 | import com.soecode.wxtools.util.xml.XStreamTransformer;
5 | import com.thoughtworks.xstream.annotations.XStreamAlias;
6 | import com.thoughtworks.xstream.annotations.XStreamConverter;
7 |
8 | @XStreamAlias("xml")
9 | public class UnifiedOrderResult {
10 | @XStreamAlias("return_code")
11 | @XStreamConverter(value = XStreamCDataConverter.class)
12 | private String returnCode;
13 |
14 | @XStreamAlias("return_msg")
15 | @XStreamConverter(value = XStreamCDataConverter.class)
16 | private String returnMsg;
17 |
18 | @XStreamAlias("appid")
19 | @XStreamConverter(value = XStreamCDataConverter.class)
20 | private String appid;
21 |
22 | @XStreamAlias("mch_id")
23 | @XStreamConverter(value = XStreamCDataConverter.class)
24 | private String mchId;
25 |
26 | @XStreamAlias("nonce_str")
27 | @XStreamConverter(value = XStreamCDataConverter.class)
28 | private String nonceStr;
29 |
30 | @XStreamAlias("openid")
31 | @XStreamConverter(value = XStreamCDataConverter.class)
32 | private String openid;
33 |
34 | @XStreamAlias("sign")
35 | @XStreamConverter(value = XStreamCDataConverter.class)
36 | private String sign;
37 |
38 | @XStreamAlias("result_code")
39 | @XStreamConverter(value = XStreamCDataConverter.class)
40 | private String resultCode;
41 |
42 | @XStreamAlias("err_code")
43 | @XStreamConverter(value = XStreamCDataConverter.class)
44 | private String errCode;
45 |
46 | @XStreamAlias("err_code_des")
47 | @XStreamConverter(value = XStreamCDataConverter.class)
48 | private String errCodeDes;
49 |
50 | @XStreamAlias("prepay_id")
51 | @XStreamConverter(value = XStreamCDataConverter.class)
52 | private String prepayId;
53 |
54 | @XStreamAlias("trade_type")
55 | @XStreamConverter(value = XStreamCDataConverter.class)
56 | private String tradeType;
57 |
58 | @XStreamAlias("code_url")
59 | @XStreamConverter(value = XStreamCDataConverter.class)
60 | private String codeUrl;
61 |
62 | public String getReturnCode() {
63 | return returnCode;
64 | }
65 |
66 | public void setReturnCode(String returnCode) {
67 | this.returnCode = returnCode;
68 | }
69 |
70 | public String getReturnMsg() {
71 | return returnMsg;
72 | }
73 |
74 | public void setReturnMsg(String returnMsg) {
75 | this.returnMsg = returnMsg;
76 | }
77 |
78 | public String getAppid() {
79 | return appid;
80 | }
81 |
82 | public void setAppid(String appid) {
83 | this.appid = appid;
84 | }
85 |
86 | public String getMchId() {
87 | return mchId;
88 | }
89 |
90 | public void setMchId(String mchId) {
91 | this.mchId = mchId;
92 | }
93 |
94 | public String getNonceStr() {
95 | return nonceStr;
96 | }
97 |
98 | public void setNonceStr(String nonceStr) {
99 | this.nonceStr = nonceStr;
100 | }
101 |
102 | public String getOpenid() {
103 | return openid;
104 | }
105 |
106 | public void setOpenid(String openid) {
107 | this.openid = openid;
108 | }
109 |
110 | public String getSign() {
111 | return sign;
112 | }
113 |
114 | public void setSign(String sign) {
115 | this.sign = sign;
116 | }
117 |
118 | public String getResultCode() {
119 | return resultCode;
120 | }
121 |
122 | public void setResultCode(String resultCode) {
123 | this.resultCode = resultCode;
124 | }
125 |
126 | public String getPrepayId() {
127 | return prepayId;
128 | }
129 |
130 | public void setPrepayId(String prepayId) {
131 | this.prepayId = prepayId;
132 | }
133 |
134 | public String getTradeType() {
135 | return tradeType;
136 | }
137 |
138 | public void setTradeType(String tradeType) {
139 | this.tradeType = tradeType;
140 | }
141 |
142 |
143 |
144 | public String getErrCode() {
145 | return errCode;
146 | }
147 |
148 | public void setErrCode(String errCode) {
149 | this.errCode = errCode;
150 | }
151 |
152 | public String getErrCodeDes() {
153 | return errCodeDes;
154 | }
155 |
156 | public void setErrCodeDes(String errCodeDes) {
157 | this.errCodeDes = errCodeDes;
158 | }
159 |
160 | public String getCodeUrl() {
161 | return codeUrl;
162 | }
163 |
164 | public void setCodeUrl(String codeUrl) {
165 | this.codeUrl = codeUrl;
166 | }
167 |
168 | public static UnifiedOrderResult fromXml(String xml) {
169 | return XStreamTransformer.fromXml(UnifiedOrderResult.class, xml);
170 | }
171 |
172 | }
173 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxBatchGetMaterialResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import org.codehaus.jackson.JsonParseException;
8 | import org.codehaus.jackson.map.DeserializationConfig;
9 | import org.codehaus.jackson.map.JsonMappingException;
10 | import org.codehaus.jackson.map.ObjectMapper;
11 |
12 | public class WxBatchGetMaterialResult {
13 | private int total_count;
14 | private int item_count;
15 | private List item = new ArrayList<>();
16 |
17 | public List getItem() {
18 | return item;
19 | }
20 |
21 | public void setItem(List item) {
22 | this.item = item;
23 | }
24 |
25 | public int getTotal_count() {
26 | return total_count;
27 | }
28 |
29 | public void setTotal_count(int total_count) {
30 | this.total_count = total_count;
31 | }
32 |
33 | public int getItem_count() {
34 | return item_count;
35 | }
36 |
37 | public void setItem_count(int item_count) {
38 | this.item_count = item_count;
39 | }
40 |
41 | public static WxBatchGetMaterialResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
42 | ObjectMapper mapper = new ObjectMapper();
43 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
44 | return mapper.readValue(json, WxBatchGetMaterialResult.class);
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "WxBatchGetMaterialResult [total_count=" + total_count + ", item_count=" + item_count + ", item=" + item
50 | + "]";
51 | }
52 |
53 | public static class MaterialItem{
54 | private String media_id;
55 | private WxNewsMediaResult content;
56 | private String update_time;
57 | private String name;
58 | private String url;
59 |
60 | public String getMedia_id() {
61 | return media_id;
62 | }
63 | public void setMedia_id(String media_id) {
64 | this.media_id = media_id;
65 | }
66 | public WxNewsMediaResult getContent() {
67 | return content;
68 | }
69 | public void setContent(WxNewsMediaResult content) {
70 | this.content = content;
71 | }
72 | public String getUpdate_time() {
73 | return update_time;
74 | }
75 | public void setUpdate_time(String update_time) {
76 | this.update_time = update_time;
77 | }
78 | public String getName() {
79 | return name;
80 | }
81 | public void setName(String name) {
82 | this.name = name;
83 | }
84 | public String getUrl() {
85 | return url;
86 | }
87 | public void setUrl(String url) {
88 | this.url = url;
89 | }
90 | @Override
91 | public String toString() {
92 | return "MaterialItem [media_id=" + media_id + ", content=" + content + ", update_time=" + update_time
93 | + ", name=" + name + ", url=" + url + "]";
94 | }
95 |
96 |
97 |
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxCurMenuInfoResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import org.codehaus.jackson.JsonGenerationException;
8 | import org.codehaus.jackson.JsonParseException;
9 | import org.codehaus.jackson.map.DeserializationConfig;
10 | import org.codehaus.jackson.map.JsonMappingException;
11 | import org.codehaus.jackson.map.ObjectMapper;
12 |
13 | public class WxCurMenuInfoResult {
14 | private int is_menu_open;
15 | private WxCurSelfMenuInfo selfmenu_info;
16 |
17 | public int getIs_menu_open() {
18 | return is_menu_open;
19 | }
20 |
21 | public void setIs_menu_open(int is_menu_open) {
22 | this.is_menu_open = is_menu_open;
23 | }
24 |
25 | public WxCurSelfMenuInfo getSelfmenu_info() {
26 | return selfmenu_info;
27 | }
28 |
29 | public void setSelfmenu_info(WxCurSelfMenuInfo selfmenu_info) {
30 | this.selfmenu_info = selfmenu_info;
31 | }
32 |
33 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException {
34 | ObjectMapper mapper = new ObjectMapper();
35 | return mapper.writeValueAsString(this);
36 | }
37 |
38 | public static WxCurMenuInfoResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
39 | ObjectMapper mapper = new ObjectMapper();
40 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
41 | return mapper.readValue(json, WxCurMenuInfoResult.class);
42 | }
43 |
44 |
45 |
46 | @Override
47 | public String toString() {
48 | return "WxCurMenuInfoResult [is_menu_open=" + is_menu_open + ", selfmenu_info=" + selfmenu_info + "]";
49 | }
50 |
51 | public static class WxCurSelfMenuInfo{
52 | private List button = new ArrayList<>();
53 |
54 | public List getButton() {
55 | return button;
56 | }
57 |
58 | public void setButton(List button) {
59 | this.button = button;
60 | }
61 |
62 | @Override
63 | public String toString() {
64 | return "WxCurSelfMenuInfo [button=" + button + "]";
65 | }
66 |
67 | }
68 |
69 | public static class WxCurMenuButtonInfo {
70 | private String type;
71 | private String name;
72 | private String key;
73 | private String url;
74 | private String value;
75 | private WxCurMenuNews news_info;
76 | private WxCurMenuButton sub_button;
77 |
78 | public WxCurMenuButton getSub_button() {
79 | return sub_button;
80 | }
81 | public void setSub_button(WxCurMenuButton sub_button) {
82 | this.sub_button = sub_button;
83 | }
84 | public String getType() {
85 | return type;
86 | }
87 | public void setType(String type) {
88 | this.type = type;
89 | }
90 | public String getName() {
91 | return name;
92 | }
93 | public void setName(String name) {
94 | this.name = name;
95 | }
96 | public String getKey() {
97 | return key;
98 | }
99 | public void setKey(String key) {
100 | this.key = key;
101 | }
102 | public String getUrl() {
103 | return url;
104 | }
105 | public void setUrl(String url) {
106 | this.url = url;
107 | }
108 | public String getValue() {
109 | return value;
110 | }
111 | public void setValue(String value) {
112 | this.value = value;
113 | }
114 | public WxCurMenuNews getNews_info() {
115 | return news_info;
116 | }
117 | public void setNews_info(WxCurMenuNews news_info) {
118 | this.news_info = news_info;
119 | }
120 | @Override
121 | public String toString() {
122 | return "WxCurMenuButtonInfo [type=" + type + ", name=" + name + ", key=" + key + ", url=" + url + ", value="
123 | + value + ", news_info=" + news_info + ", sub_button=" + sub_button + "]";
124 | }
125 |
126 | }
127 |
128 | public static class WxCurMenuButton{
129 | private List list = new ArrayList();
130 | public List getList() {
131 | return list;
132 | }
133 | public void setList(List list) {
134 | this.list = list;
135 | }
136 | @Override
137 | public String toString() {
138 | return "WxCurMenuButton [list=" + list + "]";
139 | }
140 |
141 | }
142 |
143 | public static class WxCurMenuNews{
144 | private List list = new ArrayList<>();
145 | public List getList() {
146 | return list;
147 | }
148 | public void setList(List list) {
149 | this.list = list;
150 | }
151 | @Override
152 | public String toString() {
153 | return "WxCurMenuNews [list=" + list + "]";
154 | }
155 |
156 | }
157 |
158 | public static class WxCurMenuNewsInfo{
159 | private String title;//图文消息的标题
160 | private String author;//作者
161 | private String digest;//摘要
162 | private int show_cover;//是否显示封面,0为不显示,1为显示
163 | private String cover_url;//封面图片的URL
164 | private String content_url;//正文的URL
165 | private String source_url;//原文的URL,若置空则无查看原文入口
166 | public String getTitle() {
167 | return title;
168 | }
169 | public void setTitle(String title) {
170 | this.title = title;
171 | }
172 | public String getAuthor() {
173 | return author;
174 | }
175 | public void setAuthor(String author) {
176 | this.author = author;
177 | }
178 | public String getDigest() {
179 | return digest;
180 | }
181 | public void setDigest(String digest) {
182 | this.digest = digest;
183 | }
184 | public int getShow_cover() {
185 | return show_cover;
186 | }
187 | public void setShow_cover(int show_cover) {
188 | this.show_cover = show_cover;
189 | }
190 | public String getCover_url() {
191 | return cover_url;
192 | }
193 | public void setCover_url(String cover_url) {
194 | this.cover_url = cover_url;
195 | }
196 | public String getContent_url() {
197 | return content_url;
198 | }
199 | public void setContent_url(String content_url) {
200 | this.content_url = content_url;
201 | }
202 | public String getSource_url() {
203 | return source_url;
204 | }
205 | public void setSource_url(String source_url) {
206 | this.source_url = source_url;
207 | }
208 | @Override
209 | public String toString() {
210 | return "WxCurMenuNewsInfo [title=" + title + ", author=" + author + ", digest=" + digest + ", show_cover="
211 | + show_cover + ", cover_url=" + cover_url + ", content_url=" + content_url + ", source_url="
212 | + source_url + "]";
213 | }
214 |
215 | }
216 |
217 | }
218 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxError.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 | import org.codehaus.jackson.JsonParseException;
5 | import org.codehaus.jackson.map.DeserializationConfig;
6 | import org.codehaus.jackson.map.JsonMappingException;
7 | import org.codehaus.jackson.map.ObjectMapper;
8 |
9 | public class WxError{
10 |
11 | private int errcode;
12 |
13 | private String errmsg;
14 |
15 | public WxError() {
16 | }
17 |
18 | public WxError(int errcode, String errmsg) {
19 | this.errcode = errcode;
20 | this.errmsg = errmsg;
21 | }
22 |
23 | public int getErrcode() {
24 | return errcode;
25 | }
26 |
27 |
28 | public void setErrcode(int errcode) {
29 | this.errcode = errcode;
30 | }
31 |
32 |
33 | public String getErrmsg() {
34 | return errmsg;
35 | }
36 |
37 |
38 | public void setErrmsg(String errmsg) {
39 | this.errmsg = errmsg;
40 | }
41 |
42 |
43 | public static WxError fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
44 | ObjectMapper mapper = new ObjectMapper();
45 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
46 | return mapper.readValue(json, WxError.class);
47 | }
48 |
49 |
50 | @Override
51 | public String toString() {
52 | return "WxError [errcode=" + errcode + ", errmsg=" + errmsg + "]";
53 | }
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxMaterialCountResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonParseException;
6 | import org.codehaus.jackson.map.DeserializationConfig;
7 | import org.codehaus.jackson.map.JsonMappingException;
8 | import org.codehaus.jackson.map.ObjectMapper;
9 |
10 | public class WxMaterialCountResult {
11 | private int voice_count;
12 | private int video_count;
13 | private int image_count;
14 | private int news_count;
15 | public int getVoice_count() {
16 | return voice_count;
17 | }
18 | public void setVoice_count(int voice_count) {
19 | this.voice_count = voice_count;
20 | }
21 | public int getVideo_count() {
22 | return video_count;
23 | }
24 | public void setVideo_count(int video_count) {
25 | this.video_count = video_count;
26 | }
27 | public int getImage_count() {
28 | return image_count;
29 | }
30 | public void setImage_count(int image_count) {
31 | this.image_count = image_count;
32 | }
33 | public int getNews_count() {
34 | return news_count;
35 | }
36 | public void setNews_count(int news_count) {
37 | this.news_count = news_count;
38 | }
39 | @Override
40 | public String toString() {
41 | return "WxMaterialCountResult [voice_count=" + voice_count + ", video_count=" + video_count + ", image_count="
42 | + image_count + ", news_count=" + news_count + "]";
43 | }
44 |
45 | public static WxMaterialCountResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
46 | ObjectMapper mapper = new ObjectMapper();
47 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
48 | return mapper.readValue(json, WxMaterialCountResult.class);
49 | }
50 |
51 |
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxMediaUploadResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonParseException;
6 | import org.codehaus.jackson.map.DeserializationConfig;
7 | import org.codehaus.jackson.map.JsonMappingException;
8 | import org.codehaus.jackson.map.ObjectMapper;
9 |
10 | public class WxMediaUploadResult {
11 |
12 | private String type;
13 | private String media_id;
14 | private long created_at;
15 | private String url;
16 |
17 | public String getUrl() {
18 | return url;
19 | }
20 |
21 | public void setUrl(String url) {
22 | this.url = url;
23 | }
24 |
25 | public String getType() {
26 | return type;
27 | }
28 |
29 | public void setType(String type) {
30 | this.type = type;
31 | }
32 |
33 | public String getMedia_id() {
34 | return media_id;
35 | }
36 |
37 | public void setMedia_id(String media_id) {
38 | this.media_id = media_id;
39 | }
40 |
41 | public long getCreated_at() {
42 | return created_at;
43 | }
44 |
45 | public void setCreated_at(long created_at) {
46 | this.created_at = created_at;
47 | }
48 |
49 | public static WxMediaUploadResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
50 | ObjectMapper mapper = new ObjectMapper();
51 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
52 | return mapper.readValue(json, WxMediaUploadResult.class);
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return "WxMediaUploadResult [type=" + type + ", media_id=" + media_id + ", created_at=" + created_at + ", url="
58 | + url + "]";
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxMenuResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 |
6 | import org.codehaus.jackson.JsonGenerationException;
7 | import org.codehaus.jackson.JsonParseException;
8 | import org.codehaus.jackson.map.DeserializationConfig;
9 | import org.codehaus.jackson.map.JsonMappingException;
10 | import org.codehaus.jackson.map.ObjectMapper;
11 |
12 | import com.soecode.wxtools.bean.WxMenu;
13 |
14 | public class WxMenuResult {
15 | private WxMenu menu;
16 | private List conditionalmenu;
17 |
18 | public WxMenu getMenu() {
19 | return menu;
20 | }
21 | public void setMenu(WxMenu menu) {
22 | this.menu = menu;
23 | }
24 |
25 | public List getConditionalmenu() {
26 | return conditionalmenu;
27 | }
28 |
29 | public void setConditionalmenu(List conditionalmenu) {
30 | this.conditionalmenu = conditionalmenu;
31 | }
32 |
33 |
34 | @Override
35 | public String toString() {
36 | return "WxMenuResult [menu=" + menu + ", conditionalmenu=" + conditionalmenu + "]";
37 | }
38 |
39 | public String toJson() throws JsonGenerationException, JsonMappingException, IOException {
40 | ObjectMapper mapper = new ObjectMapper();
41 | return mapper.writeValueAsString(this);
42 | }
43 |
44 | public static WxMenuResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
45 | ObjectMapper mapper = new ObjectMapper();
46 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
47 | return mapper.readValue(json, WxMenuResult.class);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxNewsMediaResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import org.codehaus.jackson.JsonParseException;
8 | import org.codehaus.jackson.map.DeserializationConfig;
9 | import org.codehaus.jackson.map.JsonMappingException;
10 | import org.codehaus.jackson.map.ObjectMapper;
11 |
12 | import com.soecode.wxtools.bean.WxNewsInfo;
13 |
14 | public class WxNewsMediaResult {
15 | private List news_item = new ArrayList<>();
16 | private String update_time;
17 | private String create_time;
18 |
19 | public String getUpdate_time() {
20 | return update_time;
21 | }
22 |
23 | public void setUpdate_time(String update_time) {
24 | this.update_time = update_time;
25 | }
26 |
27 | public String getCreate_time() {
28 | return create_time;
29 | }
30 |
31 | public void setCreate_time(String create_time) {
32 | this.create_time = create_time;
33 | }
34 |
35 | public List getNews_item() {
36 | return news_item;
37 | }
38 |
39 | public void setNews_item(List news_item) {
40 | this.news_item = news_item;
41 | }
42 |
43 | public static WxNewsMediaResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
44 | ObjectMapper mapper = new ObjectMapper();
45 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
46 | return mapper.readValue(json, WxNewsMediaResult.class);
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return "WxNewsMediaResult [news_item=" + news_item + ", update_time=" + update_time + ", create_time="
52 | + create_time + "]";
53 | }
54 |
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxOAuth2AccessTokenResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 |
5 | import org.codehaus.jackson.JsonParseException;
6 | import org.codehaus.jackson.map.DeserializationConfig;
7 | import org.codehaus.jackson.map.JsonMappingException;
8 | import org.codehaus.jackson.map.ObjectMapper;
9 |
10 | import com.soecode.wxtools.bean.WxAccessToken;
11 |
12 | public class WxOAuth2AccessTokenResult extends WxAccessToken{
13 | private String refresh_token;
14 | private String openid;
15 | private String scope;
16 | private String unionid;
17 |
18 |
19 | public String getUnionid() {
20 | return unionid;
21 | }
22 | public void setUnionid(String unionid) {
23 | this.unionid = unionid;
24 | }
25 | public String getRefresh_token() {
26 | return refresh_token;
27 | }
28 | public void setRefresh_token(String refresh_token) {
29 | this.refresh_token = refresh_token;
30 | }
31 | public String getOpenid() {
32 | return openid;
33 | }
34 | public void setOpenid(String openid) {
35 | this.openid = openid;
36 | }
37 | public String getScope() {
38 | return scope;
39 | }
40 | public void setScope(String scope) {
41 | this.scope = scope;
42 | }
43 | public static WxOAuth2AccessTokenResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
44 | ObjectMapper mapper = new ObjectMapper();
45 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
46 | return mapper.readValue(json, WxOAuth2AccessTokenResult.class);
47 | }
48 | @Override
49 | public String toString() {
50 | return "WxOAuth2AccessTokenResult [refresh_token=" + refresh_token + ", openid=" + openid + ", scope=" + scope
51 | + ", unionid=" + unionid + "]";
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxUserListResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 | import java.util.Arrays;
5 |
6 | import org.codehaus.jackson.JsonParseException;
7 | import org.codehaus.jackson.map.DeserializationConfig;
8 | import org.codehaus.jackson.map.JsonMappingException;
9 | import org.codehaus.jackson.map.ObjectMapper;
10 |
11 | public class WxUserListResult {
12 | private int total;
13 | private int count;
14 | private WxOpenId data;
15 | private String next_openid;
16 |
17 | public int getTotal() {
18 | return total;
19 | }
20 |
21 | public void setTotal(int total) {
22 | this.total = total;
23 | }
24 |
25 | public int getCount() {
26 | return count;
27 | }
28 |
29 | public void setCount(int count) {
30 | this.count = count;
31 | }
32 |
33 | public WxOpenId getData() {
34 | return data;
35 | }
36 |
37 | public void setData(WxOpenId data) {
38 | this.data = data;
39 | }
40 |
41 | public String getNext_openid() {
42 | return next_openid;
43 | }
44 |
45 | public void setNext_openid(String next_openid) {
46 | this.next_openid = next_openid;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return "WxUserListResult [total=" + total + ", count=" + count + ", data=" + data + ", next_openid="
52 | + next_openid + "]";
53 | }
54 |
55 | public static WxUserListResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
56 | ObjectMapper mapper = new ObjectMapper();
57 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
58 | return mapper.readValue(json, WxUserListResult.class);
59 | }
60 |
61 | public static class WxOpenId {
62 | private String[] openid;
63 |
64 | public String[] getOpenid() {
65 | return openid;
66 | }
67 |
68 | public void setOpenid(String[] openid) {
69 | this.openid = openid;
70 | }
71 |
72 | @Override
73 | public String toString() {
74 | return "WxOpenId [openid=" + Arrays.toString(openid) + "]";
75 | }
76 |
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxUserTagResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 | import org.codehaus.jackson.JsonParseException;
6 | import org.codehaus.jackson.map.DeserializationConfig;
7 | import org.codehaus.jackson.map.JsonMappingException;
8 | import org.codehaus.jackson.map.ObjectMapper;
9 |
10 | public class WxUserTagResult {
11 | private WxUserTag tag;
12 | private List tags;
13 |
14 | public WxUserTag getTag() {
15 | return tag;
16 | }
17 |
18 | public void setTag(WxUserTag tag) {
19 | this.tag = tag;
20 | }
21 |
22 | public List getTags() {
23 | return tags;
24 | }
25 |
26 | public void setTags(List tags) {
27 | this.tags = tags;
28 | }
29 |
30 | public static WxUserTagResult fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
31 | ObjectMapper mapper = new ObjectMapper();
32 | mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
33 | return mapper.readValue(json, WxUserTagResult.class);
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return "WxUserTagResult{" +
39 | "tag=" + tag +
40 | ", tags=" + tags +
41 | '}';
42 | }
43 |
44 | public static class WxUserTag {
45 | private int id;
46 | private String name;
47 | private int count;
48 | public int getId() {
49 | return id;
50 | }
51 | public void setId(int id) {
52 | this.id = id;
53 | }
54 | public String getName() {
55 | return name;
56 | }
57 | public void setName(String name) {
58 | this.name = name;
59 | }
60 | public int getCount() {
61 | return count;
62 | }
63 | public void setCount(int count) {
64 | this.count = count;
65 | }
66 | @Override
67 | public String toString() {
68 | return "WxUserTag [id=" + id + ", name=" + name + ", count=" + count + "]";
69 | }
70 |
71 |
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/bean/result/WxVideoMediaResult.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.bean.result;
2 |
3 | public class WxVideoMediaResult {
4 | private String title;
5 | private String description;
6 | private String down_url;
7 | public String getTitle() {
8 | return title;
9 | }
10 | public void setTitle(String title) {
11 | this.title = title;
12 | }
13 | public String getDescription() {
14 | return description;
15 | }
16 | public void setDescription(String description) {
17 | this.description = description;
18 | }
19 | public String getDown_url() {
20 | return down_url;
21 | }
22 | public void setDown_url(String down_url) {
23 | this.down_url = down_url;
24 | }
25 | @Override
26 | public String toString() {
27 | return "WxVideoMediaResult [title=" + title + ", description=" + description + ", down_url=" + down_url + "]";
28 | }
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/exception/AesException.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.exception;
2 |
3 | @SuppressWarnings("serial")
4 | public class AesException extends Exception {
5 |
6 | public final static int OK = 0;
7 | public final static int ValidateSignatureError = -40001;
8 | public final static int ParseXmlError = -40002;
9 | public final static int ComputeSignatureError = -40003;
10 | public final static int IllegalAesKey = -40004;
11 | public final static int ValidateAppidError = -40005;
12 | public final static int EncryptAESError = -40006;
13 | public final static int DecryptAESError = -40007;
14 | public final static int IllegalBuffer = -40008;
15 | //public final static int EncodeBase64Error = -40009;
16 | //public final static int DecodeBase64Error = -40010;
17 | //public final static int GenReturnXmlError = -40011;
18 |
19 | private int code;
20 |
21 | private static String getMessage(int code) {
22 | switch (code) {
23 | case ValidateSignatureError:
24 | return "签名验证错误";
25 | case ParseXmlError:
26 | return "xml解析失败";
27 | case ComputeSignatureError:
28 | return "sha加密生成签名失败";
29 | case IllegalAesKey:
30 | return "SymmetricKey非法";
31 | case ValidateAppidError:
32 | return "appid校验失败";
33 | case EncryptAESError:
34 | return "aes加密失败";
35 | case DecryptAESError:
36 | return "aes解密失败";
37 | case IllegalBuffer:
38 | return "解密后得到的buffer非法";
39 | // case EncodeBase64Error:
40 | // return "base64加密错误";
41 | // case DecodeBase64Error:
42 | // return "base64解密错误";
43 | // case GenReturnXmlError:
44 | // return "xml生成失败";
45 | default:
46 | return null; // cannot be
47 | }
48 | }
49 |
50 | public int getCode() {
51 | return code;
52 | }
53 |
54 | public AesException(int code) {
55 | super(getMessage(code));
56 | this.code = code;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/exception/WxErrorException.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.exception;
2 |
3 | import com.soecode.wxtools.bean.result.WxError;
4 |
5 | public class WxErrorException extends Exception {
6 |
7 | private static final long serialVersionUID = -6357149550353160810L;
8 |
9 | private WxError error;
10 |
11 | public WxErrorException(WxError error) {
12 | super(error.toString());
13 | this.error = error;
14 | }
15 |
16 | public WxErrorException(String msg){
17 | super(msg);
18 | }
19 |
20 | public WxError getError() {
21 | return error;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/DateUtil.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util;
2 |
3 | import java.text.ParseException;
4 | import java.text.SimpleDateFormat;
5 | import java.util.Date;
6 |
7 |
8 |
9 | public class DateUtil {
10 | public static String getCurrentWeek(String date){
11 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
12 | String week = "";
13 | try {
14 | System.out.println("date-- : " + date);
15 | if(date!=null){
16 | Date startDate = sdf.parse(date);
17 | int startDay = (int) (startDate.getTime() / 1000 / 60 / 60 / 24);
18 | int currentDay = (int) (new Date().getTime() / 1000 / 60 / 60 / 24);
19 | week = ""+((currentDay - startDay - 1) / 7 + 1);
20 | }
21 | } catch (ParseException e) {
22 | e.printStackTrace();
23 | }
24 | return week;
25 | }
26 |
27 | public static String getWeekOfDate(Date date){
28 | SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
29 | String week = sdf.format(date);
30 | return week;
31 | }
32 |
33 | public static String dateToString(Date date){
34 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
35 | return sdf.format(date);
36 | }
37 |
38 | public static String getNowTime(){
39 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
40 | return sdf.format(new Date());
41 | }
42 |
43 | public static String getTimestamp(){
44 | return Long.toString(System.currentTimeMillis() / 1000);
45 | }
46 |
47 | public static long getDelay(String targetTime){
48 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
49 | Date targetDate = null;
50 | try {
51 | targetDate = sdf.parse(targetTime);
52 | } catch (ParseException e) {
53 | e.printStackTrace();
54 | }
55 | return targetDate.getTime()-new Date().getTime();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/EmojiUtil.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util;
2 |
3 | import java.util.regex.Matcher;
4 | import java.util.regex.Pattern;
5 |
6 | public class EmojiUtil {
7 | public static String resolveToByteFromEmoji(String str) {
8 | Pattern pattern = Pattern
9 | .compile("[^(\u2E80-\u9FFF\\w\\s`~!@#\\$%\\^&\\*\\(\\)_+-?()�?��??=\\[\\]{}\\|;。,、�?��?��?�:;�?�!…�?��??:‘\"<,>\\.?/\\\\*)]");
10 | Matcher matcher = pattern.matcher(str);
11 | StringBuffer sb2 = new StringBuffer();
12 | while (matcher.find()) {
13 | matcher.appendReplacement(sb2, resolveToByte(matcher.group(0)));
14 | }
15 | matcher.appendTail(sb2);
16 | return sb2.toString();
17 | }
18 |
19 | public static String resolveToEmojiFromByte(String str) {
20 | Pattern pattern2 = Pattern.compile("<:([[-]\\d*[,]]+):>");
21 | Matcher matcher2 = pattern2.matcher(str);
22 | StringBuffer sb3 = new StringBuffer();
23 | while (matcher2.find()) {
24 | matcher2.appendReplacement(sb3, resolveToEmoji(matcher2.group(0)));
25 | }
26 | matcher2.appendTail(sb3);
27 | return sb3.toString();
28 | }
29 |
30 | private static String resolveToByte(String str) {
31 | byte[] b = str.getBytes();
32 | StringBuffer sb = new StringBuffer();
33 | sb.append("<:");
34 | for (int i = 0; i < b.length; i++) {
35 | if (i < b.length - 1) {
36 | sb.append(Byte.valueOf(b[i]).toString() + ",");
37 | } else {
38 | sb.append(Byte.valueOf(b[i]).toString());
39 | }
40 | }
41 | sb.append(":>");
42 | return sb.toString();
43 | }
44 |
45 | private static String resolveToEmoji(String str) {
46 | str = str.replaceAll("<:", "").replaceAll(":>", "");
47 | String[] s = str.split(",");
48 | byte[] b = new byte[s.length];
49 | for (int i = 0; i < s.length; i++) {
50 | b[i] = Byte.valueOf(s[i]);
51 | }
52 | return new String(b);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/PayUtil.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util;
2 |
3 | import java.util.Arrays;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 | import java.util.Set;
7 |
8 | import com.soecode.wxtools.api.WxConfig;
9 | import com.soecode.wxtools.bean.PayOrderInfo;
10 | import com.soecode.wxtools.bean.WxUnifiedOrder;
11 | import com.soecode.wxtools.util.crypto.MD5;
12 |
13 | public class PayUtil {
14 |
15 | public static WxUnifiedOrder createPayInfo(PayOrderInfo order, String notifyUrl , String openid) {
16 | Map payinfo = new HashMap<>();
17 | payinfo.put("appid", WxConfig.getInstance().getAppId());
18 | payinfo.put("mch_id", WxConfig.getInstance().getMchId());
19 | payinfo.put("device_info", "WEB");
20 | payinfo.put("nonce_str", StringUtils.randomStr(32));
21 | payinfo.put("body", order.getOrderName());
22 | payinfo.put("detail", order.getDetail());
23 | payinfo.put("out_trade_no", order.getOrderId());//商品订单号
24 | payinfo.put("total_fee", ""+order.getTotalFee());
25 | payinfo.put("attach", order.getAttach());
26 | payinfo.put("product_id", order.getProductId());
27 | payinfo.put("notify_url", notifyUrl);
28 | payinfo.put("trade_type", order.getTradeType());
29 | payinfo.put("openid", openid);
30 | payinfo.put("sign", createSign(payinfo, WxConfig.getInstance().getApiKey()));
31 |
32 | WxUnifiedOrder pay = new WxUnifiedOrder();
33 | pay.setAppid(payinfo.get("appid"));
34 | pay.setMchId(payinfo.get("mch_id"));
35 | pay.setDeviceInfo(payinfo.get("device_info"));
36 | pay.setNonceStr(payinfo.get("nonce_str"));
37 | pay.setBody(payinfo.get("body"));
38 | pay.setDetail(payinfo.get("detail"));
39 | pay.setAttach(payinfo.get("attach"));
40 | pay.setOutTradeNo(payinfo.get("out_trade_no"));
41 | pay.setTotalFee(payinfo.get("total_fee"));
42 | pay.setNotifyUrl(payinfo.get("notify_url"));
43 | pay.setTradeType(payinfo.get("trade_type"));
44 | pay.setProductId(payinfo.get("product_id"));
45 | pay.setOpenid(payinfo.get("openid"));
46 | pay.setSign(payinfo.get("sign"));
47 | return pay;
48 | }
49 |
50 | public static String createSign(Map payinfo, String keyStr){
51 | Set keysSet = payinfo.keySet();
52 | Object[] keys = keysSet.toArray();
53 | Arrays.sort(keys);
54 | StringBuffer temp = new StringBuffer();
55 | boolean first = true;
56 | for (Object key : keys) {
57 | if (first) {
58 | first = false;
59 | } else {
60 | temp.append("&");
61 | }
62 | temp.append(key).append("=");
63 | Object value = payinfo.get(key);
64 | String valueString = "";
65 | if (null != value) {
66 | valueString = value.toString();
67 | }
68 | temp.append(valueString);
69 | }
70 | String tempStr = temp.toString()+"&key="+keyStr;
71 | return MD5.getMD5(tempStr, "UTF-8").toUpperCase();
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/RandomUtils.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util;
2 |
3 | public class RandomUtils {
4 |
5 | private static final String RANDOM_STR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
6 |
7 | private static final java.util.Random RANDOM = new java.util.Random();
8 |
9 | public static String getRandomStr(int num) {
10 | StringBuilder sb = new StringBuilder();
11 | for (int i = 0; i < num; i++) {
12 | sb.append(RANDOM_STR.charAt(RANDOM.nextInt(RANDOM_STR.length())));
13 | }
14 | return sb.toString();
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/StringUtils.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util;
2 |
3 | import java.util.Random;
4 |
5 | /**
6 | * copy from apache-commons-lang3
7 | */
8 | public class StringUtils {
9 |
10 | public static boolean isBlank(CharSequence cs) {
11 | int strLen;
12 | if (cs == null || (strLen = cs.length()) == 0) {
13 | return true;
14 | }
15 | for (int i = 0; i < strLen; i++) {
16 | if (Character.isWhitespace(cs.charAt(i)) == false) {
17 | return false;
18 | }
19 | }
20 | return true;
21 | }
22 |
23 | public static boolean isNotBlank(CharSequence cs) {
24 | return !StringUtils.isBlank(cs);
25 | }
26 |
27 | public static boolean isEmpty(CharSequence cs) {
28 | return cs == null || cs.length() == 0;
29 | }
30 |
31 | public static boolean isNotEmpty(CharSequence cs) {
32 | return !StringUtils.isEmpty(cs);
33 | }
34 |
35 | public static String randomStr(int length) {
36 | String base = "abcdefghijklmnopqrstuvwxyz0123456789";
37 | Random random = new Random();
38 | StringBuffer sb = new StringBuffer();
39 | for (int i = 0; i < length; i++) {
40 | int number = random.nextInt(base.length());
41 | sb.append(base.charAt(number));
42 | }
43 | return sb.toString();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/crypto/ByteGroup.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.crypto;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class ByteGroup {
6 | ArrayList byteContainer = new ArrayList();
7 |
8 | public byte[] toBytes() {
9 | byte[] bytes = new byte[byteContainer.size()];
10 | for (int i = 0; i < byteContainer.size(); i++) {
11 | bytes[i] = byteContainer.get(i);
12 | }
13 | return bytes;
14 | }
15 |
16 | public ByteGroup addBytes(byte[] bytes) {
17 | for (byte b : bytes) {
18 | byteContainer.add(b);
19 | }
20 | return this;
21 | }
22 |
23 | public int size() {
24 | return byteContainer.size();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/crypto/MD5.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.crypto;
2 |
3 | import java.security.MessageDigest;
4 |
5 | public class MD5 {
6 |
7 | public static String getMD5(String origin, String charsetname) {
8 | String resultString = null;
9 | try {
10 | resultString = new String(origin);
11 | MessageDigest md = MessageDigest.getInstance("MD5");
12 | if (charsetname == null || "".equals(charsetname))
13 | resultString = byteArrayToHexString(md.digest(resultString.getBytes()));
14 | else
15 | resultString = byteArrayToHexString(md.digest(resultString.getBytes(charsetname)));
16 | } catch (Exception exception) {
17 |
18 | }
19 | return resultString;
20 | }
21 |
22 | private static String byteArrayToHexString(byte b[]) {
23 | StringBuffer resultSb = new StringBuffer();
24 | for (int i = 0; i < b.length; i++)
25 | resultSb.append(byteToHexString(b[i]));
26 |
27 | return resultSb.toString();
28 | }
29 |
30 | private static String byteToHexString(byte b) {
31 | int n = b;
32 | if (n < 0)
33 | n += 256;
34 | int d1 = n / 16;
35 | int d2 = n % 16;
36 | return hexDigits[d1] + hexDigits[d2];
37 | }
38 |
39 | private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d",
40 | "e", "f" };
41 | }
42 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/crypto/PKCS7Encoder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * 对公众平台发送给公众账号的消息加解密示例代码.
3 | *
4 | * @copyright Copyright (c) 1998-2014 Tencent Inc.
5 | */
6 |
7 | // ------------------------------------------------------------------------
8 |
9 | package com.soecode.wxtools.util.crypto;
10 |
11 | import java.nio.charset.Charset;
12 | import java.util.Arrays;
13 |
14 | public class PKCS7Encoder {
15 |
16 | private static final Charset CHARSET = Charset.forName("utf-8");
17 | private static final int BLOCK_SIZE = 32;
18 |
19 | public static byte[] encode(int count) {
20 | // 计算需要填充的位数
21 | int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE);
22 | if (amountToPad == 0) {
23 | amountToPad = BLOCK_SIZE;
24 | }
25 | // 获得补位所用的字符
26 | char padChr = chr(amountToPad);
27 | String tmp = new String();
28 | for (int index = 0; index < amountToPad; index++) {
29 | tmp += padChr;
30 | }
31 | return tmp.getBytes(CHARSET);
32 | }
33 |
34 | public static byte[] decode(byte[] decrypted) {
35 | int pad = (int) decrypted[decrypted.length - 1];
36 | if (pad < 1 || pad > 32) {
37 | pad = 0;
38 | }
39 | return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad);
40 | }
41 |
42 | public static char chr(int a) {
43 | byte target = (byte) (a & 0xFF);
44 | return (char) target;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/crypto/SHA1.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.crypto;
2 |
3 | import java.security.MessageDigest;
4 | import java.security.NoSuchAlgorithmException;
5 | import java.util.Arrays;
6 |
7 | import org.apache.commons.codec.digest.DigestUtils;
8 |
9 | import com.soecode.wxtools.exception.AesException;
10 |
11 |
12 | public class SHA1 {
13 |
14 | public static String gen(String token, String timestamp,String nonce) throws NoSuchAlgorithmException {
15 | String[] arr = new String[] { token, timestamp, nonce };
16 | Arrays.sort(arr);
17 | StringBuffer content = new StringBuffer();
18 | for (String a : arr) {
19 | content.append(a);
20 | }
21 | return DigestUtils.shaHex(content.toString());
22 | }
23 |
24 | public static String genWithAmple(String... arr) throws NoSuchAlgorithmException {
25 | Arrays.sort(arr);
26 | StringBuffer sb = new StringBuffer();
27 | for (int i = 0; i < arr.length; i++) {
28 | String a = arr[i];
29 | sb.append(a+"&");
30 | }
31 | String string1 = sb.toString().substring(0, sb.length()-1);
32 | return DigestUtils.shaHex(string1);
33 | }
34 |
35 | public static String getSHA1(String token, String timestamp, String nonce, String encrypt) throws AesException
36 | {
37 | try {
38 | String[] array = new String[] { token, timestamp, nonce, encrypt };
39 | StringBuffer sb = new StringBuffer();
40 | // 字符串排序
41 | Arrays.sort(array);
42 | for (int i = 0; i < 4; i++) {
43 | sb.append(array[i]);
44 | }
45 | String str = sb.toString();
46 | // SHA1签名生成
47 | MessageDigest md = MessageDigest.getInstance("SHA-1");
48 | md.update(str.getBytes());
49 | byte[] digest = md.digest();
50 |
51 | StringBuffer hexstr = new StringBuffer();
52 | String shaHex = "";
53 | for (int i = 0; i < digest.length; i++) {
54 | shaHex = Integer.toHexString(digest[i] & 0xFF);
55 | if (shaHex.length() < 2) {
56 | hexstr.append(0);
57 | }
58 | hexstr.append(shaHex);
59 | }
60 | return hexstr.toString();
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | throw new AesException(AesException.ComputeSignatureError);
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/crypto/WXBizMsgCrypt.java:
--------------------------------------------------------------------------------
1 | /**
2 | * 对公众平台发送给公众账号的消息加解密示例代码.
3 | *
4 | * @copyright Copyright (c) 1998-2014 Tencent Inc.
5 | */
6 |
7 | // ------------------------------------------------------------------------
8 |
9 | /**
10 | * 针对org.apache.commons.codec.binary.Base64,
11 | * 需要导入架包commons-codec-1.9(或commons-codec-1.8等其他版本)
12 | * 官方下载地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi
13 | */
14 | package com.soecode.wxtools.util.crypto;
15 |
16 | import java.nio.charset.Charset;
17 | import java.util.Arrays;
18 | import java.util.Random;
19 |
20 | import javax.crypto.Cipher;
21 | import javax.crypto.spec.IvParameterSpec;
22 | import javax.crypto.spec.SecretKeySpec;
23 |
24 | import org.apache.commons.codec.binary.Base64;
25 |
26 | import com.soecode.wxtools.exception.AesException;
27 |
28 |
29 | public class WXBizMsgCrypt {
30 | static Charset CHARSET = Charset.forName("utf-8");
31 | Base64 base64 = new Base64();
32 | byte[] aesKey;
33 | String token;
34 | String appId;
35 |
36 | public WXBizMsgCrypt(String token, String encodingAesKey, String appId) throws AesException {
37 | if (encodingAesKey.length() != 43) {
38 | throw new AesException(AesException.IllegalAesKey);
39 | }
40 |
41 | this.token = token;
42 | this.appId = appId;
43 | aesKey = Base64.decodeBase64(encodingAesKey + "=");
44 | }
45 |
46 | byte[] getNetworkBytesOrder(int sourceNumber) {
47 | byte[] orderBytes = new byte[4];
48 | orderBytes[3] = (byte) (sourceNumber & 0xFF);
49 | orderBytes[2] = (byte) (sourceNumber >> 8 & 0xFF);
50 | orderBytes[1] = (byte) (sourceNumber >> 16 & 0xFF);
51 | orderBytes[0] = (byte) (sourceNumber >> 24 & 0xFF);
52 | return orderBytes;
53 | }
54 |
55 | int recoverNetworkBytesOrder(byte[] orderBytes) {
56 | int sourceNumber = 0;
57 | for (int i = 0; i < 4; i++) {
58 | sourceNumber <<= 8;
59 | sourceNumber |= orderBytes[i] & 0xff;
60 | }
61 | return sourceNumber;
62 | }
63 |
64 | String getRandomStr() {
65 | String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
66 | Random random = new Random();
67 | StringBuffer sb = new StringBuffer();
68 | for (int i = 0; i < 16; i++) {
69 | int number = random.nextInt(base.length());
70 | sb.append(base.charAt(number));
71 | }
72 | return sb.toString();
73 | }
74 |
75 | String encrypt(String randomStr, String text) throws AesException {
76 | ByteGroup byteCollector = new ByteGroup();
77 | byte[] randomStrBytes = randomStr.getBytes(CHARSET);
78 | byte[] textBytes = text.getBytes(CHARSET);
79 | byte[] networkBytesOrder = getNetworkBytesOrder(textBytes.length);
80 | byte[] appidBytes = appId.getBytes(CHARSET);
81 |
82 | // randomStr + networkBytesOrder + text + appid
83 | byteCollector.addBytes(randomStrBytes);
84 | byteCollector.addBytes(networkBytesOrder);
85 | byteCollector.addBytes(textBytes);
86 | byteCollector.addBytes(appidBytes);
87 |
88 | byte[] padBytes = PKCS7Encoder.encode(byteCollector.size());
89 | byteCollector.addBytes(padBytes);
90 |
91 | byte[] unencrypted = byteCollector.toBytes();
92 |
93 | try {
94 | Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
95 | SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES");
96 | IvParameterSpec iv = new IvParameterSpec(aesKey, 0, 16);
97 | cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);
98 |
99 | byte[] encrypted = cipher.doFinal(unencrypted);
100 |
101 | String base64Encrypted = base64.encodeToString(encrypted);
102 |
103 | return base64Encrypted;
104 | } catch (Exception e) {
105 | e.printStackTrace();
106 | throw new AesException(AesException.EncryptAESError);
107 | }
108 | }
109 |
110 | String decrypt(String text) throws AesException {
111 | byte[] original;
112 | try {
113 | Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
114 | SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES");
115 | IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16));
116 | cipher.init(Cipher.DECRYPT_MODE, key_spec, iv);
117 |
118 | byte[] encrypted = Base64.decodeBase64(text);
119 |
120 | original = cipher.doFinal(encrypted);
121 | } catch (Exception e) {
122 | e.printStackTrace();
123 | throw new AesException(AesException.DecryptAESError);
124 | }
125 |
126 | String xmlContent, from_appid;
127 | try {
128 | byte[] bytes = PKCS7Encoder.decode(original);
129 |
130 | byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20);
131 | int xmlLength = recoverNetworkBytesOrder(networkOrder);
132 |
133 | xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET);
134 | from_appid = new String(Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length),
135 | CHARSET);
136 | } catch (Exception e) {
137 | e.printStackTrace();
138 | throw new AesException(AesException.IllegalBuffer);
139 | }
140 |
141 | if (!from_appid.equals(appId)) {
142 | throw new AesException(AesException.ValidateAppidError);
143 | }
144 | return xmlContent;
145 |
146 | }
147 |
148 | public String encryptMsg(String replyMsg, String timeStamp, String nonce) throws AesException {
149 | String encrypt = encrypt(getRandomStr(), replyMsg);
150 | if (timeStamp == "") {
151 | timeStamp = Long.toString(System.currentTimeMillis());
152 | }
153 | String signature = SHA1.getSHA1(token, timeStamp, nonce, encrypt);
154 | String result = XMLParse.generate(encrypt, signature, timeStamp, nonce);
155 | return result;
156 | }
157 |
158 | public String decryptMsg(String msgSignature, String timeStamp, String nonce, String postData)
159 | throws AesException {
160 | Object[] encrypt = XMLParse.extract(postData);
161 | String signature = SHA1.getSHA1(token, timeStamp, nonce, encrypt[1].toString());
162 | if (!signature.equals(msgSignature)) {
163 | throw new AesException(AesException.ValidateSignatureError);
164 | }
165 | String result = decrypt(encrypt[1].toString());
166 | return result;
167 | }
168 |
169 | public String verifyUrl(String msgSignature, String timeStamp, String nonce, String echoStr)
170 | throws AesException {
171 | String signature = SHA1.getSHA1(token, timeStamp, nonce, echoStr);
172 |
173 | if (!signature.equals(msgSignature)) {
174 | throw new AesException(AesException.ValidateSignatureError);
175 | }
176 |
177 | String result = decrypt(echoStr);
178 | return result;
179 | }
180 |
181 | }
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/crypto/XMLParse.java:
--------------------------------------------------------------------------------
1 | /**
2 | * 对公众平台发送给公众账号的消息加解密示例代码.
3 | *
4 | * @copyright Copyright (c) 1998-2014 Tencent Inc.
5 | */
6 |
7 | // ------------------------------------------------------------------------
8 |
9 | package com.soecode.wxtools.util.crypto;
10 |
11 | import java.io.StringReader;
12 |
13 | import javax.xml.parsers.DocumentBuilder;
14 | import javax.xml.parsers.DocumentBuilderFactory;
15 |
16 | import org.w3c.dom.Document;
17 | import org.w3c.dom.Element;
18 | import org.w3c.dom.NodeList;
19 | import org.xml.sax.InputSource;
20 |
21 | import com.soecode.wxtools.exception.AesException;
22 |
23 | class XMLParse {
24 |
25 | public static Object[] extract(String xmltext) throws AesException {
26 | Object[] result = new Object[3];
27 | try {
28 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
29 | DocumentBuilder db = dbf.newDocumentBuilder();
30 | StringReader sr = new StringReader(xmltext);
31 | InputSource is = new InputSource(sr);
32 | Document document = db.parse(is);
33 |
34 | Element root = document.getDocumentElement();
35 | NodeList nodelist1 = root.getElementsByTagName("Encrypt");
36 | NodeList nodelist2 = root.getElementsByTagName("ToUserName");
37 | result[0] = 0;
38 | result[1] = nodelist1.item(0).getTextContent();
39 | result[2] = nodelist2.item(0).getTextContent();
40 | return result;
41 | } catch (Exception e) {
42 | e.printStackTrace();
43 | throw new AesException(AesException.ParseXmlError);
44 | }
45 | }
46 |
47 | public static String generate(String encrypt, String signature, String timestamp, String nonce) {
48 |
49 | String format = "\n" + "\n"
50 | + "\n"
51 | + "%3$s\n" + "\n" + "";
52 | return String.format(format, encrypt, signature, timestamp, nonce);
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/file/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.file;
2 |
3 | import java.io.File;
4 | import java.io.FileOutputStream;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | public class FileUtils {
9 |
10 | public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile)
11 | throws IOException {
12 | FileOutputStream fos = null;
13 | try {
14 | File tmpFile;
15 | if (tmpDirFile == null) {
16 | tmpFile = File.createTempFile(name, '.' + ext);
17 | } else {
18 | tmpFile = File.createTempFile(name, '.' + ext, tmpDirFile);
19 | }
20 | tmpFile.deleteOnExit();//JVM结束时,删除该临时目录
21 | fos = new FileOutputStream(tmpFile);
22 | int read = 0;
23 | byte[] bytes = new byte[1024 * 100];
24 | while ((read = inputStream.read(bytes)) != -1) {
25 | fos.write(bytes, 0, read);
26 | }
27 | fos.flush();
28 | return tmpFile;
29 | } finally {
30 | if (inputStream != null) {
31 | try {
32 | inputStream.close();
33 | } catch (IOException e) {
34 | }
35 | }
36 | if (fos != null) {
37 | try {
38 | fos.close();
39 | } catch (IOException e) {
40 | }
41 | }
42 | }
43 | }
44 |
45 | public static File createMaterialFile(InputStream inputStream, String name, String ext, File materialDirFile)
46 | throws IOException {
47 | FileOutputStream fos = null;
48 | try {
49 | File materialFile;
50 | if (materialDirFile == null) {
51 | materialFile = File.createTempFile(name, '.' + ext);
52 | } else {
53 | materialFile = File.createTempFile(name, '.' + ext, materialDirFile);
54 | }
55 | fos = new FileOutputStream(materialFile);
56 | int read = 0;
57 | byte[] bytes = new byte[1024 * 100];
58 | while ((read = inputStream.read(bytes)) != -1) {
59 | fos.write(bytes, 0, read);
60 | }
61 | fos.flush();
62 | return materialFile;
63 | } finally {
64 | if (inputStream != null) {
65 | try {
66 | inputStream.close();
67 | } catch (IOException e) {
68 | }
69 | }
70 | if (fos != null) {
71 | try {
72 | fos.close();
73 | } catch (IOException e) {
74 | }
75 | }
76 | }
77 | }
78 |
79 | public static File createMaterialFile(InputStream inputStream, String name, String ext) throws IOException {
80 | return createMaterialFile(inputStream, name, ext, null);
81 | }
82 |
83 | public static File createTmpFile(InputStream inputStream, String name, String ext) throws IOException {
84 | return createTmpFile(inputStream, name, ext, null);
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/InputStreamResponseHandler.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | import org.apache.http.HttpEntity;
7 | import org.apache.http.HttpResponse;
8 | import org.apache.http.StatusLine;
9 | import org.apache.http.client.HttpResponseException;
10 | import org.apache.http.client.ResponseHandler;
11 | import org.apache.http.util.EntityUtils;
12 |
13 | public class InputStreamResponseHandler implements ResponseHandler {
14 |
15 | public static final ResponseHandler INSTANCE = new InputStreamResponseHandler();
16 |
17 | public InputStream handleResponse(final HttpResponse response) throws HttpResponseException, IOException {
18 | final StatusLine statusLine = response.getStatusLine();
19 | final HttpEntity entity = response.getEntity();
20 | if (statusLine.getStatusCode() >= 300) {
21 | EntityUtils.consume(entity);
22 | throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
23 | }
24 | return entity == null ? null : entity.getContent();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/KfHeadImageUploadRequestExecutor.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import com.soecode.wxtools.bean.result.WxError;
4 | import com.soecode.wxtools.exception.WxErrorException;
5 | import java.io.File;
6 | import java.io.IOException;
7 | import org.apache.http.HttpEntity;
8 | import org.apache.http.client.methods.CloseableHttpResponse;
9 | import org.apache.http.client.methods.HttpPost;
10 | import org.apache.http.entity.ContentType;
11 | import org.apache.http.entity.mime.HttpMultipartMode;
12 | import org.apache.http.entity.mime.MultipartEntityBuilder;
13 | import org.apache.http.impl.client.CloseableHttpClient;
14 |
15 | public class KfHeadImageUploadRequestExecutor implements RequestExecutor {
16 |
17 | public KfHeadImageUploadRequestExecutor() {}
18 |
19 | @Override
20 | public WxError execute(CloseableHttpClient httpclient, String uri, File file)
21 | throws WxErrorException, IOException {
22 | HttpPost httpPost = new HttpPost(uri);
23 |
24 | if (file != null) {
25 | HttpEntity entity = MultipartEntityBuilder.create().addBinaryBody("media", file).setMode(HttpMultipartMode.RFC6532).build();
26 | httpPost.setEntity(entity);
27 | httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
28 | }
29 | try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
30 | String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
31 | return WxError.fromJson(responseContent);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/MediaDownloadGetRequestExecutor.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.util.Map;
7 | import java.util.regex.Matcher;
8 | import java.util.regex.Pattern;
9 |
10 | import org.apache.http.Header;
11 | import org.apache.http.client.ClientProtocolException;
12 | import org.apache.http.client.methods.CloseableHttpResponse;
13 | import org.apache.http.client.methods.HttpGet;
14 | import org.apache.http.entity.ContentType;
15 | import org.apache.http.impl.client.CloseableHttpClient;
16 |
17 | import com.soecode.wxtools.bean.result.WxError;
18 | import com.soecode.wxtools.exception.WxErrorException;
19 | import com.soecode.wxtools.util.StringUtils;
20 | import com.soecode.wxtools.util.file.FileUtils;
21 |
22 | public class MediaDownloadGetRequestExecutor implements RequestExecutor> {
23 |
24 | private File tmpDirFile;
25 |
26 | public MediaDownloadGetRequestExecutor() {
27 | super();
28 | }
29 |
30 | public MediaDownloadGetRequestExecutor(File tmpDirFile) {
31 | super();
32 | this.tmpDirFile = tmpDirFile;
33 | }
34 |
35 | @Override
36 | public File execute(CloseableHttpClient httpclient, String uri, Map params)
37 | throws WxErrorException, ClientProtocolException, IOException {
38 | if (params != null) {
39 | uri += '?';
40 | for(String key : params.keySet()){
41 | uri+=key+"="+params.get(key)+"&";
42 | }
43 | uri = uri.substring(0, uri.length()-1);
44 | }
45 |
46 | HttpGet httpGet = new HttpGet(uri);
47 |
48 | try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
49 | System.out.println(response);
50 | Header[] contentTypeHeader = response.getHeaders("Content-Type");
51 | for(Header h : contentTypeHeader)
52 | System.out.println(h);
53 | if (contentTypeHeader != null && contentTypeHeader.length > 0) {
54 | // 下载媒体文件出错
55 | if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
56 | String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
57 | throw new WxErrorException(WxError.fromJson(responseContent));
58 | }
59 | }
60 | InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
61 | String fileName = getFileName(response);
62 | if (StringUtils.isBlank(fileName)) {
63 | return null;
64 | }
65 | String[] name_ext = fileName.split("\\.");
66 | File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[name_ext.length-1], tmpDirFile);
67 | return localFile;
68 | }
69 | }
70 |
71 | protected String getFileName(CloseableHttpResponse response) {
72 | Header[] contentDispositionHeader = response.getHeaders("Content-disposition");
73 | Pattern p = Pattern.compile(".*filename=\"(.*)\"");
74 | Matcher m = p.matcher(contentDispositionHeader[0].getValue());
75 | m.matches();
76 | String fileName = m.group(m.groupCount());
77 | return fileName;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/MediaDownloadPostRequestExecutor.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.util.regex.Matcher;
7 | import java.util.regex.Pattern;
8 |
9 | import org.apache.http.Header;
10 | import org.apache.http.client.ClientProtocolException;
11 | import org.apache.http.client.methods.CloseableHttpResponse;
12 | import org.apache.http.client.methods.HttpPost;
13 | import org.apache.http.entity.ContentType;
14 | import org.apache.http.entity.StringEntity;
15 | import org.apache.http.impl.client.CloseableHttpClient;
16 |
17 | import com.soecode.wxtools.bean.result.WxError;
18 | import com.soecode.wxtools.exception.WxErrorException;
19 | import com.soecode.wxtools.util.StringUtils;
20 | import com.soecode.wxtools.util.file.FileUtils;
21 |
22 | public class MediaDownloadPostRequestExecutor implements RequestExecutor {
23 |
24 | private File materialDirFile;
25 |
26 | public MediaDownloadPostRequestExecutor() {
27 | super();
28 | }
29 |
30 | public MediaDownloadPostRequestExecutor(File materialDirFile) {
31 | super();
32 | this.materialDirFile = materialDirFile;
33 | }
34 |
35 | @Override
36 | public File execute(CloseableHttpClient httpclient, String uri, String params)
37 | throws WxErrorException, ClientProtocolException, IOException {
38 | HttpPost httpPost = new HttpPost(uri);
39 |
40 | if (params != null) {
41 | httpPost.setEntity(new StringEntity(params,"UTF-8"));
42 | }
43 |
44 | try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
45 | Header[] contentTypeHeader = response.getHeaders("Content-Type");
46 | if (contentTypeHeader != null && contentTypeHeader.length > 0) {
47 | if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
48 | String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
49 | throw new WxErrorException(WxError.fromJson(responseContent));
50 | }
51 | }
52 | InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
53 | String fileName = getFileName(response);
54 | if (StringUtils.isBlank(fileName)) {
55 | return null;
56 | }
57 | String[] name_ext = fileName.split("\\.");
58 | File localFile = FileUtils.createMaterialFile(inputStream, name_ext[0], name_ext[name_ext.length-1], materialDirFile);
59 | return localFile;
60 | }
61 | }
62 |
63 | protected String getFileName(CloseableHttpResponse response) {
64 | Header[] contentDispositionHeader = response.getHeaders("Content-disposition");
65 | Pattern p = Pattern.compile(".*filename=\"(.*)\"");
66 | Matcher m = p.matcher(contentDispositionHeader[0].getValue());
67 | m.matches();
68 | String fileName = m.group(1);
69 | return fileName;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/MediaUploadRequestExecutor.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.nio.charset.StandardCharsets;
6 |
7 | import org.apache.http.HttpEntity;
8 | import org.apache.http.client.ClientProtocolException;
9 | import org.apache.http.client.methods.CloseableHttpResponse;
10 | import org.apache.http.client.methods.HttpPost;
11 | import org.apache.http.entity.ContentType;
12 | import org.apache.http.entity.mime.HttpMultipartMode;
13 | import org.apache.http.entity.mime.MultipartEntityBuilder;
14 | import org.apache.http.entity.mime.content.StringBody;
15 | import org.apache.http.impl.client.CloseableHttpClient;
16 | import org.codehaus.jackson.JsonNode;
17 | import org.codehaus.jackson.map.ObjectMapper;
18 |
19 | import com.soecode.wxtools.bean.WxVideoIntroduction;
20 | import com.soecode.wxtools.bean.result.WxError;
21 | import com.soecode.wxtools.bean.result.WxMediaUploadResult;
22 | import com.soecode.wxtools.exception.WxErrorException;
23 |
24 | public class MediaUploadRequestExecutor implements RequestExecutor {
25 | private WxVideoIntroduction introduction;
26 |
27 | public MediaUploadRequestExecutor() {
28 | }
29 |
30 | public MediaUploadRequestExecutor(WxVideoIntroduction introduction){
31 | this.introduction = introduction;
32 | }
33 |
34 | @Override
35 | public WxMediaUploadResult execute(CloseableHttpClient httpclient, String uri, File file)
36 | throws WxErrorException, IOException {
37 | HttpPost httpPost = new HttpPost(uri);
38 |
39 | if (file != null) {
40 | HttpEntity entity = null;
41 | if(this.introduction !=null){
42 | StringBody stringBody = new StringBody(introduction.toJson(),ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8));
43 | entity = MultipartEntityBuilder.create().setCharset(StandardCharsets.UTF_8).addBinaryBody("media", file).addPart("description", stringBody).setMode(HttpMultipartMode.RFC6532).build();
44 | }else{
45 | entity = MultipartEntityBuilder.create().addBinaryBody("media", file).setMode(HttpMultipartMode.RFC6532).build();
46 | }
47 | httpPost.setEntity(entity);
48 | httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
49 | }
50 | try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
51 | String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
52 | ObjectMapper mapper = new ObjectMapper();
53 | JsonNode node = mapper.readTree(responseContent);
54 | if(node.get("errcode")!=null && !(node.get("errcode").asInt()==0)){
55 | WxError error = WxError.fromJson(responseContent);
56 | throw new WxErrorException(error);
57 | }
58 | return WxMediaUploadResult.fromJson(responseContent);
59 | }
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/QrCodeDownloadGetRequestExecutor.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.util.Map;
7 | import java.util.regex.Matcher;
8 | import java.util.regex.Pattern;
9 |
10 | import org.apache.http.Header;
11 | import org.apache.http.client.ClientProtocolException;
12 | import org.apache.http.client.methods.CloseableHttpResponse;
13 | import org.apache.http.client.methods.HttpGet;
14 | import org.apache.http.entity.ContentType;
15 | import org.apache.http.impl.client.CloseableHttpClient;
16 |
17 | import com.soecode.wxtools.bean.result.WxError;
18 | import com.soecode.wxtools.exception.WxErrorException;
19 | import com.soecode.wxtools.util.StringUtils;
20 | import com.soecode.wxtools.util.file.FileUtils;
21 |
22 | public class QrCodeDownloadGetRequestExecutor implements RequestExecutor> {
23 |
24 | private File qrDirFile;
25 |
26 | public QrCodeDownloadGetRequestExecutor() {
27 | super();
28 | }
29 |
30 | public QrCodeDownloadGetRequestExecutor(File qrDirFile) {
31 | super();
32 | this.qrDirFile = qrDirFile;
33 | }
34 |
35 | @Override
36 | public File execute(CloseableHttpClient httpclient, String uri, Map params)
37 | throws WxErrorException, IOException {
38 | if (params != null) {
39 | uri += '?';
40 | for(String key : params.keySet()){
41 | uri+=key+"="+params.get(key)+"&";
42 | }
43 | uri = uri.substring(0, uri.length()-1);
44 | }
45 |
46 | HttpGet httpGet = new HttpGet(uri);
47 |
48 | try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
49 | Header[] contentTypeHeader = response.getHeaders("Content-Type");
50 | if (contentTypeHeader != null && contentTypeHeader.length > 0) {
51 | if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
52 | String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
53 | throw new WxErrorException(WxError.fromJson(responseContent));
54 | }
55 | }
56 | InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
57 | String fileName = createFileName(response);
58 | if (StringUtils.isBlank(fileName)) {
59 | return null;
60 | }
61 | String[] name_ext = fileName.split("\\.");
62 | File localFile = FileUtils.createMaterialFile(inputStream, name_ext[0], name_ext[name_ext.length-1], qrDirFile);
63 | return localFile;
64 | }
65 | }
66 |
67 | protected String createFileName(CloseableHttpResponse response) {
68 | Header[] contentDispositionHeader = response.getHeaders("Cache-control");
69 | Pattern p = Pattern.compile(".*max-age=(.*)");
70 | Matcher m = p.matcher(contentDispositionHeader[0].getValue());
71 | m.matches();
72 | String maxage = m.group(m.groupCount());
73 | contentDispositionHeader = response.getHeaders("Content-Type");
74 | p = Pattern.compile(".*image/(.*)");
75 | m = p.matcher(contentDispositionHeader[0].getValue());
76 | m.matches();
77 | String type = m.group(m.groupCount());
78 | String fileName = "qr-maxage-" +maxage +"-tmp-"+ System.currentTimeMillis()+"."+type;
79 | return fileName;
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/RequestExecutor.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import com.soecode.wxtools.exception.WxErrorException;
4 | import java.io.IOException;
5 | import org.apache.http.client.ClientProtocolException;
6 | import org.apache.http.impl.client.CloseableHttpClient;
7 |
8 | public interface RequestExecutor {
9 |
10 | T execute(CloseableHttpClient httpclient, String uri, E data)
11 | throws WxErrorException, IOException;
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/SimpleGetRequestExecutor.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import java.io.IOException;
4 | import java.util.Map;
5 |
6 | import org.apache.http.client.ClientProtocolException;
7 | import org.apache.http.client.methods.CloseableHttpResponse;
8 | import org.apache.http.client.methods.HttpGet;
9 | import org.apache.http.impl.client.CloseableHttpClient;
10 | import org.codehaus.jackson.JsonNode;
11 | import org.codehaus.jackson.map.ObjectMapper;
12 |
13 | import com.soecode.wxtools.bean.result.WxError;
14 | import com.soecode.wxtools.exception.WxErrorException;
15 |
16 | public class SimpleGetRequestExecutor implements RequestExecutor> {
17 | @Override
18 | public String execute(CloseableHttpClient httpclient, String uri, Map params)
19 | throws WxErrorException, ClientProtocolException, IOException {
20 | if (params != null) {
21 | uri += '?';
22 | for(String key : params.keySet()){
23 | uri+=key+"="+params.get(key)+"&";
24 | }
25 | uri = uri.substring(0, uri.length()-1);
26 | }
27 | HttpGet httpGet = new HttpGet(uri);
28 |
29 | try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
30 | String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
31 | ObjectMapper mapper = new ObjectMapper();
32 | JsonNode node = mapper.readTree(responseContent);
33 | if(node.get("errcode")!=null && !(node.get("errcode").asInt()==0)){
34 | WxError error = WxError.fromJson(responseContent);
35 | throw new WxErrorException(error);
36 | }
37 | return responseContent;
38 | }
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/SimplePostRequestExecutor.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import java.io.IOException;
4 |
5 | import org.apache.http.client.ClientProtocolException;
6 | import org.apache.http.client.methods.CloseableHttpResponse;
7 | import org.apache.http.client.methods.HttpPost;
8 | import org.apache.http.entity.StringEntity;
9 | import org.apache.http.impl.client.CloseableHttpClient;
10 | import org.codehaus.jackson.JsonNode;
11 | import org.codehaus.jackson.map.ObjectMapper;
12 |
13 | import com.soecode.wxtools.bean.result.WxError;
14 | import com.soecode.wxtools.exception.WxErrorException;
15 |
16 | public class SimplePostRequestExecutor implements RequestExecutor {
17 | @Override
18 | public String execute(CloseableHttpClient httpclient, String uri,String params)
19 | throws WxErrorException, ClientProtocolException, IOException {
20 | HttpPost httpPost = new HttpPost(uri);
21 |
22 | if (params != null) {
23 | httpPost.setEntity(new StringEntity(params,"UTF-8"));
24 | }
25 |
26 | try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
27 | String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
28 | ObjectMapper mapper = new ObjectMapper();
29 | JsonNode node = mapper.readTree(responseContent);
30 | if(node.get("errcode")!=null && !(node.get("errcode").asInt()==0)){
31 | WxError error = WxError.fromJson(responseContent);
32 | throw new WxErrorException(error);
33 | }
34 | return responseContent;
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/URIUtil.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import java.io.UnsupportedEncodingException;
4 |
5 | import com.soecode.wxtools.util.StringUtils;
6 |
7 | public class URIUtil {
8 |
9 | private static final String ALLOWED_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()";
10 |
11 | public static String encodeURIComponent(String input) {
12 | if (StringUtils.isEmpty(input)) {
13 | return input;
14 | }
15 |
16 | int l = input.length();
17 | StringBuilder o = new StringBuilder(l * 3);
18 | try {
19 | for (int i = 0; i < l; i++) {
20 | String e = input.substring(i, i + 1);
21 | if (ALLOWED_CHARS.indexOf(e) == -1) {
22 | byte[] b = e.getBytes("utf-8");
23 | o.append(getHex(b));
24 | continue;
25 | }
26 | o.append(e);
27 | }
28 | return o.toString();
29 | } catch (UnsupportedEncodingException e) {
30 | e.printStackTrace();
31 | }
32 | return input;
33 | }
34 |
35 | private static String getHex(byte buf[]) {
36 | StringBuilder o = new StringBuilder(buf.length * 3);
37 | for (int i = 0; i < buf.length; i++) {
38 | int n = (int) buf[i] & 0xff;
39 | o.append("%");
40 | if (n < 0x10) {
41 | o.append("0");
42 | }
43 | o.append(Long.toString(n, 16).toUpperCase());
44 | }
45 | return o.toString();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/Utf8ResponseHandler.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import java.io.IOException;
4 |
5 | import org.apache.http.Consts;
6 | import org.apache.http.HttpEntity;
7 | import org.apache.http.HttpResponse;
8 | import org.apache.http.StatusLine;
9 | import org.apache.http.client.HttpResponseException;
10 | import org.apache.http.client.ResponseHandler;
11 | import org.apache.http.util.EntityUtils;
12 |
13 | /**
14 | * copy from {@link org.apache.http.impl.client.BasicResponseHandler}
15 | *
16 | */
17 | public class Utf8ResponseHandler implements ResponseHandler {
18 |
19 | public static final ResponseHandler INSTANCE = new Utf8ResponseHandler();
20 |
21 | public String handleResponse(final HttpResponse response) throws HttpResponseException, IOException {
22 | final StatusLine statusLine = response.getStatusLine();
23 | final HttpEntity entity = response.getEntity();
24 | if (statusLine.getStatusCode() >= 300) {
25 | EntityUtils.consume(entity);
26 | throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
27 | }
28 | return entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/http/VideoDownloadPostRequestExecutor.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.http;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.util.regex.Matcher;
7 | import java.util.regex.Pattern;
8 |
9 | import org.apache.http.Header;
10 | import org.apache.http.client.ClientProtocolException;
11 | import org.apache.http.client.methods.CloseableHttpResponse;
12 | import org.apache.http.client.methods.HttpGet;
13 | import org.apache.http.client.methods.HttpPost;
14 | import org.apache.http.entity.ContentType;
15 | import org.apache.http.entity.StringEntity;
16 | import org.apache.http.impl.client.CloseableHttpClient;
17 | import org.codehaus.jackson.JsonNode;
18 | import org.codehaus.jackson.map.ObjectMapper;
19 |
20 | import com.soecode.wxtools.bean.result.WxError;
21 | import com.soecode.wxtools.bean.result.WxVideoMediaResult;
22 | import com.soecode.wxtools.exception.WxErrorException;
23 | import com.soecode.wxtools.util.StringUtils;
24 | import com.soecode.wxtools.util.file.FileUtils;
25 |
26 | public class VideoDownloadPostRequestExecutor implements RequestExecutor {
27 |
28 | private File materialDirFile;
29 |
30 | public VideoDownloadPostRequestExecutor() {
31 | super();
32 | }
33 |
34 | public VideoDownloadPostRequestExecutor(File materialDirFile) {
35 | super();
36 | this.materialDirFile = materialDirFile;
37 | }
38 |
39 | @Override
40 | public WxVideoMediaResult execute(CloseableHttpClient httpclient, String uri, String params)
41 | throws WxErrorException, ClientProtocolException, IOException {
42 | WxVideoMediaResult result = null;
43 |
44 | HttpPost httpPost = new HttpPost(uri);
45 | if (params != null) {
46 | httpPost.setEntity(new StringEntity(params,"UTF-8"));
47 | }
48 | try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
49 | String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
50 | ObjectMapper mapper = new ObjectMapper();
51 | JsonNode node = mapper.readTree(responseContent);
52 | if(node.get("errcode")!=null && !(node.get("errcode").asInt()==0)){
53 | WxError error = WxError.fromJson(responseContent);
54 | throw new WxErrorException(error);
55 | }
56 | result = mapper.readValue(responseContent, WxVideoMediaResult.class);
57 | }
58 |
59 | HttpGet httpGet = new HttpGet(result.getDown_url());
60 | try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
61 | Header[] contentTypeHeader = response.getHeaders("Content-Type");
62 | if (contentTypeHeader != null && contentTypeHeader.length > 0) {
63 | if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
64 | String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
65 | throw new WxErrorException(WxError.fromJson(responseContent));
66 | }
67 | }
68 | InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
69 | String fileName = getFileName(response);
70 | if (StringUtils.isBlank(fileName)) {
71 | return null;
72 | }
73 | String[] name_ext = fileName.split("\\.");
74 | FileUtils.createMaterialFile(inputStream, name_ext[0], name_ext[name_ext.length-1], materialDirFile);
75 | }
76 |
77 | return result;
78 | }
79 |
80 | protected String getFileName(CloseableHttpResponse response) {
81 | Header[] contentDispositionHeader = response.getHeaders("Content-Disposition");
82 | Pattern p = Pattern.compile(".*filename=(.*)");
83 | Matcher m = p.matcher(contentDispositionHeader[0].getValue());
84 | m.matches();
85 | String fileName = m.group(1);
86 | return fileName;
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/xml/XStreamCDataConverter.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.xml;
2 |
3 | import com.thoughtworks.xstream.converters.basic.StringConverter;
4 |
5 | /**
6 | * CDATA 转换器
7 | * @author antgan
8 | *
9 | */
10 | public class XStreamCDataConverter extends StringConverter {
11 |
12 | @Override
13 | public String toString(Object obj) {
14 | return "";
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/xml/XStreamInitializer.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.xml;
2 |
3 | import java.io.Writer;
4 |
5 | import com.thoughtworks.xstream.XStream;
6 | import com.thoughtworks.xstream.core.util.QuickWriter;
7 | import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
8 | import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
9 | import com.thoughtworks.xstream.io.xml.XppDriver;
10 | import com.thoughtworks.xstream.security.NullPermission;
11 | import com.thoughtworks.xstream.security.PrimitiveTypePermission;
12 |
13 | /**
14 | * XStream 自定义初始化器
15 | * @author antgan
16 | *
17 | */
18 | public class XStreamInitializer {
19 |
20 | public static XStream getInstance() {
21 | XStream xstream = new XStream(new XppDriver() {
22 | @Override
23 | public HierarchicalStreamWriter createWriter(Writer out) {
24 | return new PrettyPrintWriter(out, getNameCoder()) {
25 | protected String PREFIX_CDATA = "";
27 | protected String PREFIX_MEDIA_ID = "";
28 | protected String SUFFIX_MEDIA_ID = "";
29 |
30 | @Override
31 | protected void writeText(QuickWriter writer, String text) {
32 | if (text.startsWith(PREFIX_CDATA) && text.endsWith(SUFFIX_CDATA)) {
33 | writer.write(text);
34 | } else if (text.startsWith(PREFIX_MEDIA_ID) && text.endsWith(SUFFIX_MEDIA_ID)) {
35 | writer.write(text);
36 | } else {
37 | super.writeText(writer, text);
38 | }
39 |
40 | }
41 | };
42 | }
43 | });
44 | xstream.ignoreUnknownElements();//忽视null的节点
45 | xstream.setMode(XStream.NO_REFERENCES);
46 | xstream.addPermission(NullPermission.NULL);
47 | xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
48 | return xstream;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/xml/XStreamMediaIdConverter.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.xml;
2 |
3 | /**
4 | * MediaId 转换器
5 | * @author antgan
6 | *
7 | */
8 | public class XStreamMediaIdConverter extends XStreamCDataConverter {
9 | @Override
10 | public String toString(Object obj) {
11 | return "" + super.toString(obj) + "";
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/wx-tools/src/main/java/com/soecode/wxtools/util/xml/XStreamTransformer.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.util.xml;
2 |
3 | import java.io.InputStream;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | import com.soecode.wxtools.bean.WxXmlMessage;
8 | import com.soecode.wxtools.bean.WxXmlOutImageMessage;
9 | import com.soecode.wxtools.bean.WxXmlOutMessage;
10 | import com.soecode.wxtools.bean.WxXmlOutNewsMessage;
11 | import com.soecode.wxtools.bean.WxXmlOutTextMessage;
12 | import com.soecode.wxtools.bean.WxXmlOutVideoMessage;
13 | import com.soecode.wxtools.bean.WxXmlOutVoiceMessage;
14 | import com.thoughtworks.xstream.XStream;
15 |
16 | /**
17 | * 指定类的专属XStream
18 | * @author antgan
19 | *
20 | */
21 | public class XStreamTransformer {
22 |
23 | protected static final Map CLASS_2_XSTREAM_INSTANCE = configXStreamInstance();
24 |
25 |
26 | @SuppressWarnings("unchecked")
27 | public static T fromXml(Class clazz, String xml) {
28 | T object = (T) CLASS_2_XSTREAM_INSTANCE.get(clazz).fromXML(xml);
29 | return object;
30 | }
31 |
32 | @SuppressWarnings("unchecked")
33 | public static T fromXml(Class clazz, InputStream is) {
34 | T object = (T) CLASS_2_XSTREAM_INSTANCE.get(clazz).fromXML(is);
35 | return object;
36 | }
37 |
38 | public static String toXml(Class clazz, T object) {
39 | return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object);
40 | }
41 |
42 | private static Map configXStreamInstance() {
43 | Map map = new HashMap();
44 | map.put(WxXmlMessage.class, config_WxXmlMessage());
45 | map.put(WxXmlOutNewsMessage.class, config_WxXmlOutNewsMessage());
46 | map.put(WxXmlOutTextMessage.class, config_WxXmlOutTextMessage());
47 | map.put(WxXmlOutImageMessage.class, config_WxXmlOutImageMessage());
48 | map.put(WxXmlOutVideoMessage.class, config_WxXmlOutVideoMessage());
49 | map.put(WxXmlOutVoiceMessage.class, config_WxXmlOutVoiceMessage());
50 | return map;
51 | }
52 |
53 | private static XStream config_WxXmlMessage() {
54 | XStream xstream = XStreamInitializer.getInstance();
55 | xstream.processAnnotations(WxXmlMessage.class);
56 | xstream.processAnnotations(WxXmlMessage.ScanCodeInfo.class);
57 | xstream.processAnnotations(WxXmlMessage.SendPicsInfo.class);
58 | xstream.processAnnotations(WxXmlMessage.SendPicsInfo.Item.class);
59 | xstream.processAnnotations(WxXmlMessage.SendLocationInfo.class);
60 | return xstream;
61 | }
62 |
63 | private static XStream config_WxXmlOutImageMessage() {
64 | XStream xstream = XStreamInitializer.getInstance();
65 | xstream.processAnnotations(WxXmlOutMessage.class);
66 | xstream.processAnnotations(WxXmlOutImageMessage.class);
67 | return xstream;
68 | }
69 |
70 | private static XStream config_WxXmlOutNewsMessage() {
71 | XStream xstream = XStreamInitializer.getInstance();
72 | xstream.processAnnotations(WxXmlOutMessage.class);
73 | xstream.processAnnotations(WxXmlOutNewsMessage.class);
74 | xstream.processAnnotations(WxXmlOutNewsMessage.Item.class);
75 | return xstream;
76 | }
77 |
78 | private static XStream config_WxXmlOutTextMessage() {
79 | XStream xstream = XStreamInitializer.getInstance();
80 | xstream.processAnnotations(WxXmlOutMessage.class);
81 | xstream.processAnnotations(WxXmlOutTextMessage.class);
82 | return xstream;
83 | }
84 |
85 | private static XStream config_WxXmlOutVideoMessage() {
86 | XStream xstream = XStreamInitializer.getInstance();
87 | xstream.processAnnotations(WxXmlOutMessage.class);
88 | xstream.processAnnotations(WxXmlOutVideoMessage.class);
89 | xstream.processAnnotations(WxXmlOutVideoMessage.Video.class);
90 | return xstream;
91 | }
92 |
93 | private static XStream config_WxXmlOutVoiceMessage() {
94 | XStream xstream = XStreamInitializer.getInstance();
95 | xstream.processAnnotations(WxXmlOutMessage.class);
96 | xstream.processAnnotations(WxXmlOutVoiceMessage.class);
97 | return xstream;
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/wx-tools/src/main/resources/wx.properties:
--------------------------------------------------------------------------------
1 | wx.appId=wxb1bff1627d37417b
2 | wx.appSecret=dd037d9b9b4eea00fba14167a9f3c75d
3 | wx.token=
4 | wx.aesKey=
5 | wx.mchId=
6 | wx.apiKey=
--------------------------------------------------------------------------------
/wx-tools/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | wx-tools
4 |
5 |
--------------------------------------------------------------------------------
/wx-tools/src/test/java/com/soecode/wxtools/api/test/KfAccountTest.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.api.test;
2 |
3 | import com.soecode.wxtools.api.IService;
4 | import com.soecode.wxtools.api.WxConsts;
5 | import com.soecode.wxtools.api.WxService;
6 | import com.soecode.wxtools.bean.KfAccount;
7 | import com.soecode.wxtools.bean.KfSender;
8 | import com.soecode.wxtools.bean.SenderContent.NewsList;
9 | import com.soecode.wxtools.bean.SenderContent.NewsList.News;
10 | import com.soecode.wxtools.bean.SenderContent.Text;
11 | import com.soecode.wxtools.bean.result.KfAccountListResult;
12 | import com.soecode.wxtools.bean.result.WxError;
13 | import java.io.File;
14 | import java.util.Arrays;
15 | import org.junit.Ignore;
16 | import org.junit.Test;
17 |
18 | @Ignore
19 | public class KfAccountTest {
20 | IService iService = new WxService();
21 |
22 | @Test
23 | public void should_add_kf_account_successfully() throws Exception {
24 | WxError result = iService.addKfAccount(new KfAccount("ant@test", "ant", "ant"));
25 | System.out.println(result);
26 | }
27 |
28 | @Test
29 | public void should_update_kf_account_successfully() throws Exception {
30 | WxError result = iService.updateKfAccount(new KfAccount("ant@test", "ant", "ant"));
31 | System.out.println(result);
32 | }
33 |
34 | @Test
35 | public void should_delete_kf_account_successfully() throws Exception {
36 | WxError result = iService.deleteKfAccount(new KfAccount("ant@test", "ant", "ant"));
37 | System.out.println(result);
38 | }
39 |
40 | @Test
41 | public void should_get_all_kf_account_successfully() throws Exception {
42 | KfAccountListResult result = iService.getAllKfAccount();
43 | System.out.println(result);
44 | }
45 |
46 | @Test
47 | public void should_send_text_message_to_user_successfully() throws Exception {
48 | KfSender sender = new KfSender();
49 | sender.setTouser("oROCnuNihJnO9bnKOAORDFFriPgQ");
50 | sender.setMsgtype(WxConsts.MASS_MSG_TEXT);
51 | sender.setText(new Text("hi"));
52 | System.out.println(iService.sendMessageByKf(sender));
53 | }
54 |
55 | @Test
56 | public void should_send_news_message_to_user_successfully() throws Exception {
57 | KfSender sender = new KfSender();
58 | sender.setTouser("oROCnuNihJnO9bnKOAORDFFriPgQ");
59 | sender.setMsgtype(WxConsts.MASS_MSG_NEWS);
60 | sender.setNews(new NewsList(Arrays.asList(new News("title","desc","http://www.baidu.com","http://www.baidu.com"))));
61 | System.out.println(iService.sendMessageByKf(sender));
62 | }
63 |
64 | @Test
65 | public void should_update_kf_head_image_successfully() throws Exception {
66 | System.out.println(iService.updateKfHeadImage("oROCnuNihJnO9bnKOAORDFFriPgQ", new File("D:/wx/wx.jpg")));
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/wx-tools/src/test/java/com/soecode/wxtools/api/test/MediaTest.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.api.test;
2 |
3 | import com.soecode.wxtools.api.IService;
4 | import com.soecode.wxtools.api.WxConsts;
5 | import com.soecode.wxtools.api.WxService;
6 | import com.soecode.wxtools.bean.WxNewsInfo;
7 | import com.soecode.wxtools.bean.result.WxMediaUploadResult;
8 | import java.io.File;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import org.junit.Ignore;
12 | import org.junit.Test;
13 |
14 | @Ignore
15 | public class MediaTest {
16 |
17 | IService iService = new WxService();
18 |
19 | @Test
20 | public void should_upload_tmp_media_successfully() throws Exception {
21 | WxMediaUploadResult result = iService.uploadTempMedia(WxConsts.MEDIA_IMAGE, new File("D:/wx/wx.jpg"));
22 | System.out.println(result);
23 | }
24 |
25 | @Test
26 | public void should_download_tmp_media_successfully() throws Exception {
27 | File file = iService.downloadTempMedia("kQG6o5oSz7i-lftsReydIlrF9B3DeplO-MtunUwIY3SIUwje0PGp_VqozvrgUwRS", new File("D:/wx/"));
28 | System.out.println(file);
29 | }
30 |
31 | @Test
32 | public void should_upload_media_successfully() throws Exception {
33 | WxMediaUploadResult result = iService.uploadMedia(WxConsts.MEDIA_IMAGE, new File("D:/wx/20180517141550.jpg"), null);
34 | System.out.println(result);
35 | }
36 |
37 | @Test
38 | public void should_upload_news_media_successfully() throws Exception {
39 | WxNewsInfo news1 = new WxNewsInfo();
40 | news1.setTitle("标题1");
41 | news1.setThumb_media_id("QR3FgphTwoIpP1FZ-4c__U8tBWTHchoDa468te3P7Qg");
42 | news1.setContent("xxx");
43 | news1.setNeed_open_comment(1);
44 |
45 | List newsList = new ArrayList();
46 | newsList.add(news1);
47 | String mediaId = iService.addNewsMedia(newsList);
48 | System.out.println(mediaId);
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/wx-tools/src/test/java/com/soecode/wxtools/api/test/MenuTest.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.api.test;
2 |
3 | import com.soecode.wxtools.api.IService;
4 | import com.soecode.wxtools.api.WxConsts;
5 | import com.soecode.wxtools.api.WxService;
6 | import com.soecode.wxtools.bean.WxMenu;
7 | import com.soecode.wxtools.bean.WxMenu.WxMenuButton;
8 | import com.soecode.wxtools.bean.WxMenu.WxMenuRule;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 | import org.junit.Assert;
12 | import org.junit.Ignore;
13 | import org.junit.Test;
14 |
15 | @Ignore
16 | public class MenuTest {
17 |
18 | IService iService = new WxService();
19 |
20 | @Test
21 | public void should_create_normal_menu_successfully() throws Exception {
22 | WxMenu menu = getWxMenu();
23 | String result = iService.createMenu(menu, false);
24 | Assert.assertEquals("{\"errcode\":0,\"errmsg\":\"ok\"}", result);
25 | }
26 |
27 | @Test
28 | public void should_create_condition_menu_successfully() throws Exception {
29 | WxMenu menu = getWxMenu();
30 | WxMenuRule matchrule = new WxMenuRule();
31 | matchrule.setTag_id("103");
32 | matchrule.setCountry("中国");
33 | matchrule.setProvince("广东");
34 | menu.setMatchrule(matchrule);
35 | String result = iService.createMenu(menu, true);
36 | System.out.println(result);
37 | }
38 |
39 | @Test
40 | public void should_delete_condition_menu_successfully() throws Exception {
41 | String result = iService.deleteMenu("443508866");
42 | System.out.println(result);
43 | }
44 |
45 |
46 | private WxMenu getWxMenu() {
47 | WxMenu menu = new WxMenu();
48 | List btnList = new ArrayList<>();
49 |
50 | //设置CLICK类型的按钮1
51 | WxMenuButton btn1 = new WxMenuButton();
52 | btn1.setType(WxConsts.MENU_BUTTON_CLICK);
53 | btn1.setKey("btn1_key");
54 | btn1.setName("CLICK按钮1");
55 |
56 | //设置VIEW类型的按钮2
57 | WxMenuButton btn2 = new WxMenuButton();
58 | btn2.setType(WxConsts.MENU_BUTTON_VIEW);
59 | btn2.setUrl("http://www.baidu.com");
60 | btn2.setName("VIEW按钮2");
61 |
62 | //设置含有子按钮的按钮3
63 | List subList = new ArrayList<>();
64 | //子按钮
65 | WxMenuButton btn3_1 = new WxMenuButton();
66 | btn3_1.setType(WxConsts.MENU_BUTTON_VIEW);
67 | btn3_1.setUrl("http://www.baidu.com");
68 | btn3_1.setName("子按钮3_1");
69 | WxMenuButton btn3_2 = new WxMenuButton();
70 | btn3_2.setType(WxConsts.MENU_BUTTON_VIEW);
71 | btn3_2.setUrl("http://www.baidu.com");
72 | btn3_2.setName("子按钮3_2");
73 | subList.add(btn3_1);
74 | subList.add(btn3_2);
75 | //把子按钮列表设置进按钮3
76 | WxMenuButton btn3 = new WxMenuButton();
77 | btn3.setName("子按钮3");
78 | btn3.setSub_button(subList);
79 |
80 | //将三个按钮设置进btnList
81 | btnList.add(btn1);
82 | btnList.add(btn2);
83 | btnList.add(btn3);
84 | //设置进菜单类
85 | menu.setButton(btnList);
86 | return menu;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/wx-tools/src/test/java/com/soecode/wxtools/api/test/MessageTest.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.api.test;
2 |
3 | import com.soecode.wxtools.api.IService;
4 | import com.soecode.wxtools.api.WxConsts;
5 | import com.soecode.wxtools.api.WxService;
6 | import com.soecode.wxtools.bean.PreviewSender;
7 | import com.soecode.wxtools.bean.SenderContent.Media;
8 | import com.soecode.wxtools.bean.WxOpenidSender;
9 | import com.soecode.wxtools.bean.result.SenderResult;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import org.junit.Ignore;
13 | import org.junit.Test;
14 |
15 | @Ignore
16 | public class MessageTest {
17 |
18 | IService iService = new WxService();
19 |
20 | @Test
21 | public void should_preview_send_news_to_user() throws Exception {
22 | PreviewSender sender = new PreviewSender();
23 | sender.setTouser("oROCnuNihJnO9bnKOAORDFFriPgQ");
24 | sender.setMsgtype(WxConsts.MASS_MSG_MPNEWS);
25 | sender.setMpnews(new Media("QR3FgphTwoIpP1FZ-4c__cQTEeIHxMl7e_rWAfFYyfo"));
26 | SenderResult result = iService.sendAllPreview(sender);
27 | System.out.println(result.toString());
28 | }
29 |
30 | @Test
31 | public void should_send_news_to_user() throws Exception {
32 | WxOpenidSender sender = new WxOpenidSender();
33 | List openidList = new ArrayList<>();
34 | openidList.add("oROCnuNihJnO9bnKOAORDFFriPgQ");
35 | openidList.add("oROCnuAQMnkPpEhsAYFzU-1xhKcQ");
36 | sender.setTouser(openidList);
37 | sender.setMsgtype(WxConsts.MASS_MSG_MPNEWS);
38 | sender.setMpnews(new Media("QR3FgphTwoIpP1FZ-4c__cQTEeIHxMl7e_rWAfFYyfo"));
39 | SenderResult result = iService.sendAllByOpenid(sender);
40 | System.out.println(result.toString());
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/wx-tools/src/test/java/com/soecode/wxtools/api/test/UserInfoTest.java:
--------------------------------------------------------------------------------
1 | package com.soecode.wxtools.api.test;
2 |
3 | import com.soecode.wxtools.api.IService;
4 | import com.soecode.wxtools.api.WxConsts;
5 | import com.soecode.wxtools.api.WxService;
6 | import com.soecode.wxtools.bean.WxUserList;
7 | import com.soecode.wxtools.bean.WxUserList.WxUser;
8 | import com.soecode.wxtools.bean.WxUserList.WxUser.WxUserGet;
9 | import com.soecode.wxtools.bean.result.WxError;
10 | import com.soecode.wxtools.bean.result.WxUserListResult;
11 | import com.soecode.wxtools.bean.result.WxUserTagResult;
12 | import java.util.Arrays;
13 | import org.junit.Ignore;
14 | import org.junit.Test;
15 |
16 | @Ignore
17 | public class UserInfoTest {
18 | IService iService = new WxService();
19 |
20 |
21 | @Test
22 | public void should_create_user_tag_successfully() throws Exception {
23 | WxUserTagResult result = iService.createUserTag("TestTag2");
24 | System.out.println(result);
25 | }
26 |
27 | @Test
28 | public void should_query_all_user_tag_successfully() throws Exception {
29 | WxUserTagResult result = iService.queryAllUserTag();
30 | System.out.println(result);
31 | }
32 |
33 | @Test
34 | public void should_update_user_tag_successfully() throws Exception {
35 | WxError result = iService.updateUserTagName(104, "TestTag2_update");
36 | System.out.println(result);
37 | }
38 |
39 | @Test
40 | public void should_delete_user_tag_successfully() throws Exception {
41 | WxError result = iService.deleteUserTag(104);
42 | System.out.println(result);
43 | }
44 |
45 | @Test
46 | public void should_batch_moving_user_to_tag_successfully() throws Exception {
47 | WxError result = iService.batchMovingUserToNewTag(Arrays.asList("oROCnuNihJnO9bnKOAORDFFriPgQ"), 104);
48 | System.out.println(result);
49 | }
50 |
51 | @Test
52 | public void should_batch_remove_user_to_tag_successfully() throws Exception {
53 | WxError result = iService.batchRemoveUserTag(Arrays.asList("oROCnuNihJnO9bnKOAORDFFriPgQ"), 104);
54 | System.out.println(result);
55 | }
56 |
57 | @Test
58 | public void should_query_all_user_under_by_tag_successfully() throws Exception {
59 | WxUserListResult result = iService.queryAllUserUnderByTag(2, null);
60 | System.out.println(result);
61 | }
62 |
63 | @Test
64 | public void should_update_user_remark_successfully() throws Exception {
65 | WxError result = iService.updateUserRemark("oROCnuNihJnO9bnKOAORDFFriPgQ", "Abel");
66 | System.out.println(result);
67 | }
68 |
69 | @Test
70 | public void should_query_user_info_successfully() throws Exception {
71 | WxUser result = iService.getUserInfoByOpenId(new WxUserGet("oROCnuNihJnO9bnKOAORDFFriPgQ",
72 | WxConsts.LANG_CHINA));
73 | System.out.println(result);
74 | }
75 |
76 | @Test
77 | public void should_batch_query_user_info_successfully() throws Exception {
78 | WxUserList result = iService.batchGetUserInfo(Arrays.asList(new WxUserGet("oROCnuNihJnO9bnKOAORDFFriPgQ",
79 | WxConsts.LANG_CHINA),new WxUserGet("oROCnuAQMnkPpEhsAYFzU-1xhKcQ",
80 | WxConsts.LANG_CHINA)));
81 | System.out.println(result);
82 | }
83 |
84 | @Test
85 | public void should_batch_get_user_id_successfully() throws Exception {
86 | WxUserListResult result = iService.batchGetUserOpenId(null);
87 | System.out.println(result);
88 | }
89 |
90 | @Test
91 | public void should_batch_add_user_to_black_list_successfully() throws Exception {
92 | WxError result = iService.batchAddUserToBlackList(Arrays.asList("oROCnuNihJnO9bnKOAORDFFriPgQ"));
93 | System.out.println(result);
94 | }
95 |
96 | @Test
97 | public void should_batch_remove_user_from_black_list_successfully() throws Exception {
98 | WxError result = iService.batchRemoveUserFromBlackList(Arrays.asList("oROCnuNihJnO9bnKOAORDFFriPgQ"));
99 | System.out.println(result);
100 | }
101 |
102 | @Test
103 | public void should_batch_get_users_from_black_list_successfully() throws Exception {
104 | WxUserListResult result = iService.batchGetUsersFromBlackList(null);
105 | System.out.println(result);
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------