1
1
package me .chanjar .weixin .mp .api .impl ;
2
2
3
+ import java .io .IOException ;
4
+
5
+ import org .apache .http .HttpHost ;
6
+ import org .apache .http .client .config .RequestConfig ;
7
+ import org .apache .http .client .methods .CloseableHttpResponse ;
8
+ import org .apache .http .client .methods .HttpGet ;
9
+ import org .apache .http .conn .ssl .DefaultHostnameVerifier ;
10
+ import org .apache .http .conn .ssl .SSLConnectionSocketFactory ;
11
+ import org .apache .http .impl .client .BasicResponseHandler ;
12
+ import org .apache .http .impl .client .CloseableHttpClient ;
13
+ import org .slf4j .Logger ;
14
+ import org .slf4j .LoggerFactory ;
15
+
3
16
import com .google .gson .JsonArray ;
4
17
import com .google .gson .JsonElement ;
5
18
import com .google .gson .JsonObject ;
6
19
import com .google .gson .JsonParser ;
20
+
7
21
import me .chanjar .weixin .common .bean .WxAccessToken ;
8
22
import me .chanjar .weixin .common .bean .WxJsapiSignature ;
9
23
import me .chanjar .weixin .common .bean .result .WxError ;
12
26
import me .chanjar .weixin .common .session .WxSessionManager ;
13
27
import me .chanjar .weixin .common .util .RandomUtils ;
14
28
import me .chanjar .weixin .common .util .crypto .SHA1 ;
15
- import me .chanjar .weixin .common .util .http .*;
16
- import me .chanjar .weixin .mp .api .*;
17
- import me .chanjar .weixin .mp .bean .*;
18
- import me .chanjar .weixin .mp .bean .result .*;
19
- import org .apache .http .HttpHost ;
20
- import org .apache .http .client .config .RequestConfig ;
21
- import org .apache .http .client .methods .CloseableHttpResponse ;
22
- import org .apache .http .client .methods .HttpGet ;
23
- import org .apache .http .conn .ssl .DefaultHostnameVerifier ;
24
- import org .apache .http .conn .ssl .SSLConnectionSocketFactory ;
25
- import org .apache .http .impl .client .BasicResponseHandler ;
26
- import org .apache .http .impl .client .CloseableHttpClient ;
27
- import org .slf4j .Logger ;
28
- import org .slf4j .LoggerFactory ;
29
-
30
- import java .io .IOException ;
29
+ import me .chanjar .weixin .common .util .http .ApacheHttpClientBuilder ;
30
+ import me .chanjar .weixin .common .util .http .DefaultApacheHttpClientBuilder ;
31
+ import me .chanjar .weixin .common .util .http .RequestExecutor ;
32
+ import me .chanjar .weixin .common .util .http .SimpleGetRequestExecutor ;
33
+ import me .chanjar .weixin .common .util .http .SimplePostRequestExecutor ;
34
+ import me .chanjar .weixin .common .util .http .URIUtil ;
35
+ import me .chanjar .weixin .mp .api .WxMpCardService ;
36
+ import me .chanjar .weixin .mp .api .WxMpConfigStorage ;
37
+ import me .chanjar .weixin .mp .api .WxMpDataCubeService ;
38
+ import me .chanjar .weixin .mp .api .WxMpKefuService ;
39
+ import me .chanjar .weixin .mp .api .WxMpMaterialService ;
40
+ import me .chanjar .weixin .mp .api .WxMpMenuService ;
41
+ import me .chanjar .weixin .mp .api .WxMpPayService ;
42
+ import me .chanjar .weixin .mp .api .WxMpQrcodeService ;
43
+ import me .chanjar .weixin .mp .api .WxMpService ;
44
+ import me .chanjar .weixin .mp .api .WxMpStoreService ;
45
+ import me .chanjar .weixin .mp .api .WxMpUserBlacklistService ;
46
+ import me .chanjar .weixin .mp .api .WxMpUserService ;
47
+ import me .chanjar .weixin .mp .api .WxMpUserTagService ;
48
+ import me .chanjar .weixin .mp .bean .WxMpIndustry ;
49
+ import me .chanjar .weixin .mp .bean .WxMpMassNews ;
50
+ import me .chanjar .weixin .mp .bean .WxMpMassOpenIdsMessage ;
51
+ import me .chanjar .weixin .mp .bean .WxMpMassPreviewMessage ;
52
+ import me .chanjar .weixin .mp .bean .WxMpMassTagMessage ;
53
+ import me .chanjar .weixin .mp .bean .WxMpMassVideo ;
54
+ import me .chanjar .weixin .mp .bean .WxMpSemanticQuery ;
55
+ import me .chanjar .weixin .mp .bean .WxMpTemplateMessage ;
56
+ import me .chanjar .weixin .mp .bean .result .WxMpMassSendResult ;
57
+ import me .chanjar .weixin .mp .bean .result .WxMpMassUploadResult ;
58
+ import me .chanjar .weixin .mp .bean .result .WxMpOAuth2AccessToken ;
59
+ import me .chanjar .weixin .mp .bean .result .WxMpSemanticQueryResult ;
60
+ import me .chanjar .weixin .mp .bean .result .WxMpUser ;
31
61
32
62
public class WxMpServiceImpl implements WxMpService {
33
63
@@ -178,35 +208,35 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException
178
208
@ Override
179
209
public WxMpMassUploadResult massNewsUpload (WxMpMassNews news ) throws WxErrorException {
180
210
String url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews" ;
181
- String responseContent = execute ( new SimplePostRequestExecutor (), url , news .toJson ());
211
+ String responseContent = this . post ( url , news .toJson ());
182
212
return WxMpMassUploadResult .fromJson (responseContent );
183
213
}
184
214
185
215
@ Override
186
216
public WxMpMassUploadResult massVideoUpload (WxMpMassVideo video ) throws WxErrorException {
187
217
String url = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo" ;
188
- String responseContent = execute ( new SimplePostRequestExecutor (), url , video .toJson ());
218
+ String responseContent = this . post ( url , video .toJson ());
189
219
return WxMpMassUploadResult .fromJson (responseContent );
190
220
}
191
221
192
222
@ Override
193
223
public WxMpMassSendResult massGroupMessageSend (WxMpMassTagMessage message ) throws WxErrorException {
194
224
String url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall" ;
195
- String responseContent = execute ( new SimplePostRequestExecutor (), url , message .toJson ());
225
+ String responseContent = this . post ( url , message .toJson ());
196
226
return WxMpMassSendResult .fromJson (responseContent );
197
227
}
198
228
199
229
@ Override
200
230
public WxMpMassSendResult massOpenIdsMessageSend (WxMpMassOpenIdsMessage message ) throws WxErrorException {
201
231
String url = "https://api.weixin.qq.com/cgi-bin/message/mass/send" ;
202
- String responseContent = execute ( new SimplePostRequestExecutor (), url , message .toJson ());
232
+ String responseContent = this . post ( url , message .toJson ());
203
233
return WxMpMassSendResult .fromJson (responseContent );
204
234
}
205
235
206
236
@ Override
207
237
public WxMpMassSendResult massMessagePreview (WxMpMassPreviewMessage wxMpMassPreviewMessage ) throws Exception {
208
238
String url = "https://api.weixin.qq.com/cgi-bin/message/mass/preview" ;
209
- String responseContent = execute ( new SimplePostRequestExecutor (), url , wxMpMassPreviewMessage .toJson ());
239
+ String responseContent = this . post ( url , wxMpMassPreviewMessage .toJson ());
210
240
return WxMpMassSendResult .fromJson (responseContent );
211
241
}
212
242
@@ -216,7 +246,7 @@ public String shortUrl(String long_url) throws WxErrorException {
216
246
JsonObject o = new JsonObject ();
217
247
o .addProperty ("action" , "long2short" );
218
248
o .addProperty ("long_url" , long_url );
219
- String responseContent = execute ( new SimplePostRequestExecutor (), url , o .toString ());
249
+ String responseContent = this . post ( url , o .toString ());
220
250
JsonElement tmpJsonElement = JSON_PARSER .parse (responseContent );
221
251
return tmpJsonElement .getAsJsonObject ().get ("short_url" ).getAsString ();
222
252
}
@@ -240,20 +270,20 @@ public String setIndustry(WxMpIndustry wxMpIndustry) throws WxErrorException {
240
270
throw new IllegalArgumentException ("industry id is empty" );
241
271
}
242
272
String url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry" ;
243
- return execute ( new SimplePostRequestExecutor (), url , wxMpIndustry .toJson ());
273
+ return this . post ( url , wxMpIndustry .toJson ());
244
274
}
245
275
246
276
@ Override
247
277
public WxMpIndustry getIndustry () throws WxErrorException {
248
278
String url = "https://api.weixin.qq.com/cgi-bin/template/get_industry" ;
249
- String responseContent = execute ( new SimpleGetRequestExecutor (), url , null );
279
+ String responseContent = this . get ( url , null );
250
280
return WxMpIndustry .fromJson (responseContent );
251
281
}
252
282
253
283
@ Override
254
284
public WxMpSemanticQueryResult semanticQuery (WxMpSemanticQuery semanticQuery ) throws WxErrorException {
255
285
String url = "https://api.weixin.qq.com/semantic/semproxy/search" ;
256
- String responseContent = execute ( new SimplePostRequestExecutor (), url , semanticQuery .toJson ());
286
+ String responseContent = this . post ( url , semanticQuery .toJson ());
257
287
return WxMpSemanticQueryResult .fromJson (responseContent );
258
288
}
259
289
0 commit comments