TokenCreator新增uniqueid方法
This commit is contained in:
parent
4ccc11d8cf
commit
c8726ddc3f
@ -19,8 +19,7 @@ public class CacheManager<T extends Cacheable> {
|
||||
protected final CacheStorager<T> cacheStorager;
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public CacheManager(CacheCreator<T> cacheCreator,
|
||||
CacheStorager<T> cacheStorager) {
|
||||
public CacheManager(CacheCreator<T> cacheCreator, CacheStorager<T> cacheStorager) {
|
||||
this.cacheCreator = cacheCreator;
|
||||
this.cacheStorager = cacheStorager;
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.MapUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
/**
|
||||
* JSSDK配置类
|
||||
@ -51,17 +50,6 @@ public class JSSDKConfigurator {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 公众号的唯一标识 不填则获取weixin4j.properties#account中的id
|
||||
*
|
||||
* @param appId
|
||||
* @return
|
||||
*/
|
||||
public JSSDKConfigurator appId(String appId) {
|
||||
config.put("appId", appId);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要使用的JS接口列表
|
||||
*
|
||||
@ -96,10 +84,10 @@ public class JSSDKConfigurator {
|
||||
* @param url
|
||||
* 当前网页的URL,不包含#及其后面部分
|
||||
* @return jssdk配置JSON字符串
|
||||
* @see <a
|
||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN">公众号JSSDK</a>
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BE%AE%E4%BF%A1JS-SDK%E6%8E%A5%E5%8F%A3">企业号JSSDK</a>
|
||||
* @see <a href=
|
||||
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN">公众号JSSDK</a>
|
||||
* @see <a href=
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BE%AE%E4%BF%A1JS-SDK%E6%8E%A5%E5%8F%A3">企业号JSSDK</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String toJSONConfig(String url) throws WeixinException {
|
||||
@ -113,11 +101,8 @@ public class JSSDKConfigurator {
|
||||
signMap.put("noncestr", noncestr);
|
||||
signMap.put("jsapi_ticket", this.ticketTokenManager.getAccessToken());
|
||||
signMap.put("url", url);
|
||||
String sign = DigestUtil.SHA1(MapUtil.toJoinString(signMap, false,
|
||||
false));
|
||||
if (StringUtil.isBlank(config.getString("appId"))) {
|
||||
config.put("appId", Weixin4jConfigUtil.getWeixinAccount().getId());
|
||||
}
|
||||
String sign = DigestUtil.SHA1(MapUtil.toJoinString(signMap, false, false));
|
||||
config.put("appId", ticketTokenManager.getWeixinId());
|
||||
if (StringUtil.isBlank(config.getString("debug"))) {
|
||||
config.put("debug", false);
|
||||
}
|
||||
|
||||
@ -33,13 +33,20 @@ public abstract class TokenCreator implements CacheCreator<Token> {
|
||||
*/
|
||||
@Override
|
||||
public String key() {
|
||||
return String.format("%s%s", CACHEKEY_PREFIX, key0());
|
||||
return String.format("%s%s_%s", CACHEKEY_PREFIX, name(), uniqueid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回缓存KEY的名称:建议接口类型命名 如 mp_token_{appid}
|
||||
* 返回缓存类型命名,如mp_token
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String key0();
|
||||
public abstract String name();
|
||||
|
||||
/**
|
||||
* 返回缓存唯一标识,如appid
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String uniqueid();
|
||||
}
|
||||
|
||||
@ -23,8 +23,7 @@ public class TokenManager extends CacheManager<Token> {
|
||||
* @param cacheStorager
|
||||
* 负责token的存储
|
||||
*/
|
||||
public TokenManager(TokenCreator tokenCreator,
|
||||
CacheStorager<Token> cacheStorager) {
|
||||
public TokenManager(TokenCreator tokenCreator, CacheStorager<Token> cacheStorager) {
|
||||
super(tokenCreator, cacheStorager);
|
||||
}
|
||||
|
||||
@ -37,4 +36,13 @@ public class TokenManager extends CacheManager<Token> {
|
||||
public String getAccessToken() throws WeixinException {
|
||||
return super.getCache().getAccessToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回唯一标识ID
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getWeixinId() {
|
||||
return ((TokenCreator) cacheCreator).uniqueid();
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ public class WeixinProxy {
|
||||
* @return
|
||||
*/
|
||||
public TokenManager getTicketManager(TicketType ticketType) {
|
||||
return new TokenManager(new WeixinTicketCreator(weixinAccount.getId(), ticketType, this.tokenManager),
|
||||
return new TokenManager(new WeixinTicketCreator(ticketType, this.tokenManager),
|
||||
this.cacheStorager);
|
||||
}
|
||||
|
||||
|
||||
@ -34,8 +34,13 @@ public class WeixinComponentPreCodeCreator extends TokenCreator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("mp_component_precode_%s", componentId);
|
||||
public String name() {
|
||||
return "mp_component_precode";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
return componentId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,4 +51,5 @@ public class WeixinComponentPreCodeCreator extends TokenCreator {
|
||||
JSONObject result = response.getAsJson();
|
||||
return new Token(result.getString("pre_auth_code"), result.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -29,8 +29,13 @@ public class WeixinComponentTokenCreator extends TokenCreator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("mp_component_token_%s", ticketManager.getThirdId());
|
||||
public String name() {
|
||||
return "mp_component_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
return ticketManager.getThirdId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,10 +44,8 @@ public class WeixinComponentTokenCreator extends TokenCreator {
|
||||
obj.put("component_appid", ticketManager.getThirdId());
|
||||
obj.put("component_appsecret", ticketManager.getThirdSecret());
|
||||
obj.put("component_verify_ticket", ticketManager.getAccessTicket());
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
URLConsts.COMPONENT_TOKEN_URL, obj.toJSONString());
|
||||
WeixinResponse response = weixinExecutor.post(URLConsts.COMPONENT_TOKEN_URL, obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
return new Token(obj.getString("component_access_token"),
|
||||
obj.getLongValue("expires_in") * 1000l);
|
||||
return new Token(obj.getString("component_access_token"), obj.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,16 +29,20 @@ public class WeixinTokenComponentCreator extends TokenCreator {
|
||||
* @param componentTokenManager
|
||||
* 第三方套件凭证token
|
||||
*/
|
||||
public WeixinTokenComponentCreator(PerTicketManager perTicketManager,
|
||||
TokenManager componentTokenManager) {
|
||||
public WeixinTokenComponentCreator(PerTicketManager perTicketManager, TokenManager componentTokenManager) {
|
||||
this.perTicketManager = perTicketManager;
|
||||
this.componentTokenManager = componentTokenManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("mp_token_component_%s_%s",
|
||||
perTicketManager.getThirdId(), perTicketManager.getAuthAppId());
|
||||
public String name() {
|
||||
return String.format("mp_token_component_%s_%s", perTicketManager.getThirdId(),
|
||||
perTicketManager.getAuthAppId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,10 +52,10 @@ public class WeixinTokenComponentCreator extends TokenCreator {
|
||||
obj.put("authorizer_appid", perTicketManager.getAuthAppId());
|
||||
obj.put("authorizer_refresh_token", perTicketManager.getAccessTicket());
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(URLConsts.TOKEN_COMPONENT_URL,
|
||||
componentTokenManager.getAccessToken()), obj.toJSONString());
|
||||
String.format(URLConsts.TOKEN_COMPONENT_URL, componentTokenManager.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
return new Token(obj.getString("access_token"),
|
||||
obj.getLongValue("expires_in") * 1000l);
|
||||
return new Token(obj.getString("access_token"), obj.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -15,8 +15,8 @@ import com.foxinmy.weixin4j.util.NameValue;
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2014年9月29日
|
||||
* @since JDK 1.6
|
||||
* @see <a
|
||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN">模板消息</a>
|
||||
* @see <a href=
|
||||
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN">模板消息</a>
|
||||
*/
|
||||
public class TemplateMessage implements Serializable {
|
||||
|
||||
@ -46,6 +46,20 @@ public class TemplateMessage implements Serializable {
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
private NameValue tail;
|
||||
|
||||
/**
|
||||
* 跳小程序所需数据,不需跳小程序可不用传该数据
|
||||
*/
|
||||
private String miniprogram;
|
||||
/**
|
||||
* 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系)
|
||||
*/
|
||||
private String appid;
|
||||
/**
|
||||
* 所需跳转到小程序的具体页面路径,支持带参数,(示例index?foo=bar)
|
||||
*/
|
||||
private String pagepath;
|
||||
|
||||
/**
|
||||
* 数据项
|
||||
*/
|
||||
@ -57,8 +71,7 @@ public class TemplateMessage implements Serializable {
|
||||
private final static String DEFAULT_COLOR = "#173177";
|
||||
|
||||
@JSONCreator
|
||||
public TemplateMessage(@JSONField(name = "toUser") String toUser,
|
||||
@JSONField(name = "templateId") String templateId,
|
||||
public TemplateMessage(@JSONField(name = "toUser") String toUser, @JSONField(name = "templateId") String templateId,
|
||||
@JSONField(name = "url") String url) {
|
||||
this.toUser = toUser;
|
||||
this.templateId = templateId;
|
||||
@ -180,10 +193,33 @@ public class TemplateMessage implements Serializable {
|
||||
this.content = items;
|
||||
}
|
||||
|
||||
public String getMiniprogram() {
|
||||
return miniprogram;
|
||||
}
|
||||
|
||||
public void setMiniprogram(String miniprogram) {
|
||||
this.miniprogram = miniprogram;
|
||||
}
|
||||
|
||||
public String getAppid() {
|
||||
return appid;
|
||||
}
|
||||
|
||||
public void setAppid(String appid) {
|
||||
this.appid = appid;
|
||||
}
|
||||
|
||||
public String getPagepath() {
|
||||
return pagepath;
|
||||
}
|
||||
|
||||
public void setPagepath(String pagepath) {
|
||||
this.pagepath = pagepath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TemplateMessage [toUser=" + toUser + ", templateId="
|
||||
+ templateId + ", url=" + url + ", head=" + getHead()
|
||||
+ ", tail=" + getTail() + ", content=" + content + "]";
|
||||
return "TemplateMessage [toUser=" + toUser + ", templateId=" + templateId + ", url=" + url + ", head="
|
||||
+ getHead() + ", tail=" + getTail() + ", content=" + content + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,39 +22,37 @@ import com.foxinmy.weixin4j.type.TicketType;
|
||||
*/
|
||||
public class WeixinTicketCreator extends TokenCreator {
|
||||
|
||||
private final String appid;
|
||||
private final TicketType ticketType;
|
||||
private final TokenManager weixinTokenManager;
|
||||
|
||||
/**
|
||||
* jssdk
|
||||
*
|
||||
* @param appid
|
||||
* 公众号的appid
|
||||
* @param ticketType
|
||||
* 票据类型
|
||||
* @param weixinTokenManager
|
||||
* <font color="red">公众平台的access_token</font>
|
||||
*/
|
||||
public WeixinTicketCreator(String appid, TicketType ticketType,
|
||||
TokenManager weixinTokenManager) {
|
||||
this.appid = appid;
|
||||
public WeixinTicketCreator(TicketType ticketType, TokenManager weixinTokenManager) {
|
||||
this.ticketType = ticketType;
|
||||
this.weixinTokenManager = weixinTokenManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("mp_ticket_%s_%s", ticketType.name(), appid);
|
||||
public String name() {
|
||||
return String.format("mp_ticket_%s", ticketType.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
return weixinTokenManager.getWeixinId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token create() throws WeixinException {
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
URLConsts.JS_TICKET_URL, weixinTokenManager.getAccessToken(),
|
||||
ticketType.name()));
|
||||
WeixinResponse response = weixinExecutor
|
||||
.get(String.format(URLConsts.JS_TICKET_URL, weixinTokenManager.getAccessToken(), ticketType.name()));
|
||||
JSONObject result = response.getAsJson();
|
||||
return new Token(result.getString("ticket"),
|
||||
result.getLongValue("expires_in") * 1000l);
|
||||
return new Token(result.getString("ticket"), result.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,8 +14,8 @@ import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年1月10日
|
||||
* @since JDK 1.6
|
||||
* @see <a
|
||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183&token=&lang=zh_CN">微信公众平台获取token说明</a>
|
||||
* @see <a href=
|
||||
* "https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183&token=&lang=zh_CN">微信公众平台获取token说明</a>
|
||||
* @see com.foxinmy.weixin4j.model.Token
|
||||
*/
|
||||
public class WeixinTokenCreator extends TokenCreator {
|
||||
@ -36,17 +36,20 @@ public class WeixinTokenCreator extends TokenCreator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("mp_token_%s", appid);
|
||||
public String name() {
|
||||
return "mp_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
return appid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token create() throws WeixinException {
|
||||
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, appid,
|
||||
secret);
|
||||
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, appid, secret);
|
||||
WeixinResponse response = weixinExecutor.get(tokenUrl);
|
||||
JSONObject result = response.getAsJson();
|
||||
return new Token(result.getString("access_token"),
|
||||
result.getLongValue("expires_in") * 1000l);
|
||||
return new Token(result.getString("access_token"), result.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,10 +151,8 @@ public class WeixinProxy {
|
||||
* @param cacheStorager
|
||||
* token管理
|
||||
*/
|
||||
public WeixinProxy(WeixinAccount weixinAccount,
|
||||
CacheStorager<Token> cacheStorager) {
|
||||
this(weixinAccount, new WeixinTokenCreator(weixinAccount.getId(),
|
||||
weixinAccount.getSecret()), cacheStorager);
|
||||
public WeixinProxy(WeixinAccount weixinAccount, CacheStorager<Token> cacheStorager) {
|
||||
this(weixinAccount, new WeixinTokenCreator(weixinAccount.getId(), weixinAccount.getSecret()), cacheStorager);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,13 +167,9 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||
* @see WeixinSuiteProxy#getWeixinProxy(String, String)
|
||||
*/
|
||||
public WeixinProxy(PerTicketManager perTicketManager,
|
||||
TokenManager suiteTokenManager) {
|
||||
this(
|
||||
new WeixinAccount(perTicketManager.getThirdId(),
|
||||
perTicketManager.getThirdSecret()),
|
||||
new WeixinTokenSuiteCreator(perTicketManager, suiteTokenManager),
|
||||
perTicketManager.getCacheStorager());
|
||||
public WeixinProxy(PerTicketManager perTicketManager, TokenManager suiteTokenManager) {
|
||||
this(new WeixinAccount(perTicketManager.getThirdId(), perTicketManager.getThirdSecret()),
|
||||
new WeixinTokenSuiteCreator(perTicketManager, suiteTokenManager), perTicketManager.getCacheStorager());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,18 +180,15 @@ public class WeixinProxy {
|
||||
* @param tokenManager
|
||||
* token管理
|
||||
*/
|
||||
private WeixinProxy(WeixinAccount weixinAccount, TokenCreator tokenCreator,
|
||||
CacheStorager<Token> cacheStorager) {
|
||||
private WeixinProxy(WeixinAccount weixinAccount, TokenCreator tokenCreator, CacheStorager<Token> cacheStorager) {
|
||||
if (weixinAccount == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"weixinAccount must not be empty");
|
||||
throw new IllegalArgumentException("weixinAccount must not be empty");
|
||||
}
|
||||
if (tokenCreator == null) {
|
||||
throw new IllegalArgumentException("tokenCreator must not be empty");
|
||||
}
|
||||
if (cacheStorager == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"cacheStorager must not be empty");
|
||||
throw new IllegalArgumentException("cacheStorager must not be empty");
|
||||
}
|
||||
this.tokenManager = new TokenManager(tokenCreator, cacheStorager);
|
||||
this.weixinAccount = weixinAccount;
|
||||
@ -251,8 +242,7 @@ public class WeixinProxy {
|
||||
* @return
|
||||
*/
|
||||
public TokenManager getTicketManager(TicketType ticketType) {
|
||||
return new TokenManager(new WeixinTicketCreator(weixinAccount.getId(),
|
||||
ticketType, this.tokenManager), cacheStorager);
|
||||
return new TokenManager(new WeixinTicketCreator(ticketType, this.tokenManager), cacheStorager);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -266,7 +256,8 @@ public class WeixinProxy {
|
||||
* @param message
|
||||
* 消息对象
|
||||
* @return 如果对应用或收件人、部门、标签任何一个无权限,则本次发送失败;如果收件人、部门或标签不存在,发送仍然执行,但返回无效的部分
|
||||
* </br> { "errcode": 0, "errmsg": "ok", "invaliduser": "UserID1",
|
||||
* </br>
|
||||
* { "errcode": 0, "errmsg": "ok", "invaliduser": "UserID1",
|
||||
* "invalidparty":"PartyID1", "invalidtag":"TagID1" }
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.qy.api.NotifyApi
|
||||
@ -285,8 +276,7 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.tuple.MpNews
|
||||
* @see com.foxinmy.weixin4j.qy.model.IdParameter
|
||||
*/
|
||||
public IdParameter sendNotifyMessage(NotifyMessage message)
|
||||
throws WeixinException {
|
||||
public IdParameter sendNotifyMessage(NotifyMessage message) throws WeixinException {
|
||||
return notifyApi.sendNotifyMessage(message);
|
||||
}
|
||||
|
||||
@ -308,8 +298,7 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.qy.message.CustomeMessage
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult sendCustomeMessage(CustomeMessage message)
|
||||
throws WeixinException {
|
||||
public ApiResult sendCustomeMessage(CustomeMessage message) throws WeixinException {
|
||||
return notifyApi.sendCustomeMessage(message);
|
||||
}
|
||||
|
||||
@ -345,8 +334,7 @@ public class WeixinProxy {
|
||||
* 创建自定义菜单</a>
|
||||
* @see com.foxinmy.weixin4j.model.Button
|
||||
*/
|
||||
public ApiResult createMenu(int agentid, List<Button> buttons)
|
||||
throws WeixinException {
|
||||
public ApiResult createMenu(int agentid, List<Button> buttons) throws WeixinException {
|
||||
return menuApi.createMenu(agentid, buttons);
|
||||
}
|
||||
|
||||
@ -398,8 +386,7 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.qy.api.MediaApi
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String uploadImage(InputStream is, String fileName)
|
||||
throws WeixinException {
|
||||
public String uploadImage(InputStream is, String fileName) throws WeixinException {
|
||||
return mediaApi.uploadImage(is, fileName);
|
||||
}
|
||||
|
||||
@ -427,8 +414,7 @@ public class WeixinProxy {
|
||||
* 上传永久素材文件说明</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public MediaUploadResult uploadMedia(int agentid, InputStream is,
|
||||
String fileName) throws WeixinException {
|
||||
public MediaUploadResult uploadMedia(int agentid, InputStream is, String fileName) throws WeixinException {
|
||||
return mediaApi.uploadMedia(agentid, is, fileName);
|
||||
}
|
||||
|
||||
@ -450,8 +436,7 @@ public class WeixinProxy {
|
||||
* 获取永久媒体说明</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public MediaDownloadResult downloadMedia(int agentid, String mediaId)
|
||||
throws WeixinException {
|
||||
public MediaDownloadResult downloadMedia(int agentid, String mediaId) throws WeixinException {
|
||||
return mediaApi.downloadMedia(agentid, mediaId);
|
||||
}
|
||||
|
||||
@ -474,8 +459,7 @@ public class WeixinProxy {
|
||||
* 上传永久媒体素材</a>
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
*/
|
||||
public String uploadMaterialArticle(int agentid, List<MpArticle> articles)
|
||||
throws WeixinException {
|
||||
public String uploadMaterialArticle(int agentid, List<MpArticle> articles) throws WeixinException {
|
||||
return mediaApi.uploadMaterialArticle(agentid, articles);
|
||||
}
|
||||
|
||||
@ -493,8 +477,7 @@ public class WeixinProxy {
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%88%A0%E9%99%A4%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">
|
||||
* 删除永久媒体素材</a>
|
||||
*/
|
||||
public ApiResult deleteMaterialMedia(int agentid, String mediaId)
|
||||
throws WeixinException {
|
||||
public ApiResult deleteMaterialMedia(int agentid, String mediaId) throws WeixinException {
|
||||
return mediaApi.deleteMaterialMedia(agentid, mediaId);
|
||||
}
|
||||
|
||||
@ -511,8 +494,7 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.qy.api.MediaApi
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
*/
|
||||
public List<MpArticle> downloadArticle(int agentid, String mediaId)
|
||||
throws WeixinException {
|
||||
public List<MpArticle> downloadArticle(int agentid, String mediaId) throws WeixinException {
|
||||
return mediaApi.downloadArticle(agentid, mediaId);
|
||||
}
|
||||
|
||||
@ -533,8 +515,7 @@ public class WeixinProxy {
|
||||
* 修改永久媒体素材</a>
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
*/
|
||||
public String updateMaterialArticle(int agentid, String mediaId,
|
||||
List<MpArticle> articles) throws WeixinException {
|
||||
public String updateMaterialArticle(int agentid, String mediaId, List<MpArticle> articles) throws WeixinException {
|
||||
return mediaApi.updateMaterialArticle(agentid, mediaId, articles);
|
||||
}
|
||||
|
||||
@ -576,8 +557,7 @@ public class WeixinProxy {
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E5%88%97%E8%A1%A8">
|
||||
* 获取素材列表</a>
|
||||
*/
|
||||
public MediaRecord listMaterialMedia(int agentid, MediaType mediaType,
|
||||
Pageable pageable) throws WeixinException {
|
||||
public MediaRecord listMaterialMedia(int agentid, MediaType mediaType, Pageable pageable) throws WeixinException {
|
||||
return mediaApi.listMaterialMedia(agentid, mediaType, pageable);
|
||||
}
|
||||
|
||||
@ -593,8 +573,7 @@ public class WeixinProxy {
|
||||
* @see {@link #listMaterialMedia(int,MediaType, Pageable)}
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public List<MediaItem> listAllMaterialMedia(int agentid, MediaType mediaType)
|
||||
throws WeixinException {
|
||||
public List<MediaItem> listAllMaterialMedia(int agentid, MediaType mediaType) throws WeixinException {
|
||||
return mediaApi.listAllMaterialMedia(agentid, mediaType);
|
||||
}
|
||||
|
||||
@ -679,8 +658,7 @@ public class WeixinProxy {
|
||||
* @return 上传后的mediaId
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String batchUploadParties(List<Party> parties)
|
||||
throws WeixinException {
|
||||
public String batchUploadParties(List<Party> parties) throws WeixinException {
|
||||
return mediaApi.batchUploadParties(parties);
|
||||
}
|
||||
|
||||
@ -716,8 +694,7 @@ public class WeixinProxy {
|
||||
* @return 处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult createUser(User user, InputStream avatar)
|
||||
throws WeixinException {
|
||||
public ApiResult createUser(User user, InputStream avatar) throws WeixinException {
|
||||
return userApi.createUser(user, avatar);
|
||||
}
|
||||
|
||||
@ -753,8 +730,7 @@ public class WeixinProxy {
|
||||
* @return 处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult updateUser(User user, InputStream avatar)
|
||||
throws WeixinException {
|
||||
public ApiResult updateUser(User user, InputStream avatar) throws WeixinException {
|
||||
return userApi.updateUser(user, avatar);
|
||||
}
|
||||
|
||||
@ -849,8 +825,8 @@ public class WeixinProxy {
|
||||
* @return 成员列表
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public List<User> listUser(int partyId, boolean fetchChild,
|
||||
UserStatus userStatus, boolean findDetail) throws WeixinException {
|
||||
public List<User> listUser(int partyId, boolean fetchChild, UserStatus userStatus, boolean findDetail)
|
||||
throws WeixinException {
|
||||
return userApi.listUser(partyId, fetchChild, userStatus, findDetail);
|
||||
}
|
||||
|
||||
@ -911,8 +887,7 @@ public class WeixinProxy {
|
||||
* @return 处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult batchDeleteUser(List<String> userIds)
|
||||
throws WeixinException {
|
||||
public ApiResult batchDeleteUser(List<String> userIds) throws WeixinException {
|
||||
return userApi.batchDeleteUser(userIds);
|
||||
}
|
||||
|
||||
@ -930,8 +905,7 @@ public class WeixinProxy {
|
||||
* 邀请成员关注说明</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public InviteType inviteUser(String userId, String tips)
|
||||
throws WeixinException {
|
||||
public InviteType inviteUser(String userId, String tips) throws WeixinException {
|
||||
return userApi.inviteUser(userId, tips);
|
||||
}
|
||||
|
||||
@ -955,8 +929,9 @@ public class WeixinProxy {
|
||||
* 创建标签(创建的标签属于管理组;默认为未加锁状态)
|
||||
*
|
||||
* @param tag
|
||||
* 标签对象;</br> 标签名称,长度为1~64个字节,标签名不可与其他标签重名;</br> 标签id,整型,
|
||||
* 指定此参数时新增的标签会生成对应的标签id,不指定时则以目前最大的id自增。
|
||||
* 标签对象;</br>
|
||||
* 标签名称,长度为1~64个字节,标签名不可与其他标签重名;</br>
|
||||
* 标签id,整型, 指定此参数时新增的标签会生成对应的标签id,不指定时则以目前最大的id自增。
|
||||
* @see <a href=
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E5.88.9B.E5.BB.BA.E6.A0.87.E7.AD.BE">
|
||||
* 创建标签说明</a>
|
||||
@ -1026,8 +1001,8 @@ public class WeixinProxy {
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E8.8E.B7.E5.8F.96.E6.A0.87.E7.AD.BE.E6.88.90.E5.91.98">
|
||||
* 获取标签成员说明</a>
|
||||
* @see com.foxinmy.weixin4j.qy.api.TagApi
|
||||
* @return 成员列表<font color="red">Contacts#getUsers</font>和部门列表 <font
|
||||
* color="red">Contacts#getPartyIds</font>
|
||||
* @return 成员列表<font color="red">Contacts#getUsers</font>和部门列表
|
||||
* <font color="red">Contacts#getPartyIds</font>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public Contacts getTagUsers(int tagId) throws WeixinException {
|
||||
@ -1051,8 +1026,7 @@ public class WeixinProxy {
|
||||
* @return 非法的userIds和partyIds
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public IdParameter addTagUsers(int tagId, List<String> userIds,
|
||||
List<Integer> partyIds) throws WeixinException {
|
||||
public IdParameter addTagUsers(int tagId, List<String> userIds, List<Integer> partyIds) throws WeixinException {
|
||||
return tagApi.addTagUsers(tagId, userIds, partyIds);
|
||||
}
|
||||
|
||||
@ -1073,8 +1047,7 @@ public class WeixinProxy {
|
||||
* @return 非法的userIds和partyIds
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public IdParameter deleteTagUsers(int tagId, List<String> userIds,
|
||||
List<Integer> partyIds) throws WeixinException {
|
||||
public IdParameter deleteTagUsers(int tagId, List<String> userIds, List<Integer> partyIds) throws WeixinException {
|
||||
return tagApi.deleteTagUsers(tagId, userIds, partyIds);
|
||||
}
|
||||
|
||||
@ -1159,8 +1132,7 @@ public class WeixinProxy {
|
||||
* 邀请成员关注</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String batchInviteUser(IdParameter parameter, Callback callback,
|
||||
String tips) throws WeixinException {
|
||||
public String batchInviteUser(IdParameter parameter, Callback callback, String tips) throws WeixinException {
|
||||
return batchApi.inviteUser(parameter, callback, tips);
|
||||
}
|
||||
|
||||
@ -1168,7 +1140,8 @@ public class WeixinProxy {
|
||||
* 批量更新成员,本接口以userid为主键,增量更新企业号通讯录成员。
|
||||
* <p>
|
||||
* 1.模板中的部门需填写部门ID,多个部门用分号分隔,部门ID必须为数字</br>
|
||||
* 2.文件中存在、通讯录中也存在的成员,更新成员在文件中指定的字段值 </br> 3.文件中存在、通讯录中不存在的成员,执行添加操作</br>
|
||||
* 2.文件中存在、通讯录中也存在的成员,更新成员在文件中指定的字段值 </br>
|
||||
* 3.文件中存在、通讯录中不存在的成员,执行添加操作</br>
|
||||
* 4.通讯录中存在、文件中不存在的成员,保持不变</br>
|
||||
* </p>
|
||||
*
|
||||
@ -1184,15 +1157,15 @@ public class WeixinProxy {
|
||||
* 批量更新成员</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String batchSyncUser(String mediaId, Callback callback)
|
||||
throws WeixinException {
|
||||
public String batchSyncUser(String mediaId, Callback callback) throws WeixinException {
|
||||
return batchApi.syncUser(mediaId, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量覆盖成员,本接口以userid为主键,全量覆盖企业号通讯录成员,任务完成后企业号通讯录成员与提交的文件完全保持一致。
|
||||
* <p>
|
||||
* 1.模板中的部门需填写部门ID,多个部门用分号分隔,部门ID必须为数字</br> 2.文件中存在、通讯录中也存在的成员,完全以文件为准</br>
|
||||
* 1.模板中的部门需填写部门ID,多个部门用分号分隔,部门ID必须为数字</br>
|
||||
* 2.文件中存在、通讯录中也存在的成员,完全以文件为准</br>
|
||||
* 3.文件中存在、通讯录中不存在的成员,执行添加操作</br>
|
||||
* 4.通讯录中存在、文件中不存在的成员,执行删除操作。出于安全考虑,如果需要删除的成员多于50人,
|
||||
* 且多于现有人数的20%以上,系统将中止导入并返回相应的错误码
|
||||
@ -1210,8 +1183,7 @@ public class WeixinProxy {
|
||||
* 批量覆盖成员</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String batchReplaceUser(String mediaId, Callback callback)
|
||||
throws WeixinException {
|
||||
public String batchReplaceUser(String mediaId, Callback callback) throws WeixinException {
|
||||
return batchApi.replaceUser(mediaId, callback);
|
||||
}
|
||||
|
||||
@ -1237,7 +1209,8 @@ public class WeixinProxy {
|
||||
/**
|
||||
* 批量覆盖部门,本接口以partyid为键,全量覆盖企业号通讯录组织架构,任务完成后企业号通讯录组织架构与提交的文件完全保持一致。
|
||||
* <p>
|
||||
* 1.文件中存在、通讯录中也存在的部门,执行修改操作</br> 2.文件中存在、通讯录中不存在的部门,执行添加操作</br>
|
||||
* 1.文件中存在、通讯录中也存在的部门,执行修改操作</br>
|
||||
* 2.文件中存在、通讯录中不存在的部门,执行添加操作</br>
|
||||
* 3.文件中不存在、通讯录中存在的部门,当部门为空时,执行删除操作</br>
|
||||
* 4.CSV文件中,部门名称、部门ID、父部门ID为必填字段,部门ID必须为数字;排序为可选字段,置空或填0不修改排序
|
||||
* </p>
|
||||
@ -1254,8 +1227,7 @@ public class WeixinProxy {
|
||||
* 批量覆盖部门</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String batchReplaceParty(String mediaId, Callback callback)
|
||||
throws WeixinException {
|
||||
public String batchReplaceParty(String mediaId, Callback callback) throws WeixinException {
|
||||
return batchApi.replaceParty(mediaId, callback);
|
||||
}
|
||||
|
||||
@ -1291,8 +1263,7 @@ public class WeixinProxy {
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=Userid%E4%B8%8Eopenid%E4%BA%92%E6%8D%A2%E6%8E%A5%E5%8F%A3">
|
||||
* userid转换成openid</a>
|
||||
*/
|
||||
public String[] userid2openid(String userid, int agentid)
|
||||
throws WeixinException {
|
||||
public String[] userid2openid(String userid, int agentid) throws WeixinException {
|
||||
return userApi.userid2openid(userid, agentid);
|
||||
}
|
||||
|
||||
@ -1366,8 +1337,7 @@ public class WeixinProxy {
|
||||
* 修改会话信息</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult updateChat(ChatInfo chatInfo, String operator,
|
||||
List<String> addUsers, List<String> deleteUsers)
|
||||
public ApiResult updateChat(ChatInfo chatInfo, String operator, List<String> addUsers, List<String> deleteUsers)
|
||||
throws WeixinException {
|
||||
return chatApi.updateChat(chatInfo, operator, addUsers, deleteUsers);
|
||||
}
|
||||
@ -1386,8 +1356,7 @@ public class WeixinProxy {
|
||||
* 退出会话</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult quitChat(String chatId, String operator)
|
||||
throws WeixinException {
|
||||
public ApiResult quitChat(String chatId, String operator) throws WeixinException {
|
||||
return chatApi.quitChat(chatId, operator);
|
||||
}
|
||||
|
||||
@ -1407,8 +1376,7 @@ public class WeixinProxy {
|
||||
* 清除会话未读状态</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult clearChatNotify(String targetId, String owner,
|
||||
ChatType chatType) throws WeixinException {
|
||||
public ApiResult clearChatNotify(String targetId, String owner, ChatType chatType) throws WeixinException {
|
||||
return chatApi.clearChatNotify(targetId, owner, chatType);
|
||||
}
|
||||
|
||||
@ -1426,8 +1394,7 @@ public class WeixinProxy {
|
||||
* @return 列表中不存在的成员,剩余合法成员会继续执行。
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public List<String> setChatMute(List<ChatMute> chatMutes)
|
||||
throws WeixinException {
|
||||
public List<String> setChatMute(List<ChatMute> chatMutes) throws WeixinException {
|
||||
return chatApi.setChatMute(chatMutes);
|
||||
}
|
||||
|
||||
@ -1444,8 +1411,7 @@ public class WeixinProxy {
|
||||
* 发送消息</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public ApiResult sendChatMessage(ChatMessage message)
|
||||
throws WeixinException {
|
||||
public ApiResult sendChatMessage(ChatMessage message) throws WeixinException {
|
||||
return chatApi.sendChatMessage(message);
|
||||
}
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ public class NotifyApi extends QyApi {
|
||||
String.format(message_send_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
IdParameter idParameter = new IdParameter();
|
||||
IdParameter idParameter = IdParameter.get();
|
||||
if (obj.containsKey("invaliduser")) {
|
||||
idParameter.setUserIds(Arrays.asList(obj.getString("invaliduser")
|
||||
.split(IdParameter.SEPARATORS)));
|
||||
|
||||
@ -200,7 +200,7 @@ public class TagApi extends QyApi {
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(uri, token.getAccessToken()), obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
IdParameter idParameter = new IdParameter();
|
||||
IdParameter idParameter = IdParameter.get();
|
||||
if (obj.containsKey("invalidlist")) {
|
||||
idParameter.setUserIds(Arrays.asList(obj.getString("invalidlist")
|
||||
.split(IdParameter.SEPARATORS)));
|
||||
|
||||
@ -48,7 +48,7 @@ public class NotifyMessage implements Serializable {
|
||||
private IdParameter target;
|
||||
|
||||
public NotifyMessage(int agentid, NotifyTuple tuple) {
|
||||
this(agentid, tuple, new IdParameter(), false);
|
||||
this(agentid, tuple, IdParameter.get(), false);
|
||||
}
|
||||
|
||||
public NotifyMessage(int agentId, NotifyTuple tuple, IdParameter target, boolean isSafe) {
|
||||
|
||||
@ -35,12 +35,16 @@ public class IdParameter implements Serializable {
|
||||
@JSONField(name = "tag")
|
||||
private List<Integer> tagIds;
|
||||
|
||||
public IdParameter() {
|
||||
protected IdParameter() {
|
||||
this.userIds = new ArrayList<String>();
|
||||
this.partyIds = new ArrayList<Integer>();
|
||||
this.tagIds = new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
public static IdParameter get(){
|
||||
return new IdParameter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加成员ID列表,最多支持1000个
|
||||
*
|
||||
|
||||
@ -32,25 +32,27 @@ public class WeixinSuitePreCodeCreator extends TokenCreator {
|
||||
* @param suiteId
|
||||
* 应用套件ID
|
||||
*/
|
||||
public WeixinSuitePreCodeCreator(TokenManager suiteTokenManager,
|
||||
String suiteId) {
|
||||
public WeixinSuitePreCodeCreator(TokenManager suiteTokenManager, String suiteId) {
|
||||
this.suiteTokenManager = suiteTokenManager;
|
||||
this.suiteId = suiteId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("qy_suite_precode_%s", suiteId);
|
||||
public String name() {
|
||||
return "qy_suite_precode";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
return suiteId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token create() throws WeixinException {
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(URLConsts.SUITE_PRE_CODE_URL,
|
||||
suiteTokenManager.getAccessToken()),
|
||||
String.format(URLConsts.SUITE_PRE_CODE_URL, suiteTokenManager.getAccessToken()),
|
||||
String.format("{\"suite_id\":\"%s\"}", suiteId));
|
||||
JSONObject result = response.getAsJson();
|
||||
return new Token(result.getString("pre_auth_code"),
|
||||
result.getLongValue("expires_in") * 1000l);
|
||||
return new Token(result.getString("pre_auth_code"), result.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,8 +15,8 @@ import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年6月17日
|
||||
* @since JDK 1.6
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E5.BA.94.E7.94.A8.E5.A5.97.E4.BB.B6.E4.BB.A4.E7.89.8C">获取应用套件凭证</a>
|
||||
* @see <a href=
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E5.BA.94.E7.94.A8.E5.A5.97.E4.BB.B6.E4.BB.A4.E7.89.8C">获取应用套件凭证</a>
|
||||
* @see com.foxinmy.weixin4j.model.Token
|
||||
*/
|
||||
public class WeixinSuiteTokenCreator extends TokenCreator {
|
||||
@ -33,8 +33,13 @@ public class WeixinSuiteTokenCreator extends TokenCreator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("qy_suite_token_%s", ticketManager.getThirdId());
|
||||
public String name() {
|
||||
return "qy_suite_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
return ticketManager.getThirdId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,10 +48,8 @@ public class WeixinSuiteTokenCreator extends TokenCreator {
|
||||
obj.put("suite_id", ticketManager.getThirdId());
|
||||
obj.put("suite_secret", ticketManager.getThirdSecret());
|
||||
obj.put("suite_ticket", ticketManager.getAccessTicket());
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
URLConsts.SUITE_TOKEN_URL, obj.toJSONString());
|
||||
WeixinResponse response = weixinExecutor.post(URLConsts.SUITE_TOKEN_URL, obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
return new Token(obj.getString("suite_access_token"),
|
||||
obj.getLongValue("expires_in") * 1000l);
|
||||
return new Token(obj.getString("suite_access_token"), obj.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,16 +33,19 @@ public class WeixinTokenSuiteCreator extends TokenCreator {
|
||||
* @param suiteTokenManager
|
||||
* 第三方套件凭证token
|
||||
*/
|
||||
public WeixinTokenSuiteCreator(PerTicketManager perTicketManager,
|
||||
TokenManager suiteTokenManager) {
|
||||
public WeixinTokenSuiteCreator(PerTicketManager perTicketManager, TokenManager suiteTokenManager) {
|
||||
this.perTicketManager = perTicketManager;
|
||||
this.suiteTokenManager = suiteTokenManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("qy_token_suite_%s_%s",
|
||||
perTicketManager.getThirdId(), perTicketManager.getAuthAppId());
|
||||
public String name() {
|
||||
return String.format("qy_token_suite_%s_%s", perTicketManager.getThirdId(), perTicketManager.getAuthAppId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,11 +54,9 @@ public class WeixinTokenSuiteCreator extends TokenCreator {
|
||||
obj.put("suite_id", perTicketManager.getThirdId());
|
||||
obj.put("auth_corpid", perTicketManager.getAuthAppId());
|
||||
obj.put("permanent_code", perTicketManager.getAccessTicket());
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(URLConsts.TOKEN_SUITE_URL,
|
||||
suiteTokenManager.getAccessToken()), obj.toJSONString());
|
||||
WeixinResponse response = weixinExecutor
|
||||
.post(String.format(URLConsts.TOKEN_SUITE_URL, suiteTokenManager.getAccessToken()), obj.toJSONString());
|
||||
obj = response.getAsJson();
|
||||
return new Token(obj.getString("access_token"),
|
||||
obj.getLongValue("expires_in") * 1000l);
|
||||
return new Token(obj.getString("access_token"), obj.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,8 +37,13 @@ public class WeixinProviderTokenCreator extends TokenCreator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("qy_provider_token_%s", corpid);
|
||||
public String name() {
|
||||
return "qy_provider_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
return corpid;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,10 +51,8 @@ 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();
|
||||
return new Token(obj.getString("provider_access_token"),
|
||||
obj.getLongValue("expires_in") * 1000l);
|
||||
return new Token(obj.getString("provider_access_token"), obj.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,45 +22,42 @@ import com.foxinmy.weixin4j.type.TicketType;
|
||||
*/
|
||||
public class WeixinTicketCreator extends TokenCreator {
|
||||
|
||||
private final String corpid;
|
||||
private final TicketType ticketType;
|
||||
private final TokenManager weixinTokenManager;
|
||||
|
||||
/**
|
||||
* @param corpid
|
||||
* 企业号ID
|
||||
* @param ticketType
|
||||
* 票据类型
|
||||
* @param weixinTokenManager
|
||||
* <font color="red">企业号的access_token</font>
|
||||
*/
|
||||
public WeixinTicketCreator(String corpid, TicketType ticketType,
|
||||
TokenManager weixinTokenManager) {
|
||||
this.corpid = corpid;
|
||||
public WeixinTicketCreator(TicketType ticketType, TokenManager weixinTokenManager) {
|
||||
this.ticketType = ticketType;
|
||||
this.weixinTokenManager = weixinTokenManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("qy_ticket_%s_%s", ticketType.name(), corpid);
|
||||
public String name() {
|
||||
return String.format("qy_ticket_%s", ticketType.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
return weixinTokenManager.getWeixinId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token create() throws WeixinException {
|
||||
WeixinResponse response = null;
|
||||
if (ticketType == TicketType.jsapi) {
|
||||
response = weixinExecutor.get(String.format(
|
||||
URLConsts.JS_TICKET_URL, weixinTokenManager.getCache()
|
||||
.getAccessToken()));
|
||||
response = weixinExecutor
|
||||
.get(String.format(URLConsts.JS_TICKET_URL, weixinTokenManager.getCache().getAccessToken()));
|
||||
} else {
|
||||
response = weixinExecutor.get(String.format(
|
||||
URLConsts.SUITE_TICKET_URL, weixinTokenManager.getCache()
|
||||
.getAccessToken(), ticketType.name()));
|
||||
response = weixinExecutor.get(String.format(URLConsts.SUITE_TICKET_URL,
|
||||
weixinTokenManager.getCache().getAccessToken(), ticketType.name()));
|
||||
}
|
||||
JSONObject result = response.getAsJson();
|
||||
return new Token(result.getString("ticket"),
|
||||
result.getLong("expires_in") * 1000l).pushExtra("group_id",
|
||||
return new Token(result.getString("ticket"), result.getLong("expires_in") * 1000l).pushExtra("group_id",
|
||||
result.getString("group_id"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,17 +37,20 @@ public class WeixinTokenCreator extends TokenCreator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key0() {
|
||||
return String.format("qy_token_%s", corpid);
|
||||
public String name() {
|
||||
return "qy_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uniqueid() {
|
||||
return corpid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token create() throws WeixinException {
|
||||
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, corpid,
|
||||
corpsecret);
|
||||
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, corpid, corpsecret);
|
||||
WeixinResponse response = weixinExecutor.get(tokenUrl);
|
||||
JSONObject result = response.getAsJson();
|
||||
return new Token(result.getString("access_token"),
|
||||
result.getLongValue("expires_in") * 1000l);
|
||||
return new Token(result.getString("access_token"), result.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user