WxOpenComponentService.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. package me.chanjar.weixin.open.api;
  2. import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
  3. import me.chanjar.weixin.common.error.WxErrorException;
  4. import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
  5. import me.chanjar.weixin.open.bean.WxOpenCreateResult;
  6. import me.chanjar.weixin.open.bean.WxOpenGetResult;
  7. import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate;
  8. import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage;
  9. import me.chanjar.weixin.open.bean.result.*;
  10. import java.util.List;
  11. /**
  12. * .
  13. *
  14. * @author <a href="https://github.com/007gzs">007</a>
  15. */
  16. public interface WxOpenComponentService {
  17. /**
  18. * The constant API_COMPONENT_TOKEN_URL.
  19. */
  20. String API_COMPONENT_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_component_token";
  21. /**
  22. * The constant API_CREATE_PREAUTHCODE_URL.
  23. */
  24. String API_CREATE_PREAUTHCODE_URL = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode";
  25. /**
  26. * The constant API_QUERY_AUTH_URL.
  27. */
  28. String API_QUERY_AUTH_URL = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth";
  29. /**
  30. * The constant API_AUTHORIZER_TOKEN_URL.
  31. */
  32. String API_AUTHORIZER_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token";
  33. /**
  34. * The constant API_GET_AUTHORIZER_INFO_URL.
  35. */
  36. String API_GET_AUTHORIZER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info";
  37. /**
  38. * The constant API_GET_AUTHORIZER_OPTION_URL.
  39. */
  40. String API_GET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option";
  41. /**
  42. * The constant API_SET_AUTHORIZER_OPTION_URL.
  43. */
  44. String API_SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option";
  45. /**
  46. * The constant API_GET_AUTHORIZER_LIST.
  47. */
  48. String API_GET_AUTHORIZER_LIST = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list";
  49. /**
  50. * The constant COMPONENT_LOGIN_PAGE_URL.
  51. */
  52. String COMPONENT_LOGIN_PAGE_URL = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s&auth_type=xxx&biz_appid=xxx";
  53. /**
  54. * 手机端打开授权链接.
  55. */
  56. String COMPONENT_MOBILE_LOGIN_PAGE_URL = "https://mp.weixin.qq.com/safe/bindcomponent?action=bindcomponent&no_scan=1&auth_type=3&component_appid=%s&pre_auth_code=%s&redirect_uri=%s&auth_type=xxx&biz_appid=xxx#wechat_redirect";
  57. /**
  58. * The constant CONNECT_OAUTH2_AUTHORIZE_URL.
  59. */
  60. String CONNECT_OAUTH2_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s&component_appid=%s#wechat_redirect";
  61. /**
  62. * 用code换取oauth2的access token.
  63. */
  64. String OAUTH2_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=%s&code=%s&grant_type=authorization_code&component_appid=%s";
  65. /**
  66. * 刷新oauth2的access token.
  67. */
  68. String OAUTH2_REFRESH_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/component/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s&component_appid=%s";
  69. /**
  70. * The constant MINIAPP_JSCODE_2_SESSION.
  71. */
  72. String MINIAPP_JSCODE_2_SESSION = "https://api.weixin.qq.com/sns/component/jscode2session?appid=%s&js_code=%s&grant_type=authorization_code&component_appid=%s";
  73. /**
  74. * The constant CREATE_OPEN_URL.
  75. */
  76. String CREATE_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/create";
  77. /**
  78. * The constant BIND_OPEN_URL.
  79. */
  80. String BIND_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/bind";
  81. /**
  82. * The constant UNBIND_OPEN_URL.
  83. */
  84. String UNBIND_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/unbind";
  85. /**
  86. * The constant GET_OPEN_URL.
  87. */
  88. String GET_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/get";
  89. /**
  90. * 快速创建小程序接口.
  91. */
  92. String FAST_REGISTER_WEAPP_URL = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp?action=create";
  93. /**
  94. * The constant FAST_REGISTER_WEAPP_SEARCH_URL.
  95. */
  96. String FAST_REGISTER_WEAPP_SEARCH_URL = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp?action=search";
  97. /**
  98. * 代小程序实现业务.
  99. * 小程序代码模版库管理:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1506504150_nMMh6&token=&lang=zh_CN
  100. * access_token 为 component_access_token
  101. */
  102. String GET_TEMPLATE_DRAFT_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatedraftlist";
  103. /**
  104. * The constant GET_TEMPLATE_LIST_URL.
  105. */
  106. String GET_TEMPLATE_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatelist";
  107. /**
  108. * The constant ADD_TO_TEMPLATE_URL.
  109. */
  110. String ADD_TO_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/addtotemplate";
  111. /**
  112. * The constant DELETE_TEMPLATE_URL.
  113. */
  114. String DELETE_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/deletetemplate";
  115. /**
  116. * Gets wx mp service by appid.
  117. *
  118. * @param appid the appid
  119. * @return the wx mp service by appid
  120. */
  121. WxOpenMpService getWxMpServiceByAppid(String appid);
  122. /**
  123. * 获取指定appid的开放平台小程序服务(继承一般小程序服务能力).
  124. *
  125. * @param appid .
  126. * @return . wx ma service by appid
  127. */
  128. WxOpenMaService getWxMaServiceByAppid(String appid);
  129. /**
  130. * 获取指定appid的快速创建的小程序服务.
  131. *
  132. * @param appid .
  133. * @return . wx fast ma service by appid
  134. */
  135. WxOpenFastMaService getWxFastMaServiceByAppid(String appid);
  136. /**
  137. * Gets wx open config storage.
  138. *
  139. * @return the wx open config storage
  140. */
  141. WxOpenConfigStorage getWxOpenConfigStorage();
  142. /**
  143. * Check signature boolean.
  144. *
  145. * @param timestamp the timestamp
  146. * @param nonce the nonce
  147. * @param signature the signature
  148. * @return the boolean
  149. */
  150. boolean checkSignature(String timestamp, String nonce, String signature);
  151. /**
  152. * Gets component access token.
  153. *
  154. * @param forceRefresh the force refresh
  155. * @return the component access token
  156. * @throws WxErrorException the wx error exception
  157. */
  158. String getComponentAccessToken(boolean forceRefresh) throws WxErrorException;
  159. /**
  160. * Post string.
  161. *
  162. * @param uri the uri
  163. * @param postData the post data
  164. * @return the string
  165. * @throws WxErrorException the wx error exception
  166. */
  167. String post(String uri, String postData) throws WxErrorException;
  168. /**
  169. * Post string.
  170. *
  171. * @param uri the uri
  172. * @param postData the post data
  173. * @param accessTokenKey the access token key
  174. * @return the string
  175. * @throws WxErrorException the wx error exception
  176. */
  177. String post(String uri, String postData, String accessTokenKey) throws WxErrorException;
  178. /**
  179. * Get string.
  180. *
  181. * @param uri the uri
  182. * @return the string
  183. * @throws WxErrorException the wx error exception
  184. */
  185. String get(String uri) throws WxErrorException;
  186. /**
  187. * Get string.
  188. *
  189. * @param uri the uri
  190. * @param accessTokenKey the access token key
  191. * @return the string
  192. * @throws WxErrorException the wx error exception
  193. */
  194. String get(String uri, String accessTokenKey) throws WxErrorException;
  195. /**
  196. * 获取用户授权页URL(来路URL和成功跳转URL 的域名都需要为三方平台设置的 登录授权的发起页域名).
  197. *
  198. * @param redirectUri the redirect uri
  199. * @return the pre auth url
  200. * @throws WxErrorException the wx error exception
  201. */
  202. String getPreAuthUrl(String redirectUri) throws WxErrorException;
  203. /**
  204. * .
  205. *
  206. * @param redirectUri the redirect uri
  207. * @param authType 要授权的帐号类型:1则商户点击链接后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示。如果为未指定,则默认小程序和公众号都展示。第三方平台开发者可以使用本字段来控制授权的帐号类型。
  208. * @param bizAppid 指定授权唯一的小程序或公众号 注:authType、bizAppid 互斥。
  209. * @return the pre auth url
  210. * @throws WxErrorException the wx error exception
  211. */
  212. String getPreAuthUrl(String redirectUri, String authType, String bizAppid) throws WxErrorException;
  213. /**
  214. * 获取预授权链接(手机端预授权).
  215. *
  216. * @param redirectUri .
  217. * @return . mobile pre auth url
  218. * @throws WxErrorException .
  219. */
  220. String getMobilePreAuthUrl(String redirectUri) throws WxErrorException;
  221. /**
  222. * 获取预授权链接(手机端预授权).
  223. *
  224. * @param redirectUri .
  225. * @param authType .
  226. * @param bizAppid .
  227. * @return . mobile pre auth url
  228. * @throws WxErrorException .
  229. */
  230. String getMobilePreAuthUrl(String redirectUri, String authType, String bizAppid) throws WxErrorException;
  231. /**
  232. * Route string.
  233. *
  234. * @param wxMessage the wx message
  235. * @return the string
  236. * @throws WxErrorException the wx error exception
  237. */
  238. String route(WxOpenXmlMessage wxMessage) throws WxErrorException;
  239. /**
  240. * 使用授权码换取公众号或小程序的接口调用凭据和授权信息.
  241. *
  242. * @param authorizationCode the authorization code
  243. * @return the query auth
  244. * @throws WxErrorException the wx error exception
  245. */
  246. WxOpenQueryAuthResult getQueryAuth(String authorizationCode) throws WxErrorException;
  247. /**
  248. * 获取授权方的帐号基本信息.
  249. *
  250. * @param authorizerAppid the authorizer appid
  251. * @return the authorizer info
  252. * @throws WxErrorException the wx error exception
  253. */
  254. WxOpenAuthorizerInfoResult getAuthorizerInfo(String authorizerAppid) throws WxErrorException;
  255. /**
  256. * 获取授权方的选项设置信息.
  257. *
  258. * @param authorizerAppid the authorizer appid
  259. * @param optionName the option name
  260. * @return the authorizer option
  261. * @throws WxErrorException the wx error exception
  262. */
  263. WxOpenAuthorizerOptionResult getAuthorizerOption(String authorizerAppid, String optionName) throws WxErrorException;
  264. /**
  265. * 获取所有授权方列表.
  266. *
  267. * @param begin the begin
  268. * @param len the len
  269. * @return the authorizer list
  270. * @throws WxErrorException the wx error exception
  271. */
  272. WxOpenAuthorizerListResult getAuthorizerList(int begin, int len) throws WxErrorException;
  273. /**
  274. * 设置授权方的选项信息.
  275. *
  276. * @param authorizerAppid the authorizer appid
  277. * @param optionName the option name
  278. * @param optionValue the option value
  279. * @throws WxErrorException the wx error exception
  280. */
  281. void setAuthorizerOption(String authorizerAppid, String optionName, String optionValue) throws WxErrorException;
  282. /**
  283. * Gets authorizer access token.
  284. *
  285. * @param appid the appid
  286. * @param forceRefresh the force refresh
  287. * @return the authorizer access token
  288. * @throws WxErrorException the wx error exception
  289. */
  290. String getAuthorizerAccessToken(String appid, boolean forceRefresh) throws WxErrorException;
  291. /**
  292. * Oauth 2 get access token wx mp o auth 2 access token.
  293. *
  294. * @param appid the appid
  295. * @param code the code
  296. * @return the wx mp o auth 2 access token
  297. * @throws WxErrorException the wx error exception
  298. */
  299. WxOAuth2AccessToken oauth2getAccessToken(String appid, String code) throws WxErrorException;
  300. /**
  301. * Check signature boolean.
  302. *
  303. * @param appId the app id
  304. * @param timestamp the timestamp
  305. * @param nonce the nonce
  306. * @param signature the signature
  307. * @return the boolean
  308. */
  309. boolean checkSignature(String appId, String timestamp, String nonce, String signature);
  310. /**
  311. * Oauth 2 refresh access token wx mp o auth 2 access token.
  312. *
  313. * @param appid the appid
  314. * @param refreshToken the refresh token
  315. * @return the wx mp o auth 2 access token
  316. * @throws WxErrorException the wx error exception
  317. */
  318. WxOAuth2AccessToken oauth2refreshAccessToken(String appid, String refreshToken) throws WxErrorException;
  319. /**
  320. * Oauth 2 build authorization url string.
  321. *
  322. * @param appid the appid
  323. * @param redirectUri the redirect uri
  324. * @param scope the scope
  325. * @param state the state
  326. * @return the string
  327. */
  328. String oauth2buildAuthorizationUrl(String appid, String redirectUri, String scope, String state);
  329. /**
  330. * Miniapp jscode 2 session wx ma jscode 2 session result.
  331. *
  332. * @param appId the app id
  333. * @param jsCode the js code
  334. * @return the wx ma jscode 2 session result
  335. * @throws WxErrorException the wx error exception
  336. */
  337. WxMaJscode2SessionResult miniappJscode2Session(String appId, String jsCode) throws WxErrorException;
  338. /**
  339. * 获取草稿箱内的所有临时代码草稿.
  340. *
  341. * @return 草稿箱代码模板列表 (draftId)
  342. * @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档
  343. */
  344. List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException;
  345. /**
  346. * 获取代码模版库中的所有小程序代码模版.
  347. *
  348. * @return 小程序代码模版列表 (templateId)
  349. * @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档
  350. */
  351. List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException;
  352. /**
  353. * 将草稿箱的草稿选为小程序代码模版.
  354. *
  355. * @param draftId 草稿ID,本字段可通过“获取草稿箱内的所有临时代码草稿”接口获得
  356. * @throws WxErrorException 操作失败时抛出,具体错误码请看此接口的注释文档
  357. * @see #getTemplateDraftList #getTemplateDraftList
  358. */
  359. void addToTemplate(long draftId) throws WxErrorException;
  360. /**
  361. * 删除指定小程序代码模版.
  362. *
  363. * @param templateId 要删除的模版ID
  364. * @throws WxErrorException 操作失败时抛出,具体错误码请看此接口的注释文档
  365. * @see #getTemplateList #getTemplateList
  366. */
  367. void deleteTemplate(long templateId) throws WxErrorException;
  368. /**
  369. * https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1498704199_1bcax&token=6df5e3650041eff2cd3ec3662425ad8d7beec8d9&lang=zh_CN
  370. * 创建 开放平台帐号并绑定公众号/小程序.
  371. * https://api.weixin.qq.com/cgi-bin/open/create
  372. *
  373. * @param appId 公众号/小程序的appId
  374. * @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
  375. * @return . wx open create result
  376. * @throws WxErrorException .
  377. */
  378. WxOpenCreateResult createOpenAccount(String appId, String appIdType) throws WxErrorException;
  379. /**
  380. * https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/bind.html
  381. * 将公众号/小程序绑定到开放平台帐号下
  382. *
  383. * @param appId 公众号/小程序的appId
  384. * @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
  385. * @param openAppid 开放平台帐号 appid,由创建开发平台帐号接口返回
  386. * @return the boolean
  387. * @throws WxErrorException the wx error exception
  388. */
  389. Boolean bindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException;
  390. /**
  391. * https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/unbind.html
  392. * 将公众号/小程序从开放平台帐号下解绑
  393. *
  394. * @param appId 公众号/小程序的appId
  395. * @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
  396. * @param openAppid 开放平台帐号 appid,由创建开发平台帐号接口返回
  397. * @return the boolean
  398. * @throws WxErrorException the wx error exception
  399. */
  400. Boolean unbindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException;
  401. /**
  402. * https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/get.html
  403. * 获取公众号/小程序所绑定的开放平台帐号
  404. *
  405. * @param appId 公众号/小程序的appId
  406. * @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
  407. * @return 开放平台帐号 appid,由创建开发平台帐号接口返回
  408. * @throws WxErrorException the wx error exception
  409. */
  410. WxOpenGetResult getOpenAccount(String appId, String appIdType) throws WxErrorException;
  411. /**
  412. * https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21538208049W8uwq&token=&lang=zh_CN
  413. * 第三方平台快速创建小程序.
  414. * 注意:创建任务逻辑串行,单次任务结束后才可以使用相同信息下发第二次任务,请注意规避任务阻塞
  415. *
  416. * @param name 企业名(需与工商部门登记信息一致)
  417. * @param code 企业代码
  418. * @param codeType 企业代码类型 1:统一社会信用代码(18位) 2:组织机构代码(9位xxxxxxxx-x) 3:营业执照注册号(15位)
  419. * @param legalPersonaWechat 法人微信号
  420. * @param legalPersonaName 法人姓名(绑定银行卡)
  421. * @param componentPhone 第三方联系电话(方便法人与第三方联系)
  422. * @return . wx open result
  423. * @throws WxErrorException .
  424. */
  425. WxOpenResult fastRegisterWeapp(String name, String code, String codeType, String legalPersonaWechat, String legalPersonaName, String componentPhone) throws WxErrorException;
  426. /**
  427. * https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21538208049W8uwq&token=&lang=zh_CN
  428. * 查询第三方平台快速创建小程序的任务状态
  429. * 注意:该接口只提供当下任务结果查询,不建议过分依赖该接口查询所创建小程序。
  430. * 小程序的成功状态可在第三方服务器中自行对账、查询。
  431. * 不要频繁调用search接口,消息接收需通过服务器查看。调用search接口会消耗接口整体调用quato
  432. *
  433. * @param name 企业名(需与工商部门登记信息一致)
  434. * @param legalPersonaWechat 法人微信号
  435. * @param legalPersonaName 法人姓名(绑定银行卡)
  436. * @return the wx open result
  437. * @throws WxErrorException .
  438. */
  439. WxOpenResult fastRegisterWeappSearch(String name, String legalPersonaWechat, String legalPersonaName) throws WxErrorException;
  440. }