Skip to content

Commit d659e5b

Browse files
committed
开放low-level方法,当本项目跟不上微信api的更新速度的时候,开发人员还可以使用
1 parent 294ad07 commit d659e5b

4 files changed

Lines changed: 91 additions & 5 deletions

File tree

‎weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import me.chanjar.weixin.common.bean.WxMenu;
99
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
10+
import me.chanjar.weixin.common.util.http.RequestExecutor;
1011
import me.chanjar.weixin.cp.bean.*;
1112
import me.chanjar.weixin.cp.bean.WxCpDepart;
1213
import me.chanjar.weixin.cp.bean.WxCpUser;
@@ -65,8 +66,8 @@ public interface WxCpService {
6566
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
6667
* </pre>
6768
*
68-
* @param mediaType 媒体类型, 请看{@link WxConsts}
69-
* @param fileType 文件类型,请看{@link WxConsts}
69+
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
70+
* @param fileType 文件类型,请看{@link me.chanjar.weixin.common.api.WxConsts}
7071
* @param inputStream 输入流
7172
* @throws WxErrorException
7273
*/
@@ -281,6 +282,40 @@ public WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputS
281282
*/
282283
public void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorException;
283284

285+
/**
286+
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
287+
* @param url
288+
* @param queryParam
289+
* @return
290+
* @throws WxErrorException
291+
*/
292+
String get(String url, String queryParam) throws WxErrorException;
293+
294+
/**
295+
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求
296+
* @param url
297+
* @param postData
298+
* @return
299+
* @throws WxErrorException
300+
*/
301+
String post(String url, String postData) throws WxErrorException;
302+
303+
/**
304+
* <pre>
305+
* Service没有实现某个API的时候,可以用这个,
306+
* 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
307+
* 可以参考,{@link me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor}的实现方法
308+
* </pre>
309+
* @param executor
310+
* @param uri
311+
* @param data
312+
* @param <T>
313+
* @param <E>
314+
* @return
315+
* @throws WxErrorException
316+
*/
317+
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
318+
284319
/**
285320
* 注入 {@link WxCpConfigStorage} 的实现
286321
*

‎weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ public void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorExc
308308
execute(new SimplePostRequestExecutor(), url, jsonObject.toString());
309309
}
310310

311+
public String get(String url, String queryParam) throws WxErrorException {
312+
return execute(new SimpleGetRequestExecutor(), url, queryParam);
313+
}
314+
315+
public String post(String url, String postData) throws WxErrorException {
316+
return execute(new SimplePostRequestExecutor(), url, postData);
317+
}
318+
311319
/**
312320
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
313321
*

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import me.chanjar.weixin.common.bean.WxMenu;
44
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
5+
import me.chanjar.weixin.common.util.http.RequestExecutor;
56
import me.chanjar.weixin.mp.bean.*;
67
import me.chanjar.weixin.mp.bean.result.*;
78
import me.chanjar.weixin.common.exception.WxErrorException;
@@ -318,8 +319,42 @@ public interface WxMpService {
318319
public void templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException;
319320

320321
/**
321-
* 注入 {@link WxMpConfigStorage} 的实现
322-
* @param wxConfigProvider
322+
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
323+
* @param url
324+
* @param queryParam
325+
* @return
326+
* @throws WxErrorException
327+
*/
328+
String get(String url, String queryParam) throws WxErrorException;
329+
330+
/**
331+
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求
332+
* @param url
333+
* @param postData
334+
* @return
335+
* @throws WxErrorException
323336
*/
337+
String post(String url, String postData) throws WxErrorException;
338+
339+
/**
340+
* <pre>
341+
* Service没有实现某个API的时候,可以用这个,
342+
* 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
343+
* 可以参考,{@link me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor}的实现方法
344+
* </pre>
345+
* @param executor
346+
* @param uri
347+
* @param data
348+
* @param <T>
349+
* @param <E>
350+
* @return
351+
* @throws WxErrorException
352+
*/
353+
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
354+
355+
/**
356+
* 注入 {@link WxMpConfigStorage} 的实现
357+
* @param wxConfigProvider
358+
*/
324359
public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider);
325360
}

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,15 @@ public void templateSend(WxMpTemplateMessage templateMessage) throws WxErrorExce
279279
execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
280280
}
281281

282-
/**
282+
public String get(String url, String queryParam) throws WxErrorException {
283+
return execute(new SimpleGetRequestExecutor(), url, queryParam);
284+
}
285+
286+
public String post(String url, String postData) throws WxErrorException {
287+
return execute(new SimplePostRequestExecutor(), url, postData);
288+
}
289+
290+
/**
283291
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
284292
* @param executor
285293
* @param uri

0 commit comments

Comments
 (0)