WxMaConfig.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. package cn.binarywang.wx.miniapp.config;
  2. import java.util.concurrent.locks.Lock;
  3. import java.util.function.Consumer;
  4. import me.chanjar.weixin.common.bean.WxAccessToken;
  5. import me.chanjar.weixin.common.bean.WxAccessTokenEntity;
  6. import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
  7. /**
  8. * 小程序配置
  9. *
  10. * @author <a href="https://github.com/binarywang">Binary Wang</a>
  11. */
  12. public interface WxMaConfig {
  13. default void setUpdateAccessTokenBefore(Consumer<WxAccessTokenEntity> updateAccessTokenBefore) {}
  14. /**
  15. * Gets access token.
  16. *
  17. * @return the access token
  18. */
  19. String getAccessToken();
  20. // region 稳定版access token
  21. boolean isStableAccessToken();
  22. void useStableAccessToken(boolean useStableAccessToken);
  23. // endregion
  24. /**
  25. * Gets access token lock.
  26. *
  27. * @return the access token lock
  28. */
  29. Lock getAccessTokenLock();
  30. /**
  31. * Is access token expired boolean.
  32. *
  33. * @return the boolean
  34. */
  35. boolean isAccessTokenExpired();
  36. /** 强制将access token过期掉 */
  37. void expireAccessToken();
  38. /**
  39. * 应该是线程安全的
  40. *
  41. * @param accessToken 要更新的WxAccessToken对象
  42. */
  43. default void updateAccessToken(WxAccessToken accessToken) {
  44. updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
  45. }
  46. /**
  47. * 应该是线程安全的
  48. *
  49. * @param accessToken 新的accessToken值
  50. * @param expiresInSeconds 过期时间,以秒为单位
  51. */
  52. void updateAccessToken(String accessToken, int expiresInSeconds);
  53. default void updateAccessTokenProcessor(String accessToken, int expiresInSeconds) {
  54. WxAccessTokenEntity wxAccessTokenEntity = new WxAccessTokenEntity();
  55. wxAccessTokenEntity.setAppid(getAppid());
  56. wxAccessTokenEntity.setAccessToken(accessToken);
  57. wxAccessTokenEntity.setExpiresIn(expiresInSeconds);
  58. updateAccessTokenBefore(wxAccessTokenEntity);
  59. updateAccessToken(accessToken, expiresInSeconds);
  60. }
  61. default void updateAccessTokenBefore(WxAccessTokenEntity wxAccessTokenEntity) {}
  62. /**
  63. * Gets jsapi ticket.
  64. *
  65. * @return the jsapi ticket
  66. */
  67. String getJsapiTicket();
  68. /**
  69. * Gets jsapi ticket lock.
  70. *
  71. * @return the jsapi ticket lock
  72. */
  73. Lock getJsapiTicketLock();
  74. /**
  75. * Is jsapi ticket expired boolean.
  76. *
  77. * @return the boolean
  78. */
  79. boolean isJsapiTicketExpired();
  80. /** 强制将jsapi ticket过期掉 */
  81. void expireJsapiTicket();
  82. /**
  83. * 应该是线程安全的
  84. *
  85. * @param jsapiTicket 新的jsapi ticket值
  86. * @param expiresInSeconds 过期时间,以秒为单位
  87. */
  88. void updateJsapiTicket(String jsapiTicket, int expiresInSeconds);
  89. /**
  90. * 卡券api_ticket.
  91. *
  92. * @return the card api ticket
  93. */
  94. String getCardApiTicket();
  95. /**
  96. * Gets card api ticket lock.
  97. *
  98. * @return the card api ticket lock
  99. */
  100. Lock getCardApiTicketLock();
  101. /**
  102. * Is card api ticket expired boolean.
  103. *
  104. * @return the boolean
  105. */
  106. boolean isCardApiTicketExpired();
  107. /** 强制将卡券api ticket过期掉. */
  108. void expireCardApiTicket();
  109. /**
  110. * 应该是线程安全的.
  111. *
  112. * @param apiTicket 新的卡券api ticket值
  113. * @param expiresInSeconds 过期时间,以秒为单位
  114. */
  115. void updateCardApiTicket(String apiTicket, int expiresInSeconds);
  116. /**
  117. * Gets appid.
  118. *
  119. * @return the appid
  120. */
  121. String getAppid();
  122. /**
  123. * Gets secret.
  124. *
  125. * @return the secret
  126. */
  127. String getSecret();
  128. /**
  129. * Gets token.
  130. *
  131. * @return the token
  132. */
  133. String getToken();
  134. /**
  135. * Gets aes key.
  136. *
  137. * @return the aes key
  138. */
  139. String getAesKey();
  140. /**
  141. * Gets original id.
  142. *
  143. * @return the original id
  144. */
  145. String getOriginalId();
  146. /**
  147. * Gets cloud env.
  148. *
  149. * @return the cloud env
  150. */
  151. String getCloudEnv();
  152. /**
  153. * Gets msg data format.
  154. *
  155. * @return the msg data format
  156. */
  157. String getMsgDataFormat();
  158. /**
  159. * Gets expires time.
  160. *
  161. * @return the expires time
  162. */
  163. long getExpiresTime();
  164. /**
  165. * Gets http proxy host.
  166. *
  167. * @return the http proxy host
  168. */
  169. String getHttpProxyHost();
  170. /**
  171. * Gets http proxy port.
  172. *
  173. * @return the http proxy port
  174. */
  175. int getHttpProxyPort();
  176. /**
  177. * Gets http proxy username.
  178. *
  179. * @return the http proxy username
  180. */
  181. String getHttpProxyUsername();
  182. /**
  183. * Gets http proxy password.
  184. *
  185. * @return the http proxy password
  186. */
  187. String getHttpProxyPassword();
  188. /**
  189. * http 请求重试间隔
  190. *
  191. * <pre>
  192. * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
  193. * </pre>
  194. */
  195. int getRetrySleepMillis();
  196. /**
  197. * http 请求最大重试次数
  198. *
  199. * <pre>
  200. * {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
  201. * </pre>
  202. */
  203. int getMaxRetryTimes();
  204. /**
  205. * http client builder
  206. *
  207. * @return ApacheHttpClientBuilder apache http client builder
  208. */
  209. ApacheHttpClientBuilder getApacheHttpClientBuilder();
  210. /**
  211. * 是否自动刷新token
  212. *
  213. * @return the boolean
  214. */
  215. boolean autoRefreshToken();
  216. /**
  217. * 设置自定义的apiHost地址
  218. * 具体取值,可以参考https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Interface_field_description.html
  219. *
  220. * @param apiHostUrl api域名地址
  221. */
  222. void setApiHostUrl(String apiHostUrl);
  223. /**
  224. * 获取自定义的apiHost地址,用于替换原请求中的https://api.weixin.qq.com
  225. * 具体取值,可以参考https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Interface_field_description.html
  226. *
  227. * @return 自定义的api域名地址
  228. */
  229. String getApiHostUrl();
  230. /**
  231. * 获取自定义的获取accessToken地址,用于向自定义统一服务获取accessToken
  232. *
  233. * @return 自定义的获取accessToken地址
  234. */
  235. String getAccessTokenUrl();
  236. /**
  237. * 设置自定义的获取accessToken地址 可用于设置获取accessToken的自定义服务
  238. *
  239. * @param accessTokenUrl 自定义的获取accessToken地址
  240. */
  241. void setAccessTokenUrl(String accessTokenUrl);
  242. /**
  243. * 服务端API签名用到的RSA私钥【pkcs8格式,会以 -----BEGIN PRIVATE KEY-----开头, 'BEGIN RSA PRIVATE
  244. * KEY'的是pkcs1格式,需要转换(可用openssl转换)。 设置参考:
  245. * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/getting_started/api_signature.html
  246. *
  247. * @return rsa private key string
  248. */
  249. String getApiSignatureRsaPrivateKey();
  250. /**
  251. * 服务端API签名用到的AES密钥
  252. * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/getting_started/api_signature.html
  253. *
  254. * @return aes key string
  255. */
  256. String getApiSignatureAesKey();
  257. /** 密钥对应的序号 */
  258. String getApiSignatureAesKeySn();
  259. /** 密钥对应的序号 */
  260. String getApiSignatureRsaPrivateKeySn();
  261. /** 密钥对应的小程序ID (普通小程序同 appId, 托管第三方平台的是 componentAppId) */
  262. String getWechatMpAppid();
  263. }