@@ -86,6 +86,7 @@ public class WxMpServiceImpl implements WxMpService {
86
86
87
87
protected WxSessionManager sessionManager = new StandardSessionManager ();
88
88
89
+ @ Override
89
90
public boolean checkSignature (String timestamp , String nonce , String signature ) {
90
91
try {
91
92
return SHA1 .gen (wxMpConfigStorage .getToken (), timestamp , nonce ).equals (signature );
@@ -94,10 +95,12 @@ public boolean checkSignature(String timestamp, String nonce, String signature)
94
95
}
95
96
}
96
97
98
+ @ Override
97
99
public String getAccessToken () throws WxErrorException {
98
100
return getAccessToken (false );
99
101
}
100
102
103
+ @ Override
101
104
public String getAccessToken (boolean forceRefresh ) throws WxErrorException {
102
105
if (forceRefresh ) {
103
106
wxMpConfigStorage .expireAccessToken ();
@@ -137,10 +140,12 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
137
140
return wxMpConfigStorage .getAccessToken ();
138
141
}
139
142
143
+ @ Override
140
144
public String getJsapiTicket () throws WxErrorException {
141
145
return getJsapiTicket (false );
142
146
}
143
147
148
+ @ Override
144
149
public String getJsapiTicket (boolean forceRefresh ) throws WxErrorException {
145
150
if (forceRefresh ) {
146
151
wxMpConfigStorage .expireJsapiTicket ();
@@ -161,6 +166,7 @@ public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
161
166
return wxMpConfigStorage .getJsapiTicket ();
162
167
}
163
168
169
+ @ Override
164
170
public WxJsapiSignature createJsapiSignature (String url ) throws WxErrorException {
165
171
long timestamp = System .currentTimeMillis () / 1000 ;
166
172
String noncestr = RandomUtils .getRandomStr ();
@@ -184,11 +190,13 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException
184
190
}
185
191
}
186
192
193
+ @ Override
187
194
public void customMessageSend (WxMpCustomMessage message ) throws WxErrorException {
188
195
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send" ;
189
196
execute (new SimplePostRequestExecutor (), url , message .toJson ());
190
197
}
191
198
199
+ @ Override
192
200
public void menuCreate (WxMenu menu ) throws WxErrorException {
193
201
if (menu .getMatchRule () != null ) {
194
202
String url = "https://api.weixin.qq.com/cgi-bin/menu/addconditional" ;
@@ -199,16 +207,19 @@ public void menuCreate(WxMenu menu) throws WxErrorException {
199
207
}
200
208
}
201
209
210
+ @ Override
202
211
public void menuDelete () throws WxErrorException {
203
212
String url = "https://api.weixin.qq.com/cgi-bin/menu/delete" ;
204
213
execute (new SimpleGetRequestExecutor (), url , null );
205
214
}
206
215
216
+ @ Override
207
217
public void menuDelete (String menuid ) throws WxErrorException {
208
218
String url = "https://api.weixin.qq.com/cgi-bin/menu/delconditional" ;
209
219
execute (new SimpleGetRequestExecutor (), url , "menuid=" + menuid );
210
220
}
211
221
222
+ @ Override
212
223
public WxMenu menuGet () throws WxErrorException {
213
224
String url = "https://api.weixin.qq.com/cgi-bin/menu/get" ;
214
225
try {
@@ -223,6 +234,7 @@ public WxMenu menuGet() throws WxErrorException {
223
234
}
224
235
}
225
236
237
+ @ Override
226
238
public WxMenu menuTryMatch (String userid ) throws WxErrorException {
227
239
String url = "https://api.weixin.qq.com/cgi-bin/menu/trymatch" ;
228
240
try {
@@ -237,25 +249,30 @@ public WxMenu menuTryMatch(String userid) throws WxErrorException {
237
249
}
238
250
}
239
251
252
+ @ Override
240
253
public WxMediaUploadResult mediaUpload (String mediaType , String fileType , InputStream inputStream ) throws WxErrorException , IOException {
241
254
return mediaUpload (mediaType , FileUtils .createTmpFile (inputStream , UUID .randomUUID ().toString (), fileType ));
242
255
}
243
256
257
+ @ Override
244
258
public WxMediaUploadResult mediaUpload (String mediaType , File file ) throws WxErrorException {
245
259
String url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?type=" + mediaType ;
246
260
return execute (new MediaUploadRequestExecutor (), url , file );
247
261
}
248
262
263
+ @ Override
249
264
public File mediaDownload (String media_id ) throws WxErrorException {
250
265
String url = "http://file.api.weixin.qq.com/cgi-bin/media/get" ;
251
266
return execute (new MediaDownloadRequestExecutor (wxMpConfigStorage .getTmpDirFile ()), url , "media_id=" + media_id );
252
267
}
253
268
269
+ @ Override
254
270
public WxMpMaterialUploadResult materialFileUpload (String mediaType , WxMpMaterial material ) throws WxErrorException {
255
271
String url = "https://api.weixin.qq.com/cgi-bin/material/add_material?type=" + mediaType ;
256
272
return execute (new MaterialUploadRequestExecutor (), url , material );
257
273
}
258
274
275
+ @ Override
259
276
public WxMpMaterialUploadResult materialNewsUpload (WxMpMaterialNews news ) throws WxErrorException {
260
277
if (news == null || news .isEmpty ()) {
261
278
throw new IllegalArgumentException ("news is empty!" );
@@ -265,21 +282,25 @@ public WxMpMaterialUploadResult materialNewsUpload(WxMpMaterialNews news) throws
265
282
return WxMpMaterialUploadResult .fromJson (responseContent );
266
283
}
267
284
285
+ @ Override
268
286
public InputStream materialImageOrVoiceDownload (String media_id ) throws WxErrorException {
269
287
String url = "https://api.weixin.qq.com/cgi-bin/material/get_material" ;
270
288
return execute (new MaterialVoiceAndImageDownloadRequestExecutor (wxMpConfigStorage .getTmpDirFile ()), url , media_id );
271
289
}
272
290
291
+ @ Override
273
292
public WxMpMaterialVideoInfoResult materialVideoInfo (String media_id ) throws WxErrorException {
274
293
String url = "https://api.weixin.qq.com/cgi-bin/material/get_material" ;
275
294
return execute (new MaterialVideoInfoRequestExecutor (), url , media_id );
276
295
}
277
296
297
+ @ Override
278
298
public WxMpMaterialNews materialNewsInfo (String media_id ) throws WxErrorException {
279
299
String url = "https://api.weixin.qq.com/cgi-bin/material/get_material" ;
280
300
return execute (new MaterialNewsInfoRequestExecutor (), url , media_id );
281
301
}
282
302
303
+ @ Override
283
304
public boolean materialNewsUpdate (WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate ) throws WxErrorException {
284
305
String url = "https://api.weixin.qq.com/cgi-bin/material/update_news" ;
285
306
String responseText = post (url , wxMpMaterialArticleUpdate .toJson ());
@@ -291,11 +312,13 @@ public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleU
291
312
}
292
313
}
293
314
315
+ @ Override
294
316
public boolean materialDelete (String media_id ) throws WxErrorException {
295
317
String url = "https://api.weixin.qq.com/cgi-bin/material/del_material" ;
296
318
return execute (new MaterialDeleteRequestExecutor (), url , media_id );
297
319
}
298
320
321
+ @ Override
299
322
public WxMpMaterialCountResult materialCount () throws WxErrorException {
300
323
String url = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount" ;
301
324
String responseText = get (url , null );
@@ -307,6 +330,7 @@ public WxMpMaterialCountResult materialCount() throws WxErrorException {
307
330
}
308
331
}
309
332
333
+ @ Override
310
334
public WxMpMaterialNewsBatchGetResult materialNewsBatchGet (int offset , int count ) throws WxErrorException {
311
335
String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material" ;
312
336
Map <String , Object > params = new HashMap <>();
@@ -322,6 +346,7 @@ public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count
322
346
}
323
347
}
324
348
349
+ @ Override
325
350
public WxMpMaterialFileBatchGetResult materialFileBatchGet (String type , int offset , int count ) throws WxErrorException {
326
351
String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material" ;
327
352
Map <String , Object > params = new HashMap <>();
@@ -337,30 +362,35 @@ public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offs
337
362
}
338
363
}
339
364
365
+ @ Override
340
366
public WxMpMassUploadResult massNewsUpload (WxMpMassNews news ) throws WxErrorException {
341
367
String url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews" ;
342
368
String responseContent = execute (new SimplePostRequestExecutor (), url , news .toJson ());
343
369
return WxMpMassUploadResult .fromJson (responseContent );
344
370
}
345
371
372
+ @ Override
346
373
public WxMpMassUploadResult massVideoUpload (WxMpMassVideo video ) throws WxErrorException {
347
374
String url = "http://file.api.weixin.qq.com/cgi-bin/media/uploadvideo" ;
348
375
String responseContent = execute (new SimplePostRequestExecutor (), url , video .toJson ());
349
376
return WxMpMassUploadResult .fromJson (responseContent );
350
377
}
351
378
379
+ @ Override
352
380
public WxMpMassSendResult massGroupMessageSend (WxMpMassGroupMessage message ) throws WxErrorException {
353
381
String url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall" ;
354
382
String responseContent = execute (new SimplePostRequestExecutor (), url , message .toJson ());
355
383
return WxMpMassSendResult .fromJson (responseContent );
356
384
}
357
385
386
+ @ Override
358
387
public WxMpMassSendResult massOpenIdsMessageSend (WxMpMassOpenIdsMessage message ) throws WxErrorException {
359
388
String url = "https://api.weixin.qq.com/cgi-bin/message/mass/send" ;
360
389
String responseContent = execute (new SimplePostRequestExecutor (), url , message .toJson ());
361
390
return WxMpMassSendResult .fromJson (responseContent );
362
391
}
363
392
393
+ @ Override
364
394
public WxMpGroup groupCreate (String name ) throws WxErrorException {
365
395
String url = "https://api.weixin.qq.com/cgi-bin/groups/create" ;
366
396
JsonObject json = new JsonObject ();
@@ -375,6 +405,7 @@ public WxMpGroup groupCreate(String name) throws WxErrorException {
375
405
return WxMpGroup .fromJson (responseContent );
376
406
}
377
407
408
+ @ Override
378
409
public List <WxMpGroup > groupGet () throws WxErrorException {
379
410
String url = "https://api.weixin.qq.com/cgi-bin/groups/get" ;
380
411
String responseContent = execute (new SimpleGetRequestExecutor (), url , null );
@@ -388,6 +419,7 @@ public List<WxMpGroup> groupGet() throws WxErrorException {
388
419
}.getType ());
389
420
}
390
421
422
+ @ Override
391
423
public long userGetGroup (String openid ) throws WxErrorException {
392
424
String url = "https://api.weixin.qq.com/cgi-bin/groups/getid" ;
393
425
JsonObject o = new JsonObject ();
@@ -397,11 +429,13 @@ public long userGetGroup(String openid) throws WxErrorException {
397
429
return GsonHelper .getAsLong (tmpJsonElement .getAsJsonObject ().get ("groupid" ));
398
430
}
399
431
432
+ @ Override
400
433
public void groupUpdate (WxMpGroup group ) throws WxErrorException {
401
434
String url = "https://api.weixin.qq.com/cgi-bin/groups/update" ;
402
435
execute (new SimplePostRequestExecutor (), url , group .toJson ());
403
436
}
404
437
438
+ @ Override
405
439
public void userUpdateGroup (String openid , long to_groupid ) throws WxErrorException {
406
440
String url = "https://api.weixin.qq.com/cgi-bin/groups/members/update" ;
407
441
JsonObject json = new JsonObject ();
@@ -410,6 +444,7 @@ public void userUpdateGroup(String openid, long to_groupid) throws WxErrorExcept
410
444
execute (new SimplePostRequestExecutor (), url , json .toString ());
411
445
}
412
446
447
+ @ Override
413
448
public void userUpdateRemark (String openid , String remark ) throws WxErrorException {
414
449
String url = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark" ;
415
450
JsonObject json = new JsonObject ();
@@ -418,19 +453,22 @@ public void userUpdateRemark(String openid, String remark) throws WxErrorExcepti
418
453
execute (new SimplePostRequestExecutor (), url , json .toString ());
419
454
}
420
455
456
+ @ Override
421
457
public WxMpUser userInfo (String openid , String lang ) throws WxErrorException {
422
458
String url = "https://api.weixin.qq.com/cgi-bin/user/info" ;
423
459
lang = lang == null ? "zh_CN" : lang ;
424
460
String responseContent = execute (new SimpleGetRequestExecutor (), url , "openid=" + openid + "&lang=" + lang );
425
461
return WxMpUser .fromJson (responseContent );
426
462
}
427
463
464
+ @ Override
428
465
public WxMpUserList userList (String next_openid ) throws WxErrorException {
429
466
String url = "https://api.weixin.qq.com/cgi-bin/user/get" ;
430
467
String responseContent = execute (new SimpleGetRequestExecutor (), url , next_openid == null ? null : "next_openid=" + next_openid );
431
468
return WxMpUserList .fromJson (responseContent );
432
469
}
433
470
471
+ @ Override
434
472
public WxMpQrCodeTicket qrCodeCreateTmpTicket (int scene_id , Integer expire_seconds ) throws WxErrorException {
435
473
String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create" ;
436
474
JsonObject json = new JsonObject ();
@@ -447,6 +485,7 @@ public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_secon
447
485
return WxMpQrCodeTicket .fromJson (responseContent );
448
486
}
449
487
488
+ @ Override
450
489
public WxMpQrCodeTicket qrCodeCreateLastTicket (int scene_id ) throws WxErrorException {
451
490
String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create" ;
452
491
JsonObject json = new JsonObject ();
@@ -460,6 +499,7 @@ public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorExcep
460
499
return WxMpQrCodeTicket .fromJson (responseContent );
461
500
}
462
501
502
+ @ Override
463
503
public WxMpQrCodeTicket qrCodeCreateLastTicket (String scene_str ) throws WxErrorException {
464
504
String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create" ;
465
505
JsonObject json = new JsonObject ();
@@ -473,6 +513,7 @@ public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorE
473
513
return WxMpQrCodeTicket .fromJson (responseContent );
474
514
}
475
515
516
+ @ Override
476
517
public File qrCodePicture (WxMpQrCodeTicket ticket ) throws WxErrorException {
477
518
String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode" ;
478
519
return execute (new QrCodeRequestExecutor (), url , ticket );
@@ -490,6 +531,7 @@ public String qrCodePictureUrl(String ticket) throws WxErrorException {
490
531
}
491
532
}
492
533
534
+ @ Override
493
535
public String shortUrl (String long_url ) throws WxErrorException {
494
536
String url = "https://api.weixin.qq.com/cgi-bin/shorturl" ;
495
537
JsonObject o = new JsonObject ();
@@ -500,6 +542,7 @@ public String shortUrl(String long_url) throws WxErrorException {
500
542
return tmpJsonElement .getAsJsonObject ().get ("short_url" ).getAsString ();
501
543
}
502
544
545
+ @ Override
503
546
public String templateSend (WxMpTemplateMessage templateMessage ) throws WxErrorException {
504
547
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send" ;
505
548
String responseContent = execute (new SimplePostRequestExecutor (), url , templateMessage .toJson ());
@@ -510,6 +553,7 @@ public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorEx
510
553
throw new WxErrorException (WxError .fromJson (responseContent ));
511
554
}
512
555
556
+ @ Override
513
557
public WxMpSemanticQueryResult semanticQuery (WxMpSemanticQuery semanticQuery ) throws WxErrorException {
514
558
String url = "https://api.weixin.qq.com/semantic/semproxy/search" ;
515
559
String responseContent = execute (new SimplePostRequestExecutor (), url , semanticQuery .toJson ());
@@ -658,10 +702,12 @@ public List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) thro
658
702
}.getType ());
659
703
}
660
704
705
+ @ Override
661
706
public String get (String url , String queryParam ) throws WxErrorException {
662
707
return execute (new SimpleGetRequestExecutor (), url , queryParam );
663
708
}
664
709
710
+ @ Override
665
711
public String post (String url , String postData ) throws WxErrorException {
666
712
return execute (new SimplePostRequestExecutor (), url , postData );
667
713
}
@@ -675,6 +721,7 @@ public String post(String url, String postData) throws WxErrorException {
675
721
* @return
676
722
* @throws WxErrorException
677
723
*/
724
+ @ Override
678
725
public <T , E > T execute (RequestExecutor <T , E > executor , String uri , E data ) throws WxErrorException {
679
726
int retryTimes = 0 ;
680
727
do {
@@ -740,6 +787,7 @@ protected CloseableHttpClient getHttpclient() {
740
787
return httpClient ;
741
788
}
742
789
790
+ @ Override
743
791
public void setWxMpConfigStorage (WxMpConfigStorage wxConfigProvider ) {
744
792
this .wxMpConfigStorage = wxConfigProvider ;
745
793
@@ -791,6 +839,7 @@ public WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, double a
791
839
return getPrepayId (packageParams );
792
840
}
793
841
842
+ @ Override
794
843
public WxMpPrepayIdResult getPrepayId (final Map <String , String > parameters ) {
795
844
String nonce_str = System .currentTimeMillis () + "" ;
796
845
0 commit comments