Merge pull request #1730 from Wechat-Group/develop

合并develop分支,发布最新正式版
This commit is contained in:
Binary Wang
2020-08-24 00:20:47 +08:00
committed by GitHub
467 changed files with 12371 additions and 3987 deletions

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java</artifactId>
<version>3.8.0</version>
<version>3.9.0</version>
</parent>
<artifactId>weixin-java-open</artifactId>

View File

@@ -1,7 +1,6 @@
package me.chanjar.weixin.open.api;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.google.gson.JsonObject;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
@@ -10,7 +9,6 @@ import me.chanjar.weixin.open.bean.WxOpenGetResult;
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate;
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage;
import me.chanjar.weixin.open.bean.result.*;
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
import java.util.List;
@@ -20,21 +18,51 @@ import java.util.List;
* @author <a href="https://github.com/007gzs">007</a>
*/
public interface WxOpenComponentService {
/**
* The constant API_COMPONENT_TOKEN_URL.
*/
String API_COMPONENT_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_component_token";
/**
* The constant API_CREATE_PREAUTHCODE_URL.
*/
String API_CREATE_PREAUTHCODE_URL = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode";
/**
* The constant API_QUERY_AUTH_URL.
*/
String API_QUERY_AUTH_URL = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth";
/**
* The constant API_AUTHORIZER_TOKEN_URL.
*/
String API_AUTHORIZER_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token";
/**
* The constant API_GET_AUTHORIZER_INFO_URL.
*/
String API_GET_AUTHORIZER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info";
/**
* The constant API_GET_AUTHORIZER_OPTION_URL.
*/
String API_GET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option";
/**
* The constant API_SET_AUTHORIZER_OPTION_URL.
*/
String API_SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option";
/**
* The constant API_GET_AUTHORIZER_LIST.
*/
String API_GET_AUTHORIZER_LIST = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list";
/**
* The constant COMPONENT_LOGIN_PAGE_URL.
*/
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";
/**
* 手机端打开授权链接.
*/
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";
/**
* The constant CONNECT_OAUTH2_AUTHORIZE_URL.
*/
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";
/**
@@ -46,29 +74,72 @@ public interface WxOpenComponentService {
*/
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";
/**
* The constant MINIAPP_JSCODE_2_SESSION.
*/
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";
/**
* The constant CREATE_OPEN_URL.
*/
String CREATE_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/create";
/**
* The constant BIND_OPEN_URL.
*/
String BIND_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/bind";
/**
* The constant UNBIND_OPEN_URL.
*/
String UNBIND_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/unbind";
/**
* The constant GET_OPEN_URL.
*/
String GET_OPEN_URL = "https://api.weixin.qq.com/cgi-bin/open/get";
/**
* 快速创建小程序接口.
*/
String FAST_REGISTER_WEAPP_URL = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp?action=create";
/**
* The constant FAST_REGISTER_WEAPP_SEARCH_URL.
*/
String FAST_REGISTER_WEAPP_SEARCH_URL = "https://api.weixin.qq.com/cgi-bin/component/fastregisterweapp?action=search";
/**
* 代小程序实现业务.
* 小程序代码模版库管理https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1506504150_nMMh6&token=&lang=zh_CN
* access_token 为 component_access_token
*/
String GET_TEMPLATE_DRAFT_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatedraftlist";
/**
* The constant GET_TEMPLATE_LIST_URL.
*/
String GET_TEMPLATE_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatelist";
/**
* The constant ADD_TO_TEMPLATE_URL.
*/
String ADD_TO_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/addtotemplate";
/**
* The constant DELETE_TEMPLATE_URL.
*/
String DELETE_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/deletetemplate";
/**
* Gets wx mp service by appid.
*
* @param appid the appid
* @return the wx mp service by appid
*/
WxMpService getWxMpServiceByAppid(String appid);
/**
* 获取指定appid的开放平台小程序服务继承一般小程序服务能力.
*
* @param appid .
* @return .
* @return . wx ma service by appid
*/
WxOpenMaService getWxMaServiceByAppid(String appid);
@@ -76,35 +147,93 @@ public interface WxOpenComponentService {
* 获取指定appid的快速创建的小程序服务.
*
* @param appid .
* @return .
* @return . wx fast ma service by appid
*/
WxOpenFastMaService getWxFastMaServiceByAppid(String appid);
/**
* Gets wx open config storage.
*
* @return the wx open config storage
*/
WxOpenConfigStorage getWxOpenConfigStorage();
/**
* Check signature boolean.
*
* @param timestamp the timestamp
* @param nonce the nonce
* @param signature the signature
* @return the boolean
*/
boolean checkSignature(String timestamp, String nonce, String signature);
/**
* Gets component access token.
*
* @param forceRefresh the force refresh
* @return the component access token
* @throws WxErrorException the wx error exception
*/
String getComponentAccessToken(boolean forceRefresh) throws WxErrorException;
/**
* Post string.
*
* @param uri the uri
* @param postData the post data
* @return the string
* @throws WxErrorException the wx error exception
*/
String post(String uri, String postData) throws WxErrorException;
/**
* Post string.
*
* @param uri the uri
* @param postData the post data
* @param accessTokenKey the access token key
* @return the string
* @throws WxErrorException the wx error exception
*/
String post(String uri, String postData, String accessTokenKey) throws WxErrorException;
/**
* Get string.
*
* @param uri the uri
* @return the string
* @throws WxErrorException the wx error exception
*/
String get(String uri) throws WxErrorException;
/**
* Get string.
*
* @param uri the uri
* @param accessTokenKey the access token key
* @return the string
* @throws WxErrorException the wx error exception
*/
String get(String uri, String accessTokenKey) throws WxErrorException;
/**
* 获取用户授权页URL来路URL和成功跳转URL 的域名都需要为三方平台设置的 登录授权的发起页域名).
*
* @param redirectUri the redirect uri
* @return the pre auth url
* @throws WxErrorException the wx error exception
*/
String getPreAuthUrl(String redirectUri) throws WxErrorException;
/**
* .
*
* @param authType 要授权的帐号类型1则商户点击链接后手机端仅展示公众号、2表示仅展示小程序3表示公众号和小程序都展示。如果为未指定则默认小程序和公众号都展示。第三方平台开发者可以使用本字段来控制授权的帐号类型。
* @param bizAppid 指定授权唯一的小程序或公众号
* 注authType、bizAppid 互斥。
* @param redirectUri the redirect uri
* @param authType 要授权的帐号类型1则商户点击链接后手机端仅展示公众号、2表示仅展示小程序3表示公众号和小程序都展示。如果为未指定则默认小程序和公众号都展示。第三方平台开发者可以使用本字段来控制授权的帐号类型。
* @param bizAppid 指定授权唯一的小程序或公众号authType、bizAppid 互斥。
* @return the pre auth url
* @throws WxErrorException the wx error exception
*/
String getPreAuthUrl(String redirectUri, String authType, String bizAppid) throws WxErrorException;
@@ -112,7 +241,7 @@ public interface WxOpenComponentService {
* 获取预授权链接(手机端预授权).
*
* @param redirectUri .
* @return .
* @return . mobile pre auth url
* @throws WxErrorException .
*/
String getMobilePreAuthUrl(String redirectUri) throws WxErrorException;
@@ -123,64 +252,134 @@ public interface WxOpenComponentService {
* @param redirectUri .
* @param authType .
* @param bizAppid .
* @return .
* @return . mobile pre auth url
* @throws WxErrorException .
*/
String getMobilePreAuthUrl(String redirectUri, String authType, String bizAppid) throws WxErrorException;
/**
* Route string.
*
* @param wxMessage the wx message
* @return the string
* @throws WxErrorException the wx error exception
*/
String route(WxOpenXmlMessage wxMessage) throws WxErrorException;
/**
* 使用授权码换取公众号或小程序的接口调用凭据和授权信息.
*
* @param authorizationCode the authorization code
* @return the query auth
* @throws WxErrorException the wx error exception
*/
WxOpenQueryAuthResult getQueryAuth(String authorizationCode) throws WxErrorException;
/**
* 获取授权方的帐号基本信息.
*
* @param authorizerAppid the authorizer appid
* @return the authorizer info
* @throws WxErrorException the wx error exception
*/
WxOpenAuthorizerInfoResult getAuthorizerInfo(String authorizerAppid) throws WxErrorException;
/**
* 获取授权方的选项设置信息.
*
* @param authorizerAppid the authorizer appid
* @param optionName the option name
* @return the authorizer option
* @throws WxErrorException the wx error exception
*/
WxOpenAuthorizerOptionResult getAuthorizerOption(String authorizerAppid, String optionName) throws WxErrorException;
/**
* 获取所有授权方列表.
*
* @param begin the begin
* @param len the len
* @return the authorizer list
* @throws WxErrorException the wx error exception
*/
WxOpenAuthorizerListResult getAuthorizerList(int begin, int len) throws WxErrorException;
/**
* 设置授权方的选项信息.
*
* @param authorizerAppid the authorizer appid
* @param optionName the option name
* @param optionValue the option value
* @throws WxErrorException the wx error exception
*/
void setAuthorizerOption(String authorizerAppid, String optionName, String optionValue) throws WxErrorException;
/**
* Gets authorizer access token.
*
* @param appid the appid
* @param forceRefresh the force refresh
* @return the authorizer access token
* @throws WxErrorException the wx error exception
*/
String getAuthorizerAccessToken(String appid, boolean forceRefresh) throws WxErrorException;
/**
* Oauth 2 get access token wx mp o auth 2 access token.
*
* @param appid the appid
* @param code the code
* @return the wx mp o auth 2 access token
* @throws WxErrorException the wx error exception
*/
WxMpOAuth2AccessToken oauth2getAccessToken(String appid, String code) throws WxErrorException;
/**
* Check signature boolean.
*
* @param appId the app id
* @param timestamp the timestamp
* @param nonce the nonce
* @param signature the signature
* @return the boolean
*/
boolean checkSignature(String appId, String timestamp, String nonce, String signature);
/**
* Oauth 2 refresh access token wx mp o auth 2 access token.
*
* @param appid the appid
* @param refreshToken the refresh token
* @return the wx mp o auth 2 access token
* @throws WxErrorException the wx error exception
*/
WxMpOAuth2AccessToken oauth2refreshAccessToken(String appid, String refreshToken) throws WxErrorException;
/**
* Oauth 2 build authorization url string.
*
* @param appid the appid
* @param redirectUri the redirect uri
* @param scope the scope
* @param state the state
* @return the string
*/
String oauth2buildAuthorizationUrl(String appid, String redirectUri, String scope, String state);
WxMaJscode2SessionResult miniappJscode2Session(String appId, String jsCode) throws WxErrorException;
/**
* 代小程序实现业务.
* 小程序代码模版库管理https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1506504150_nMMh6&token=&lang=zh_CN
* access_token 为 component_access_token
* Miniapp jscode 2 session wx ma jscode 2 session result.
*
* @param appId the app id
* @param jsCode the js code
* @return the wx ma jscode 2 session result
* @throws WxErrorException the wx error exception
*/
String GET_TEMPLATE_DRAFT_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatedraftlist";
String GET_TEMPLATE_LIST_URL = "https://api.weixin.qq.com/wxa/gettemplatelist";
String ADD_TO_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/addtotemplate";
String DELETE_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/deletetemplate";
WxMaJscode2SessionResult miniappJscode2Session(String appId, String jsCode) throws WxErrorException;
/**
* 获取草稿箱内的所有临时代码草稿.
*
* @return 草稿箱代码模板列表draftId
* @return 草稿箱代码模板列表 draftId
* @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档
*/
List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException;
@@ -188,7 +387,7 @@ public interface WxOpenComponentService {
/**
* 获取代码模版库中的所有小程序代码模版.
*
* @return 小程序代码模版列表templateId
* @return 小程序代码模版列表 templateId
* @throws WxErrorException 获取失败时返回,具体错误码请看此接口的注释文档
*/
List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException;
@@ -198,7 +397,7 @@ public interface WxOpenComponentService {
*
* @param draftId 草稿ID本字段可通过“获取草稿箱内的所有临时代码草稿”接口获得
* @throws WxErrorException 操作失败时抛出,具体错误码请看此接口的注释文档
* @see #getTemplateDraftList
* @see #getTemplateDraftList #getTemplateDraftList
*/
void addToTemplate(long draftId) throws WxErrorException;
@@ -207,7 +406,7 @@ public interface WxOpenComponentService {
*
* @param templateId 要删除的模版ID
* @throws WxErrorException 操作失败时抛出,具体错误码请看此接口的注释文档
* @see #getTemplateList
* @see #getTemplateList #getTemplateList
*/
void deleteTemplate(long templateId) throws WxErrorException;
@@ -216,40 +415,47 @@ public interface WxOpenComponentService {
* 创建 开放平台帐号并绑定公众号/小程序.
* https://api.weixin.qq.com/cgi-bin/open/create
*
* @param appId 公众号/小程序的appId
* @return .
* @param appId 公众号/小程序的appId
* @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
* @return . wx open create result
* @throws WxErrorException .
*/
WxOpenCreateResult createOpenAccount(String appId) throws WxErrorException;
WxOpenCreateResult createOpenAccount(String appId, String appIdType) throws WxErrorException;
/**
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/bind.html
* 将公众号/小程序绑定到开放平台帐号下
*
* @param appId 公众号/小程序的appId
* @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
* @param openAppid 开放平台帐号 appid由创建开发平台帐号接口返回
* @return the boolean
* @throws WxErrorException the wx error exception
*/
Boolean bindOpenAccount(String appId, String openAppid) throws WxErrorException;
Boolean bindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException;
/**
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/unbind.html
* 将公众号/小程序从开放平台帐号下解绑
*
* @param appId 公众号/小程序的appId
* @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
* @param openAppid 开放平台帐号 appid由创建开发平台帐号接口返回
* @return the boolean
* @throws WxErrorException the wx error exception
*/
Boolean unbindOpenAccount(String appId, String openAppid) throws WxErrorException;
Boolean unbindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException;
/**
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/api/account/get.html
* 获取公众号/小程序所绑定的开放平台帐号
*
* @param appId 公众号/小程序的appId
* @param appId 公众号/小程序的appId
* @param appIdType appId类型 me.chanjar.weixin.common.api.WxConsts.AppIdType mp-公众号 mini-小程序
* @return 开放平台帐号 appid由创建开发平台帐号接口返回
* @throws WxErrorException the wx error exception
*/
WxOpenGetResult getOpenAccount(String appId) throws WxErrorException;
WxOpenGetResult getOpenAccount(String appId, String appIdType) throws WxErrorException;
/**
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21538208049W8uwq&token=&lang=zh_CN
@@ -262,7 +468,7 @@ public interface WxOpenComponentService {
* @param legalPersonaWechat 法人微信号
* @param legalPersonaName 法人姓名(绑定银行卡)
* @param componentPhone 第三方联系电话(方便法人与第三方联系)
* @return .
* @return . wx open result
* @throws WxErrorException .
*/
WxOpenResult fastRegisterWeapp(String name, String code, String codeType, String legalPersonaWechat, String legalPersonaName, String componentPhone) throws WxErrorException;
@@ -277,6 +483,7 @@ public interface WxOpenComponentService {
* @param name 企业名(需与工商部门登记信息一致)
* @param legalPersonaWechat 法人微信号
* @param legalPersonaName 法人姓名(绑定银行卡)
* @return the wx open result
* @throws WxErrorException .
*/
WxOpenResult fastRegisterWeappSearch(String name, String legalPersonaWechat, String legalPersonaName) throws WxErrorException;

View File

@@ -9,54 +9,172 @@ import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken;
import java.util.concurrent.locks.Lock;
/**
* The interface Wx open config storage.
*
* @author <a href="https://github.com/007gzs">007</a>
*/
public interface WxOpenConfigStorage {
/**
* Gets component app id.
*
* @return the component app id
*/
String getComponentAppId();
/**
* Sets component app id.
*
* @param componentAppId the component app id
*/
void setComponentAppId(String componentAppId);
/**
* Gets component app secret.
*
* @return the component app secret
*/
String getComponentAppSecret();
/**
* Sets component app secret.
*
* @param componentAppSecret the component app secret
*/
void setComponentAppSecret(String componentAppSecret);
/**
* Gets component token.
*
* @return the component token
*/
String getComponentToken();
/**
* Sets component token.
*
* @param componentToken the component token
*/
void setComponentToken(String componentToken);
/**
* Gets component aes key.
*
* @return the component aes key
*/
String getComponentAesKey();
/**
* Sets component aes key.
*
* @param componentAesKey the component aes key
*/
void setComponentAesKey(String componentAesKey);
/**
* Gets component verify ticket.
*
* @return the component verify ticket
*/
String getComponentVerifyTicket();
/**
* Sets component verify ticket.
*
* @param componentVerifyTicket the component verify ticket
*/
void setComponentVerifyTicket(String componentVerifyTicket);
/**
* Gets component access token.
*
* @return the component access token
*/
String getComponentAccessToken();
/**
* Is component access token expired boolean.
*
* @return the boolean
*/
boolean isComponentAccessTokenExpired();
/**
* Expire component access token.
*/
void expireComponentAccessToken();
/**
* Update component access token.
*
* @param componentAccessToken the component access token
*/
void updateComponentAccessToken(WxOpenComponentAccessToken componentAccessToken);
/**
* Gets http proxy host.
*
* @return the http proxy host
*/
String getHttpProxyHost();
/**
* Gets http proxy port.
*
* @return the http proxy port
*/
int getHttpProxyPort();
/**
* Gets http proxy username.
*
* @return the http proxy username
*/
String getHttpProxyUsername();
/**
* Gets http proxy password.
*
* @return the http proxy password
*/
String getHttpProxyPassword();
/**
* Gets apache http client builder.
*
* @return the apache http client builder
*/
ApacheHttpClientBuilder getApacheHttpClientBuilder();
/**
* Gets wx mp config storage.
*
* @param appId the app id
* @return the wx mp config storage
*/
WxMpConfigStorage getWxMpConfigStorage(String appId);
/**
* Gets wx ma config.
*
* @param appId the app id
* @return the wx ma config
*/
WxMaConfig getWxMaConfig(String appId);
/**
* Gets component access token lock.
*
* @return the component access token lock
*/
Lock getComponentAccessTokenLock();
/**
* Gets lock by key.
*
* @param key the key
* @return the lock by key
*/
Lock getLockByKey(String key);
/**
@@ -69,25 +187,61 @@ public interface WxOpenConfigStorage {
/**
* 是否自动刷新token
*
* @return the boolean
*/
boolean autoRefreshToken();
/**
* Gets authorizer refresh token.
*
* @param appId the app id
* @return the authorizer refresh token
*/
String getAuthorizerRefreshToken(String appId);
/**
* Sets authorizer refresh token.
*
* @param appId the app id
* @param authorizerRefreshToken the authorizer refresh token
*/
void setAuthorizerRefreshToken(String appId, String authorizerRefreshToken);
/**
* setAuthorizerRefreshToken(String appId, String authorizerRefreshToken) 方法重载方法
* @param appId the app id
* @param authorizerRefreshToken the authorizer refresh token
*/
void updateAuthorizerRefreshToken(String appId, String authorizerRefreshToken);
/**
* Gets authorizer access token.
*
* @param appId the app id
* @return the authorizer access token
*/
String getAuthorizerAccessToken(String appId);
/**
* Is authorizer access token expired boolean.
*
* @param appId the app id
* @return the boolean
*/
boolean isAuthorizerAccessTokenExpired(String appId);
/**
* 强制将access token过期掉
*
* @param appId the app id
*/
void expireAuthorizerAccessToken(String appId);
/**
* 应该是线程安全的
*
* @param appId the app id
* @param authorizerAccessToken 要更新的WxAccessToken对象
*/
void updateAuthorizerAccessToken(String appId, WxOpenAuthorizerAccessToken authorizerAccessToken);
@@ -95,41 +249,72 @@ public interface WxOpenConfigStorage {
/**
* 应该是线程安全的
*
* @param appId the app id
* @param authorizerAccessToken 新的accessToken值
* @param expiresInSeconds 过期时间,以秒为单位
*/
void updateAuthorizerAccessToken(String appId, String authorizerAccessToken, int expiresInSeconds);
/**
* Gets jsapi ticket.
*
* @param appId the app id
* @return the jsapi ticket
*/
String getJsapiTicket(String appId);
/**
* Is jsapi ticket expired boolean.
*
* @param appId the app id
* @return the boolean
*/
boolean isJsapiTicketExpired(String appId);
/**
* 强制将jsapi ticket过期掉
*
* @param appId the app id
*/
void expireJsapiTicket(String appId);
/**
* 应该是线程安全的
*
* @param appId the app id
* @param jsapiTicket 新的jsapi ticket值
* @param expiresInSeconds 过期时间,以秒为单位
*/
void updateJsapiTicket(String appId, String jsapiTicket, int expiresInSeconds);
/**
* Gets card api ticket.
*
* @param appId the app id
* @return the card api ticket
*/
String getCardApiTicket(String appId);
/**
* Is card api ticket expired boolean.
*
* @param appId the app id
* @return the boolean
*/
boolean isCardApiTicketExpired(String appId);
/**
* 强制将卡券api ticket过期掉
*
* @param appId the app id
*/
void expireCardApiTicket(String appId);
/**
* 应该是线程安全的
*
* @param appId the app id
* @param cardApiTicket 新的cardApi ticket值
* @param expiresInSeconds 过期时间,以秒为单位
*/
@@ -137,10 +322,11 @@ public interface WxOpenConfigStorage {
/**
* 设置第三方平台基础信息
* @param componentAppId 第三方平台 appid
*
* @param componentAppId 第三方平台 appid
* @param componentAppSecret 第三方平台 appsecret
* @param componentToken 消息校验Token
* @param componentAesKey 消息加解密Key
* @param componentToken 消息校验Token
* @param componentAesKey 消息加解密Key
*/
void setWxOpenInfo(String componentAppId, String componentAppSecret, String componentToken, String componentAesKey);
}

View File

@@ -17,10 +17,9 @@ import java.util.Map;
* </pre>
*
* @author yqx
* @date 2018/9/12
* @date 2018 /9/12
*/
public interface WxOpenMaService extends WxMaService {
/**
* 设置小程序服务器域名.
*
@@ -73,11 +72,8 @@ public interface WxOpenMaService extends WxMaService {
/**
* 以下接口基础信息设置
* <p>
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21517799059ZSEMr&token=6f965b5daf30a98a6bbd2a386faea5c934e929bf&lang=zh_CN
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=21517799059ZSEMr&token=6f965b5daf30a98a6bbd2a386faea5c934e929bf&lang=zh_CN
* </p>
*/
/**
* 1. 设置小程序隐私设置(是否可被搜索)
*/
String API_CHANGE_WXA_SEARCH_STATUS = "https://api.weixin.qq.com/wxa/changewxasearchstatus";
@@ -101,11 +97,8 @@ public interface WxOpenMaService extends WxMaService {
/**
* 以下接口为三方平台代小程序实现的代码管理功能
* <p>
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140610_Uavc4&token=fe774228c66725425675810097f9e48d0737a4bf&lang=zh_CN
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489140610_Uavc4&token=fe774228c66725425675810097f9e48d0737a4bf&lang=zh_CN
* </p>
*/
/**
* 1. 为授权的小程序帐号上传小程序代码
*/
String API_CODE_COMMIT = "https://api.weixin.qq.com/wxa/commit";
@@ -167,10 +160,8 @@ public interface WxOpenMaService extends WxMaService {
/**
* 14.设置小程序“扫普通链接二维码打开小程序”能力
*
* <p>
* https://mp.weixin.qq.com/debug/wxadoc/introduction/qrcode.html
*/
/**
* 14.1 增加或修改二维码规则
*/
String API_QRCODE_JUMP_ADD = "https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumpadd";
@@ -229,112 +220,142 @@ public interface WxOpenMaService extends WxMaService {
*/
String API_SPEED_AUDIT = "https://api.weixin.qq.com/wxa/speedupaudit";
/**
* 获得小程序的域名配置信息
*
* @return the domain
* @throws WxErrorException the wx error exception
*/
WxOpenMaDomainResult getDomain() throws WxErrorException;
/**
* 修改域名
*
* @param action delete删除, set覆盖, get获取
* @param action delete删除, set覆盖, get获取
* @param requestDomains the requestdomain list
* @param wsRequestDomains the wsrequestdomain list
* @param uploadDomains the uploaddomain list
* @param downloadDomains the downloaddomain list
* @return the wx open ma domain result
* @throws WxErrorException the wx error exception
*/
WxOpenMaDomainResult modifyDomain(String action, List<String> requestdomainList, List<String> wsrequestdomainList, List<String> uploaddomainList, List<String> downloaddomainList) throws WxErrorException;
WxOpenMaDomainResult modifyDomain(String action, List<String> requestDomains, List<String> wsRequestDomains,
List<String> uploadDomains, List<String> downloadDomains) throws WxErrorException;
/**
* 获取小程序的业务域名
*
* @return 直接返回字符串
* @return 直接返回字符串 web view domain
* @throws WxErrorException the wx error exception
*/
String getWebViewDomain() throws WxErrorException;
/**
* 获取小程序的业务域名
*
* @return
* @return web view domain info
* @throws WxErrorException the wx error exception
*/
public WxOpenMaWebDomainResult getWebViewDomainInfo() throws WxErrorException;
/**
* 设置小程序的业务域名
*
* @param action add添加, delete删除, set覆盖
* @return 直接返回字符串
*/
String setWebViewDomain(String action, List<String> domainList) throws WxErrorException;
WxOpenMaWebDomainResult getWebViewDomainInfo() throws WxErrorException;
/**
* 设置小程序的业务域名
*
* @param action add添加, delete删除, set覆盖
* @param domainList
* @return
* @param domainList the domain list
* @return 直接返回字符串 web view domain
* @throws WxErrorException the wx error exception
*/
String setWebViewDomain(String action, List<String> domainList) throws WxErrorException;
/**
* 设置小程序的业务域名
*
* @param action add添加, delete删除, set覆盖
* @param domainList the domain list
* @return web view domain info
* @throws WxErrorException the wx error exception
*/
WxOpenMaWebDomainResult setWebViewDomainInfo(String action, List<String> domainList) throws WxErrorException;
/**
* 获取小程序的信息
*
* @return the account basic info
* @throws WxErrorException the wx error exception
*/
String getAccountBasicInfo() throws WxErrorException;
/**
* 绑定小程序体验者
*
* @param wechatid 体验者微信号不是openid
* @return
* @throws WxErrorException
* @param wechatId 体验者微信号不是openid
* @return wx open ma bind tester result
* @throws WxErrorException the wx error exception
*/
WxOpenMaBindTesterResult bindTester(String wechatid) throws WxErrorException;
WxOpenMaBindTesterResult bindTester(String wechatId) throws WxErrorException;
/**
* 解除绑定小程序体验者
*
* @param wechatid 体验者微信号不是openid
* @param wechatId 体验者微信号不是openid
* @return the wx open result
* @throws WxErrorException the wx error exception
*/
WxOpenResult unbindTester(String wechatid) throws WxErrorException;
WxOpenResult unbindTester(String wechatId) throws WxErrorException;
/**
* 解除绑定小程序体验者其他平台绑定的体验者无法获取到wechatid可用此方法解绑详见文档
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/unbind_tester.html
*
* @param userstr 人员对应的唯一字符串, 可通过获取已绑定的体验者列表获取人员对应的字符串
* @param userStr 人员对应的唯一字符串, 可通过获取已绑定的体验者列表获取人员对应的字符串
* @return the wx open result
* @throws WxErrorException the wx error exception
*/
WxOpenResult unbindTesterByUserstr(String userstr) throws WxErrorException;
WxOpenResult unbindTesterByUserStr(String userStr) throws WxErrorException;
/**
* 获得体验者列表
*
* @return the tester list
* @throws WxErrorException the wx error exception
*/
WxOpenMaTesterListResult getTesterList() throws WxErrorException;
/**
* 设置小程序隐私设置(是否可被搜索)
*
* @param status 1表示不可搜索0表示可搜索
* @return the wx open result
* @throws WxErrorException the wx error exception
*/
public WxOpenResult changeWxaSearchStatus(Integer status) throws WxErrorException;
WxOpenResult changeWxaSearchStatus(Integer status) throws WxErrorException;
/**
* 2. 查询小程序当前隐私设置(是否可被搜索)
*
* @return the wxa search status
* @throws WxErrorException the wx error exception
*/
public WxOpenMaSearchStatusResult getWxaSearchStatus() throws WxErrorException;
WxOpenMaSearchStatusResult getWxaSearchStatus() throws WxErrorException;
/**
* 3.1 获取展示的公众号信息
*
* @return the show wxa item
* @throws WxErrorException the wx error exception
*/
public WxOpenMaShowItemResult getShowWxaItem() throws WxErrorException;
WxOpenMaShowItemResult getShowWxaItem() throws WxErrorException;
/**
* 3.2 设置展示的公众号
*
* @param flag 0 关闭1 开启
* @param mpappid 如果开启需要传新的公众号appid
* @param mpAppId 如果开启需要传新的公众号appid
* @return the wx open result
* @throws WxErrorException the wx error exception
*/
public WxOpenResult updateShowwxaitem(Integer flag, String mpappid) throws WxErrorException;
WxOpenResult updateShowWxaItem(Integer flag, String mpAppId) throws WxErrorException;
/**
* 1、为授权的小程序帐号上传小程序代码
@@ -343,11 +364,18 @@ public interface WxOpenMaService extends WxMaService {
* @param userVersion 用户定义版本
* @param userDesc 用户定义版本描述
* @param extInfo 第三方自定义的配置
* @return the wx open result
* @throws WxErrorException the wx error exception
*/
WxOpenResult codeCommit(Long templateId, String userVersion, String userDesc, WxMaOpenCommitExtInfo extInfo) throws WxErrorException;
/**
* 获取体验小程序的体验二维码
*
* @param pagePath the page path
* @param params the params
* @return the test qrcode
* @throws WxErrorException the wx error exception
*/
File getTestQrcode(String pagePath, Map<String, String> params) throws WxErrorException;
@@ -356,124 +384,203 @@ public interface WxOpenMaService extends WxMaService {
* <p>
* 注意:该接口可获取已设置的二级类目及用于代码审核的可选三级类目。
* </p>
*
* @return the category list
* @throws WxErrorException the wx error exception
*/
WxOpenMaCategoryListResult getCategoryList() throws WxErrorException;
/**
* 获取小程序的第三方提交代码的页面配置(仅供第三方开发者代小程序调用)
*
* @return
* @throws WxErrorException
* @return page list
* @throws WxErrorException the wx error exception
*/
WxOpenMaPageListResult getPageList() throws WxErrorException;
/**
* 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用)
*
* @param submitAuditMessage the submit audit message
* @return the wx open ma submit audit result
* @throws WxErrorException the wx error exception
*/
WxOpenMaSubmitAuditResult submitAudit(WxOpenMaSubmitAuditMessage submitAuditMessage) throws WxErrorException;
/**
* 查询某个指定版本的审核状态(仅供第三方代小程序调用)
*
* @param auditId the auditid
* @return the audit status
* @throws WxErrorException the wx error exception
*/
WxOpenMaQueryAuditResult getAuditStatus(Long auditid) throws WxErrorException;
WxOpenMaQueryAuditResult getAuditStatus(Long auditId) throws WxErrorException;
/**
* 查询最新一次提交的审核状态(仅供第三方代小程序调用).
* 8. 查询最新一次提交的审核状态(仅供第三方代小程序调用)
*
* @return 。
* @throws WxErrorException 。
*/
WxOpenMaQueryAuditResult getLatestAuditStatus() throws WxErrorException;
/**
* 发布已通过审核的小程序(仅供第三方代小程序调用).
* 9. 发布已通过审核的小程序(仅供第三方代小程序调用)
* <p>
* 请填写空的数据包POST的json数据包为空即可。
* </p>
*
* @return 。
* @throws WxErrorException 。
*/
WxOpenResult releaesAudited() throws WxErrorException;
WxOpenResult releaseAudited() throws WxErrorException;
/**
* 10. 修改小程序线上代码的可见状态(仅供第三方代小程序调用)
*
* @param action the action
* @return the wx open result
* @throws WxErrorException the wx error exception
*/
public WxOpenResult changeVisitstatus(String action) throws WxErrorException;
WxOpenResult changeVisitStatus(String action) throws WxErrorException;
/**
* 11. 小程序版本回退(仅供第三方代小程序调用)
*
* @return 。
* @throws WxErrorException 。
*/
WxOpenResult revertCodeReleaes() throws WxErrorException;
WxOpenResult revertCodeRelease() throws WxErrorException;
/**
* 15. 小程序审核撤回
* <p>
* 单个帐号每天审核撤回次数最多不超过1次一个月不超过10次。
* </p>
*
* @return 。
* @throws WxErrorException 。
*/
WxOpenResult undoCodeAudit() throws WxErrorException;
/**
* 查询当前设置的最低基础库版本及各版本用户占比 (仅供第三方代小程序调用)
* 12. 查询当前设置的最低基础库版本及各版本用户占比 (仅供第三方代小程序调用)
*
* @return 。
* @throws WxErrorException 。
*/
String getSupportVersion() throws WxErrorException;
/**
* 查询当前设置的最低基础库版本及各版本用户占比 (仅供第三方代小程序调用)
* 12. 查询当前设置的最低基础库版本及各版本用户占比 (仅供第三方代小程序调用)
*
* @return . support version info
* @throws WxErrorException .
*/
WxOpenMaWeappSupportVersionResult getSupportVersionInfo() throws WxErrorException;
/**
* 设置最低基础库版本(仅供第三方代小程序调用)
*
* @param version the version
* @return the support version
* @throws WxErrorException the wx error exception
*/
String setSupportVersion(String version) throws WxErrorException;
/**
* 设置最低基础库版本(仅供第三方代小程序调用)
* 13. 设置最低基础库版本(仅供第三方代小程序调用)
*
* @param version the version
* @return support version info
* @throws WxErrorException the wx error exception
*/
WxOpenResult setSupportVersionInfo(String version) throws WxErrorException;
/**
* 16. 小程序分阶段发布 - 1)分阶段发布接口
*
* @param grayPercentage 灰度的百分比1到100的整数
* @return . wx open result
* @throws WxErrorException .
*/
WxOpenResult grayrelease(Integer grayPercentage) throws WxErrorException;
WxOpenResult grayRelease(Integer grayPercentage) throws WxErrorException;
/**
* 16. 小程序分阶段发布 - 2)取消分阶段发布
*
* @return . wx open result
* @throws WxErrorException .
*/
WxOpenResult revertgrayrelease() throws WxErrorException;
WxOpenResult revertGrayRelease() throws WxErrorException;
/**
* 16. 小程序分阶段发布 - 3)查询当前分阶段发布详情
*
* @return . gray release plan
* @throws WxErrorException .
*/
WxOpenMaGrayReleasePlanResult getgrayreleaseplan() throws WxErrorException;
WxOpenMaGrayReleasePlanResult getGrayReleasePlan() throws WxErrorException;
/**
* 查询服务商的当月提审限额和加急次数Quota
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/code/query_quota.html
*
* @return the wx open ma query quota result
* @throws WxErrorException the wx error exception
*/
WxOpenMaQueryQuotaResult queryQuota() throws WxErrorException;
/**
* 加急审核申请
* 有加急次数的第三方可以通过该接口对已经提审的小程序进行加急操作加急后的小程序预计2-12小时内审完。
*
* @param auditId the auditid
* @return the boolean
* @throws WxErrorException the wx error exception
*/
Boolean speedAudit(Long auditid) throws WxErrorException;
Boolean speedAudit(Long auditId) throws WxErrorException;
/**
* (1)增加或修改二维码规则
*
* @param wxQrcodeJumpRule the wx qrcode jump rule
* @return the wx open result
* @throws WxErrorException the wx error exception
*/
WxOpenResult addQrcodeJump(WxQrcodeJumpRule wxQrcodeJumpRule) throws WxErrorException;
/**
* (2)获取已设置的二维码规则
*
* @return the qrcode jump
* @throws WxErrorException the wx error exception
*/
WxGetQrcodeJumpResult getQrcodeJump() throws WxErrorException;
/**
* (3)获取校验文件名称及内容
*
* @return the wx downlooad qrcode jump result
* @throws WxErrorException the wx error exception
*/
WxDownlooadQrcodeJumpResult downloadQrcodeJump() throws WxErrorException;
/**
* (4)删除已设置的二维码规则
*
* @param prefix the prefix
* @return the wx open result
* @throws WxErrorException the wx error exception
*/
WxOpenResult deleteQrcodeJump(String prefix) throws WxErrorException;
/**
* (5)发布已设置的二维码规则
*
* @param prefix the prefix
* @return the wx open result
* @throws WxErrorException the wx error exception
*/
WxOpenResult publishQrcodeJump(String prefix) throws WxErrorException;
}

View File

@@ -3,22 +3,49 @@ package me.chanjar.weixin.open.api;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* The interface Wx open service.
*
* @author <a href="https://github.com/007gzs">007</a>
*/
public interface WxOpenService {
/**
* Gets wx open component service.
*
* @return the wx open component service
*/
WxOpenComponentService getWxOpenComponentService();
/**
* Gets wx open config storage.
*
* @return the wx open config storage
*/
WxOpenConfigStorage getWxOpenConfigStorage();
/**
* Sets wx open config storage.
*
* @param wxOpenConfigStorage the wx open config storage
*/
void setWxOpenConfigStorage(WxOpenConfigStorage wxOpenConfigStorage);
/**
* 当本Service没有实现某个API的时候可以用这个针对所有微信API中的GET请求
*
* @param url the url
* @param queryParam the query param
* @return the string
* @throws WxErrorException the wx error exception
*/
String get(String url, String queryParam) throws WxErrorException;
/**
* 当本Service没有实现某个API的时候可以用这个针对所有微信API中的POST请求
*
* @param url the url
* @param postData the post data
* @return the string
* @throws WxErrorException the wx error exception
*/
String post(String url, String postData) throws WxErrorException;

View File

@@ -2,12 +2,15 @@ package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
@@ -18,29 +21,25 @@ import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage;
import me.chanjar.weixin.open.bean.result.*;
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
/**
* @author <a href="https://github.com/007gzs">007</a>
*/
@Slf4j
@AllArgsConstructor
public class WxOpenComponentServiceImpl implements WxOpenComponentService {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final Map<String, WxOpenMaService> WX_OPEN_MA_SERVICE_MAP = new ConcurrentHashMap<>();
private static final Map<String, WxMpService> WX_OPEN_MP_SERVICE_MAP = new ConcurrentHashMap<>();
private static final Map<String, WxOpenFastMaService> WX_OPEN_FAST_MA_SERVICE_MAP = new ConcurrentHashMap<>();
protected final Logger log = LoggerFactory.getLogger(this.getClass());
private WxOpenService wxOpenService;
public WxOpenComponentServiceImpl(WxOpenService wxOpenService) {
this.wxOpenService = wxOpenService;
}
private final WxOpenService wxOpenService;
@Override
public WxMpService getWxMpServiceByAppid(String appId) {
@@ -147,14 +146,8 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
return getWxOpenService().post(uriWithComponentAccessToken, postData);
} catch (WxErrorException e) {
WxError error = e.getError();
/*
* 发生以下情况时尝试刷新access_token
* 40001 获取access_token时AppSecret错误或者access_token无效
* 42001 access_token超时
* 40014 不合法的access_token请开发者认真比对access_token的有效性如是否过期或查看是否正在为恰当的公众号调用接口
*/
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) {
// 强制设置wxMpConfigStorage它的access token过期了这样在下一次请求里就会刷新access token
if (WxConsts.ACCESS_TOKEN_ERROR_CODES.contains(error.getErrorCode())) {
// 强制设置access token过期这样在下一次请求里就会刷新access token
Lock lock = this.getWxOpenConfigStorage().getComponentAccessTokenLock();
lock.lock();
try {
@@ -168,6 +161,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
}
if (this.getWxOpenConfigStorage().autoRefreshToken()) {
log.warn("即将重新获取新的access_token错误代码{},错误信息:{}", error.getErrorCode(), error.getErrorMsg());
return this.post(uri, postData, accessTokenKey);
}
}
@@ -191,13 +185,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
return getWxOpenService().get(uriWithComponentAccessToken, null);
} catch (WxErrorException e) {
WxError error = e.getError();
/*
* 发生以下情况时尝试刷新access_token
* 40001 获取access_token时AppSecret错误或者access_token无效
* 42001 access_token超时
* 40014 不合法的access_token请开发者认真比对access_token的有效性如是否过期或查看是否正在为恰当的公众号调用接口
*/
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) {
if (WxConsts.ACCESS_TOKEN_ERROR_CODES.contains(error.getErrorCode())) {
// 强制设置wxMpConfigStorage它的access token过期了这样在下一次请求里就会刷新access token
Lock lock = this.getWxOpenConfigStorage().getComponentAccessTokenLock();
lock.lock();
@@ -211,6 +199,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
lock.unlock();
}
if (this.getWxOpenConfigStorage().autoRefreshToken()) {
log.warn("即将重新获取新的access_token错误代码{},错误信息:{}", error.getErrorCode(), error.getErrorMsg());
return this.get(uri, accessTokenKey);
}
}
@@ -227,41 +216,33 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
}
@Override
public String getPreAuthUrl(String redirectURI, String authType, String bizAppid) throws WxErrorException {
return createPreAuthUrl(redirectURI, authType, bizAppid, false);
public String getPreAuthUrl(String redirectUri, String authType, String bizAppid) throws WxErrorException {
return createPreAuthUrl(redirectUri, authType, bizAppid, false);
}
@Override
public String getMobilePreAuthUrl(String redirectURI) throws WxErrorException {
return getMobilePreAuthUrl(redirectURI, null, null);
public String getMobilePreAuthUrl(String redirectUri) throws WxErrorException {
return getMobilePreAuthUrl(redirectUri, null, null);
}
@Override
public String getMobilePreAuthUrl(String redirectURI, String authType, String bizAppid) throws WxErrorException {
return createPreAuthUrl(redirectURI, authType, bizAppid, true);
public String getMobilePreAuthUrl(String redirectUri, String authType, String bizAppid) throws WxErrorException {
return createPreAuthUrl(redirectUri, authType, bizAppid, true);
}
/**
* 创建预授权链接
*
* @param redirectURI
* @param authType
* @param bizAppid
* @param isMobile 是否移动端预授权
* @return
* @throws WxErrorException
*/
private String createPreAuthUrl(String redirectURI, String authType, String bizAppid, boolean isMobile) throws WxErrorException {
private String createPreAuthUrl(String redirectUri, String authType, String bizAppid, boolean isMobile) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
String responseContent = post(API_CREATE_PREAUTHCODE_URL, jsonObject.toString());
jsonObject = WxGsonBuilder.create().fromJson(responseContent, JsonObject.class);
StringBuilder preAuthUrl = new StringBuilder(String.format((isMobile ? COMPONENT_MOBILE_LOGIN_PAGE_URL : COMPONENT_LOGIN_PAGE_URL),
String preAuthUrlStr = String.format((isMobile ? COMPONENT_MOBILE_LOGIN_PAGE_URL : COMPONENT_LOGIN_PAGE_URL),
getWxOpenConfigStorage().getComponentAppId(),
jsonObject.get("pre_auth_code").getAsString(),
URIUtil.encodeURIComponent(redirectURI)));
String preAuthUrlStr = preAuthUrl.toString();
URIUtil.encodeURIComponent(redirectUri));
if (StringUtils.isNotEmpty(authType)) {
preAuthUrlStr = preAuthUrlStr.replace("&auth_type=xxx", "&auth_type=" + authType);
} else {
@@ -320,7 +301,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
authorizationInfo.getAuthorizerAccessToken(), authorizationInfo.getExpiresIn());
}
if (authorizationInfo.getAuthorizerRefreshToken() != null) {
getWxOpenConfigStorage().setAuthorizerRefreshToken(authorizationInfo.getAuthorizerAppid(), authorizationInfo.getAuthorizerRefreshToken());
getWxOpenConfigStorage().updateAuthorizerRefreshToken(authorizationInfo.getAuthorizerAppid(), authorizationInfo.getAuthorizerRefreshToken());
}
return queryAuth;
}
@@ -336,7 +317,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
@Override
public WxOpenAuthorizerListResult getAuthorizerList(int begin, int len) throws WxErrorException {
begin = begin < 0 ? 0 : begin;
begin = Math.max(begin, 0);
len = len == 0 ? 10 : len;
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
@@ -349,7 +330,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
String authorizerAppid = data.get("authorizer_appid");
String refreshToken = data.get("refresh_token");
if (authorizerAppid != null && refreshToken != null) {
this.getWxOpenConfigStorage().setAuthorizerRefreshToken(authorizerAppid, refreshToken);
this.getWxOpenConfigStorage().updateAuthorizerRefreshToken(authorizerAppid, refreshToken);
}
}
}
@@ -383,11 +364,15 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
return config.getAuthorizerAccessToken(appId);
}
Lock lock = config.getWxMpConfigStorage(appId).getAccessTokenLock();
lock.lock();
boolean locked = false;
try {
if (!config.isAuthorizerAccessTokenExpired(appId) && !forceRefresh) {
return config.getAuthorizerAccessToken(appId);
}
do {
locked = lock.tryLock(100, TimeUnit.MILLISECONDS);
if (!forceRefresh && !config.isAuthorizerAccessTokenExpired(appId)) {
return config.getAuthorizerAccessToken(appId);
}
} while (!locked);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
jsonObject.addProperty("authorizer_appid", appId);
@@ -396,9 +381,14 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
WxOpenAuthorizerAccessToken wxOpenAuthorizerAccessToken = WxOpenAuthorizerAccessToken.fromJson(responseContent);
config.updateAuthorizerAccessToken(appId, wxOpenAuthorizerAccessToken);
config.updateAuthorizerRefreshToken(appId,wxOpenAuthorizerAccessToken.getAuthorizerRefreshToken());
return config.getAuthorizerAccessToken(appId);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
lock.unlock();
if (locked) {
lock.unlock();
}
}
}
@@ -437,7 +427,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
@Override
public List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException {
String responseContent = get(GET_TEMPLATE_DRAFT_LIST_URL, "access_token");
JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject();
JsonObject response = GsonParser.parse(StringUtils.defaultString(responseContent, "{}"));
boolean hasDraftList = response.has("draft_list");
if (hasDraftList) {
return WxOpenGsonBuilder.create().fromJson(response.getAsJsonArray("draft_list"),
@@ -451,7 +441,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
@Override
public List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException {
String responseContent = get(GET_TEMPLATE_LIST_URL, "access_token");
JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject();
JsonObject response = GsonParser.parse(StringUtils.defaultString(responseContent, "{}"));
boolean hasTemplateList = response.has("template_list");
if (hasTemplateList) {
return WxOpenGsonBuilder.create().fromJson(response.getAsJsonArray("template_list"),
@@ -476,47 +466,71 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
post(DELETE_TEMPLATE_URL, param.toString(), "access_token");
}
/**
* 微信开放平台帐号管理统一请求入口
*
* @param appId 操作appId 小程序/公众号
* @param appIdType 操作类型 小程序/公众号
* @param requestUrl 请求地址
* @param param 请求参数
* @return 请求结果
* @throws WxErrorException
*/
private String openAccountServicePost(String appId, String appIdType, String requestUrl, JsonObject param) throws WxErrorException {
String result = "";
switch (appIdType) {
case WxConsts.AppIdType.MP_TYPE:
WxMpService wxMpService = this.getWxMpServiceByAppid(appId);
result = wxMpService.post(requestUrl, param.toString());
return result;
case WxConsts.AppIdType.MINI_TYPE:
WxOpenMaService maService = this.getWxMaServiceByAppid(appId);
result = maService.post(requestUrl, param.toString());
return result;
default:
throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("appIdType类型异常").build());
}
}
@Override
public WxOpenCreateResult createOpenAccount(String appId) throws WxErrorException {
public WxOpenCreateResult createOpenAccount(String appId, String appIdType) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("appid", appId);
String json = post(CREATE_OPEN_URL, param.toString(), "access_token");
String json = openAccountServicePost(appId, appIdType, CREATE_OPEN_URL, param);
return WxOpenCreateResult.fromJson(json);
}
@Override
public Boolean bindOpenAccount(String appId, String openAppid) throws WxErrorException {
public Boolean bindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("appid", appId);
param.addProperty("open_appid", openAppid);
String json = post(BIND_OPEN_URL, param.toString(), "access_token");
String json = openAccountServicePost(appId, appIdType, BIND_OPEN_URL, param);
return WxOpenResult.fromJson(json).isSuccess();
}
@Override
public Boolean unbindOpenAccount(String appId, String openAppid) throws WxErrorException {
public Boolean unbindOpenAccount(String appId, String appIdType, String openAppid) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("appid", appId);
param.addProperty("open_appid", openAppid);
String json = post(UNBIND_OPEN_URL, param.toString(), "access_token");
String json = openAccountServicePost(appId, appIdType, UNBIND_OPEN_URL, param);
return WxOpenResult.fromJson(json).isSuccess();
}
@Override
public WxOpenGetResult getOpenAccount(String appId) throws WxErrorException {
public WxOpenGetResult getOpenAccount(String appId, String appIdType) throws WxErrorException {
JsonObject param = new JsonObject();
param.addProperty("appid", appId);
String json = post(GET_OPEN_URL, param.toString(), "access_token");
String json = openAccountServicePost(appId, appIdType, GET_OPEN_URL, param);
return WxOpenGetResult.fromJson(json);
}

View File

@@ -22,9 +22,9 @@ import java.util.Map;
* @since 2019/1/23 15:27
*/
public class WxOpenFastMaServiceImpl extends WxMaServiceImpl implements WxOpenFastMaService {
private WxOpenComponentService wxOpenComponentService;
private WxMaConfig wxMaConfig;
private String appId;
private final WxOpenComponentService wxOpenComponentService;
private final WxMaConfig wxMaConfig;
private final String appId;
public WxOpenFastMaServiceImpl(WxOpenComponentService wxOpenComponentService, String appId, WxMaConfig wxMaConfig) {
this.wxOpenComponentService = wxOpenComponentService;

View File

@@ -142,7 +142,7 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
map.put(key, token);
}
token.token = tokenString;
if (expiresInSeconds != null) {
if (expiresInSeconds != null && expiresInSeconds != -1) {
token.expiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
}
}
@@ -157,6 +157,11 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
updateToken(authorizerRefreshTokens, appId, authorizerRefreshToken, null);
}
@Override
public void updateAuthorizerRefreshToken(String appId, String authorizerRefreshToken) {
this.setAuthorizerRefreshToken(appId, authorizerRefreshToken);
}
@Override
public String getAuthorizerAccessToken(String appId) {
return getTokenString(authorizerAccessTokens, appId);
@@ -230,8 +235,10 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
}
private static class WxOpenInnerConfigStorage implements WxMpConfigStorage, WxMaConfig {
private WxOpenConfigStorage wxOpenConfigStorage;
private String appId;
private final WxOpenConfigStorage wxOpenConfigStorage;
private final String appId;
private WxMpHostConfig hostConfig;
/**
* 小程序原始ID
*/
@@ -522,7 +529,12 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
@Override
public WxMpHostConfig getHostConfig() {
return null;
return this.hostConfig;
}
@Override
public void setHostConfig(WxMpHostConfig hostConfig) {
this.hostConfig = hostConfig;
}
}
}

View File

@@ -4,7 +4,7 @@ import lombok.NonNull;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import redis.clients.jedis.Jedis;
import redis.clients.util.Pool;
import redis.clients.jedis.util.Pool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;

View File

@@ -1,5 +1,6 @@
package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
@@ -20,18 +21,19 @@ import java.util.List;
import java.util.Map;
/**
* @author <a href="https://github.com/007gzs">007</a>
* <pre>
* 增加开放平台代小程序管理服务能力
* 说明:这里让这个服务公开便于调用者模拟本地测试服务
* </pre>
*
* @author <a href="https://github.com/007gzs">007</a>
* @author yqx
* @date 2018-09-12
*/
public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaService {
private WxOpenComponentService wxOpenComponentService;
private WxMaConfig wxMaConfig;
private String appId;
private final WxOpenComponentService wxOpenComponentService;
private final WxMaConfig wxMaConfig;
private final String appId;
public WxOpenMaServiceImpl(WxOpenComponentService wxOpenComponentService, String appId, WxMaConfig wxMaConfig) {
this.wxOpenComponentService = wxOpenComponentService;
@@ -55,72 +57,38 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
return wxOpenComponentService.getAuthorizerAccessToken(appId, forceRefresh);
}
/**
* 获得小程序的域名配置信息
*
* @return
*/
@Override
public WxOpenMaDomainResult getDomain() throws WxErrorException {
return modifyDomain("get", null, null, null, null);
}
/**
* 修改服务器域名
*
* @param action delete删除, set覆盖, get获取
* @param requestdomainList
* @param wsrequestdomainList
* @param uploaddomainList
* @param downloaddomainList
* @return
* @throws WxErrorException
*/
@Override
public WxOpenMaDomainResult modifyDomain(String action, List<String> requestdomainList, List<String> wsrequestdomainList, List<String> uploaddomainList, List<String> downloaddomainList) throws WxErrorException {
public WxOpenMaDomainResult modifyDomain(String action, List<String> requestDomains, List<String> wsRequestDomains, List<String> uploadDomains, List<String> downloadDomains) throws WxErrorException {
// if (!"get".equals(action) && (requestdomainList == null || wsrequestdomainList == null || uploaddomainList == null || downloaddomainList == null)) {
// throw new WxErrorException(WxError.builder().errorCode(44004).errorMsg("域名参数不能为空").build());
// }
JsonObject requestJson = new JsonObject();
requestJson.addProperty("action", action);
if (!"get".equals(action)) {
requestJson.add("requestdomain", toJsonArray(requestdomainList));
requestJson.add("wsrequestdomain", toJsonArray(wsrequestdomainList));
requestJson.add("uploaddomain", toJsonArray(uploaddomainList));
requestJson.add("downloaddomain", toJsonArray(downloaddomainList));
requestJson.add("requestdomain", toJsonArray(requestDomains));
requestJson.add("wsrequestdomain", toJsonArray(wsRequestDomains));
requestJson.add("uploaddomain", toJsonArray(uploadDomains));
requestJson.add("downloaddomain", toJsonArray(downloadDomains));
}
String response = post(API_MODIFY_DOMAIN, GSON.toJson(requestJson));
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaDomainResult.class);
}
/**
* 获取小程序的业务域名
*
* @return
*/
@Override
public String getWebViewDomain() throws WxErrorException {
return setWebViewDomain("get", null);
}
/**
* 获取小程序的业务域名
*
* @return
*/
@Override
public WxOpenMaWebDomainResult getWebViewDomainInfo() throws WxErrorException {
return setWebViewDomainInfo("get", null);
}
/**
* 设置小程序的业务域名
*
* @param action add添加, delete删除, set覆盖
* @param domainList
* @return
*/
@Override
public String setWebViewDomain(String action, List<String> domainList) throws WxErrorException {
JsonObject requestJson = new JsonObject();
@@ -128,18 +96,10 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
if (!"get".equals(action)) {
requestJson.add("webviewdomain", toJsonArray(domainList));
}
String response = post(API_SET_WEBVIEW_DOMAIN, GSON.toJson(requestJson));
//TODO 转化为对象返回
return response;
return post(API_SET_WEBVIEW_DOMAIN, GSON.toJson(requestJson));
}
/**
* 设置小程序的业务域名
*
* @param action add添加, delete删除, set覆盖
* @return
*/
@Override
public WxOpenMaWebDomainResult setWebViewDomainInfo(String action, List<String> domainList) throws WxErrorException {
String response = this.setWebViewDomain(action, domainList);
@@ -147,73 +107,36 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
}
/**
* 获取小程序的信息,GET请求
* <pre>
* 注意这里不能直接用小程序的access_token
* //TODO 待调整
* </pre>
*
* @return
* @throws WxErrorException
*/
@Override
public String getAccountBasicInfo() throws WxErrorException {
String response = get(API_GET_ACCOUNT_BASICINFO, "");
return response;
return get(API_GET_ACCOUNT_BASICINFO, "");
}
/**
* 绑定小程序体验者
*
* @param wechatid 体验者微信号不是openid
* @return
* @throws WxErrorException
*/
@Override
public WxOpenMaBindTesterResult bindTester(String wechatid) throws WxErrorException {
public WxOpenMaBindTesterResult bindTester(String wechatId) throws WxErrorException {
JsonObject paramJson = new JsonObject();
paramJson.addProperty("wechatid", wechatid);
paramJson.addProperty("wechatid", wechatId);
String response = post(API_BIND_TESTER, GSON.toJson(paramJson));
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaBindTesterResult.class);
}
/**
* 解除绑定小程序体验者
*
* @param wechatid 体验者微信号不是openid
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult unbindTester(String wechatid) throws WxErrorException {
public WxOpenResult unbindTester(String wechatId) throws WxErrorException {
JsonObject paramJson = new JsonObject();
paramJson.addProperty("wechatid", wechatid);
paramJson.addProperty("wechatid", wechatId);
String response = post(API_UNBIND_TESTER, GSON.toJson(paramJson));
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 解除绑定小程序体验者
* @param userstr 人员对应的唯一字符串, 可通过获取已绑定的体验者列表获取人员对应的字符串
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult unbindTesterByUserstr(String userstr) throws WxErrorException {
public WxOpenResult unbindTesterByUserStr(String userStr) throws WxErrorException {
JsonObject paramJson = new JsonObject();
paramJson.addProperty("userstr", userstr);
paramJson.addProperty("userstr", userStr);
String response = post(API_UNBIND_TESTER, GSON.toJson(paramJson));
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 获得体验者列表
*
* @return
* @throws WxErrorException
*/
@Override
public WxOpenMaTesterListResult getTesterList() throws WxErrorException {
JsonObject paramJson = new JsonObject();
@@ -222,12 +145,6 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaTesterListResult.class);
}
/**
* 设置小程序隐私设置(是否可被搜索)
*
* @param status 1表示不可搜索0表示可搜索
*/
@Override
public WxOpenResult changeWxaSearchStatus(Integer status) throws WxErrorException {
JsonObject paramJson = new JsonObject();
@@ -236,53 +153,27 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 2. 查询小程序当前隐私设置(是否可被搜索)
*/
@Override
public WxOpenMaSearchStatusResult getWxaSearchStatus() throws WxErrorException {
String response = get(API_GET_WXA_SEARCH_STATUS, null);
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaSearchStatusResult.class);
}
/**
* 3.1 获取展示的公众号信息
*/
@Override
public WxOpenMaShowItemResult getShowWxaItem() throws WxErrorException {
String response = get(API_GET_SHOW_WXA_ITEM, null);
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaShowItemResult.class);
}
/**
* 3.2 设置展示的公众号
*
* @param flag 0 关闭1 开启
* @param mpappid 如果开启需要传新的公众号appid
*/
@Override
public WxOpenResult updateShowwxaitem(Integer flag, String mpappid) throws WxErrorException {
public WxOpenResult updateShowWxaItem(Integer flag, String mpAppId) throws WxErrorException {
JsonObject paramJson = new JsonObject();
paramJson.addProperty("wxa_subscribe_biz_flag", flag);
paramJson.addProperty("appid", mpappid);
paramJson.addProperty("appid", mpAppId);
String response = post(API_UPDATE_SHOW_WXA_ITEM, GSON.toJson(paramJson));
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 1、为授权的小程序帐号上传小程序代码
*
* @param templateId 代码模板ID
* @param userVersion 用户定义版本
* @param userDesc 用户定义版本描述
* @param extInfo 第三方自定义的配置
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult codeCommit(Long templateId, String userVersion, String userDesc, WxMaOpenCommitExtInfo extInfo) throws WxErrorException {
JsonObject params = new JsonObject();
@@ -295,313 +186,152 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 获取体验小程序的体验二维码
*
* @param pagePath
* @param params
* @return
*/
@Override
public File getTestQrcode(String pagePath, Map<String, String> params) throws WxErrorException {
WxMaQrcodeParam qrcodeParam = WxMaQrcodeParam.create(pagePath);
qrcodeParam.addPageParam(params);
return execute(MaQrCodeRequestExecutor.create(getRequestHttp()), API_TEST_QRCODE, qrcodeParam);
WxMaService wxMaService = this;
return wxMaService.execute(MaQrCodeRequestExecutor.create(getRequestHttp()), API_TEST_QRCODE, qrcodeParam);
}
/**
* 获取授权小程序帐号的可选类目
* <p>
* 注意:该接口可获取已设置的二级类目及用于代码审核的可选三级类目。
* </p>
*
* @return WxOpenMaCategoryListResult
* @throws WxErrorException
*/
@Override
public WxOpenMaCategoryListResult getCategoryList() throws WxErrorException {
String response = get(API_GET_CATEGORY, null);
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaCategoryListResult.class);
}
/**
* 获取小程序的第三方提交代码的页面配置(仅供第三方开发者代小程序调用)
*
* @return
* @throws WxErrorException
*/
@Override
public WxOpenMaPageListResult getPageList() throws WxErrorException {
String response = get(API_GET_PAGE, null);
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaPageListResult.class);
}
/**
* 将第三方提交的代码包提交审核(仅供第三方开发者代小程序调用)
*
* @param submitAuditMessage
* @return
* @throws WxErrorException
*/
@Override
public WxOpenMaSubmitAuditResult submitAudit(WxOpenMaSubmitAuditMessage submitAuditMessage) throws WxErrorException {
String response = post(API_SUBMIT_AUDIT, GSON.toJson(submitAuditMessage));
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaSubmitAuditResult.class);
}
/**
* 7. 查询某个指定版本的审核状态(仅供第三方代小程序调用)
*
* @param auditid
* @return
* @throws WxErrorException
*/
@Override
public WxOpenMaQueryAuditResult getAuditStatus(Long auditid) throws WxErrorException {
public WxOpenMaQueryAuditResult getAuditStatus(Long auditId) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("auditid", auditid);
params.addProperty("auditid", auditId);
String response = post(API_GET_AUDIT_STATUS, GSON.toJson(params));
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaQueryAuditResult.class);
}
/**
* 8. 查询最新一次提交的审核状态(仅供第三方代小程序调用)
*
* @return
* @throws WxErrorException
*/
@Override
public WxOpenMaQueryAuditResult getLatestAuditStatus() throws WxErrorException {
String response = get(API_GET_LATEST_AUDIT_STATUS, null);
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaQueryAuditResult.class);
}
/**
* 9. 发布已通过审核的小程序(仅供第三方代小程序调用)
* <p>
* 请填写空的数据包POST的json数据包为空即可。
* </p>
*
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult releaesAudited() throws WxErrorException {
public WxOpenResult releaseAudited() throws WxErrorException {
JsonObject params = new JsonObject();
String response = post(API_RELEASE, GSON.toJson(params));
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 10. 修改小程序线上代码的可见状态(仅供第三方代小程序调用)
*
* @param action 设置可访问状态发布后默认可访问close为不可见open为可见
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult changeVisitstatus(String action) throws WxErrorException {
public WxOpenResult changeVisitStatus(String action) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("action", action);
String response = post(API_CHANGE_VISITSTATUS, GSON.toJson(params));
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 11. 小程序版本回退(仅供第三方代小程序调用)
*
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult revertCodeReleaes() throws WxErrorException {
public WxOpenResult revertCodeRelease() throws WxErrorException {
String response = get(API_REVERT_CODE_RELEASE, null);
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 15. 小程序审核撤回
* <p>
* 单个帐号每天审核撤回次数最多不超过1次一个月不超过10次。
* </p>
*
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult undoCodeAudit() throws WxErrorException {
String response = get(API_UNDO_CODE_AUDIT, null);
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 12. 查询当前设置的最低基础库版本及各版本用户占比 (仅供第三方代小程序调用)
*
* @return
* @throws WxErrorException
*/
@Override
public String getSupportVersion() throws WxErrorException {
JsonObject params = new JsonObject();
String response = post(API_GET_WEAPP_SUPPORT_VERSION, GSON.toJson(params));
return response;
return post(API_GET_WEAPP_SUPPORT_VERSION, GSON.toJson(params));
}
/**
* 12. 查询当前设置的最低基础库版本及各版本用户占比 (仅供第三方代小程序调用)
*
* @return
* @throws WxErrorException
*/
@Override
public WxOpenMaWeappSupportVersionResult getSupportVersionInfo() throws WxErrorException {
String response = this.getSupportVersion();
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaWeappSupportVersionResult.class);
}
/**
* 13. 设置最低基础库版本(仅供第三方代小程序调用)
*
* @param version
* @return
* @throws WxErrorException
*/
@Override
public String setSupportVersion(String version) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("version", version);
String response = post(API_SET_WEAPP_SUPPORT_VERSION, GSON.toJson(params));
return response;
return post(API_SET_WEAPP_SUPPORT_VERSION, GSON.toJson(params));
}
/**
* 13. 设置最低基础库版本(仅供第三方代小程序调用)
*
* @param version
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult setSupportVersionInfo(String version) throws WxErrorException {
String response = this.setSupportVersion(version);
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 16. 小程序分阶段发布 - 1)分阶段发布接口
*
* @param grayPercentage 灰度的百分比1到100的整数
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult grayrelease(Integer grayPercentage) throws WxErrorException {
public WxOpenResult grayRelease(Integer grayPercentage) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("gray_percentage", grayPercentage);
String response = post(API_GRAY_RELEASE, GSON.toJson(params));
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 16. 小程序分阶段发布 - 2)取消分阶段发布
*
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult revertgrayrelease() throws WxErrorException {
public WxOpenResult revertGrayRelease() throws WxErrorException {
String response = get(API_REVERT_GRAY_RELEASE, null);
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 16. 小程序分阶段发布 - 3)查询当前分阶段发布详情
*
* @return
* @throws WxErrorException
*/
@Override
public WxOpenMaGrayReleasePlanResult getgrayreleaseplan() throws WxErrorException {
public WxOpenMaGrayReleasePlanResult getGrayReleasePlan() throws WxErrorException {
String response = get(API_GET_GRAY_RELEASE_PLAN, null);
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaGrayReleasePlanResult.class);
}
/**
* 查询服务商的当月提审限额和加急次数Quota
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/code/query_quota.html
*/
@Override
public WxOpenMaQueryQuotaResult queryQuota() throws WxErrorException {
String response = get(API_QUERY_QUOTA, null);
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaQueryQuotaResult.class);
}
/**
* 加急审核申请
* 有加急次数的第三方可以通过该接口对已经提审的小程序进行加急操作加急后的小程序预计2-12小时内审完。
*/
@Override
public Boolean speedAudit(Long auditid) throws WxErrorException {
public Boolean speedAudit(Long auditId) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("auditid", auditid);
params.addProperty("auditid", auditId);
String response = post(API_SPEED_AUDIT, GSON.toJson(params));
WxOpenResult result = WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
return result.isSuccess();
}
/**
* (1)增加或修改二维码规则
* @param wxQrcodeJumpRule
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult addQrcodeJump(WxQrcodeJumpRule wxQrcodeJumpRule) throws WxErrorException {
String response = post(API_QRCODE_JUMP_ADD, GSON.toJson(wxQrcodeJumpRule));
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* (2)获取已设置的二维码规则
* @return
* @throws WxErrorException
*/
@Override
public WxGetQrcodeJumpResult getQrcodeJump() throws WxErrorException {
String response = post(API_QRCODE_JUMP_GET, "{}");
return WxMaGsonBuilder.create().fromJson(response, WxGetQrcodeJumpResult.class);
}
/**
* (3)获取校验文件名称及内容
* @return
* @throws WxErrorException
*/
@Override
public WxDownlooadQrcodeJumpResult downloadQrcodeJump() throws WxErrorException {
String response = post(API_QRCODE_JUMP_DOWNLOAD, "{}");
return WxMaGsonBuilder.create().fromJson(response, WxDownlooadQrcodeJumpResult.class);
}
/**
* (4)删除已设置的二维码规则
* @param prefix
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult deleteQrcodeJump(String prefix) throws WxErrorException {
JsonObject params = new JsonObject();
@@ -610,12 +340,6 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* (5)发布已设置的二维码规则
* @param prefix
* @return
* @throws WxErrorException
*/
@Override
public WxOpenResult publishQrcodeJump(String prefix) throws WxErrorException {
JsonObject params = new JsonObject();
@@ -624,12 +348,6 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
/**
* 将字符串对象转化为GsonArray对象
*
* @param strList
* @return
*/
private JsonArray toJsonArray(List<String> strList) {
JsonArray jsonArray = new JsonArray();
if (strList != null && !strList.isEmpty()) {

View File

@@ -31,18 +31,4 @@ public class WxOpenMpServiceImpl extends WxMpServiceImpl {
return wxOpenComponentService.getAuthorizerAccessToken(appId, forceRefresh);
}
@Override
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException {
return wxOpenComponentService.oauth2getAccessToken(appId, code);
}
@Override
public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException {
return wxOpenComponentService.oauth2refreshAccessToken(appId, refreshToken);
}
@Override
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) {
return wxOpenComponentService.oauth2buildAuthorizationUrl(appId, redirectURI, scope, state);
}
}

View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.open.api.impl;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;

View File

@@ -1,5 +1,6 @@
package me.chanjar.weixin.open.bean;
import lombok.Data;
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
import java.io.Serializable;
@@ -7,30 +8,17 @@ import java.io.Serializable;
/**
* @author <a href="https://github.com/007gzs">007</a>
*/
@Data
public class WxOpenAuthorizerAccessToken implements Serializable {
private static final long serialVersionUID = -4069745419280727420L;
private String authorizerAccessToken;
private String authorizerRefreshToken;
private int expiresIn = -1;
public static WxOpenAuthorizerAccessToken fromJson(String json) {
return WxOpenGsonBuilder.create().fromJson(json, WxOpenAuthorizerAccessToken.class);
}
public String getAuthorizerAccessToken() {
return authorizerAccessToken;
}
public void setAuthorizerAccessToken(String authorizerAccessToken) {
this.authorizerAccessToken = authorizerAccessToken;
}
public int getExpiresIn() {
return expiresIn;
}
public void setExpiresIn(int expiresIn) {
this.expiresIn = expiresIn;
}
}

View File

@@ -1,6 +1,5 @@
package me.chanjar.weixin.open.bean;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;

View File

@@ -3,8 +3,6 @@ package me.chanjar.weixin.open.bean.ma;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import java.util.List;
/**
* @author zxfreedom
* @description

View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.open.executor;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;

View File

@@ -6,7 +6,7 @@ import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.net.MimeTypes;
import jodd.util.StringPool;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;

View File

@@ -1,6 +1,6 @@
package me.chanjar.weixin.open.executor;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
@@ -11,8 +11,6 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;

View File

@@ -3,7 +3,7 @@ package me.chanjar.weixin.open.executor;
import java.io.File;
import java.io.IOException;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestExecutor;

View File

@@ -1,7 +1,8 @@
package me.chanjar.weixin.open.util;
import com.google.common.base.CharMatcher;
import com.google.common.io.BaseEncoding;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import org.apache.commons.codec.binary.Base64;
/**
* @author <a href="https://github.com/007gzs">007</a>
@@ -24,6 +25,6 @@ public class WxOpenCryptUtil extends me.chanjar.weixin.common.util.crypto.WxCryp
this.token = token;
this.appidOrCorpid = appId;
this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
this.aesKey = BaseEncoding.base64().decode(CharMatcher.whitespace().removeFrom(encodingAesKey));
}
}

View File

@@ -15,6 +15,7 @@ public class WxOpenAuthorizerAccessTokenGsonAdapter implements JsonDeserializer<
WxOpenAuthorizerAccessToken authorizerAccessToken = new WxOpenAuthorizerAccessToken();
JsonObject jsonObject = jsonElement.getAsJsonObject();
authorizerAccessToken.setAuthorizerAccessToken(GsonHelper.getString(jsonObject, "authorizer_access_token"));
authorizerAccessToken.setAuthorizerRefreshToken(GsonHelper.getString(jsonObject, "authorizer_refresh_token"));
authorizerAccessToken.setExpiresIn(GsonHelper.getPrimitiveInteger(jsonObject, "expires_in"));
return authorizerAccessToken;
}

View File

@@ -0,0 +1,160 @@
package me.chanjar.weixin.open.api.impl;
import org.testng.annotations.Test;
/**
* 单元测试类.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-06-06
*/
public class WxOpenComponentServiceImplTest {
@Test
public void testGetWxMpServiceByAppid() {
}
@Test
public void testGetWxMaServiceByAppid() {
}
@Test
public void testGetWxFastMaServiceByAppid() {
}
@Test
public void testGetWxOpenService() {
}
@Test
public void testGetWxOpenConfigStorage() {
}
@Test
public void testCheckSignature() {
}
@Test
public void testGetComponentAccessToken() {
}
@Test
public void testPost() {
}
@Test
public void testTestPost() {
}
@Test
public void testGet() {
}
@Test
public void testTestGet() {
}
@Test
public void testGetPreAuthUrl() {
}
@Test
public void testTestGetPreAuthUrl() {
}
@Test
public void testGetMobilePreAuthUrl() {
}
@Test
public void testTestGetMobilePreAuthUrl() {
}
@Test
public void testRoute() {
}
@Test
public void testGetQueryAuth() {
}
@Test
public void testGetAuthorizerInfo() {
}
@Test
public void testGetAuthorizerList() {
}
@Test
public void testGetAuthorizerOption() {
}
@Test
public void testSetAuthorizerOption() {
}
@Test
public void testGetAuthorizerAccessToken() {
}
@Test
public void testOauth2getAccessToken() {
}
@Test
public void testTestCheckSignature() {
}
@Test
public void testOauth2refreshAccessToken() {
}
@Test
public void testOauth2buildAuthorizationUrl() {
}
@Test
public void testMiniappJscode2Session() {
}
@Test
public void testGetTemplateDraftList() {
}
@Test
public void testGetTemplateList() {
}
@Test
public void testAddToTemplate() {
}
@Test
public void testDeleteTemplate() {
}
@Test
public void testCreateOpenAccount() {
}
@Test
public void testBindOpenAccount() {
}
@Test
public void testUnbindOpenAccount() {
}
@Test
public void testGetOpenAccount() {
}
@Test
public void testFastRegisterWeapp() {
}
@Test
public void testFastRegisterWeappSearch() {
}
}

View File

@@ -0,0 +1,218 @@
package me.chanjar.weixin.open.api.impl;
import org.testng.annotations.Test;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-06-06
*/
public class WxOpenFastMaServiceImplTest {
@Test
public void testInitHttp() {
}
@Test
public void testGetRequestHttpClient() {
}
@Test
public void testGetRequestHttpProxy() {
}
@Test
public void testGetRequestType() {
}
@Test
public void testDoGetAccessTokenRequest() {
}
@Test
public void testGetRequestHttp() {
}
@Test
public void testGetPaidUnionId() {
}
@Test
public void testJsCode2SessionInfo() {
}
@Test
public void testSetDynamicData() {
}
@Test
public void testCheckSignature() {
}
@Test
public void testGetAccessToken() {
}
@Test
public void testTestGetAccessToken() {
}
@Test
public void testGet() {
}
@Test
public void testPost() {
}
@Test
public void testTestPost() {
}
@Test
public void testExecute() {
}
@Test
public void testExtractAccessToken() {
}
@Test
public void testGetWxMaConfig() {
}
@Test
public void testSetWxMaConfig() {
}
@Test
public void testSetRetrySleepMillis() {
}
@Test
public void testSetMaxRetryTimes() {
}
@Test
public void testGetMsgService() {
}
@Test
public void testGetMediaService() {
}
@Test
public void testGetUserService() {
}
@Test
public void testGetQrcodeService() {
}
@Test
public void testGetTemplateService() {
}
@Test
public void testGetSubscribeService() {
}
@Test
public void testGetAnalysisService() {
}
@Test
public void testGetCodeService() {
}
@Test
public void testGetJsapiService() {
}
@Test
public void testGetSettingService() {
}
@Test
public void testGetShareService() {
}
@Test
public void testGetRunService() {
}
@Test
public void testGetSecCheckService() {
}
@Test
public void testGetPluginService() {
}
@Test
public void testGetExpressService() {
}
@Test
public void testGetCloudService() {
}
@Test
public void testGetLiveService() {
}
@Test
public void testTestGetWxMaConfig() {
}
@Test
public void testTestGetAccessToken1() {
}
@Test
public void testGetAccountBasicInfo() {
}
@Test
public void testSetNickname() {
}
@Test
public void testQuerySetNicknameStatus() {
}
@Test
public void testCheckWxVerifyNickname() {
}
@Test
public void testModifyHeadImage() {
}
@Test
public void testModifySignature() {
}
@Test
public void testComponentRebindAdmin() {
}
@Test
public void testGetAllCategories() {
}
@Test
public void testAddCategory() {
}
@Test
public void testDeleteCategory() {
}
@Test
public void testGetCategory() {
}
@Test
public void testModifyCategory() {
}
}

View File

@@ -0,0 +1,334 @@
package me.chanjar.weixin.open.api.impl;
import org.testng.annotations.Test;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-06-06
*/
public class WxOpenMaServiceImplTest {
@Test
public void testInitHttp() {
}
@Test
public void testGetRequestHttpClient() {
}
@Test
public void testGetRequestHttpProxy() {
}
@Test
public void testGetRequestType() {
}
@Test
public void testDoGetAccessTokenRequest() {
}
@Test
public void testGetRequestHttp() {
}
@Test
public void testGetPaidUnionId() {
}
@Test
public void testJsCode2SessionInfo() {
}
@Test
public void testSetDynamicData() {
}
@Test
public void testCheckSignature() {
}
@Test
public void testGetAccessToken() {
}
@Test
public void testTestGetAccessToken() {
}
@Test
public void testGet() {
}
@Test
public void testPost() {
}
@Test
public void testTestPost() {
}
@Test
public void testExecute() {
}
@Test
public void testExtractAccessToken() {
}
@Test
public void testGetWxMaConfig() {
}
@Test
public void testSetWxMaConfig() {
}
@Test
public void testSetRetrySleepMillis() {
}
@Test
public void testSetMaxRetryTimes() {
}
@Test
public void testGetMsgService() {
}
@Test
public void testGetMediaService() {
}
@Test
public void testGetUserService() {
}
@Test
public void testGetQrcodeService() {
}
@Test
public void testGetTemplateService() {
}
@Test
public void testGetSubscribeService() {
}
@Test
public void testGetAnalysisService() {
}
@Test
public void testGetCodeService() {
}
@Test
public void testGetJsapiService() {
}
@Test
public void testGetSettingService() {
}
@Test
public void testGetShareService() {
}
@Test
public void testGetRunService() {
}
@Test
public void testGetSecCheckService() {
}
@Test
public void testGetPluginService() {
}
@Test
public void testGetExpressService() {
}
@Test
public void testGetCloudService() {
}
@Test
public void testGetLiveService() {
}
@Test
public void testTestJsCode2SessionInfo() {
}
@Test
public void testTestGetWxMaConfig() {
}
@Test
public void testTestGetAccessToken1() {
}
@Test
public void testGetDomain() {
}
@Test
public void testModifyDomain() {
}
@Test
public void testGetWebViewDomain() {
}
@Test
public void testGetWebViewDomainInfo() {
}
@Test
public void testSetWebViewDomain() {
}
@Test
public void testSetWebViewDomainInfo() {
}
@Test
public void testGetAccountBasicInfo() {
}
@Test
public void testBindTester() {
}
@Test
public void testUnbindTester() {
}
@Test
public void testUnbindTesterByUserStr() {
}
@Test
public void testGetTesterList() {
}
@Test
public void testChangeWxaSearchStatus() {
}
@Test
public void testGetWxaSearchStatus() {
}
@Test
public void testGetShowWxaItem() {
}
@Test
public void testUpdateShowWxaItem() {
}
@Test
public void testCodeCommit() {
}
@Test
public void testGetTestQrcode() {
}
@Test
public void testGetCategoryList() {
}
@Test
public void testGetPageList() {
}
@Test
public void testSubmitAudit() {
}
@Test
public void testGetAuditStatus() {
}
@Test
public void testGetLatestAuditStatus() {
}
@Test
public void testReleaseAudited() {
}
@Test
public void testChangeVisitStatus() {
}
@Test
public void testRevertCodeRelease() {
}
@Test
public void testUndoCodeAudit() {
}
@Test
public void testGetSupportVersion() {
}
@Test
public void testGetSupportVersionInfo() {
}
@Test
public void testSetSupportVersion() {
}
@Test
public void testSetSupportVersionInfo() {
}
@Test
public void testGrayRelease() {
}
@Test
public void testRevertGrayRelease() {
}
@Test
public void testGetGrayReleasePlan() {
}
@Test
public void testQueryQuota() {
}
@Test
public void testSpeedAudit() {
}
@Test
public void testAddQrcodeJump() {
}
@Test
public void testGetQrcodeJump() {
}
@Test
public void testDownloadQrcodeJump() {
}
@Test
public void testDeleteQrcodeJump() {
}
@Test
public void testPublishQrcodeJump() {
}
}