1 package com.foxinmy.weixin4j.wxa;
2
3 import java.util.Properties;
4
5 import com.foxinmy.weixin4j.cache.CacheStorager;
6 import com.foxinmy.weixin4j.cache.FileCacheStorager;
7 import com.foxinmy.weixin4j.model.Token;
8 import com.foxinmy.weixin4j.model.WeixinAccount;
9 import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
10 import com.foxinmy.weixin4j.token.TokenCreator;
11 import com.foxinmy.weixin4j.token.TokenManager;
12 import com.foxinmy.weixin4j.wxa.api.CustomMessageApi;
13 import com.foxinmy.weixin4j.wxa.api.LoginApi;
14 import com.foxinmy.weixin4j.wxa.api.QrCodeApi;
15 import com.foxinmy.weixin4j.wxa.api.SecCheckApi;
16 import com.foxinmy.weixin4j.wxa.api.TemplateApi;
17 import com.foxinmy.weixin4j.wxa.api.TemplateMessageApi;
18 import com.foxinmy.weixin4j.wxa.api.SubscribeMessageApi;
19
20
21
22
23
24
25 public class WeixinAppFacade {
26
27 private final LoginApi loginApi;
28
29 private final QrCodeApi qrCodeApi;
30
31 private final TemplateApi templateApi;
32
33 private final TemplateMessageApi templateMessageApi;
34
35 private final CustomMessageApi customMessageApi;
36
37 private final SecCheckApi secCheckApi;
38
39 private final SubscribeMessageApi subscribeMessageApi;
40
41
42
43
44
45
46 public WeixinAppFacade(
47 WeixinAccount weixinAccount
48 ) {
49 this(
50 weixinAccount,
51 new FileCacheStorager<Token>()
52 );
53 }
54
55
56
57
58
59
60
61 public WeixinAppFacade(
62 WeixinAccount weixinAccount,
63 CacheStorager<Token> cacheStorager
64 ) {
65 this(
66 weixinAccount,
67 cacheStorager,
68 null
69 );
70 }
71
72
73
74
75
76
77
78
79
80 public WeixinAppFacade(
81 WeixinAccount weixinAccount,
82 CacheStorager<Token> cacheStorager,
83 Properties properties
84 ) {
85 this(
86 weixinAccount,
87 new WeixinTokenCreator(weixinAccount.getId(), weixinAccount.getSecret()),
88 cacheStorager,
89 properties
90 );
91 }
92
93 private WeixinAppFacade(
94 WeixinAccount weixinAccount,
95 TokenCreator tokenCreator,
96 CacheStorager<Token> cacheStorager,
97 Properties properties
98 ) {
99 if (weixinAccount == null) {
100 throw new IllegalArgumentException(
101 "weixinAccount must not be empty");
102 }
103
104 if (tokenCreator == null) {
105 throw new IllegalArgumentException(
106 "tokenCreator must not be empty");
107 }
108
109 if (cacheStorager == null) {
110 throw new IllegalArgumentException(
111 "cacheStorager must not be empty");
112 }
113
114 final TokenManager tokenManager = new TokenManager(tokenCreator, cacheStorager);
115
116 this.loginApi = new LoginApi(weixinAccount, properties);
117 this.qrCodeApi = new QrCodeApi(tokenManager, properties);
118 this.templateApi = new TemplateApi(tokenManager, properties);
119 this.templateMessageApi = new TemplateMessageApi(tokenManager, properties);
120 this.customMessageApi = new CustomMessageApi(tokenManager, properties);
121 this.secCheckApi = new SecCheckApi(tokenManager, properties);
122 this.subscribeMessageApi = new SubscribeMessageApi(tokenManager, properties);
123 }
124
125
126
127
128
129
130 public LoginApi getLoginApi() {
131 return loginApi;
132 }
133
134
135
136
137
138
139 public QrCodeApi getQrCodeApi() {
140 return qrCodeApi;
141 }
142
143
144
145
146
147
148 public TemplateApi getTemplateApi() {
149 return templateApi;
150 }
151
152
153
154
155
156
157 public TemplateMessageApi getTemplateMessageApi() {
158 return templateMessageApi;
159 }
160
161
162
163
164
165
166
167 public SubscribeMessageApi getSubscribeMessageApi() {
168 return subscribeMessageApi;
169 }
170
171
172
173
174
175
176 public CustomMessageApi getCustomMessageApi() {
177 return customMessageApi;
178 }
179
180
181
182
183
184
185
186 public SecCheckApi getSecCheckApi() {
187 return secCheckApi;
188 }
189
190 }