新增第三方组件WeixinComponentProxy
This commit is contained in:
1 parent
73125123cb
commit
ed5703c36f
12 files changed
+294
-43
No files matched your search
@@ -55,8 +55,8 @@ public class WeixinSuiteProxy {
|
||||
* 默认使用文件方式保存token、使用weixin4j.properties配置的账号信息
|
||||
*/
|
||||
public WeixinSuiteProxy() {
|
||||
this(new Weixin4jSettings<WeixinQyAccount>(JSON.parseObject(
|
||||
Weixin4jConfigUtil.getValue("account"), WeixinQyAccount.class)));
|
||||
this(new Weixin4jSettings<WeixinQyAccount>(
|
||||
JSON.parseObject(Weixin4jConfigUtil.getValue("account"), WeixinQyAccount.class)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,18 +71,15 @@ public class WeixinSuiteProxy {
|
||||
this.suiteMap = new HashMap<String, SuiteApi>(suites.size());
|
||||
for (WeixinAccount suite : suites) {
|
||||
this.suiteMap.put(suite.getId(), new SuiteApi(
|
||||
new TicketManager(suite.getId(), suite.getSecret(),
|
||||
settings.getCacheStorager0())));
|
||||
new TicketManager(suite.getId(), suite.getSecret(), settings.getCacheStorager0())));
|
||||
}
|
||||
this.suiteMap.put(null, suiteMap.get(suites.get(0).getId()));
|
||||
}
|
||||
if (StringUtil.isNotBlank(settings.getAccount().getId())
|
||||
&& StringUtil.isNotBlank(settings.getAccount()
|
||||
.getProviderSecret())) {
|
||||
&& StringUtil.isNotBlank(settings.getAccount().getProviderSecret())) {
|
||||
this.providerApi = new ProviderApi(
|
||||
new TokenManager(new WeixinProviderTokenCreator(settings
|
||||
.getAccount().getId(), settings.getAccount()
|
||||
.getProviderSecret()), settings.getCacheStorager0()),
|
||||
new TokenManager(new WeixinProviderTokenCreator(settings.getAccount().getId(),
|
||||
settings.getAccount().getProviderSecret()), settings.getCacheStorager0()),
|
||||
settings.getCacheStorager0());
|
||||
}
|
||||
}
|
||||
@@ -119,16 +116,17 @@ public class WeixinSuiteProxy {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取套件的预授权码
|
||||
* 获取套件的预授权码 <font color="red">需先缓存ticket</font>
|
||||
*
|
||||
* @param suiteId
|
||||
* 套件ID
|
||||
* @return 预授权码
|
||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi#getTicketManager()
|
||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi#getPreCodeManager()
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String preSuiteTicket(String suiteId) throws WeixinException {
|
||||
public String getPreSuiteTicket(String suiteId) throws WeixinException {
|
||||
Token token = suite(suiteId).getTicketManager().getTicket();
|
||||
if (token == null || StringUtil.isBlank(token.getAccessToken())) {
|
||||
throw new WeixinException("maybe oauth first?");
|
||||
@@ -137,7 +135,7 @@ public class WeixinSuiteProxy {
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存套件ticket(多个套件
|
||||
* 缓存套件ticket
|
||||
*
|
||||
* @param suiteId
|
||||
* 套件ID
|
||||
@@ -148,8 +146,7 @@ public class WeixinSuiteProxy {
|
||||
* 推送suite_ticket协议</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public void cacheTicket(String suiteId, String suiteTicket)
|
||||
throws WeixinException {
|
||||
public void cacheTicket(String suiteId, String suiteTicket) throws WeixinException {
|
||||
suite(suiteId).getTicketManager().cachingTicket(suiteTicket);
|
||||
}
|
||||
|
||||
@@ -164,8 +161,7 @@ public class WeixinSuiteProxy {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String getSuiteAuthorizeURL(String suiteId) throws WeixinException {
|
||||
String redirectUri = Weixin4jConfigUtil
|
||||
.getValue("suite.oauth.redirect.uri");
|
||||
String redirectUri = Weixin4jConfigUtil.getValue("suite.oauth.redirect.uri");
|
||||
return getSuiteAuthorizeURL(suiteId, redirectUri, "state");
|
||||
}
|
||||
|
||||
@@ -185,11 +181,9 @@ public class WeixinSuiteProxy {
|
||||
* @return 请求授权的URL
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String getSuiteAuthorizeURL(String suiteId, String redirectUri,
|
||||
String state) throws WeixinException {
|
||||
public String getSuiteAuthorizeURL(String suiteId, String redirectUri, String state) throws WeixinException {
|
||||
try {
|
||||
return String.format(URLConsts.SUITE_OAUTH_URL, suiteId,
|
||||
suite(suiteId).getTicketManager().getTicket(),
|
||||
return String.format(URLConsts.SUITE_OAUTH_URL, suiteId, getPreSuiteTicket(suiteId),
|
||||
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
;
|
||||
@@ -231,8 +225,7 @@ public class WeixinSuiteProxy {
|
||||
* 获取登录企业号官网的url</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String getLoginUrl(String corpId, LoginTargetType targetType,
|
||||
int agentId) throws WeixinException {
|
||||
public String getLoginUrl(String corpId, LoginTargetType targetType, int agentId) throws WeixinException {
|
||||
return providerApi.getLoginUrl(corpId, targetType, agentId);
|
||||
}
|
||||
|
||||
@@ -247,8 +240,7 @@ public class WeixinSuiteProxy {
|
||||
* @return
|
||||
*/
|
||||
public WeixinProxy getWeixinProxy(String suiteId, String authCorpId) {
|
||||
return new WeixinProxy(suite(suiteId).getPerTicketManager(authCorpId),
|
||||
suite(suiteId).getTokenManager());
|
||||
return new WeixinProxy(suite(suiteId).getPerTicketManager(authCorpId), suite(suiteId).getTokenManager());
|
||||
}
|
||||
|
||||
public final static String VERSION = "1.7.0";
|
||||
|
||||
@@ -59,7 +59,7 @@ public class SuiteApi extends QyApi {
|
||||
/**
|
||||
* 应用套件token
|
||||
*
|
||||
* @return
|
||||
* @return 应用套件的token管理
|
||||
*/
|
||||
public TokenManager getTokenManager() {
|
||||
return this.tokenManager;
|
||||
@@ -68,7 +68,7 @@ public class SuiteApi extends QyApi {
|
||||
/**
|
||||
* 应用套件ticket
|
||||
*
|
||||
* @return
|
||||
* @return 应用套件的ticket管理
|
||||
*/
|
||||
public TicketManager getTicketManager() {
|
||||
return this.ticketManager;
|
||||
@@ -77,7 +77,7 @@ public class SuiteApi extends QyApi {
|
||||
/**
|
||||
* 应用套件预授权码
|
||||
*
|
||||
* @return
|
||||
* @return 应用套件的precode管理
|
||||
*/
|
||||
public TokenManager getPreCodeManager() {
|
||||
return this.preCodeManager;
|
||||
@@ -88,7 +88,7 @@ public class SuiteApi extends QyApi {
|
||||
*
|
||||
* @param authCorpid
|
||||
* 授权方corpid
|
||||
* @return
|
||||
* @return 应用套件的preticket管理
|
||||
*/
|
||||
public PerTicketManager getPerTicketManager(String authCorpId) {
|
||||
return new PerTicketManager(authCorpId, ticketManager.getThirdId(),
|
||||
|
||||
@@ -77,7 +77,7 @@ public class WeixinQyAccount extends WeixinAccount {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WeixinQyAccount [" + super.toString() + ", suiteAccounts="
|
||||
return "WeixinQyAccount [" + super.toString() + ", suites="
|
||||
+ suites + ", providerSecret=" + providerSecret
|
||||
+ ", chatSecret=" + chatSecret + "]";
|
||||
}
|
||||
|
||||
@@ -25,5 +25,5 @@ weixin4j.user.oauth.redirect.uri=
|
||||
# \u4f01\u4e1a\u53f7\u7b2c\u4e09\u65b9\u63d0\u4f9b\u5546\u6388\u6743\u540e\u91cd\u5b9a\u5411\u7684url(\u5728\u4f7f\u7528OauthApi\u65f6\u586b\u5199)
|
||||
weixin4j.third.oauth.redirect.uri=
|
||||
|
||||
# \u4f01\u4e1a\u53f7\u7b2c\u4e09\u65b9\u5e94\u7528\u5957\u4ef6\u6388\u6743\u540e\u91cd\u5b9a\u5411\u7684url(\u5728\u4f7f\u7528OauthApi\u65f6\u586b\u5199)
|
||||
# \u4f01\u4e1a\u53f7\u7b2c\u4e09\u65b9\u5e94\u7528\u5957\u4ef6\u6388\u6743\u540e\u91cd\u5b9a\u5411\u7684url(\u5728\u4f7f\u7528SuiteApi\u65f6\u586b\u5199)
|
||||
weixin4j.suite.oauth.redirect.uri=
|
||||
Reference in new issue
Block a user