WxMaService.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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.service.WxImgProcService;
  6. import me.chanjar.weixin.common.service.WxOcrService;
  7. import me.chanjar.weixin.common.service.WxService;
  8. import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
  9. import me.chanjar.weixin.common.util.http.RequestExecutor;
  10. import me.chanjar.weixin.common.util.http.RequestHttp;
  11. import java.util.Map;
  12. /**
  13. * The interface Wx ma service.
  14. *
  15. * @author <a href="https://github.com/binarywang">Binary Wang</a>
  16. */
  17. public interface WxMaService extends WxService {
  18. /**
  19. * 获取access_token.
  20. */
  21. String GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
  22. /**
  23. * The constant JSCODE_TO_SESSION_URL.
  24. */
  25. String JSCODE_TO_SESSION_URL = "https://api.weixin.qq.com/sns/jscode2session";
  26. /**
  27. * getPaidUnionId
  28. */
  29. String GET_PAID_UNION_ID_URL = "https://api.weixin.qq.com/wxa/getpaidunionid";
  30. /**
  31. * 导入抽样数据
  32. */
  33. String SET_DYNAMIC_DATA_URL = "https://api.weixin.qq.com/wxa/setdynamicdata";
  34. /**
  35. * 获取登录后的session信息.
  36. *
  37. * @param jsCode 登录时获取的 code
  38. * @return the wx ma jscode 2 session result
  39. * @throws WxErrorException the wx error exception
  40. */
  41. WxMaJscode2SessionResult jsCode2SessionInfo(String jsCode) throws WxErrorException;
  42. /**
  43. * 导入抽样数据
  44. * <pre>
  45. * 第三方通过调用微信API,将数据写入到setdynamicdata这个API。每个Post数据包不超过5K,若数据过多可开多进(线)程并发导入数据(例如:数据量为十万量级可以开50个线程并行导数据)。
  46. * 文档地址:https://wsad.weixin.qq.com/wsad/zh_CN/htmledition/widget-docs-v3/html/custom/quickstart/implement/import/index.html
  47. * http请求方式:POST http(s)://api.weixin.qq.com/wxa/setdynamicdata?access_token=ACCESS_TOKEN
  48. * </pre>
  49. *
  50. * @param lifespan 数据有效时间,秒为单位,一般为86400,一天一次导入的频率
  51. * @param type 用于标识数据所属的服务类目
  52. * @param scene 1代表用于搜索的数据
  53. * @param data 推送到微信后台的数据列表,该数据被微信用于流量分配,注意该字段为string类型而不是object
  54. * @throws WxErrorException .
  55. */
  56. void setDynamicData(int lifespan, String type, int scene, String data) throws WxErrorException;
  57. /**
  58. * <pre>
  59. * 验证消息的确来自微信服务器.
  60. * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319&token=&lang=zh_CN
  61. * </pre>
  62. *
  63. * @param timestamp the timestamp
  64. * @param nonce the nonce
  65. * @param signature the signature
  66. * @return the boolean
  67. */
  68. boolean checkSignature(String timestamp, String nonce, String signature);
  69. /**
  70. * 获取access_token, 不强制刷新access_token.
  71. *
  72. * @return the access token
  73. * @throws WxErrorException the wx error exception
  74. * @see #getAccessToken(boolean) #getAccessToken(boolean)
  75. */
  76. String getAccessToken() throws WxErrorException;
  77. /**
  78. * <pre>
  79. * 获取access_token,本方法线程安全.
  80. * 且在多线程同时刷新时只刷新一次,避免超出2000次/日的调用次数上限
  81. *
  82. * 另:本service的所有方法都会在access_token过期是调用此方法
  83. *
  84. * 程序员在非必要情况下尽量不要主动调用此方法
  85. *
  86. * 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183&token=&lang=zh_CN
  87. * </pre>
  88. *
  89. * @param forceRefresh 强制刷新
  90. * @return the access token
  91. * @throws WxErrorException the wx error exception
  92. */
  93. String getAccessToken(boolean forceRefresh) throws WxErrorException;
  94. /**
  95. * <pre>
  96. * 用户支付完成后,获取该用户的 UnionId,无需用户授权。本接口支持第三方平台代理查询。
  97. *
  98. * 注意:调用前需要用户完成支付,且在支付后的五分钟内有效。
  99. * 请求地址: GET https://api.weixin.qq.com/wxa/getpaidunionid?access_token=ACCESS_TOKEN&openid=OPENID
  100. * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api/getPaidUnionId.html
  101. * </pre>
  102. *
  103. * @param openid 必填 支付用户唯一标识
  104. * @param transactionId 非必填 微信支付订单号
  105. * @param mchId 非必填 微信支付分配的商户号,和商户订单号配合使用
  106. * @param outTradeNo 非必填 微信支付商户订单号,和商户号配合使用
  107. * @return UnionId. paid union id
  108. * @throws WxErrorException .
  109. */
  110. String getPaidUnionId(String openid, String transactionId, String mchId, String outTradeNo) throws WxErrorException;
  111. /**
  112. * <pre>
  113. * Service没有实现某个API的时候,可以用这个,
  114. * 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
  115. * 可以参考,{@link MediaUploadRequestExecutor}的实现方法
  116. * </pre>
  117. *
  118. * @param <T> .
  119. * @param <E> .
  120. * @param executor 执行器
  121. * @param uri 接口请求地址
  122. * @param data 参数或请求数据
  123. * @return . t
  124. * @throws WxErrorException the wx error exception
  125. */
  126. <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
  127. /**
  128. * <pre>
  129. * 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试.
  130. * 默认:1000ms
  131. * </pre>
  132. *
  133. * @param retrySleepMillis 重试等待毫秒数
  134. */
  135. void setRetrySleepMillis(int retrySleepMillis);
  136. /**
  137. * <pre>
  138. * 设置当微信系统响应系统繁忙时,最大重试次数.
  139. * 默认:5次
  140. * </pre>
  141. *
  142. * @param maxRetryTimes 最大重试次数
  143. */
  144. void setMaxRetryTimes(int maxRetryTimes);
  145. /**
  146. * 获取WxMaConfig 对象.
  147. *
  148. * @return WxMaConfig wx ma config
  149. */
  150. WxMaConfig getWxMaConfig();
  151. /**
  152. * 注入 {@link WxMaConfig} 的实现.
  153. *
  154. * @param maConfig config
  155. */
  156. void setWxMaConfig(WxMaConfig maConfig);
  157. /**
  158. * Map里 加入新的 {@link WxMaConfig},适用于动态添加新的微信公众号配置.
  159. *
  160. * @param miniappId 小程序标识
  161. * @param configStorage 新的微信配置
  162. */
  163. void addConfig(String miniappId, WxMaConfig configStorage);
  164. /**
  165. * 从 Map中 移除 {@link String miniappId} 所对应的 {@link WxMaConfig},适用于动态移除小程序配置.
  166. *
  167. * @param miniappId 对应小程序的标识
  168. */
  169. void removeConfig(String miniappId);
  170. /**
  171. * 注入多个 {@link WxMaConfig} 的实现. 并为每个 {@link WxMaConfig} 赋予不同的 {@link String mpId} 值
  172. * 随机采用一个{@link String mpId}进行Http初始化操作
  173. *
  174. * @param configs WxMaConfig map
  175. */
  176. void setMultiConfigs(Map<String, WxMaConfig> configs);
  177. /**
  178. * 注入多个 {@link WxMaConfig} 的实现. 并为每个 {@link WxMaConfig} 赋予不同的 {@link String label} 值
  179. *
  180. * @param configs WxMaConfig map
  181. * @param defaultMiniappId 设置一个{@link WxMaConfig} 所对应的{@link String defaultMiniappId}进行Http初始化
  182. */
  183. void setMultiConfigs(Map<String, WxMaConfig> configs, String defaultMiniappId);
  184. /**
  185. * 进行相应的公众号切换.
  186. *
  187. * @param mpId 公众号标识
  188. * @return 切换是否成功 boolean
  189. */
  190. boolean switchover(String mpId);
  191. /**
  192. * 进行相应的公众号切换.
  193. *
  194. * @param miniappId 小程序标识
  195. * @return 切换成功 ,则返回当前对象,方便链式调用,否则抛出异常
  196. */
  197. WxMaService switchoverTo(String miniappId);
  198. /**
  199. * 返回消息(客服消息和模版消息)发送接口方法实现类,以方便调用其各个接口.
  200. *
  201. * @return WxMaMsgService msg service
  202. */
  203. WxMaMsgService getMsgService();
  204. /**
  205. * 返回素材相关接口方法的实现类对象,以方便调用其各个接口.
  206. *
  207. * @return WxMaMediaService media service
  208. */
  209. WxMaMediaService getMediaService();
  210. /**
  211. * 返回用户相关接口方法的实现类对象,以方便调用其各个接口.
  212. *
  213. * @return WxMaUserService user service
  214. */
  215. WxMaUserService getUserService();
  216. /**
  217. * 返回二维码相关接口方法的实现类对象,以方便调用其各个接口.
  218. *
  219. * @return WxMaQrcodeService qrcode service
  220. */
  221. WxMaQrcodeService getQrcodeService();
  222. /**
  223. * 返回获取小程序scheme码实现对象,以方便调用其各个接口.
  224. *
  225. * @return WxMaSchemeService wx ma scheme service
  226. */
  227. WxMaSchemeService getWxMaSchemeService();
  228. /**
  229. * 返回订阅消息配置相关接口方法的实现类对象, 以方便调用其各个接口.
  230. *
  231. * @return WxMaSubscribeService subscribe service
  232. */
  233. WxMaSubscribeService getSubscribeService();
  234. /**
  235. * 数据分析相关查询服务.
  236. *
  237. * @return WxMaAnalysisService analysis service
  238. */
  239. WxMaAnalysisService getAnalysisService();
  240. /**
  241. * 返回代码操作相关的 API.
  242. *
  243. * @return WxMaCodeService code service
  244. */
  245. WxMaCodeService getCodeService();
  246. /**
  247. * 返回jsapi操作相关的 API服务类对象.
  248. *
  249. * @return WxMaJsapiService jsapi service
  250. */
  251. WxMaJsapiService getJsapiService();
  252. /**
  253. * 小程序修改服务器地址、成员管理 API.
  254. *
  255. * @return WxMaSettingService setting service
  256. */
  257. WxMaSettingService getSettingService();
  258. /**
  259. * 返回分享相关查询服务.
  260. *
  261. * @return WxMaShareService share service
  262. */
  263. WxMaShareService getShareService();
  264. /**
  265. * 返回微信运动相关接口服务对象.
  266. *
  267. * @return WxMaShareService run service
  268. */
  269. WxMaRunService getRunService();
  270. /**
  271. * 返回内容安全相关接口服务对象.
  272. *
  273. * @return WxMaShareService sec check service
  274. */
  275. WxMaSecCheckService getSecCheckService();
  276. /**
  277. * 返回插件相关接口服务对象.
  278. *
  279. * @return WxMaPluginService plugin service
  280. */
  281. WxMaPluginService getPluginService();
  282. /**
  283. * 初始化http请求对象.
  284. */
  285. void initHttp();
  286. /**
  287. * 请求http请求相关信息.
  288. *
  289. * @return . request http
  290. */
  291. RequestHttp getRequestHttp();
  292. /**
  293. * 获取物流助手接口服务对象
  294. *
  295. * @return . express service
  296. */
  297. WxMaExpressService getExpressService();
  298. /**
  299. * 获取云开发接口服务对象
  300. *
  301. * @return . cloud service
  302. */
  303. WxMaCloudService getCloudService();
  304. /**
  305. * 获取服务端网络接口服务对象
  306. *
  307. * @return 。internet service
  308. */
  309. WxMaInternetService getInternetService();
  310. /**
  311. * 获取直播接口服务对象
  312. *
  313. * @return . live service
  314. */
  315. WxMaLiveService getLiveService();
  316. /**
  317. * 获取直播间商品服务对象
  318. *
  319. * @return . live goods service
  320. */
  321. WxMaLiveGoodsService getLiveGoodsService();
  322. /**
  323. * 获取直播成员管理接口服务对象
  324. *
  325. * @return . live service
  326. */
  327. WxMaLiveMemberService getLiveMemberService();
  328. /**
  329. * 获取ocr实现接口服务对象
  330. *
  331. * @return 。
  332. */
  333. WxOcrService getOcrService();
  334. /**
  335. * 返回图像处理接口的实现类对象,以方便调用其各个接口.
  336. *
  337. * @return WxImgProcService img proc service
  338. */
  339. WxImgProcService getImgProcService();
  340. /**
  341. * 返回小程序交易组件-售后服务接口
  342. *
  343. * @return
  344. */
  345. WxMaShopAfterSaleService getShopAfterSaleService();
  346. /**
  347. * 返回小程序交易组件-物流服务接口
  348. *
  349. * @return
  350. */
  351. WxMaShopDeliveryService getShopDeliveryService();
  352. /**
  353. * 返回小程序交易组件-订单服务接口
  354. *
  355. * @return
  356. */
  357. WxMaShopOrderService getShopOrderService();
  358. /**
  359. * 返回小程序交易组件-spu商品服务接口
  360. *
  361. * @return
  362. */
  363. WxMaShopSpuService getShopSpuService();
  364. /**
  365. * 返回小程序交易组件-接入申请接口
  366. *
  367. * @return
  368. */
  369. WxMaShopRegisterService getShopRegisterService();
  370. /**
  371. * 返回小程序交易组件-商户入驻接口
  372. *
  373. * @return
  374. */
  375. WxMaShopAccountService getShopAccountService();
  376. /**
  377. * 小程序交易组件-接入商品前必需接口-类目相关
  378. *
  379. * @return
  380. */
  381. WxMaShopCatService getShopCatService();
  382. /**
  383. * 小程序交易组件-接入商品前必需接口-上传图片
  384. *
  385. * @return
  386. */
  387. WxMaShopImgService getShopImgService();
  388. /**
  389. * 小程序交易组件-接入商品前必需接口-审核相关接口
  390. *
  391. * @return
  392. */
  393. WxMaShopAuditService getShopAuditService();
  394. /**
  395. * 获取小程序Link服务接口
  396. *
  397. * @return
  398. */
  399. WxMaLinkService getLinkService();
  400. /**
  401. * 获取电子发票报销方服务接口
  402. *
  403. * @return
  404. */
  405. WxMaReimburseInvoiceService getReimburseInvoiceService();
  406. /**
  407. * 返回设备订阅消息相关接口服务对象
  408. *
  409. * @return WxMaDeviceSubscribeService plugin service
  410. */
  411. WxMaDeviceSubscribeService getDeviceSubscribeService();
  412. /**
  413. * 返回小程序广告接入相关接口服务对象
  414. *
  415. * @return WxMaDeviceSubscribeService plugin service
  416. */
  417. WxMaMarketingService getMarketingService();
  418. }