forked from binarywang/WxJava
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWxCpService.java
556 lines (493 loc) · 15.5 KB
/
WxCpService.java
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
package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.service.WxService;
import me.chanjar.weixin.common.session.WxSession;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.cp.bean.WxCpAgentJsapiSignature;
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
/**
* 微信API的Service.
*
* @author chanjaster
*/
public interface WxCpService extends WxService {
/**
* <pre>
* 验证推送过来的消息的正确性
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=验证消息真实性
* </pre>
*
* @param msgSignature 消息签名
* @param timestamp 时间戳
* @param nonce 随机数
* @param data 微信传输过来的数据,有可能是echoStr,有可能是xml消息
* @return the boolean
*/
boolean checkSignature(String msgSignature, String timestamp, String nonce, String data);
/**
* 获取access_token, 不强制刷新access_token
*
* @return the access token
* @throws WxErrorException the wx error exception
* @see #getAccessToken(boolean) #getAccessToken(boolean)#getAccessToken(boolean)
*/
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 the access token
* @throws WxErrorException the wx error exception
*/
String getAccessToken(boolean forceRefresh) throws WxErrorException;
/**
* 获得jsapi_ticket,不强制刷新jsapi_ticket
*
* @return the jsapi ticket
* @throws WxErrorException the wx error exception
* @see #getJsapiTicket(boolean) #getJsapiTicket(boolean)#getJsapiTicket(boolean)
*/
String getJsapiTicket() throws WxErrorException;
/**
* <pre>
* 获得jsapi_ticket
* 获得时会检查jsapiToken是否过期,如果过期了,那么就刷新一下,否则就什么都不干
*
* 详情请见:http://qydev.weixin.qq.com/wiki/index.php?title=微信JS接口#.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 the jsapi ticket
* @throws WxErrorException the wx error exception
*/
String getJsapiTicket(boolean forceRefresh) throws WxErrorException;
/**
* 获得jsapi_ticket,不强制刷新jsapi_ticket
* 应用的jsapi_ticket用于计算agentConfig(参见“通过agentConfig注入应用的权限”)的签名,签名计算方法与上述介绍的config的签名算法完全相同,但需要注意以下区别:
* <p>
* 签名的jsapi_ticket必须使用以下接口获取。且必须用wx.agentConfig中的agentid对应的应用secret去获取access_token。
* 签名用的noncestr和timestamp必须与wx.agentConfig中的nonceStr和timestamp相同。
*
* @return the agent jsapi ticket
* @throws WxErrorException the wx error exception
* @see #getJsapiTicket(boolean) #getJsapiTicket(boolean)#getJsapiTicket(boolean)
*/
String getAgentJsapiTicket() throws WxErrorException;
/**
* <pre>
* 获取应用的jsapi_ticket
* 应用的jsapi_ticket用于计算agentConfig(参见“通过agentConfig注入应用的权限”)的签名,签名计算方法与上述介绍的config的签名算法完全相同,但需要注意以下区别:
*
* 签名的jsapi_ticket必须使用以下接口获取。且必须用wx.agentConfig中的agentid对应的应用secret去获取access_token。
* 签名用的noncestr和timestamp必须与wx.agentConfig中的nonceStr和timestamp相同。
*
* 获得时会检查jsapiToken是否过期,如果过期了,那么就刷新一下,否则就什么都不干
*
* 详情请见:https://work.weixin.qq.com/api/doc#10029/%E8%8E%B7%E5%8F%96%E5%BA%94%E7%94%A8%E7%9A%84jsapi_ticket
* </pre>
*
* @param forceRefresh 强制刷新
* @return the agent jsapi ticket
* @throws WxErrorException the wx error exception
*/
String getAgentJsapiTicket(boolean forceRefresh) throws WxErrorException;
/**
* <pre>
* 创建调用jsapi时所需要的签名
*
* 详情请见:http://qydev.weixin.qq.com/wiki/index.php?title=微信JS接口#.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 the wx jsapi signature
* @throws WxErrorException the wx error exception
*/
WxJsapiSignature createJsapiSignature(String url) throws WxErrorException;
/**
* <pre>
* 创建调用wx.agentConfig时所需要的签名
*
* 详情请见:https://open.work.weixin.qq.com/api/doc/90000/90136/94313
* </pre>
*
* @param url url
* @return the agent jsapi signature
* @throws WxErrorException
*/
WxCpAgentJsapiSignature createAgentJsapiSignature(String url) throws WxErrorException;
/**
* 小程序登录凭证校验
*
* @param jsCode 登录时获取的 code
* @return the wx cp ma js code 2 session result
* @throws WxErrorException the wx error exception
*/
WxCpMaJsCode2SessionResult jsCode2Session(String jsCode) throws WxErrorException;
/**
* <pre>
* 获取微信服务器的ip段
* http://qydev.weixin.qq.com/wiki/index.php?title=回调模式#.E8.8E.B7.E5.8F.96.E5.BE.AE.E4.BF.A1.E6.9C.8D.E5.8A.A1.E5.99.A8.E7.9A.84ip.E6.AE.B5
* </pre>
*
* @return { "ip_list": ["101.226.103.*", "101.226.62.*"] }
* @throws WxErrorException the wx error exception
*/
String[] getCallbackIp() throws WxErrorException;
/**
* <pre>
* 获取服务商凭证
* 文档地址:https://work.weixin.qq.com/api/doc#90001/90143/91200
* 请求方式:POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token
* </pre>
*
* @param corpId 服务商的corpid
* @param providerSecret 服务商的secret,在服务商管理后台可见
* @return { "errcode":0 , "errmsg":"ok" , "provider_access_token":"enLSZ5xxxxxxJRL", "expires_in":7200 }
* @throws WxErrorException .
*/
WxCpProviderToken getProviderToken(String corpId, String providerSecret) throws WxErrorException;
/**
* 当不需要自动带accessToken的时候,可以用这个发起post请求
*
* @param url 接口地址
* @param postData 请求body字符串
* @return the string
* @throws WxErrorException the wx error exception
*/
String postWithoutToken(String url, String postData) throws WxErrorException;
/**
* <pre>
* Service没有实现某个API的时候,可以用这个,
* 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
* 可以参考,{@link MediaUploadRequestExecutor}的实现方法
* </pre>
*
* @param <T> 请求值类型
* @param <E> 返回值类型
* @param executor 执行器
* @param uri 请求地址
* @param data 参数
* @return the t
* @throws WxErrorException the wx error exception
*/
<T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
/**
* <pre>
* 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试
* 默认:1000ms
* </pre>
*
* @param retrySleepMillis 重试休息时间
*/
void setRetrySleepMillis(int retrySleepMillis);
/**
* <pre>
* 设置当微信系统响应系统繁忙时,最大重试次数
* 默认:5次
* </pre>
*
* @param maxRetryTimes 最大重试次数
*/
void setMaxRetryTimes(int maxRetryTimes);
/**
* 获取某个sessionId对应的session,如果sessionId没有对应的session,则新建一个并返回。
*
* @param id id可以为任意字符串,建议使用FromUserName作为id
* @return the session
*/
WxSession getSession(String id);
/**
* 获取某个sessionId对应的session,如果sessionId没有对应的session,若create为true则新建一个,否则返回null。
*
* @param id id可以为任意字符串,建议使用FromUserName作为id
* @param create 是否新建
* @return the session
*/
WxSession getSession(String id, boolean create);
/**
* 获取WxSessionManager 对象
*
* @return WxSessionManager session manager
*/
WxSessionManager getSessionManager();
/**
* <pre>
* 设置WxSessionManager,只有当需要使用个性化的WxSessionManager的时候才需要调用此方法,
* WxCpService默认使用的是{@link me.chanjar.weixin.common.session.StandardSessionManager}
* </pre>
*
* @param sessionManager 会话管理器
*/
void setSessionManager(WxSessionManager sessionManager);
/**
* 上传部门列表覆盖企业号上的部门信息
*
* @param mediaId 媒体id
* @return the string
* @throws WxErrorException the wx error exception
*/
String replaceParty(String mediaId) throws WxErrorException;
/**
* 上传用户列表,增量更新成员
* @param mediaId 媒体id
* @return jobId 异步任务id
* @throws WxErrorException the wx error exception
*/
String syncUser(String mediaId) throws WxErrorException;
/**
* 上传用户列表覆盖企业号上的用户信息
*
* @param mediaId 媒体id
* @return the string
* @throws WxErrorException the wx error exception
*/
String replaceUser(String mediaId) throws WxErrorException;
/**
* 获取异步任务结果
*
* @param jobId 异步任务id
* @return the task result
* @throws WxErrorException the wx error exception
*/
String getTaskResult(String jobId) throws WxErrorException;
/**
* 初始化http请求对象
*/
void initHttp();
/**
* 获取WxCpConfigStorage 对象
*
* @return WxCpConfigStorage wx cp config storage
*/
WxCpConfigStorage getWxCpConfigStorage();
/**
* 注入 {@link WxCpConfigStorage} 的实现
*
* @param wxConfigProvider 配置对象
*/
void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider);
/**
* 构造扫码登录链接 - 构造独立窗口登录二维码
* @param redirectUri 重定向地址,需要进行UrlEncode
* @param state 用于保持请求和回调的状态,授权请求后原样带回给企业。该参数可用于防止csrf攻击(跨站请求伪造攻击),建议企业带上该参数,可设置为简单的随机数加session进行校验
* @return .
*/
String buildQrConnectUrl(String redirectUri, String state);
/**
* 获取部门相关接口的服务类对象
*
* @return the department service
*/
WxCpDepartmentService getDepartmentService();
/**
* 获取媒体相关接口的服务类对象
*
* @return the media service
*/
WxCpMediaService getMediaService();
/**
* 获取菜单相关接口的服务类对象
*
* @return the menu service
*/
WxCpMenuService getMenuService();
/**
* 获取Oauth2相关接口的服务类对象
*
* @return the oauth 2 service
*/
WxCpOAuth2Service getOauth2Service();
/**
* 获取标签相关接口的服务类对象
*
* @return the tag service
*/
WxCpTagService getTagService();
/**
* 获取用户相关接口的服务类对象
*
* @return the user service
*/
WxCpUserService getUserService();
/**
* Gets external contact service.
*
* @return the external contact service
*/
WxCpExternalContactService getExternalContactService();
/**
* 获取群聊服务
*
* @return 群聊服务 chat service
*/
WxCpChatService getChatService();
/**
* 获取任务卡片服务
*
* @return 任务卡片服务 task card service
*/
WxCpTaskCardService getTaskCardService();
/**
* Gets agent service.
*
* @return the agent service
*/
WxCpAgentService getAgentService();
/**
* Gets message service.
*
* @return the message service
*/
WxCpMessageService getMessageService();
/**
* 获取OA相关接口的服务类对象.
*
* @return the oa service
*/
WxCpOaService getOaService();
/**
* 获取家校应用复学码相关接口的服务类对象
*
* @return
*/
WxCpSchoolService getSchoolService();
/**
* 获取家校沟通相关接口的服务类对象
*
* @return
*/
WxCpSchoolUserService getSchoolUserService();
/**
* 获取家校应用健康上报的服务类对象
*
* @return
*/
WxCpSchoolHealthService getSchoolHealthService();
/**
* 获取直播相关接口的服务类对象
*
* @return the Living service
*/
WxCpLivingService getLivingService();
/**
* 获取OA 自建应用相关接口的服务类对象
*
* @return
*/
WxCpOaAgentService getOaAgentService();
/**
* 获取OA效率工具 微盘的服务类对象
*
* @return
*/
WxCpOaWeDriveService getOaWeDriveService();
/**
* 获取会话存档相关接口的服务类对象
*
* @return
*/
WxCpMsgAuditService getMsgAuditService();
/**
* 获取日历相关接口的服务类对象
*
* @return the oa calendar service
*/
WxCpOaCalendarService getOaCalendarService();
/**
* 获取日程相关接口的服务类对象
*
* @return the oa schedule service
*/
WxCpOaScheduleService getOaScheduleService();
/**
* 获取群机器人消息推送服务
*
* @return 群机器人消息推送服务 group robot service
*/
WxCpGroupRobotService getGroupRobotService();
/**
* 获取工作台服务
*
* @return the workbench service
*/
WxCpAgentWorkBenchService getWorkBenchService();
/**
* 获取微信客服服务
*
* @return 微信客服服务
*/
WxCpKfService getKfService();
/**
* http请求对象
*
* @return the request http
*/
RequestHttp<?, ?> getRequestHttp();
/**
* Sets user service.
*
* @param userService the user service
*/
void setUserService(WxCpUserService userService);
/**
* Sets department service.
*
* @param departmentService the department service
*/
void setDepartmentService(WxCpDepartmentService departmentService);
/**
* Sets media service.
*
* @param mediaService the media service
*/
void setMediaService(WxCpMediaService mediaService);
/**
* Sets menu service.
*
* @param menuService the menu service
*/
void setMenuService(WxCpMenuService menuService);
/**
* Sets oauth 2 service.
*
* @param oauth2Service the oauth 2 service
*/
void setOauth2Service(WxCpOAuth2Service oauth2Service);
/**
* Sets tag service.
*
* @param tagService the tag service
*/
void setTagService(WxCpTagService tagService);
/**
* Sets kf service.
*
* @param kfService the kf service
*/
void setKfService(WxCpKfService kfService);
/**
* 获取异步导出服务
*
* @return 异步导出服务
*/
WxCpExportService getExportService();
/**
* 设置异步导出服务
*
* @param exportService 异步导出服务
*/
void setExportService(WxCpExportService exportService);
}