-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Expand file tree
/
Copy pathWxMpService.java
More file actions
939 lines (857 loc) · 32.4 KB
/
WxMpService.java
File metadata and controls
939 lines (857 loc) · 32.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.common.bean.WxCardApiSignature;
import me.chanjar.weixin.common.bean.WxMenu;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.mp.bean.*;
import me.chanjar.weixin.mp.bean.result.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 微信API的Service
*/
public interface WxMpService {
public static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
/**
* <pre>
* 验证推送过来的消息的正确性
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=验证消息真实性
* </pre>
* @param timestamp
* @param nonce
* @param signature
* @return
*/
public boolean checkSignature(String timestamp, String nonce, String signature);
/**
* 获取access_token, 不强制刷新access_token
* @see #getAccessToken(boolean)
* @return
* @throws WxErrorException
*/
public String getAccessToken() throws WxErrorException;
/**
* <pre>
* 获取access_token,本方法线程安全
* 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限
*
* 另:本service的所有方法都会在access_token过期是调用此方法
*
* 程序员在非必要情况下尽量不要主动调用此方法
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
* </pre>
* @param forceRefresh 强制刷新
* @return
* @throws me.chanjar.weixin.common.exception.WxErrorException
*/
public String getAccessToken(boolean forceRefresh) throws WxErrorException;
/**
* 获得jsapi_ticket,不强制刷新jsapi_ticket
* @see #getJsapiTicket(boolean)
* @return
* @throws WxErrorException
*/
public String getJsapiTicket() throws WxErrorException;
/**
* <pre>
* 获得jsapi_ticket
* 获得时会检查jsapiToken是否过期,如果过期了,那么就刷新一下,否则就什么都不干
*
* 详情请见:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95
* </pre>
* @param forceRefresh 强制刷新
* @return
* @throws WxErrorException
*/
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException;
/**
* <pre>
* 创建调用jsapi时所需要的签名
*
* 详情请见:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95
* </pre>
* @param url url
* @return
*/
public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException;
/**
* <pre>
* 上传多媒体文件
*
* 上传的多媒体文件有格式和大小限制,如下:
* 图片(image): 1M,支持JPG格式
* 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
* 视频(video):10MB,支持MP4格式
* 缩略图(thumb):64KB,支持JPG格式
*
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
* </pre>
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param fileType 文件类型,请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param inputStream 输入流
* @throws WxErrorException
*/
public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream) throws WxErrorException, IOException;
/**
* <pre>
* 上传非图文永久素材
*
* 上传的多媒体文件有格式和大小限制,如下:
* 图片(image): 图片大小不超过2M,支持bmp/png/jpeg/jpg/gif格式
* 语音(voice):语音大小不超过5M,长度不超过60秒,支持mp3/wma/wav/amr格式
* 视频(video):在上传视频素材时需要POST另一个表单,id为description,包含素材的描述信息,内容格式为JSON
* 缩略图(thumb):文档未说明
*
* 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
* </pre>
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param material 上传的素材, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterial}
* @return
* @throws WxErrorException
*/
public WxMpMaterialUploadResult materialFileUpload(String mediaType, WxMpMaterial material) throws WxErrorException;
/**
* <pre>
* 上传永久图文素材
*
* 详情请见: http://mp.weixin.qq.com/wiki/14/7e6c03263063f4813141c3e17dd4350a.html
* </pre>
* @param news 上传的图文消息, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialNews}
* @return
* @throws WxErrorException
*/
public WxMpMaterialUploadResult materialNewsUpload(WxMpMaterialNews news) throws WxErrorException;
/**
* <pre>
* 下载声音或者图片永久素材
*
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
* </pre>
* @param media_id 永久素材的id
* @return
* @throws WxErrorException
*/
public InputStream materialImageOrVoiceDownload(String media_id) throws WxErrorException;
/**
* <pre>
* 获取视频永久素材的信息和下载地址
*
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
* </pre>
* @param media_id 永久素材的id
* @return
* @throws WxErrorException
*/
public WxMpMaterialVideoInfoResult materialVideoInfo(String media_id) throws WxErrorException;
/**
* <pre>
* 获取图文永久素材的信息
*
* 详情请见: http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
* </pre>
* @param media_id 永久素材的id
* @return
* @throws WxErrorException
*/
public WxMpMaterialNews materialNewsInfo(String media_id) throws WxErrorException;
/**
* <pre>
* 更新图文永久素材
*
* 详情请见: http://mp.weixin.qq.com/wiki/4/19a59cba020d506e767360ca1be29450.html
* </pre>
* @param wxMpMaterialArticleUpdate 用来更新图文素材的bean, 请看{@link me.chanjar.weixin.mp.bean.WxMpMaterialArticleUpdate}
* @return
* @throws WxErrorException
*/
public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException;
/**
* <pre>
* 删除永久素材
*
* 详情请见: http://mp.weixin.qq.com/wiki/5/e66f61c303db51a6c0f90f46b15af5f5.html
* </pre>
* @param media_id 永久素材的id
* @return
* @throws WxErrorException
*/
public boolean materialDelete(String media_id) throws WxErrorException;
/**
* <pre>
* 获取各类素材总数
*
* 详情请见: http://mp.weixin.qq.com/wiki/16/8cc64f8c189674b421bee3ed403993b8.html
* </pre>
* @return
* @throws WxErrorException
*/
public WxMpMaterialCountResult materialCount() throws WxErrorException;
/**
* <pre>
* 分页获取图文素材列表
*
* 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
* </pre>
* @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
* @param count 返回素材的数量,取值在1到20之间
* @return
* @throws WxErrorException
*/
public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException;
/**
* <pre>
* 分页获取其他媒体素材列表
*
* 详情请见: http://mp.weixin.qq.com/wiki/12/2108cd7aafff7f388f41f37efa710204.html
* </pre>
* @param type 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
* @param count 返回素材的数量,取值在1到20之间
* @return
* @throws WxErrorException
*/
public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException;
/**
* @see #mediaUpload(String, String, InputStream)
* @param mediaType
* @param file
* @throws WxErrorException
*/
public WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException;
/**
* <pre>
* 下载多媒体文件
* 根据微信文档,视频文件下载不了,会返回null
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
* </pre>
* @params media_id
* @return 保存到本地的临时文件
* @throws WxErrorException
*/
public File mediaDownload(String media_id) throws WxErrorException;
/**
* <pre>
* 发送客服消息
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息
* </pre>
* @param message
* @throws WxErrorException
*/
public void customMessageSend(WxMpCustomMessage message) throws WxErrorException;
/**
* <pre>
* 上传群发用的图文消息,上传后才能群发图文消息
*
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
* </pre>
* @param news
* @throws WxErrorException
* @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassGroupMessage)
* @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage)
*/
public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException;
/**
* <pre>
* 上传群发用的视频,上传后才能群发视频消息
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
* </pre>
* @return
* @throws WxErrorException
* @see #massGroupMessageSend(me.chanjar.weixin.mp.bean.WxMpMassGroupMessage)
* @see #massOpenIdsMessageSend(me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage)
*/
public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException;
/**
* <pre>
* 分组群发消息
* 如果发送图文消息,必须先使用 {@link #massNewsUpload(me.chanjar.weixin.mp.bean.WxMpMassNews)} 获得media_id,然后再发送
* 如果发送视频消息,必须先使用 {@link #massVideoUpload(me.chanjar.weixin.mp.bean.WxMpMassVideo)} 获得media_id,然后再发送
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
* </pre>
* @param message
* @throws WxErrorException
* @return
*/
public WxMpMassSendResult massGroupMessageSend(WxMpMassGroupMessage message) throws WxErrorException;
/**
* <pre>
* 按openId列表群发消息
* 如果发送图文消息,必须先使用 {@link #massNewsUpload(me.chanjar.weixin.mp.bean.WxMpMassNews)} 获得media_id,然后再发送
* 如果发送视频消息,必须先使用 {@link #massVideoUpload(me.chanjar.weixin.mp.bean.WxMpMassVideo)} 获得media_id,然后再发送
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=高级群发接口
* </pre>
* @param message
* @return
* @throws WxErrorException
*/
public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException;
/**
* <pre>
* 自定义菜单创建接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口
* 如果要创建个性化菜单,请设置matchrule属性
* 详情请见:http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html
* </pre>
* @param menu
* @throws WxErrorException
*/
public void menuCreate(WxMenu menu) throws WxErrorException;
/**
* <pre>
* 自定义菜单删除接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口
* </pre>
* @throws WxErrorException
*/
public void menuDelete() throws WxErrorException;
/**
* <pre>
* 删除个性化菜单接口
* 详情请见: http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html
* </pre>
* @param menuid
* @throws WxErrorException
*/
public void menuDelete(String menuid) throws WxErrorException;
/**
* <pre>
* 自定义菜单查询接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口
* </pre>
* @return
* @throws WxErrorException
*/
public WxMenu menuGet() throws WxErrorException;
/**
* <pre>
* 测试个性化菜单匹配结果
* 详情请见: http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html
* </pre>
* @param userid 可以是粉丝的OpenID,也可以是粉丝的微信号。
* @throws WxErrorException
*/
public WxMenu menuTryMatch(String userid) throws WxErrorException;
/**
* <pre>
* 分组管理接口 - 创建分组
* 最多支持创建500个分组
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
* </pre>
* @param name 分组名字(30个字符以内)
* @throws WxErrorException
*/
public WxMpGroup groupCreate(String name) throws WxErrorException;
/**
* <pre>
* 分组管理接口 - 查询所有分组
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
* </pre>
* @return
* @throws WxErrorException
*/
public List<WxMpGroup> groupGet() throws WxErrorException;
/**
* <pre>
* 分组管理接口 - 查询用户所在分组
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
* </pre>
* @param openid 微信用户的openid
* @throws WxErrorException
*/
public long userGetGroup(String openid) throws WxErrorException;
/**
* <pre>
* 分组管理接口 - 修改分组名
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
*
* 如果id为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
* </pre>
* @param group 要更新的group,group的id,name必须设置
* @throws WxErrorException
*/
public void groupUpdate(WxMpGroup group) throws WxErrorException;
/**
* <pre>
* 分组管理接口 - 移动用户分组
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
*
* 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
* </pre>
* @param openid 用户openid
* @param to_groupid 移动到的分组id
* @throws WxErrorException
*/
public void userUpdateGroup(String openid, long to_groupid) throws WxErrorException;
/**
* <pre>
* 设置用户备注名接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=设置用户备注名接口
* </pre>
* @param openid 用户openid
* @param remark 备注名
* @throws WxErrorException
*/
public void userUpdateRemark(String openid, String remark) throws WxErrorException;
/**
* <pre>
* 获取用户基本信息
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取用户基本信息
* </pre>
* @param openid 用户openid
* @param lang 语言,zh_CN 简体(默认),zh_TW 繁体,en 英语
* @return
* @throws WxErrorException
*/
public WxMpUser userInfo(String openid, String lang) throws WxErrorException;
/**
* <pre>
* 获取关注者列表
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取关注者列表
* </pre>
* @param next_openid 可选,第一个拉取的OPENID,null为从头开始拉取
* @return
* @throws WxErrorException
*/
public WxMpUserList userList(String next_openid) throws WxErrorException;
/**
* <pre>
* 换取临时二维码ticket
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
* </pre>
* @param scene_id 参数。
* @param expire_seconds 过期秒数,默认60秒,最小60秒,最大1800秒
* @return
* @throws WxErrorException
*/
public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException;
/**
* <pre>
* 换取永久二维码ticket
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
* </pre>
* @param scene_id 参数。永久二维码时最大值为100000(目前参数只支持1--100000)
* @return
* @throws WxErrorException
*/
public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException;
/**
* <pre>
* 换取永久字符串二维码ticket
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
* </pre>
*
* @param scene_str 参数。字符串类型长度现在为1到64
* @return
* @throws WxErrorException
*/
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException;
/**
* <pre>
* 换取二维码图片文件,jpg格式
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
* </pre>
* @param ticket 二维码ticket
* @return
* @throws WxErrorException
*/
public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException;
/**
* <pre>
* 换取二维码图片url地址
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
* </pre>
* @param ticket 二维码ticket
* @return
* @throws WxErrorException
*/
public String qrCodePictureUrl(String ticket) throws WxErrorException;
/**
* <pre>
* 长链接转短链接接口
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=长链接转短链接接口
* </pre>
* @param long_url
* @return
* @throws WxErrorException
*/
public String shortUrl(String long_url) throws WxErrorException;
/**
* <pre>
* 发送模板消息
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=模板消息接口
* </pre>
* @param templateMessage
* @throws WxErrorException
* @return msgid
*/
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException;
/**
* <pre>
* 语义查询接口
* 详情请见:http://mp.weixin.qq.com/wiki/index.php?title=语义理解
* </pre>
* @param semanticQuery
* @return
* @throws WxErrorException
*/
WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) throws WxErrorException;
/**
* <pre>
* 构造oauth2授权的url连接
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
* </pre>
* @param scope
* @param state
* @return url
*/
public String oauth2buildAuthorizationUrl(String scope, String state);
/**
* <pre>
* 构造oauth2授权的url连接
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
* </pre>
* @param redirectURI
* 用户授权完成后的重定向链接,无需urlencode, 方法内会进行encode
* @param scope
* @param state
* @return url
*/
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state);
/**
* <pre>
* 用code换取oauth2的access token
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
* </pre>
* @param code
* @return
*/
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException;
/**
* <pre>
* 刷新oauth2的access token
* </pre>
* @param refreshToken
* @return
*/
public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException;
/**
* <pre>
* 用oauth2获取用户信息, 当前面引导授权时的scope是snsapi_userinfo的时候才可以
* </pre>
* @param oAuth2AccessToken
* @param lang zh_CN, zh_TW, en
*/
public WxMpUser oauth2getUserInfo(WxMpOAuth2AccessToken oAuth2AccessToken, String lang) throws WxErrorException;
/**
* <pre>
* 验证oauth2的access token是否有效
* </pre>
* @param oAuth2AccessToken
* @return
*/
public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken oAuth2AccessToken);
/**
* <pre>
* 获取微信服务器IP地址
* http://mp.weixin.qq.com/wiki/0/2ad4b6bfd29f30f71d39616c2a0fcedc.html
* </pre>
* @return
* @throws WxErrorException
*/
String[] getCallbackIP() throws WxErrorException;
/**
* <pre>
* 获取用户增减数据
* http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
* </pre>
* @param beginDate 最大时间跨度7天
* @param endDate endDate不能早于begingDate
* @return
* @throws WxErrorException
*/
List<WxMpUserSummary> getUserSummary(Date beginDate, Date endDate) throws WxErrorException;
/**
* <pre>
* 获取累计用户数据
* http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
* </pre>
* @param beginDate 最大时间跨度7天
* @param endDate endDate不能早于begingDate
* @return
* @throws WxErrorException
*/
List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException;
/**
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
* @param url
* @param queryParam
* @return
* @throws WxErrorException
*/
String get(String url, String queryParam) throws WxErrorException;
/**
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求
* @param url
* @param postData
* @return
* @throws WxErrorException
*/
String post(String url, String postData) throws WxErrorException;
/**
* <pre>
* Service没有实现某个API的时候,可以用这个,
* 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
* 可以参考,{@link me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor}的实现方法
* </pre>
* @param executor
* @param uri
* @param data
* @param <T>
* @param <E>
* @return
* @throws WxErrorException
*/
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
/**
* 注入 {@link WxMpConfigStorage} 的实现
* @param wxConfigProvider
*/
public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider);
/**
* <pre>
* 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试
* 默认:1000ms
* </pre>
* @param retrySleepMillis
*/
void setRetrySleepMillis(int retrySleepMillis);
/**
* <pre>
* 设置当微信系统响应系统繁忙时,最大重试次数
* 默认:5次
* </pre>
* @param maxRetryTimes
*/
void setMaxRetryTimes(int maxRetryTimes);
/**
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
* @param openId 支付人openId
* @param outTradeNo 商户端对应订单号
* @param amt 金额(单位元)
* @param body 商品描述
* @param tradeType 交易类型 JSAPI,NATIVE,APP,WAP
* @param ip 发起支付的客户端IP
* @param notifyUrl 通知地址
* @return
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPrepayId(Map<String, String>) instead
*/
@Deprecated
WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl);
/**
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
*
* @param parameters
* All required/optional parameters for weixin payment
* @return
* @throws IllegalArgumentException
*/
WxMpPrepayIdResult getPrepayId(Map<String, String> parameters);
/**
* 该接口调用“统一下单”接口,并拼装JSSDK发起支付请求需要的参数
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
* @param parameters
* the required or optional parameters
* @return
* @throws WxErrorException
*/
Map<String, String> getJSSDKPayInfo(Map<String, String> parameters) throws WxErrorException;
/**
* 该接口调用“统一下单”接口,并拼装JSSDK发起支付请求需要的参数
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
* @param openId 支付人openId
* @param outTradeNo 商户端对应订单号
* @param amt 金额(单位元)
* @param body 商品描述
* @param tradeType 交易类型 JSAPI,NATIVE,APP,WAP
* @param ip 发起支付的客户端IP
* @param notifyUrl 通知地址
* @return
* @throws WxErrorException
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getJSSDKPayInfo(Map<String, String>) instead
*/
@Deprecated
Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl) throws WxErrorException;
/**
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
* @param transactionId
* @param outTradeNo
*/
WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo);
/**
* 读取支付结果通知
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
* @param xmlData
* @return
*/
WxMpPayCallback getJSSDKCallbackData(String xmlData);
/**
* 微信支付-申请退款
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
* @param parameters 需要传入的退款参数的Map。以下几项为参数的必须项:<br/>
* <li/> transaction_id
* <li/> out_trade_no (仅在上述transaction_id为空时是必须项)
* <li/> out_refund_no
* <li/> total_fee
* <li/> refund_fee
* @return 退款操作结果
* @throws WxErrorException
*/
public WxMpPayRefundResult refundPay(Map<String, String> parameters) throws WxErrorException;
/**
* <pre>
* 计算Map键值对是否和签名相符,
* 按照字段名的 ASCII 码从小到大排序(字典序)后,使用 URL 键值对的 格式(即 key1=value1&key2=value2...)拼接成字符串
* </pre>
* @param kvm
* @param signature
* @return
*/
public boolean checkJSSDKCallbackDataSignature(Map<String, String> kvm, String signature);
/**
* 发送微信红包给个人用户
*
* 需要传入的必填参数如下:
* mch_billno//商户订单号
* send_name//商户名称
* re_openid//用户openid
* total_amount//红包总额
* total_num//红包发放总人数
* wishing//红包祝福语
* client_ip//服务器Ip地址
* act_name//活动名称
* remark //备注
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5
*
* 使用现金红包功能需要在xml配置文件中额外设置:
* <partnerId></partnerId>微信商户平台ID
* <partnerKey></partnerKey>商户平台设置的API密钥
*
* @param parameters
* @return
* @throws WxErrorException
*/
public WxRedpackResult sendRedpack(Map<String, String> parameters) throws WxErrorException;
/**
* 获得卡券api_ticket,不强制刷新卡券api_ticket
* @see #getCardApiTicket(boolean)
* @return 卡券api_ticket
* @throws WxErrorException
*/
public String getCardApiTicket() throws WxErrorException;
/**
* <pre>
* 获得卡券api_ticket
* 获得时会检查卡券apiToken是否过期,如果过期了,那么就刷新一下,否则就什么都不干
*
* 详情请见:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD.954-.E5.8D.A1.E5.88.B8.E6.89.A9.E5.B1.95.E5.AD.97.E6.AE.B5.E5.8F.8A.E7.AD.BE.E5.90.8D.E7.94.9F.E6.88.90.E7.AE.97.E6.B3.95
* </pre>
* @param forceRefresh 强制刷新
* @return 卡券api_ticket
* @throws WxErrorException
*/
public String getCardApiTicket(boolean forceRefresh) throws WxErrorException;
/**
* <pre>
* 创建调用卡券api时所需要的签名
*
* 详情请见:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD
* .954-.E5.8D.A1.E5.88.B8.E6.89.A9.E5.B1.95.E5.AD.97.E6.AE.B5.E5.8F.8A.E7.AD.BE.E5.90.8D.E7.94
* .9F.E6.88.90.E7.AE.97.E6.B3.95
* </pre>
*
* @param optionalSignParam 参与签名的参数数组。
* 可以为下列字段:app_id, card_id, card_type, code, openid, location_id
* </br>注意:当做wx.chooseCard调用时,必须传入app_id参与签名,否则会造成签名失败导致拉取卡券列表为空
* @return 卡券Api签名对象
*/
public WxCardApiSignature createCardApiSignature(String... optionalSignParam) throws
WxErrorException;
/**
* 卡券Code解码
* @param encryptCode 加密Code,通过JSSDK的chooseCard接口获得
* @return 解密后的Code
* @throws WxErrorException
*/
public String decryptCardCode(String encryptCode) throws WxErrorException;
/**
* 卡券Code查询
* @param cardId 卡券ID代表一类卡券
* @param code 单张卡券的唯一标准
* @param checkConsume 是否校验code核销状态,填入true和false时的code异常状态返回数据不同
* @return WxMpCardResult对象
* @throws WxErrorException
*/
public WxMpCardResult queryCardCode(String cardId, String code, boolean checkConsume)
throws WxErrorException;
/**
* 卡券Code核销。核销失败会抛出异常
*
* @param code 单张卡券的唯一标准
* @return 调用返回的JSON字符串。
* <br>可用 com.google.gson.JsonParser#parse 等方法直接取JSON串中的errcode等信息。
* @throws WxErrorException
*/
public String consumeCardCode(String code) throws WxErrorException;
/**
* 卡券Code核销。核销失败会抛出异常
*
* @param code 单张卡券的唯一标准
* @param cardId 当自定义Code卡券时需要传入card_id
* @return 调用返回的JSON字符串。
* <br>可用 com.google.gson.JsonParser#parse 等方法直接取JSON串中的errcode等信息。
* @throws WxErrorException
*/
public String consumeCardCode(String code, String cardId) throws WxErrorException;
/**
* 卡券Mark接口。
* 开发者在帮助消费者核销卡券之前,必须帮助先将此code(卡券串码)与一个openid绑定(即mark住),
* 才能进一步调用核销接口,否则报错。
* @param code 卡券的code码
* @param cardId 卡券的ID
* @param openId 用券用户的openid
* @param isMark 是否要mark(占用)这个code,填写true或者false,表示占用或解除占用
* @throws WxErrorException
*/
public void markCardCode(String code, String cardId, String openId, boolean isMark) throws
WxErrorException;
/**
* 查看卡券详情接口
* 详见 https://mp.weixin.qq.com/wiki/14/8dd77aeaee85f922db5f8aa6386d385e.html#.E6.9F.A5.E7.9C.8B.E5.8D.A1.E5.88.B8.E8.AF.A6.E6.83.85
* @param cardId 卡券的ID
* @return 返回的卡券详情JSON字符串
* <br> [注] 由于返回的JSON格式过于复杂,难以定义其对应格式的Bean并且难以维护,因此只返回String格式的JSON串。
* <br> 可由 com.google.gson.JsonParser#parse 等方法直接取JSON串中的某个字段。
* @throws WxErrorException
*/
public String getCardDetail(String cardId) throws WxErrorException;
/*
* <pre>
* 预览接口
* 详情请见:http://mp.weixin.qq.com/wiki/15/40b6865b893947b764e2de8e4a1fb55f.html#.E9.A2.84.E8.A7.88.E6.8E.A5.E5.8F.A3.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91
* </pre>
* @param wxMpMassPreviewMessage
* @return wxMpMassSendResult
* @throws WxErrorException
*/
public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception;
}