|
|
|
@@ -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";
|
|
|
|
|