重构Cache实现
This commit is contained in:
@@ -38,7 +38,7 @@ import com.foxinmy.weixin4j.qy.model.IdParameter;
|
||||
import com.foxinmy.weixin4j.qy.model.Party;
|
||||
import com.foxinmy.weixin4j.qy.model.Tag;
|
||||
import com.foxinmy.weixin4j.qy.model.User;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuitePerCodeHolder;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuitePerCodeManager;
|
||||
import com.foxinmy.weixin4j.qy.suite.WeixinTokenSuiteCreator;
|
||||
import com.foxinmy.weixin4j.qy.token.WeixinTicketCreator;
|
||||
import com.foxinmy.weixin4j.qy.token.WeixinTokenCreator;
|
||||
@@ -47,7 +47,7 @@ import com.foxinmy.weixin4j.qy.type.InviteType;
|
||||
import com.foxinmy.weixin4j.qy.type.KfType;
|
||||
import com.foxinmy.weixin4j.qy.type.UserStatus;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.foxinmy.weixin4j.type.TicketType;
|
||||
@@ -106,7 +106,7 @@ public class WeixinProxy {
|
||||
/**
|
||||
* token实现
|
||||
*/
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
/**
|
||||
* 配置信息
|
||||
*/
|
||||
@@ -126,30 +126,30 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.setting.Weixin4jSettings
|
||||
*/
|
||||
public WeixinProxy(Weixin4jSettings settings) {
|
||||
this(new TokenHolder(new WeixinTokenCreator(settings.getAccount()
|
||||
this(new TokenManager(new WeixinTokenCreator(settings.getAccount()
|
||||
.getId(), settings.getAccount().getSecret()),
|
||||
settings.getTokenStorager0()));
|
||||
settings.getCacheStorager0()));
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方套件(永久授权码机制)
|
||||
*
|
||||
* @param perCodeHolder
|
||||
* @param perCodeManager
|
||||
* 第三方套件永久授权码
|
||||
* {@link com.foxinmy.weixin4j.qy.api.SuiteApi#getPerCodeHolder(String)}
|
||||
* @param suiteTokenHolder
|
||||
* {@link com.foxinmy.weixin4j.qy.api.SuiteApi#getPerCodeManager(String)}
|
||||
* @param suitetokenManager
|
||||
* 第三方套件凭证token
|
||||
* {@link com.foxinmy.weixin4j.qy.api.SuiteApi#getTokenSuiteHolder(String)}
|
||||
* {@link com.foxinmy.weixin4j.qy.api.SuiteApi#getTokenSuiteManager(String)}
|
||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||
* @see WeixinSuiteProxy#getWeixinProxy(String, String)
|
||||
*/
|
||||
public WeixinProxy(SuitePerCodeHolder perCodeHolder,
|
||||
TokenHolder suiteTokenHolder) {
|
||||
this(new TokenHolder(new WeixinTokenSuiteCreator(perCodeHolder,
|
||||
suiteTokenHolder), perCodeHolder.getTokenStorager()));
|
||||
public WeixinProxy(SuitePerCodeManager perCodeManager,
|
||||
TokenManager suiteTokenManager) {
|
||||
this(new TokenManager(new WeixinTokenSuiteCreator(perCodeManager,
|
||||
suiteTokenManager), perCodeManager.getCacheStorager()));
|
||||
this.settings = new Weixin4jSettings(new WeixinAccount(
|
||||
perCodeHolder.getAuthCorpId(), null));
|
||||
perCodeManager.getAuthCorpId(), null));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,20 +157,20 @@ public class WeixinProxy {
|
||||
* color="red">WeixinTokenCreator或WeixinTokenSuiteCreator</font>
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.qy.token.WeixinTokenCreator
|
||||
* @param tokenHolder
|
||||
* @param tokenManager
|
||||
*/
|
||||
private WeixinProxy(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
this.partyApi = new PartyApi(tokenHolder);
|
||||
this.userApi = new UserApi(tokenHolder);
|
||||
this.tagApi = new TagApi(tokenHolder);
|
||||
this.helperApi = new HelperApi(tokenHolder);
|
||||
this.agentApi = new AgentApi(tokenHolder);
|
||||
this.batchApi = new BatchApi(tokenHolder);
|
||||
this.notifyApi = new NotifyApi(tokenHolder);
|
||||
this.menuApi = new MenuApi(tokenHolder);
|
||||
this.mediaApi = new MediaApi(tokenHolder);
|
||||
this.chatApi = new ChatApi(tokenHolder);
|
||||
private WeixinProxy(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
this.partyApi = new PartyApi(tokenManager);
|
||||
this.userApi = new UserApi(tokenManager);
|
||||
this.tagApi = new TagApi(tokenManager);
|
||||
this.helperApi = new HelperApi(tokenManager);
|
||||
this.agentApi = new AgentApi(tokenManager);
|
||||
this.batchApi = new BatchApi(tokenManager);
|
||||
this.notifyApi = new NotifyApi(tokenManager);
|
||||
this.menuApi = new MenuApi(tokenManager);
|
||||
this.mediaApi = new MediaApi(tokenManager);
|
||||
this.chatApi = new ChatApi(tokenManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,8 +178,8 @@ public class WeixinProxy {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getTokenHolder() {
|
||||
return this.tokenHolder;
|
||||
public TokenManager getTokenManager() {
|
||||
return this.tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,16 +192,16 @@ public class WeixinProxy {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取JSSDK Ticket的tokenHolder
|
||||
* 获取JSSDK Ticket的tokenManager
|
||||
*
|
||||
* @param ticketType
|
||||
* 票据类型
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getTicketHolder(TicketType ticketType) {
|
||||
return new TokenHolder(new WeixinTicketCreator(getWeixinAccount()
|
||||
.getId(), ticketType, this.tokenHolder),
|
||||
this.settings.getTokenStorager0());
|
||||
public TokenManager getTicketManager(TicketType ticketType) {
|
||||
return new TokenManager(new WeixinTicketCreator(getWeixinAccount()
|
||||
.getId(), ticketType, this.tokenManager),
|
||||
this.settings.getCacheStorager0());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,12 +12,12 @@ import com.foxinmy.weixin4j.qy.api.ProviderApi;
|
||||
import com.foxinmy.weixin4j.qy.api.SuiteApi;
|
||||
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.WeixinQyAccount;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuiteTicketHolder;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuiteTicketManager;
|
||||
import com.foxinmy.weixin4j.qy.suite.Weixin4jSuiteSettings;
|
||||
import com.foxinmy.weixin4j.qy.token.WeixinProviderTokenCreator;
|
||||
import com.foxinmy.weixin4j.qy.type.LoginTargetType;
|
||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
@@ -64,8 +64,8 @@ public class WeixinSuiteProxy {
|
||||
for (WeixinAccount suite : suiteSettings.getAccount()
|
||||
.getSuiteAccounts()) {
|
||||
this.suiteMap.put(suite.getId(), new SuiteApi(
|
||||
new SuiteTicketHolder(suite.getId(), suite.getSecret(),
|
||||
suiteSettings.getTokenStorager0())));
|
||||
new SuiteTicketManager(suite.getId(), suite.getSecret(),
|
||||
suiteSettings.getCacheStorager0())));
|
||||
this.suiteMap.put(
|
||||
null,
|
||||
suiteMap.get(suiteSettings.getAccount()
|
||||
@@ -75,12 +75,12 @@ public class WeixinSuiteProxy {
|
||||
if (StringUtil.isNotBlank(suiteSettings.getAccount().getId())
|
||||
&& StringUtil.isNotBlank(suiteSettings.getAccount()
|
||||
.getProviderSecret())) {
|
||||
this.providerApi = new ProviderApi(new TokenHolder(
|
||||
this.providerApi = new ProviderApi(new TokenManager(
|
||||
new WeixinProviderTokenCreator(suiteSettings
|
||||
.getAccount().getId(), suiteSettings
|
||||
.getAccount().getProviderSecret()),
|
||||
suiteSettings.getTokenStorager0()),
|
||||
suiteSettings.getTokenStorager0());
|
||||
suiteSettings.getCacheStorager0()),
|
||||
suiteSettings.getCacheStorager0());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class WeixinSuiteProxy {
|
||||
*/
|
||||
public void cacheTicket(String suiteId, String suiteTicket)
|
||||
throws WeixinException {
|
||||
suite(suiteId).getTicketHolder().cachingTicket(suiteTicket);
|
||||
suite(suiteId).getTicketManager().cachingTicket(suiteTicket);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +160,7 @@ public class WeixinSuiteProxy {
|
||||
* @see <a href="http://qydev.weixin.qq.com/wiki/index.php?title
|
||||
* =%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%AE%A1%E7%90%86%E5%91%98%E6%
|
||||
* 8E%88%E6%9D%83%E5%BA%94%E7%94%A8">企业号第三方应用套件授权</a>
|
||||
* @see {@link SuiteApi#getPreCodeHolder}
|
||||
* @see {@link SuiteApi#getPreCodeManager}
|
||||
* @return 请求授权的URL
|
||||
* @throws WeixinException
|
||||
*/
|
||||
@@ -168,7 +168,7 @@ public class WeixinSuiteProxy {
|
||||
String state) throws WeixinException {
|
||||
try {
|
||||
return String.format(URLConsts.SUITE_OAUTH_URL, suiteId,
|
||||
suite(suiteId).getTicketHolder().getTicket(),
|
||||
suite(suiteId).getTicketManager().getTicket(),
|
||||
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
;
|
||||
@@ -226,8 +226,8 @@ public class WeixinSuiteProxy {
|
||||
* @return
|
||||
*/
|
||||
public WeixinProxy getWeixinProxy(String suiteId, String authCorpId) {
|
||||
return new WeixinProxy(suite(suiteId).getPerCodeHolder(authCorpId),
|
||||
suite(suiteId).getSuiteTokenHolder());
|
||||
return new WeixinProxy(suite(suiteId).getPerCodeManager(authCorpId),
|
||||
suite(suiteId).getSuiteTokenManager());
|
||||
}
|
||||
|
||||
public final static String VERSION = "1.6.9";
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.foxinmy.weixin4j.qy.model.AgentInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.AgentOverview;
|
||||
import com.foxinmy.weixin4j.qy.model.AgentSetter;
|
||||
import com.foxinmy.weixin4j.qy.model.User;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 管理应用接口
|
||||
@@ -26,10 +26,10 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%BA%94%E7%94%A8">管理应用接口说明</a>
|
||||
*/
|
||||
public class AgentApi extends QyApi {
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public AgentApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public AgentApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ public class AgentApi extends QyApi {
|
||||
*/
|
||||
public AgentInfo getAgent(int agentid) throws WeixinException {
|
||||
String agent_get_uri = getRequestUri("agent_get_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(agent_get_uri,
|
||||
token.getAccessToken(), agentid));
|
||||
JSONObject jsonObj = response.getAsJson();
|
||||
@@ -74,7 +74,7 @@ public class AgentApi extends QyApi {
|
||||
*/
|
||||
public JsonResult setAgent(AgentSetter agentSet) throws WeixinException {
|
||||
String agent_set_uri = getRequestUri("agent_set_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(agent_set_uri, token.getAccessToken()),
|
||||
JSON.toJSONString(agentSet, typeFilter));
|
||||
@@ -108,7 +108,7 @@ public class AgentApi extends QyApi {
|
||||
*/
|
||||
public List<AgentOverview> listAgentOverview() throws WeixinException {
|
||||
String agent_list_uri = getRequestUri("agent_list_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(agent_list_uri,
|
||||
token.getAccessToken()));
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.qy.model.BatchResult;
|
||||
import com.foxinmy.weixin4j.qy.model.Callback;
|
||||
import com.foxinmy.weixin4j.qy.model.IdParameter;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 批量异步任务API
|
||||
@@ -25,10 +25,10 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
*/
|
||||
public class BatchApi extends QyApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public BatchApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public BatchApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ public class BatchApi extends QyApi {
|
||||
public String inviteUser(IdParameter parameter, Callback callback,
|
||||
String tips) throws WeixinException {
|
||||
String batch_inviteuser_uri = getRequestUri("batch_inviteuser_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.putAll(parameter.getParameter());
|
||||
obj.put("callback", callback);
|
||||
@@ -89,7 +89,7 @@ public class BatchApi extends QyApi {
|
||||
|
||||
private String batch(String batchUrl, String mediaId, Callback callback)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("media_id", mediaId);
|
||||
obj.put("callback", callback);
|
||||
@@ -162,7 +162,7 @@ public class BatchApi extends QyApi {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public BatchResult getBatchResult(String jobId) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String batch_getresult_uri = getRequestUri("batch_getresult_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
batch_getresult_uri, token.getAccessToken(), jobId));
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.foxinmy.weixin4j.qy.message.ChatMessage;
|
||||
import com.foxinmy.weixin4j.qy.model.ChatInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.ChatMute;
|
||||
import com.foxinmy.weixin4j.qy.type.ChatType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.tuple.ChatTuple;
|
||||
import com.foxinmy.weixin4j.util.ObjectId;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
@@ -28,10 +28,10 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1">企业号消息服务</a>
|
||||
*/
|
||||
public class ChatApi extends QyApi {
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public ChatApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public ChatApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ public class ChatApi extends QyApi {
|
||||
obj.put("chatid", chatId);
|
||||
}
|
||||
String message_chat_create_uri = getRequestUri("message_chat_create_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
weixinExecutor.post(
|
||||
String.format(message_chat_create_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -73,7 +73,7 @@ public class ChatApi extends QyApi {
|
||||
*/
|
||||
public ChatInfo getChat(String chatId) throws WeixinException {
|
||||
String message_chat_get_uri = getRequestUri("message_chat_get_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
message_chat_get_uri, token.getAccessToken(), chatId));
|
||||
return response.getAsJson().getObject("chat_info", ChatInfo.class);
|
||||
@@ -105,7 +105,7 @@ public class ChatApi extends QyApi {
|
||||
obj.put("add_user_list", addUsers);
|
||||
obj.put("del_user_list", deleteUsers);
|
||||
String message_chat_update_uri = getRequestUri("message_chat_update_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(message_chat_update_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -130,7 +130,7 @@ public class ChatApi extends QyApi {
|
||||
obj.put("chatid", chatId);
|
||||
obj.put("op_user", operator);
|
||||
String message_chat_quit_uri = getRequestUri("message_chat_quit_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(message_chat_quit_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -157,7 +157,7 @@ public class ChatApi extends QyApi {
|
||||
chat.put("type", chatType.name());
|
||||
chat.put("id", targetId);
|
||||
String message_chat_clearnotify_uri = getRequestUri("message_chat_clearnotify_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(message_chat_clearnotify_uri,
|
||||
token.getAccessToken()),
|
||||
@@ -184,7 +184,7 @@ public class ChatApi extends QyApi {
|
||||
JSONObject mute = new JSONObject();
|
||||
mute.put("user_mute_list", chatMutes);
|
||||
String message_chat_setmute_uri = getRequestUri("message_chat_setmute_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor
|
||||
.post(String.format(message_chat_setmute_uri,
|
||||
token.getAccessToken()), mute.toJSONString());
|
||||
@@ -216,7 +216,7 @@ public class ChatApi extends QyApi {
|
||||
msg.put("msgtype", msgtype);
|
||||
msg.put(msgtype, tuple);
|
||||
String message_chat_send_uri = getRequestUri("message_chat_send_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(message_chat_send_uri, token.getAccessToken()),
|
||||
msg.toJSONString());
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 辅助API
|
||||
@@ -18,10 +18,10 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
* @see
|
||||
*/
|
||||
public class HelperApi extends QyApi {
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public HelperApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public HelperApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ public class HelperApi extends QyApi {
|
||||
*/
|
||||
public List<String> getWechatServerIp() throws WeixinException {
|
||||
String getcallbackip_uri = getRequestUri("getcallbackip_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(getcallbackip_uri,
|
||||
token.getAccessToken()));
|
||||
return JSON.parseArray(response.getAsJson().getString("ip_list"),
|
||||
|
||||
@@ -39,7 +39,7 @@ import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.qy.model.Callback;
|
||||
import com.foxinmy.weixin4j.qy.model.Party;
|
||||
import com.foxinmy.weixin4j.qy.model.User;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.foxinmy.weixin4j.util.FileUtil;
|
||||
@@ -61,10 +61,10 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
*/
|
||||
public class MediaApi extends QyApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public MediaApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public MediaApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ public class MediaApi extends QyApi {
|
||||
fileName = String.format("%s.jpg", fileName);
|
||||
}
|
||||
String media_uploadimg_uri = getRequestUri("media_uploadimg_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(String.format(
|
||||
media_uploadimg_uri, token.getAccessToken()),
|
||||
new FormBodyPart("media", new InputStreamBody(is,
|
||||
@@ -146,7 +146,7 @@ public class MediaApi extends QyApi {
|
||||
",%s,", suffixName))) {
|
||||
mediaType = MediaType.video;
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
try {
|
||||
WeixinResponse response = null;
|
||||
if (agentid > 0) {
|
||||
@@ -200,7 +200,7 @@ public class MediaApi extends QyApi {
|
||||
*/
|
||||
public MediaDownloadResult downloadMedia(int agentid, String mediaId)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
try {
|
||||
HttpRequest request = null;
|
||||
if (agentid > 0) {
|
||||
@@ -273,7 +273,7 @@ public class MediaApi extends QyApi {
|
||||
*/
|
||||
public String uploadMaterialArticle(int agentid, List<MpArticle> articles)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String material_article_upload_uri = getRequestUri("material_article_upload_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("agentid", agentid);
|
||||
@@ -301,7 +301,7 @@ public class MediaApi extends QyApi {
|
||||
*/
|
||||
public JsonResult deleteMaterialMedia(int agentid, String mediaId)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String material_media_del_uri = getRequestUri("material_media_del_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
material_media_del_uri, token.getAccessToken(), mediaId,
|
||||
@@ -348,7 +348,7 @@ public class MediaApi extends QyApi {
|
||||
*/
|
||||
public String updateMaterialArticle(int agentid, String mediaId,
|
||||
List<MpArticle> articles) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String material_article_update_uri = getRequestUri("material_article_update_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("agentid", agentid);
|
||||
@@ -375,7 +375,7 @@ public class MediaApi extends QyApi {
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E6%80%BB%E6%95%B0">获取素材总数</a>
|
||||
*/
|
||||
public MediaCounter countMaterialMedia(int agentid) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String material_media_count_uri = getRequestUri("material_media_count_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
material_media_count_uri, token.getAccessToken(), agentid));
|
||||
@@ -406,7 +406,7 @@ public class MediaApi extends QyApi {
|
||||
*/
|
||||
public MediaRecord listMaterialMedia(int agentid, MediaType mediaType,
|
||||
Pageable pageable) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String material_media_list_uri = getRequestUri("material_media_list_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("agentid", agentid);
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Button;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.type.ButtonType;
|
||||
|
||||
/**
|
||||
@@ -29,10 +29,10 @@ import com.foxinmy.weixin4j.type.ButtonType;
|
||||
*/
|
||||
public class MenuApi extends QyApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public MenuApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public MenuApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,7 @@ public class MenuApi extends QyApi {
|
||||
*/
|
||||
public JsonResult createMenu(int agentid, List<Button> buttons) throws WeixinException {
|
||||
String menu_create_uri = getRequestUri("menu_create_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("button", buttons);
|
||||
WeixinResponse response = weixinExecutor.post(String.format(menu_create_uri, token.getAccessToken(), agentid),
|
||||
@@ -91,7 +91,7 @@ public class MenuApi extends QyApi {
|
||||
*/
|
||||
public List<Button> getMenu(int agentid) throws WeixinException {
|
||||
String menu_get_uri = getRequestUri("menu_get_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(menu_get_uri, token.getAccessToken(), agentid));
|
||||
|
||||
JSONArray buttons = response.getAsJson().getJSONObject("menu").getJSONArray("button");
|
||||
@@ -121,7 +121,7 @@ public class MenuApi extends QyApi {
|
||||
*/
|
||||
public JsonResult deleteMenu(int agentid) throws WeixinException {
|
||||
String menu_delete_uri = getRequestUri("menu_delete_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(menu_delete_uri, token.getAccessToken(), agentid));
|
||||
|
||||
return response.getAsJsonResult();
|
||||
|
||||
@@ -15,12 +15,13 @@ import com.foxinmy.weixin4j.qy.message.CustomeMessage;
|
||||
import com.foxinmy.weixin4j.qy.message.NotifyMessage;
|
||||
import com.foxinmy.weixin4j.qy.model.IdParameter;
|
||||
import com.foxinmy.weixin4j.qy.type.KfType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.tuple.MpNews;
|
||||
import com.foxinmy.weixin4j.tuple.NotifyTuple;
|
||||
|
||||
/**
|
||||
* 客服消息API
|
||||
*
|
||||
*
|
||||
* @className NotifyApi
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2014年11月21日
|
||||
@@ -39,10 +40,10 @@ import com.foxinmy.weixin4j.tuple.NotifyTuple;
|
||||
*/
|
||||
public class NotifyApi extends QyApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public NotifyApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public NotifyApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +53,7 @@ public class NotifyApi extends QyApi {
|
||||
* 2)发送人员不在通讯录权限范围内:不执行发送任务,返回首个出错的userid</br>
|
||||
* 3)发送人员不在应用可见范围内:不执行发送任务,返回首个出错的userid</br>
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param message
|
||||
* 普通消息对象
|
||||
* @return 如果无权限,则本次发送失败;如果收件人不存在或未关注,发送仍然执行。两种情况下均返回无效的部分</br> { "errcode":
|
||||
@@ -76,6 +77,11 @@ public class NotifyApi extends QyApi {
|
||||
public IdParameter sendNotifyMessage(NotifyMessage message)
|
||||
throws WeixinException {
|
||||
NotifyTuple tuple = message.getTuple();
|
||||
if (tuple instanceof MpNews) {
|
||||
if (((MpNews) tuple).getArticles().isEmpty()) {
|
||||
throw new WeixinException("notify fail:articles is required");
|
||||
}
|
||||
}
|
||||
Map<String, String> target = message.getTarget().getParameter();
|
||||
String msgtype = tuple.getMessageType();
|
||||
JSONObject obj = (JSONObject) JSON.toJSON(message);
|
||||
@@ -87,7 +93,7 @@ public class NotifyApi extends QyApi {
|
||||
obj.putAll(target);
|
||||
}
|
||||
String message_send_uri = getRequestUri("message_send_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(message_send_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -118,7 +124,7 @@ public class NotifyApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 发送客服消息
|
||||
*
|
||||
*
|
||||
* @param message
|
||||
* 客服消息对象
|
||||
* @return 发送结果
|
||||
@@ -140,7 +146,7 @@ public class NotifyApi extends QyApi {
|
||||
obj.put("msgtype", msgtype);
|
||||
obj.put(msgtype, tuple);
|
||||
String message_kf_send_uri = getRequestUri("message_kf_send_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(message_kf_send_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -149,7 +155,7 @@ public class NotifyApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 获取客服列表
|
||||
*
|
||||
*
|
||||
* @param kfType
|
||||
* 客服类型 为空时返回全部类型的客服
|
||||
* @return 第一个元素为内部客服(internal),第二个元素为外部客服(external)
|
||||
@@ -163,7 +169,7 @@ public class NotifyApi extends QyApi {
|
||||
if (kfType != null) {
|
||||
message_kf_list_uri += "&type=" + kfType.name();
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
message_kf_list_uri, token.getAccessToken()));
|
||||
JSONObject obj = response.getAsJson();
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.qy.model.Party;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 部门API
|
||||
@@ -23,10 +23,10 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E9%83%A8%E9%97%A8">管理部门说明</a>
|
||||
*/
|
||||
public class PartyApi extends QyApi {
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public PartyApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public PartyApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ public class PartyApi extends QyApi {
|
||||
if (party.getId() < 1) {
|
||||
obj.remove("id");
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(department_create_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -79,7 +79,7 @@ public class PartyApi extends QyApi {
|
||||
if (party.getOrder() < 0) {
|
||||
obj.remove("order");
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(department_update_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -102,7 +102,7 @@ public class PartyApi extends QyApi {
|
||||
if (partId > 0) {
|
||||
department_list_uri += String.format("&id=%d", partId);
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
department_list_uri, token.getAccessToken()));
|
||||
return JSON.parseArray(response.getAsJson().getString("department"),
|
||||
@@ -121,7 +121,7 @@ public class PartyApi extends QyApi {
|
||||
*/
|
||||
public JsonResult deleteParty(int partId) throws WeixinException {
|
||||
String department_delete_uri = getRequestUri("department_delete_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(String.format(
|
||||
department_delete_uri, token.getAccessToken(), partId));
|
||||
return response.getAsJsonResult();
|
||||
|
||||
@@ -2,18 +2,19 @@ package com.foxinmy.weixin4j.qy.api;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.cache.CacheStorager;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||
import com.foxinmy.weixin4j.qy.type.LoginTargetType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 服务商相关API
|
||||
*
|
||||
*
|
||||
* @className ProviderApi
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年12月30日
|
||||
@@ -22,18 +23,18 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%99%BB%E5%BD%95%E6%8E%88%E6%9D%83">企业号登录授权说明</a>
|
||||
*/
|
||||
public class ProviderApi extends QyApi {
|
||||
private final TokenHolder providerTokenHolder;
|
||||
private final TokenStorager tokenStorager;
|
||||
private final TokenManager providerTokenManager;
|
||||
private final CacheStorager<Token> cacheStorager;
|
||||
|
||||
public ProviderApi(TokenHolder providerTokenHolder,
|
||||
TokenStorager tokenStorager) {
|
||||
this.providerTokenHolder = providerTokenHolder;
|
||||
this.tokenStorager = tokenStorager;
|
||||
public ProviderApi(TokenManager providerTokenManager,
|
||||
CacheStorager<Token> cacheStorager) {
|
||||
this.providerTokenManager = providerTokenManager;
|
||||
this.cacheStorager = cacheStorager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方套件获取企业号管理员登录信息
|
||||
*
|
||||
*
|
||||
* @param authCode
|
||||
* oauth2.0授权企业号管理员登录产生的code
|
||||
* @return 登陆信息
|
||||
@@ -46,25 +47,27 @@ public class ProviderApi extends QyApi {
|
||||
String oauth_logininfo_uri = getRequestUri("oauth_logininfo_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(oauth_logininfo_uri,
|
||||
providerTokenHolder.getAccessToken()),
|
||||
providerTokenManager.getAccessToken()),
|
||||
String.format("{\"auth_code\":\"%s\"}", authCode));
|
||||
JSONObject obj = response.getAsJson();
|
||||
OUserInfo oUser = JSON.toJavaObject(obj, OUserInfo.class);
|
||||
oUser.getRedirectLoginInfo().setAccessToken(
|
||||
obj.getJSONObject("redirect_login_info").getString(
|
||||
"login_ticket"));
|
||||
tokenStorager.caching(getLoginTicketCacheKey(oUser.getCorpInfo()
|
||||
obj = obj.getJSONObject("redirect_login_info");
|
||||
Token loginInfo = new Token(obj.getString("login_ticket"),
|
||||
obj.getLongValue("expires_in") * 1000l);
|
||||
oUser.setRedirectLoginInfo(loginInfo);
|
||||
cacheStorager.caching(getLoginTicketCacheKey(oUser.getCorpInfo()
|
||||
.getCorpId()), oUser.getRedirectLoginInfo());
|
||||
return oUser;
|
||||
}
|
||||
|
||||
private String getLoginTicketCacheKey(String coprId) {
|
||||
return String.format("weixin4j_qy_provider_ticket_%s", coprId);
|
||||
return String.format("%sqy_provider_ticket_%s",
|
||||
TokenCreator.CACHEKEY_PREFIX, coprId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录企业号官网的url
|
||||
*
|
||||
*
|
||||
* @param corpId
|
||||
* <font color="red">oauth授权的corpid</font>
|
||||
* @param targetType
|
||||
@@ -78,7 +81,7 @@ public class ProviderApi extends QyApi {
|
||||
*/
|
||||
public String getLoginUrl(String corpId, LoginTargetType targetType,
|
||||
int agentId) throws WeixinException {
|
||||
Token token = tokenStorager.lookup(getLoginTicketCacheKey(corpId));
|
||||
Token token = cacheStorager.lookup(getLoginTicketCacheKey(corpId));
|
||||
if (token == null || StringUtil.isBlank(token.getAccessToken())) {
|
||||
throw new WeixinException("maybe oauth first?");
|
||||
}
|
||||
@@ -91,7 +94,7 @@ public class ProviderApi extends QyApi {
|
||||
}
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(oauth_loginurl_uri,
|
||||
providerTokenHolder.getAccessToken()),
|
||||
providerTokenManager.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
return response.getAsJson().getString("login_url");
|
||||
}
|
||||
|
||||
@@ -10,17 +10,17 @@ import com.foxinmy.weixin4j.qy.model.AgentInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.AgentSetter;
|
||||
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.User;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuitePerCodeHolder;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuiteTicketHolder;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuitePerCodeManager;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuiteTicketManager;
|
||||
import com.foxinmy.weixin4j.qy.suite.WeixinSuitePreCodeCreator;
|
||||
import com.foxinmy.weixin4j.qy.suite.WeixinSuiteTokenCreator;
|
||||
import com.foxinmy.weixin4j.qy.suite.WeixinTokenSuiteCreator;
|
||||
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 第三方应用套件
|
||||
*
|
||||
*
|
||||
* @className SuiteApi
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年6月17日
|
||||
@@ -32,87 +32,87 @@ public class SuiteApi extends QyApi {
|
||||
/**
|
||||
* 应用套件token
|
||||
*/
|
||||
private final TokenHolder suiteTokenHolder;
|
||||
private final TokenManager suiteTokenManager;
|
||||
/**
|
||||
* 应用套件ticket
|
||||
*/
|
||||
private final SuiteTicketHolder suiteTicketHolder;
|
||||
private final SuiteTicketManager suiteTicketManager;
|
||||
/**
|
||||
* 应用套件pre_code
|
||||
*/
|
||||
private final TokenHolder suitePreCodeHolder;
|
||||
private final TokenManager suitePreCodeManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param suiteTicketHolder
|
||||
*
|
||||
* @param suiteTicketManager
|
||||
* 套件ticket存取
|
||||
*/
|
||||
public SuiteApi(SuiteTicketHolder suiteTicketHolder) {
|
||||
this.suiteTicketHolder = suiteTicketHolder;
|
||||
this.suiteTokenHolder = new TokenHolder(new WeixinSuiteTokenCreator(
|
||||
suiteTicketHolder), suiteTicketHolder.getTokenStorager());
|
||||
this.suitePreCodeHolder = new TokenHolder(
|
||||
new WeixinSuitePreCodeCreator(suiteTokenHolder,
|
||||
suiteTicketHolder.getSuiteId()),
|
||||
suiteTicketHolder.getTokenStorager());
|
||||
public SuiteApi(SuiteTicketManager suiteTicketManager) {
|
||||
this.suiteTicketManager = suiteTicketManager;
|
||||
this.suiteTokenManager = new TokenManager(new WeixinSuiteTokenCreator(
|
||||
suiteTicketManager), suiteTicketManager.getCacheStorager());
|
||||
this.suitePreCodeManager = new TokenManager(
|
||||
new WeixinSuitePreCodeCreator(suiteTokenManager,
|
||||
suiteTicketManager.getSuiteId()),
|
||||
suiteTicketManager.getCacheStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用套件token
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getSuiteTokenHolder() {
|
||||
return this.suiteTokenHolder;
|
||||
public TokenManager getSuiteTokenManager() {
|
||||
return this.suiteTokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用套件ticket
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SuiteTicketHolder getTicketHolder() {
|
||||
return this.suiteTicketHolder;
|
||||
public SuiteTicketManager getTicketManager() {
|
||||
return this.suiteTicketManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用套件预授权码
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getPreCodeHolder() {
|
||||
return this.suitePreCodeHolder;
|
||||
public TokenManager getPreCodeManager() {
|
||||
return this.suitePreCodeManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用套件永久授权码:企业号的永久授权码
|
||||
*
|
||||
*
|
||||
* @param authCorpid
|
||||
* 授权方corpid
|
||||
* @return
|
||||
*/
|
||||
public SuitePerCodeHolder getPerCodeHolder(String authCorpId) {
|
||||
return new SuitePerCodeHolder(authCorpId,
|
||||
suiteTicketHolder.getSuiteId(),
|
||||
suiteTicketHolder.getTokenStorager());
|
||||
public SuitePerCodeManager getPerCodeManager(String authCorpId) {
|
||||
return new SuitePerCodeManager(authCorpId,
|
||||
suiteTicketManager.getSuiteId(),
|
||||
suiteTicketManager.getCacheStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业号access_token(永久授权码)
|
||||
*
|
||||
*
|
||||
* @param authCorpid
|
||||
* 授权方corpid
|
||||
* @return 企业号token
|
||||
*/
|
||||
public TokenHolder getTokenSuiteHolder(String authCorpId) {
|
||||
return new TokenHolder(new WeixinTokenSuiteCreator(
|
||||
getPerCodeHolder(authCorpId), suiteTokenHolder),
|
||||
suiteTicketHolder.getTokenStorager());
|
||||
public TokenManager getTokenSuiteManager(String authCorpId) {
|
||||
return new TokenManager(new WeixinTokenSuiteCreator(
|
||||
getPerCodeManager(authCorpId), suiteTokenManager),
|
||||
suiteTicketManager.getCacheStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置套件授权配置:如果需要对某次授权进行配置,则调用本接口,目前仅可以设置哪些应用可以授权,不调用则默认允许所有应用进行授权。
|
||||
*
|
||||
*
|
||||
* @param appids
|
||||
* 允许进行授权的应用id,如1、2、3
|
||||
* @return 处理结果
|
||||
@@ -124,19 +124,20 @@ public class SuiteApi extends QyApi {
|
||||
public JsonResult setSuiteSession(int... appids) throws WeixinException {
|
||||
String suite_set_session_uri = getRequestUri("suite_set_session_uri");
|
||||
JSONObject para = new JSONObject();
|
||||
para.put("pre_auth_code", suitePreCodeHolder.getAccessToken());
|
||||
para.put("pre_auth_code", suitePreCodeManager.getAccessToken());
|
||||
JSONObject appid = new JSONObject();
|
||||
appid.put("appid", appids);
|
||||
para.put("session_info", appid);
|
||||
WeixinResponse response = weixinExecutor
|
||||
.post(String.format(suite_set_session_uri,
|
||||
suiteTokenHolder.getAccessToken()), para.toJSONString());
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(suite_set_session_uri,
|
||||
suiteTokenManager.getAccessToken()),
|
||||
para.toJSONString());
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业号的永久授权码
|
||||
*
|
||||
*
|
||||
* @param authCode
|
||||
* 临时授权码会在授权成功时附加在redirect_uri中跳转回应用提供商网站。
|
||||
* @return 授权得到的信息
|
||||
@@ -150,34 +151,34 @@ public class SuiteApi extends QyApi {
|
||||
throws WeixinException {
|
||||
String suite_get_permanent_uri = getRequestUri("suite_get_permanent_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||
obj.put("suite_id", suiteTicketManager.getSuiteId());
|
||||
obj.put("auth_code", authCode);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(suite_get_permanent_uri,
|
||||
suiteTokenHolder.getAccessToken()), obj.toJSONString());
|
||||
WeixinResponse response = weixinExecutor
|
||||
.post(String.format(suite_get_permanent_uri,
|
||||
suiteTokenManager.getAccessToken()), obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
obj.put("corp_info", obj.remove("auth_corp_info"));
|
||||
obj.put("user_info", obj.remove("auth_user_info"));
|
||||
OUserInfo oInfo = JSON.toJavaObject(obj, OUserInfo.class);
|
||||
// 微信授权企业号的永久授权码
|
||||
SuitePerCodeHolder suitePerCodeHolder = getPerCodeHolder(oInfo
|
||||
SuitePerCodeManager suitePerCodeManager = getPerCodeManager(oInfo
|
||||
.getCorpInfo().getCorpId());
|
||||
// 缓存微信企业号access_token
|
||||
TokenCreator tokenCreator = new WeixinTokenSuiteCreator(
|
||||
suitePerCodeHolder, suiteTokenHolder);
|
||||
Token token = new Token(obj.getString("access_token"));
|
||||
token.setExpiresIn(obj.getIntValue("expires_in"));
|
||||
suiteTicketHolder.getTokenStorager().caching(
|
||||
tokenCreator.key(), token);
|
||||
suitePerCodeManager, suiteTokenManager);
|
||||
Token token = new Token(obj.getString("access_token"),
|
||||
obj.getLongValue("expires_in") * 1000l);
|
||||
suiteTicketManager.getCacheStorager()
|
||||
.caching(tokenCreator.key(), token);
|
||||
// 缓存微信企业号永久授权码
|
||||
suitePerCodeHolder
|
||||
.cachingPermanentCode(obj.getString("permanent_code"));
|
||||
suitePerCodeManager.cachingPermanentCode(obj
|
||||
.getString("permanent_code"));
|
||||
return oInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业号的授权信息
|
||||
*
|
||||
*
|
||||
* @param authCorpId
|
||||
* 授权方corpid
|
||||
* @return 授权方信息
|
||||
@@ -189,13 +190,13 @@ public class SuiteApi extends QyApi {
|
||||
public OUserInfo getOAuthInfo(String authCorpId) throws WeixinException {
|
||||
String suite_get_authinfo_uri = getRequestUri("suite_get_authinfo_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||
obj.put("suite_id", suiteTicketManager.getSuiteId());
|
||||
obj.put("auth_corpid", authCorpId);
|
||||
obj.put("permanent_code", getPerCodeHolder(authCorpId)
|
||||
obj.put("permanent_code", getPerCodeManager(authCorpId)
|
||||
.getPermanentCode());
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(suite_get_authinfo_uri,
|
||||
suiteTokenHolder.getAccessToken()), obj.toJSONString());
|
||||
WeixinResponse response = weixinExecutor
|
||||
.post(String.format(suite_get_authinfo_uri,
|
||||
suiteTokenManager.getAccessToken()), obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
obj.put("corp_info", obj.remove("auth_corp_info"));
|
||||
obj.put("user_info", obj.remove("auth_user_info"));
|
||||
@@ -204,7 +205,7 @@ public class SuiteApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 获取企业号应用
|
||||
*
|
||||
*
|
||||
* @param authCorpId
|
||||
* 授权方corpid
|
||||
* @param agentid
|
||||
@@ -219,14 +220,14 @@ public class SuiteApi extends QyApi {
|
||||
throws WeixinException {
|
||||
String suite_get_agent_uri = getRequestUri("suite_get_agent_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||
obj.put("suite_id", suiteTicketManager.getSuiteId());
|
||||
obj.put("auth_corpid", authCorpId);
|
||||
obj.put("permanent_code", getPerCodeHolder(authCorpId)
|
||||
obj.put("permanent_code", getPerCodeManager(authCorpId)
|
||||
.getPermanentCode());
|
||||
obj.put("agentid", agentid);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(suite_get_agent_uri,
|
||||
suiteTokenHolder.getAccessToken()), obj.toJSONString());
|
||||
WeixinResponse response = weixinExecutor
|
||||
.post(String.format(suite_get_agent_uri,
|
||||
suiteTokenManager.getAccessToken()), obj.toJSONString());
|
||||
JSONObject jsonObj = response.getAsJson();
|
||||
AgentInfo agent = JSON.toJavaObject(jsonObj, AgentInfo.class);
|
||||
agent.setAllowUsers(JSON.parseArray(
|
||||
@@ -242,7 +243,7 @@ public class SuiteApi extends QyApi {
|
||||
|
||||
/**
|
||||
* 设置企业应用的选项设置信息,如:地理位置上报等
|
||||
*
|
||||
*
|
||||
* @param authCorpId
|
||||
* 授权方corpid
|
||||
* @param agentSet
|
||||
@@ -257,14 +258,14 @@ public class SuiteApi extends QyApi {
|
||||
throws WeixinException {
|
||||
String suite_set_agent_uri = getRequestUri("suite_set_agent_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||
obj.put("suite_id", suiteTicketManager.getSuiteId());
|
||||
obj.put("auth_corpid", authCorpId);
|
||||
obj.put("permanent_code", getPerCodeHolder(authCorpId)
|
||||
obj.put("permanent_code", getPerCodeManager(authCorpId)
|
||||
.getPermanentCode());
|
||||
obj.put("agent", agentSet);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(suite_set_agent_uri,
|
||||
suiteTokenHolder.getAccessToken()),
|
||||
suiteTokenManager.getAccessToken()),
|
||||
JSON.toJSONString(obj, AgentApi.typeFilter));
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.foxinmy.weixin4j.qy.model.Contacts;
|
||||
import com.foxinmy.weixin4j.qy.model.IdParameter;
|
||||
import com.foxinmy.weixin4j.qy.model.Tag;
|
||||
import com.foxinmy.weixin4j.qy.model.User;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 标签API
|
||||
@@ -27,10 +27,10 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
* 管理标签</a>
|
||||
*/
|
||||
public class TagApi extends QyApi {
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public TagApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public TagApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ public class TagApi extends QyApi {
|
||||
*/
|
||||
public int createTag(Tag tag) throws WeixinException {
|
||||
String tag_create_uri = getRequestUri("tag_create_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = (JSONObject) JSON.toJSON(tag);
|
||||
if (obj.getIntValue("tagid") <= 0) {
|
||||
obj.remove("tagid");
|
||||
@@ -72,7 +72,7 @@ public class TagApi extends QyApi {
|
||||
*/
|
||||
public JsonResult updateTag(Tag tag) throws WeixinException {
|
||||
String tag_update_uri = getRequestUri("tag_update_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(tag_update_uri, token.getAccessToken()),
|
||||
JSON.toJSONString(tag));
|
||||
@@ -92,7 +92,7 @@ public class TagApi extends QyApi {
|
||||
*/
|
||||
public JsonResult deleteTag(int tagId) throws WeixinException {
|
||||
String tag_delete_uri = getRequestUri("tag_delete_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
tag_delete_uri, token.getAccessToken(), tagId));
|
||||
return response.getAsJsonResult();
|
||||
@@ -110,7 +110,7 @@ public class TagApi extends QyApi {
|
||||
*/
|
||||
public List<Tag> listTag() throws WeixinException {
|
||||
String tag_list_uri = getRequestUri("tag_list_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
tag_list_uri, token.getAccessToken()));
|
||||
return JSON.parseArray(response.getAsJson().getString("taglist"),
|
||||
@@ -133,7 +133,7 @@ public class TagApi extends QyApi {
|
||||
*/
|
||||
public Contacts getTagUsers(int tagId) throws WeixinException {
|
||||
String tag_get_user_uri = getRequestUri("tag_get_user_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
tag_get_user_uri, token.getAccessToken(), tagId));
|
||||
JSONObject obj = response.getAsJson();
|
||||
@@ -196,7 +196,7 @@ public class TagApi extends QyApi {
|
||||
obj.put("tagid", tagId);
|
||||
obj.put("userlist", userIds);
|
||||
obj.put("partylist", partyIds);
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(uri, token.getAccessToken()), obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.User;
|
||||
import com.foxinmy.weixin4j.qy.type.InviteType;
|
||||
import com.foxinmy.weixin4j.qy.type.UserStatus;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.NameValue;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
@@ -33,11 +33,11 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
*/
|
||||
public class UserApi extends QyApi {
|
||||
private final MediaApi mediaApi;
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public UserApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
this.mediaApi = new MediaApi(tokenHolder);
|
||||
public UserApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
this.mediaApi = new MediaApi(tokenManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ public class UserApi extends QyApi {
|
||||
} else {
|
||||
obj.put("avatar_mediaid", obj.remove("avatar"));
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(uri, token.getAccessToken()), obj.toJSONString());
|
||||
return response.getAsJsonResult();
|
||||
@@ -152,7 +152,7 @@ public class UserApi extends QyApi {
|
||||
*/
|
||||
public User getUser(String userid) throws WeixinException {
|
||||
String user_get_uri = getRequestUri("user_get_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
user_get_uri, token.getAccessToken(), userid));
|
||||
JSONObject obj = response.getAsJson();
|
||||
@@ -202,7 +202,7 @@ public class UserApi extends QyApi {
|
||||
*/
|
||||
public String[] getUserIdByCode(String code) throws WeixinException {
|
||||
String user_getid_uri = getRequestUri("user_getid_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
user_getid_uri, token.getAccessToken(), code));
|
||||
JSONObject result = response.getAsJson();
|
||||
@@ -261,7 +261,7 @@ public class UserApi extends QyApi {
|
||||
UserStatus userStatus, boolean findDetail) throws WeixinException {
|
||||
String user_list_uri = findDetail ? getRequestUri("user_list_uri")
|
||||
: getRequestUri("user_slist_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
if (userStatus == null) {
|
||||
userStatus = UserStatus.UNFOLLOW;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ public class UserApi extends QyApi {
|
||||
*/
|
||||
public JsonResult deleteUser(String userid) throws WeixinException {
|
||||
String user_delete_uri = getRequestUri("user_delete_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
user_delete_uri, token.getAccessToken(), userid));
|
||||
return response.getAsJsonResult();
|
||||
@@ -338,7 +338,7 @@ public class UserApi extends QyApi {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("useridlist", userIds);
|
||||
String user_delete_uri = getRequestUri("user_batchdelete_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(String.format(
|
||||
user_delete_uri, token.getAccessToken(), obj.toJSONString()));
|
||||
return response.getAsJsonResult();
|
||||
@@ -357,7 +357,7 @@ public class UserApi extends QyApi {
|
||||
*/
|
||||
public JsonResult authsucc(String userId) throws WeixinException {
|
||||
String user_authsucc_uri = getRequestUri("user_authsucc_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
user_authsucc_uri, token.getAccessToken(), userId));
|
||||
return response.getAsJsonResult();
|
||||
@@ -382,7 +382,7 @@ public class UserApi extends QyApi {
|
||||
obj.put("userid", userId);
|
||||
obj.put("invite_tips", tips);
|
||||
String invite_user_uri = getRequestUri("invite_user_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(invite_user_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -419,7 +419,7 @@ public class UserApi extends QyApi {
|
||||
}
|
||||
String userid2openid_uri = getRequestUri("userid2openid_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(userid2openid_uri, tokenHolder.getAccessToken()),
|
||||
String.format(userid2openid_uri, tokenManager.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
return new String[] { obj.getString("openid"), obj.getString("appid") };
|
||||
@@ -440,7 +440,7 @@ public class UserApi extends QyApi {
|
||||
public String openid2userid(String openid) throws WeixinException {
|
||||
String openid2userid_uri = getRequestUri("openid2userid_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(openid2userid_uri, tokenHolder.getAccessToken()),
|
||||
String.format(openid2userid_uri, tokenManager.getAccessToken()),
|
||||
String.format("{\"openid\": \"%s\"}", openid));
|
||||
return response.getAsJson().getString("userid");
|
||||
}
|
||||
|
||||
+23
-25
@@ -3,11 +3,10 @@ package com.foxinmy.weixin4j.qy.jssdk;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
@@ -15,7 +14,7 @@ import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
|
||||
/**
|
||||
* JSSDK联系人筛选配置
|
||||
*
|
||||
*
|
||||
* @className JSSDKContactConfigurator
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年12月25日
|
||||
@@ -23,22 +22,22 @@ import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
* @see
|
||||
*/
|
||||
public class JSSDKContactConfigurator {
|
||||
private final TokenHolder ticketTokenHolder;
|
||||
private final TokenManager ticketTokenManager;
|
||||
private JSSDKContactParameter contactParameter;
|
||||
|
||||
/**
|
||||
* ticket保存类 可调用WeixinProxy#getTicketHolder获取
|
||||
*
|
||||
* @param ticketTokenHolder
|
||||
* ticket保存类 可调用WeixinProxy#getTicketManager获取
|
||||
*
|
||||
* @param ticketTokenManager
|
||||
*/
|
||||
public JSSDKContactConfigurator(TokenHolder ticketTokenHolder) {
|
||||
this.ticketTokenHolder = ticketTokenHolder;
|
||||
public JSSDKContactConfigurator(TokenManager ticketTokenManager) {
|
||||
this.ticketTokenManager = ticketTokenManager;
|
||||
this.contactParameter = new JSSDKContactParameter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 可选范围:部门ID列表(如果partyIds为0则表示显示管理组下所有部门)
|
||||
*
|
||||
*
|
||||
* @param departmentIds
|
||||
* @return
|
||||
*/
|
||||
@@ -49,7 +48,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 可选范围:标签ID列表(如果tagIds为0则表示显示所有标签)
|
||||
*
|
||||
*
|
||||
* @param tagIds
|
||||
* @return
|
||||
*/
|
||||
@@ -60,7 +59,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 可选范围:用户ID列表
|
||||
*
|
||||
*
|
||||
* @param userIds
|
||||
* @return
|
||||
*/
|
||||
@@ -71,7 +70,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 单选模式
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public JSSDKContactConfigurator singleMode() {
|
||||
@@ -81,7 +80,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 多选模式
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public JSSDKContactConfigurator multiMode() {
|
||||
@@ -91,7 +90,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 限制部门
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public JSSDKContactConfigurator limitDepartment() {
|
||||
@@ -101,7 +100,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 限制标签
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public JSSDKContactConfigurator limitTag() {
|
||||
@@ -111,7 +110,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 限制用户
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public JSSDKContactConfigurator limitUser() {
|
||||
@@ -121,7 +120,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 已选部门ID
|
||||
*
|
||||
*
|
||||
* @param selectedDepartmentIds
|
||||
* @return
|
||||
*/
|
||||
@@ -133,7 +132,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 已选标签ID
|
||||
*
|
||||
*
|
||||
* @param selectedTagIds
|
||||
* @return
|
||||
*/
|
||||
@@ -144,7 +143,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 已选用户ID
|
||||
*
|
||||
*
|
||||
* @param selectedUserIds
|
||||
* @return
|
||||
*/
|
||||
@@ -155,7 +154,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 生成config配置JSON串
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* 当前网页的URL,不包含#及其后面部分
|
||||
* @return
|
||||
@@ -167,7 +166,7 @@ public class JSSDKContactConfigurator {
|
||||
|
||||
/**
|
||||
* 生成config配置JSON串
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* 当前网页的URL,不包含#及其后面部分
|
||||
* @param parameter
|
||||
@@ -180,7 +179,7 @@ public class JSSDKContactConfigurator {
|
||||
Map<String, String> signMap = new HashMap<String, String>();
|
||||
String timestamp = DateUtil.timestamp2string();
|
||||
String noncestr = RandomUtil.generateString(24);
|
||||
Token token = this.ticketTokenHolder.getToken();
|
||||
Token token = this.ticketTokenManager.getCache();
|
||||
signMap.put("timestamp", timestamp);
|
||||
signMap.put("nonceStr", noncestr);
|
||||
signMap.put("group_ticket", token.getAccessToken());
|
||||
@@ -189,8 +188,7 @@ public class JSSDKContactConfigurator {
|
||||
.toJoinString(signMap, false, true));
|
||||
JSONObject config = new JSONObject();
|
||||
config.put("signature", sign);
|
||||
config.put("groupId", JSON.parseObject(token.getOriginalResult())
|
||||
.getString("group_id"));
|
||||
config.put("groupId", token.getExtra().get("group_id"));
|
||||
config.put("timestamp", timestamp);
|
||||
config.put("noncestr", noncestr);
|
||||
config.put("params", parameter);
|
||||
|
||||
@@ -2,14 +2,12 @@ package com.foxinmy.weixin4j.qy.message;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONCreator;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.qy.type.ChatType;
|
||||
import com.foxinmy.weixin4j.tuple.ChatTuple;
|
||||
|
||||
/**
|
||||
* 会话消息对象
|
||||
*
|
||||
*
|
||||
* @className ChatMessage
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年8月1日
|
||||
@@ -39,11 +37,8 @@ public class ChatMessage implements Serializable {
|
||||
*/
|
||||
private ChatTuple chatTuple;
|
||||
|
||||
@JSONCreator
|
||||
public ChatMessage(@JSONField(name = "targetId") String targetId,
|
||||
@JSONField(name = "chatType") ChatType chatType,
|
||||
@JSONField(name = "senderId") String senderId,
|
||||
@JSONField(name = "chatTuple") ChatTuple chatTuple) {
|
||||
public ChatMessage(String targetId, ChatType chatType, String senderId,
|
||||
ChatTuple chatTuple) {
|
||||
this.targetId = targetId;
|
||||
this.chatType = chatType;
|
||||
this.senderId = senderId;
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
/**
|
||||
* 调用某些接口时填入的回调信息
|
||||
*
|
||||
*
|
||||
* @className Callback
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年3月30日
|
||||
|
||||
@@ -2,12 +2,11 @@ package com.foxinmy.weixin4j.qy.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONCreator;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
/**
|
||||
* 成员新消息免打扰
|
||||
*
|
||||
*
|
||||
* @className ChatMute
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年8月1日
|
||||
@@ -24,7 +23,7 @@ public class ChatMute implements Serializable {
|
||||
|
||||
/**
|
||||
* 默认关闭免打扰
|
||||
*
|
||||
*
|
||||
* @param userid
|
||||
*/
|
||||
public ChatMute(String userId) {
|
||||
@@ -33,15 +32,13 @@ public class ChatMute implements Serializable {
|
||||
|
||||
/**
|
||||
* 传入true时开启免打扰
|
||||
*
|
||||
* @param userid
|
||||
*
|
||||
* @param userId
|
||||
* 成员userid
|
||||
* @param status
|
||||
* 是否开启免打扰
|
||||
*/
|
||||
@JSONCreator
|
||||
public ChatMute(@JSONField(name = "userId") String userId,
|
||||
@JSONField(name = "status") boolean status) {
|
||||
public ChatMute(String userId, boolean status) {
|
||||
this.userId = userId;
|
||||
this.status = status ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.foxinmy.weixin4j.util.NameValue;
|
||||
|
||||
/**
|
||||
* 部门成员对象
|
||||
*
|
||||
*
|
||||
* @className User
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2014年11月19日
|
||||
@@ -32,7 +32,7 @@ public class User implements Serializable {
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 非必须 成员所属部门id列表。注意,每个部门的直属员工上限为1000个
|
||||
* 非必须 成员所属部门id列表,不超过20个
|
||||
*/
|
||||
@JSONField(name = "department")
|
||||
private List<Integer> partyIds;
|
||||
|
||||
+18
-18
@@ -1,62 +1,62 @@
|
||||
package com.foxinmy.weixin4j.qy.suite;
|
||||
|
||||
import com.foxinmy.weixin4j.cache.CacheStorager;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
|
||||
/**
|
||||
* 应用套件永久授权码的存取
|
||||
*
|
||||
* @className SuitePerCodeHolder
|
||||
*
|
||||
* @className SuitePerCodeManager
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年6月22日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class SuitePerCodeHolder {
|
||||
public class SuitePerCodeManager {
|
||||
|
||||
private final String authCorpId;
|
||||
private final String suiteId;
|
||||
private final TokenStorager tokenStorager;
|
||||
private final CacheStorager<Token> cacheStorager;
|
||||
|
||||
public SuitePerCodeHolder(String authCorpId, String suiteId,
|
||||
TokenStorager tokenStorager) {
|
||||
public SuitePerCodeManager(String authCorpId, String suiteId,
|
||||
CacheStorager<Token> cacheStorager) {
|
||||
this.authCorpId = authCorpId;
|
||||
this.suiteId = suiteId;
|
||||
this.tokenStorager = tokenStorager;
|
||||
this.cacheStorager = cacheStorager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存永久授权码
|
||||
*
|
||||
*
|
||||
* @param permanentCode
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public void cachingPermanentCode(String permanentCode)
|
||||
throws WeixinException {
|
||||
Token token = new Token(permanentCode);
|
||||
token.setExpiresIn(-1);
|
||||
tokenStorager.caching(getCacheKey(), token);
|
||||
cacheStorager.caching(getCacheKey(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取永久授权码的key
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getCacheKey() {
|
||||
return String.format("weixin4j_qy_suite_percode_%s_%s", suiteId,
|
||||
authCorpId);
|
||||
return String.format("%sqy_suite_percode_%s_%s",
|
||||
TokenCreator.CACHEKEY_PREFIX, suiteId, authCorpId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找永久授权码
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String getPermanentCode() throws WeixinException {
|
||||
return tokenStorager.lookup(getCacheKey()).getAccessToken();
|
||||
return cacheStorager.lookup(getCacheKey()).getAccessToken();
|
||||
}
|
||||
|
||||
public String getSuiteId() {
|
||||
@@ -67,7 +67,7 @@ public class SuitePerCodeHolder {
|
||||
return this.authCorpId;
|
||||
}
|
||||
|
||||
public TokenStorager getTokenStorager() {
|
||||
return this.tokenStorager;
|
||||
public CacheStorager<Token> getCacheStorager() {
|
||||
return this.cacheStorager;
|
||||
}
|
||||
}
|
||||
+18
-17
@@ -1,60 +1,61 @@
|
||||
package com.foxinmy.weixin4j.qy.suite;
|
||||
|
||||
import com.foxinmy.weixin4j.cache.CacheStorager;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
|
||||
/**
|
||||
* 应用套件ticket的存取
|
||||
*
|
||||
* @className SuiteTicketHolder
|
||||
*
|
||||
* @className SuiteTicketManager
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年6月22日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class SuiteTicketHolder {
|
||||
public class SuiteTicketManager {
|
||||
|
||||
private final String suiteId;
|
||||
private final String suiteSecret;
|
||||
private final TokenStorager tokenStorager;
|
||||
private final CacheStorager<Token> cacheStorager;
|
||||
|
||||
public SuiteTicketHolder(String suiteId, String suiteSecret,
|
||||
TokenStorager tokenStorager) {
|
||||
public SuiteTicketManager(String suiteId, String suiteSecret,
|
||||
CacheStorager<Token> cacheStorager) {
|
||||
this.suiteId = suiteId;
|
||||
this.suiteSecret = suiteSecret;
|
||||
this.tokenStorager = tokenStorager;
|
||||
this.cacheStorager = cacheStorager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ticket
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String getTicket() throws WeixinException {
|
||||
return tokenStorager.lookup(getCacheKey()).getAccessToken();
|
||||
return cacheStorager.lookup(getCacheKey()).getAccessToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ticket的key
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getCacheKey() {
|
||||
return String.format("weixin4j_qy_suite_ticket_%s", suiteId);
|
||||
return String.format("%sqy_suite_ticket_%s",
|
||||
TokenCreator.CACHEKEY_PREFIX, suiteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存ticket
|
||||
*
|
||||
*
|
||||
* @param ticket
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public void cachingTicket(String ticket) throws WeixinException {
|
||||
Token token = new Token(ticket);
|
||||
token.setExpiresIn(-1);
|
||||
tokenStorager.caching(getCacheKey(), token);
|
||||
cacheStorager.caching(getCacheKey(), token);
|
||||
}
|
||||
|
||||
public String getSuiteId() {
|
||||
@@ -65,7 +66,7 @@ public class SuiteTicketHolder {
|
||||
return this.suiteSecret;
|
||||
}
|
||||
|
||||
public TokenStorager getTokenStorager() {
|
||||
return this.tokenStorager;
|
||||
public CacheStorager<Token> getCacheStorager() {
|
||||
return this.cacheStorager;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,9 @@ package com.foxinmy.weixin4j.qy.suite;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.cache.CacheStorager;
|
||||
import com.foxinmy.weixin4j.cache.FileCacheStorager;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.qy.model.WeixinQyAccount;
|
||||
import com.foxinmy.weixin4j.setting.SystemSettings;
|
||||
@@ -19,6 +22,10 @@ import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
* @see
|
||||
*/
|
||||
public class Weixin4jSuiteSettings extends SystemSettings<WeixinQyAccount> {
|
||||
/**
|
||||
* Token的存储方式 默认为FileCacheStorager
|
||||
*/
|
||||
private CacheStorager<Token> cacheStorager;
|
||||
|
||||
/**
|
||||
* 默认使用weixin4j.properties配置的信息
|
||||
@@ -61,6 +68,17 @@ public class Weixin4jSuiteSettings extends SystemSettings<WeixinQyAccount> {
|
||||
return getTmpdir();
|
||||
}
|
||||
|
||||
public CacheStorager<Token> getCacheStorager() {
|
||||
return cacheStorager;
|
||||
}
|
||||
|
||||
public CacheStorager<Token> getCacheStorager0() {
|
||||
if (cacheStorager == null) {
|
||||
return new FileCacheStorager<Token>(getTmpdir0());
|
||||
}
|
||||
return cacheStorager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Weixin4jSuiteSettings [" + super.toString() + "]";
|
||||
|
||||
+10
-10
@@ -6,7 +6,7 @@ import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 微信企业号应用套件预授权码创建
|
||||
@@ -22,18 +22,19 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
*/
|
||||
public class WeixinSuitePreCodeCreator extends TokenCreator {
|
||||
|
||||
private final TokenHolder suiteTokenHolder;
|
||||
private final TokenManager suiteTokenManager;
|
||||
private final String suiteId;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param suiteTokenHolder
|
||||
* @param suiteTokenManager
|
||||
* 应用套件的token
|
||||
* @param suiteId
|
||||
* 应用套件ID
|
||||
*/
|
||||
public WeixinSuitePreCodeCreator(TokenHolder suiteTokenHolder, String suiteId) {
|
||||
this.suiteTokenHolder = suiteTokenHolder;
|
||||
public WeixinSuitePreCodeCreator(TokenManager suiteTokenManager,
|
||||
String suiteId) {
|
||||
this.suiteTokenManager = suiteTokenManager;
|
||||
this.suiteId = suiteId;
|
||||
}
|
||||
|
||||
@@ -45,12 +46,11 @@ public class WeixinSuitePreCodeCreator extends TokenCreator {
|
||||
@Override
|
||||
public Token create() throws WeixinException {
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(URLConsts.SUITE_PRE_CODE_URL, suiteTokenHolder.getAccessToken()),
|
||||
String.format(URLConsts.SUITE_PRE_CODE_URL,
|
||||
suiteTokenManager.getAccessToken()),
|
||||
String.format("{\"suite_id\":\"%s\"}", suiteId));
|
||||
JSONObject result = response.getAsJson();
|
||||
Token token = new Token(result.getString("pre_auth_code"));
|
||||
token.setExpiresIn(result.getIntValue("expires_in"));
|
||||
token.setOriginalResult(response.getAsString());
|
||||
return token;
|
||||
return new Token(result.getString("pre_auth_code"),
|
||||
result.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-16
@@ -1,4 +1,4 @@
|
||||
package com.foxinmy.weixin4j.qy.suite;
|
||||
package com.foxinmy.weixin4j.qy.suite;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
@@ -20,34 +20,32 @@ import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
*/
|
||||
public class WeixinSuiteTokenCreator extends TokenCreator {
|
||||
|
||||
private final SuiteTicketHolder ticketHolder;
|
||||
private final SuiteTicketManager ticketManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param stringStorager
|
||||
* 套件ticket存取器
|
||||
* @param ticketManager
|
||||
* 套件ticket存取
|
||||
*/
|
||||
public WeixinSuiteTokenCreator(SuiteTicketHolder ticketHolder) {
|
||||
this.ticketHolder = ticketHolder;
|
||||
public WeixinSuiteTokenCreator(SuiteTicketManager ticketManager) {
|
||||
this.ticketManager = ticketManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("qy_suite_token_%s", ticketHolder.getSuiteId());
|
||||
return String.format("qy_suite_token_%s", ticketManager.getSuiteId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token create() throws WeixinException {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("suite_id", ticketHolder.getSuiteId());
|
||||
obj.put("suite_secret", ticketHolder.getSuiteSecret());
|
||||
obj.put("suite_ticket", ticketHolder.getTicket());
|
||||
WeixinResponse response = weixinExecutor.post(URLConsts.SUITE_TOKEN_URL,
|
||||
obj.toJSONString());
|
||||
obj.put("suite_id", ticketManager.getSuiteId());
|
||||
obj.put("suite_secret", ticketManager.getSuiteSecret());
|
||||
obj.put("suite_ticket", ticketManager.getTicket());
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
URLConsts.SUITE_TOKEN_URL, obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
Token token = new Token(obj.getString("suite_access_token"));
|
||||
token.setExpiresIn(obj.getIntValue("expires_in"));
|
||||
token.setOriginalResult(response.getAsString());
|
||||
return token;
|
||||
return new Token(obj.getString("suite_access_token"),
|
||||
obj.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
+18
-17
@@ -6,7 +6,7 @@ import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 微信企业号token创建(永久授权码)
|
||||
@@ -22,38 +22,39 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
*/
|
||||
public class WeixinTokenSuiteCreator extends TokenCreator {
|
||||
|
||||
private final SuitePerCodeHolder perCodeHolder;
|
||||
private final TokenHolder suiteTokenHolder;
|
||||
private final SuitePerCodeManager perCodeManager;
|
||||
private final TokenManager suiteTokenManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param perCodeHolder
|
||||
* @param perCodeManager
|
||||
* 第三方套件永久授权码
|
||||
* @param suiteTokenHolder
|
||||
* @param suitetokenManager
|
||||
* 第三方套件凭证token
|
||||
*/
|
||||
public WeixinTokenSuiteCreator(SuitePerCodeHolder perCodeHolder, TokenHolder suiteTokenHolder) {
|
||||
this.perCodeHolder = perCodeHolder;
|
||||
this.suiteTokenHolder = suiteTokenHolder;
|
||||
public WeixinTokenSuiteCreator(SuitePerCodeManager perCodeManager,
|
||||
TokenManager suiteTokenManager) {
|
||||
this.perCodeManager = perCodeManager;
|
||||
this.suiteTokenManager = suiteTokenManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("qy_token_suite_%s_%s", perCodeHolder.getSuiteId(), perCodeHolder.getAuthCorpId());
|
||||
return String.format("qy_token_suite_%s_%s",
|
||||
perCodeManager.getSuiteId(), perCodeManager.getAuthCorpId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token create() throws WeixinException {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("suite_id", perCodeHolder.getSuiteId());
|
||||
obj.put("auth_corpid", perCodeHolder.getAuthCorpId());
|
||||
obj.put("permanent_code", perCodeHolder.getPermanentCode());
|
||||
obj.put("suite_id", perCodeManager.getSuiteId());
|
||||
obj.put("auth_corpid", perCodeManager.getAuthCorpId());
|
||||
obj.put("permanent_code", perCodeManager.getPermanentCode());
|
||||
WeixinResponse response = weixinExecutor
|
||||
.post(String.format(URLConsts.TOKEN_SUITE_URL, suiteTokenHolder.getAccessToken()), obj.toJSONString());
|
||||
.post(String.format(URLConsts.TOKEN_SUITE_URL,
|
||||
suiteTokenManager.getAccessToken()), obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
Token token = new Token(obj.getString("access_token"));
|
||||
token.setExpiresIn(obj.getIntValue("expires_in"));
|
||||
token.setOriginalResult(response.getAsString());
|
||||
return token;
|
||||
return new Token(obj.getString("access_token"),
|
||||
obj.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-6
@@ -10,7 +10,7 @@ import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
/**
|
||||
* 微信企业号应用提供商凭证创建
|
||||
*
|
||||
* @className WeixinTokenCreator
|
||||
* @className WeixinProviderTokenCreator
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年1月10日
|
||||
* @since JDK 1.6
|
||||
@@ -46,11 +46,10 @@ public class WeixinProviderTokenCreator extends TokenCreator {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("corpid", corpid);
|
||||
obj.put("provider_secret", providersecret);
|
||||
WeixinResponse response = weixinExecutor.post(URLConsts.PROVIDER_TOKEN_URL, obj.toJSONString());
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
URLConsts.PROVIDER_TOKEN_URL, obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
Token token = new Token(obj.getString("provider_access_token"));
|
||||
token.setExpiresIn(obj.getIntValue("expires_in"));
|
||||
token.setOriginalResult(response.getAsString());
|
||||
return token;
|
||||
return new Token(obj.getString("provider_access_token"),
|
||||
obj.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.type.TicketType;
|
||||
|
||||
/**
|
||||
@@ -23,20 +23,21 @@ public class WeixinTicketCreator extends TokenCreator {
|
||||
|
||||
private final String corpid;
|
||||
private final TicketType ticketType;
|
||||
private final TokenHolder weixinTokenHolder;
|
||||
private final TokenManager weixinTokenManager;
|
||||
|
||||
/**
|
||||
* @param corpid
|
||||
* 企业号ID
|
||||
* @param ticketType
|
||||
* 票据类型
|
||||
* @param weixinTokenHolder
|
||||
* <font color="red">企业号的的access_token</font>
|
||||
* @param weixinTokenManager
|
||||
* <font color="red">企业号的access_token</font>
|
||||
*/
|
||||
public WeixinTicketCreator(String corpid, TicketType ticketType, TokenHolder weixinTokenHolder) {
|
||||
public WeixinTicketCreator(String corpid, TicketType ticketType,
|
||||
TokenManager weixinTokenManager) {
|
||||
this.corpid = corpid;
|
||||
this.ticketType = ticketType;
|
||||
this.weixinTokenHolder = weixinTokenHolder;
|
||||
this.weixinTokenManager = weixinTokenManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,16 +49,16 @@ public class WeixinTicketCreator extends TokenCreator {
|
||||
public Token create() throws WeixinException {
|
||||
WeixinResponse response = null;
|
||||
if (ticketType == TicketType.jsapi) {
|
||||
response = weixinExecutor
|
||||
.get(String.format(URLConsts.JS_TICKET_URL, weixinTokenHolder.getToken().getAccessToken()));
|
||||
response = weixinExecutor.get(String.format(
|
||||
URLConsts.JS_TICKET_URL, weixinTokenManager.getCache()
|
||||
.getAccessToken()));
|
||||
} else {
|
||||
response = weixinExecutor.get(String.format(URLConsts.SUITE_TICKET_URL,
|
||||
weixinTokenHolder.getToken().getAccessToken(), ticketType.name()));
|
||||
response = weixinExecutor.get(String.format(
|
||||
URLConsts.SUITE_TICKET_URL, weixinTokenManager.getCache()
|
||||
.getAccessToken(), ticketType.name()));
|
||||
}
|
||||
JSONObject result = response.getAsJson();
|
||||
Token token = new Token(result.getString("ticket"));
|
||||
token.setExpiresIn(result.getIntValue("expires_in"));
|
||||
token.setOriginalResult(response.getAsString());
|
||||
return token;
|
||||
return new Token(result.getString("ticket"),
|
||||
result.getLong("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.foxinmy.weixin4j.qy.token;
|
||||
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
@@ -46,10 +46,8 @@ public class WeixinTokenCreator extends TokenCreator {
|
||||
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, corpid,
|
||||
corpsecret);
|
||||
WeixinResponse response = weixinExecutor.get(tokenUrl);
|
||||
Token token = response.getAsObject(new TypeReference<Token>() {
|
||||
});
|
||||
token.setCreateTime(System.currentTimeMillis());
|
||||
token.setOriginalResult(response.getAsString());
|
||||
return token;
|
||||
JSONObject result = response.getAsJson();
|
||||
return new Token(result.getString("access_token"),
|
||||
result.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class AgentTest extends TokenTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
this.agentApi = new AgentApi(tokenHolder);
|
||||
this.agentApi = new AgentApi(tokenManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,8 +27,8 @@ public class BatchTest extends TokenTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
this.batchApi = new BatchApi(tokenHolder);
|
||||
this.mediaApi = new MediaApi(tokenHolder);
|
||||
this.batchApi = new BatchApi(tokenManager);
|
||||
this.mediaApi = new MediaApi(tokenManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,7 +18,7 @@ public class ChatTest extends TokenTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
chatApi = new ChatApi(tokenHolder);
|
||||
chatApi = new ChatApi(tokenManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,7 +23,7 @@ public class HelperTest extends TokenTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
this.helperApi = new HelperApi(tokenHolder);
|
||||
this.helperApi = new HelperApi(tokenManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -29,7 +29,7 @@ public class MediaTest extends TokenTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
mediaApi = new MediaApi(tokenHolder);
|
||||
mediaApi = new MediaApi(tokenManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,7 +28,7 @@ public class MenuTest extends TokenTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
menuApi = new MenuApi(tokenHolder);
|
||||
menuApi = new MenuApi(tokenManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,7 +30,7 @@ public class NotifyTest extends TokenTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
notifyApi = new NotifyApi(tokenHolder);
|
||||
notifyApi = new NotifyApi(tokenManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,7 +25,7 @@ public class PartyTest extends TokenTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
this.partyApi = new PartyApi(tokenHolder);
|
||||
this.partyApi = new PartyApi(tokenManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TagTest extends TokenTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
this.tagApi = new TagApi(tokenHolder);
|
||||
this.tagApi = new TagApi(tokenManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.junit.Test;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.qy.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* token测试
|
||||
@@ -19,19 +19,19 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
*/
|
||||
public class TokenTest {
|
||||
|
||||
protected TokenHolder tokenHolder;
|
||||
protected TokenManager tokenManager;
|
||||
protected Weixin4jSettings settings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.settings = new Weixin4jSettings();
|
||||
tokenHolder = new TokenHolder(new WeixinTokenCreator(settings
|
||||
tokenManager = new TokenManager(new WeixinTokenCreator(settings
|
||||
.getAccount().getId(), settings.getAccount()
|
||||
.getSecret()), settings.getTokenStorager0());
|
||||
.getSecret()), settings.getCacheStorager0());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws WeixinException {
|
||||
Assert.assertNotNull(tokenHolder.getToken());
|
||||
Assert.assertNotNull(tokenManager.getCache());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ public class UserTest extends TokenTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
this.userApi = new UserApi(tokenHolder);
|
||||
this.mediaApi = new MediaApi(tokenHolder);
|
||||
this.userApi = new UserApi(tokenManager);
|
||||
this.mediaApi = new MediaApi(tokenManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user