WxMaService.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package cn.binarywang.wx.miniapp.api;
  2. import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
  3. import cn.binarywang.wx.miniapp.config.WxMaConfig;
  4. import me.chanjar.weixin.common.error.WxErrorException;
  5. import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
  6. import me.chanjar.weixin.common.util.http.RequestExecutor;
  7. import me.chanjar.weixin.common.util.http.RequestHttp;
  8. /**
  9. * @author <a href="https://github.com/binarywang">Binary Wang</a>
  10. */
  11. public interface WxMaService {
  12. /**
  13. * 获取access_token.
  14. */
  15. String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
  16. String JSCODE_TO_SESSION_URL = "https://api.weixin.qq.com/sns/jscode2session";
  17. /**
  18. * 获取登录后的session信息.
  19. *
  20. * @param jsCode 登录时获取的 code
  21. */
  22. WxMaJscode2SessionResult jsCode2SessionInfo(String jsCode) throws WxErrorException;
  23. /**
  24. * <pre>
  25. * 验证消息的确来自微信服务器.
  26. * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319&token=&lang=zh_CN
  27. * </pre>
  28. */
  29. boolean checkSignature(String timestamp, String nonce, String signature);
  30. /**
  31. * 获取access_token, 不强制刷新access_token.
  32. *
  33. * @see #getAccessToken(boolean)
  34. */
  35. String getAccessToken() throws WxErrorException;
  36. /**
  37. * <pre>
  38. * 获取access_token,本方法线程安全.
  39. * 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限
  40. *
  41. * 另:本service的所有方法都会在access_token过期是调用此方法
  42. *
  43. * 程序员在非必要情况下尽量不要主动调用此方法
  44. *
  45. * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183&token=&lang=zh_CN
  46. * </pre>
  47. *
  48. * @param forceRefresh 强制刷新
  49. */
  50. String getAccessToken(boolean forceRefresh) throws WxErrorException;
  51. /**
  52. * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求.
  53. */
  54. String get(String url, String queryParam) throws WxErrorException;
  55. /**
  56. * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求.
  57. */
  58. String post(String url, String postData) throws WxErrorException;
  59. /**
  60. * <pre>
  61. * Service没有实现某个API的时候,可以用这个,
  62. * 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
  63. * 可以参考,{@link MediaUploadRequestExecutor}的实现方法
  64. * </pre>
  65. */
  66. <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
  67. /**
  68. * <pre>
  69. * 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试.
  70. * 默认:1000ms
  71. * </pre>
  72. */
  73. void setRetrySleepMillis(int retrySleepMillis);
  74. /**
  75. * <pre>
  76. * 设置当微信系统响应系统繁忙时,最大重试次数.
  77. * 默认:5次
  78. * </pre>
  79. */
  80. void setMaxRetryTimes(int maxRetryTimes);
  81. /**
  82. * 获取WxMaConfig 对象.
  83. *
  84. * @return WxMaConfig
  85. */
  86. WxMaConfig getWxMaConfig();
  87. /**
  88. * 注入 {@link WxMaConfig} 的实现.
  89. */
  90. void setWxMaConfig(WxMaConfig wxConfigProvider);
  91. /**
  92. * 返回消息(客服消息和模版消息)发送接口方法实现类,以方便调用其各个接口.
  93. *
  94. * @return WxMaMsgService
  95. */
  96. WxMaMsgService getMsgService();
  97. /**
  98. * 返回素材相关接口方法的实现类对象,以方便调用其各个接口.
  99. *
  100. * @return WxMaMediaService
  101. */
  102. WxMaMediaService getMediaService();
  103. /**
  104. * 返回用户相关接口方法的实现类对象,以方便调用其各个接口.
  105. *
  106. * @return WxMaUserService
  107. */
  108. WxMaUserService getUserService();
  109. /**
  110. * 返回二维码相关接口方法的实现类对象,以方便调用其各个接口.
  111. *
  112. * @return WxMaQrcodeService
  113. */
  114. WxMaQrcodeService getQrcodeService();
  115. /**
  116. * 返回模板配置相关接口方法的实现类对象, 以方便调用其各个接口.
  117. *
  118. * @return WxMaTemplateService
  119. */
  120. WxMaTemplateService getTemplateService();
  121. /**
  122. * 数据分析相关查询服务.
  123. *
  124. * @return WxMaAnalysisService
  125. */
  126. WxMaAnalysisService getAnalysisService();
  127. /**
  128. * 返回代码操作相关的 API.
  129. *
  130. * @return WxMaCodeService
  131. */
  132. WxMaCodeService getCodeService();
  133. /**
  134. * 返回jsapi操作相关的 API服务类对象.
  135. *
  136. * @return WxMaJsapiService
  137. */
  138. WxMaJsapiService getJsapiService();
  139. /**
  140. * 小程序修改服务器地址、成员管理 API.
  141. *
  142. * @return WxMaSettingService
  143. */
  144. WxMaSettingService getSettingService();
  145. /**
  146. * 返回分享相关查询服务.
  147. * @return WxMaShareService
  148. */
  149. WxMaShareService getShareService();
  150. /**
  151. * 返回微信运动相关接口服务对象.
  152. * @return WxMaShareService
  153. */
  154. WxMaRunService getRunService();
  155. /**
  156. * 返回内容安全相关接口服务对象.
  157. * @return WxMaShareService
  158. */
  159. WxMaSecCheckService getSecCheckService();
  160. /**
  161. * 初始化http请求对象.
  162. */
  163. void initHttp();
  164. /**
  165. * 请求http请求相关信息.
  166. */
  167. RequestHttp getRequestHttp();
  168. }