update something
This commit is contained in:
parent
e8422b1076
commit
dbdc5eee72
@ -56,6 +56,17 @@ public class WeixinSuiteProxy {
|
|||||||
this.suiteApi = new SuiteApi(suiteId, suiteSecret, tokenStorager);
|
this.suiteApi = new SuiteApi(suiteId, suiteSecret, tokenStorager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param suiteTicketHolder
|
||||||
|
* 套件ticket存取
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public WeixinSuiteProxy(SuiteTicketHolder suiteTicketHolder)
|
||||||
|
throws WeixinException {
|
||||||
|
this.suiteApi = new SuiteApi(suiteTicketHolder);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用套件token
|
* 应用套件token
|
||||||
*
|
*
|
||||||
@ -100,7 +111,7 @@ public class WeixinSuiteProxy {
|
|||||||
* @return 企业号token
|
* @return 企业号token
|
||||||
*/
|
*/
|
||||||
public TokenHolder crateTokenHolder(String authCorpid) {
|
public TokenHolder crateTokenHolder(String authCorpid) {
|
||||||
return suiteApi.crateTokenHolder(authCorpid);
|
return suiteApi.createTokenHolder(authCorpid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -47,10 +47,6 @@ public class SuiteApi extends QyApi {
|
|||||||
* 应用套件pre_code
|
* 应用套件pre_code
|
||||||
*/
|
*/
|
||||||
private final TokenHolder suitePreCodeHolder;
|
private final TokenHolder suitePreCodeHolder;
|
||||||
/**
|
|
||||||
* 应用套件ID
|
|
||||||
*/
|
|
||||||
private final String suiteId;
|
|
||||||
|
|
||||||
public SuiteApi() throws WeixinException {
|
public SuiteApi() throws WeixinException {
|
||||||
this(DEFAULT_WEIXIN_ACCOUNT.getSuiteId(), DEFAULT_WEIXIN_ACCOUNT
|
this(DEFAULT_WEIXIN_ACCOUNT.getSuiteId(), DEFAULT_WEIXIN_ACCOUNT
|
||||||
@ -67,22 +63,32 @@ public class SuiteApi extends QyApi {
|
|||||||
* 应用ID
|
* 应用ID
|
||||||
* @param suiteSecret
|
* @param suiteSecret
|
||||||
* 应用secret
|
* 应用secret
|
||||||
* @param ticketStorager
|
|
||||||
* 应用ticket存储器(用于读取)
|
|
||||||
* @param tokenStorager
|
* @param tokenStorager
|
||||||
* 应用token存储器
|
* 应用token存储器
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public SuiteApi(String suiteId, String suiteSecret,
|
public SuiteApi(String suiteId, String suiteSecret,
|
||||||
TokenStorager tokenStorager) throws WeixinException {
|
TokenStorager tokenStorager) throws WeixinException {
|
||||||
this.suiteTicketHolder = new SuiteTicketHolder(tokenStorager);
|
this(new SuiteTicketHolder(suiteId, suiteSecret, tokenStorager));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param suiteTicketHolder
|
||||||
|
* 套件ticket存取
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public SuiteApi(SuiteTicketHolder suiteTicketHolder) throws WeixinException {
|
||||||
|
this.suiteTicketHolder = suiteTicketHolder;
|
||||||
this.suiteTokenHolder = new TokenHolder(new WeixinSuiteTokenCreator(
|
this.suiteTokenHolder = new TokenHolder(new WeixinSuiteTokenCreator(
|
||||||
suiteId, suiteSecret, suiteTicketHolder), tokenStorager);
|
suiteTicketHolder), suiteTicketHolder.getTokenStorager());
|
||||||
this.suitePreCodeHolder = new TokenHolder(
|
this.suitePreCodeHolder = new TokenHolder(
|
||||||
new WeixinSuitePreCodeCreator(suiteTokenHolder, suiteId),
|
new WeixinSuitePreCodeCreator(suiteTokenHolder,
|
||||||
tokenStorager);
|
suiteTicketHolder.getSuiteId()),
|
||||||
this.suitePerCodeHolder = new SuitePerCodeHolder(tokenStorager);
|
suiteTicketHolder.getTokenStorager());
|
||||||
this.suiteId = suiteId;
|
this.suitePerCodeHolder = new SuitePerCodeHolder(
|
||||||
|
suiteTicketHolder.getSuiteId(),
|
||||||
|
suiteTicketHolder.getTokenStorager());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,8 +134,8 @@ public class SuiteApi extends QyApi {
|
|||||||
* 授权方corpid
|
* 授权方corpid
|
||||||
* @return 企业号token
|
* @return 企业号token
|
||||||
*/
|
*/
|
||||||
public TokenHolder crateTokenHolder(String authCorpid) {
|
public TokenHolder createTokenHolder(String authCorpid) {
|
||||||
return new TokenHolder(new WeixinTokenSuiteCreator(suiteId, authCorpid,
|
return new TokenHolder(new WeixinTokenSuiteCreator(authCorpid,
|
||||||
suitePerCodeHolder), suiteTicketHolder.getTokenStorager());
|
suitePerCodeHolder), suiteTicketHolder.getTokenStorager());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +153,7 @@ public class SuiteApi extends QyApi {
|
|||||||
public JsonResult setSuiteSession(int... appids) throws WeixinException {
|
public JsonResult setSuiteSession(int... appids) throws WeixinException {
|
||||||
String suite_set_session_uri = getRequestUri("suite_set_session_uri");
|
String suite_set_session_uri = getRequestUri("suite_set_session_uri");
|
||||||
JSONObject para = new JSONObject();
|
JSONObject para = new JSONObject();
|
||||||
para.put("pre_auth_code", suiteTicketHolder.getTicket(suiteId));
|
para.put("pre_auth_code", suiteTicketHolder.getTicket());
|
||||||
para.put("session_info", appids);
|
para.put("session_info", appids);
|
||||||
WeixinResponse response = weixinClient
|
WeixinResponse response = weixinClient
|
||||||
.post(String.format(suite_set_session_uri,
|
.post(String.format(suite_set_session_uri,
|
||||||
@ -171,7 +177,7 @@ public class SuiteApi extends QyApi {
|
|||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
String suite_get_permanent_uri = getRequestUri("suite_get_permanent_uri");
|
String suite_get_permanent_uri = getRequestUri("suite_get_permanent_uri");
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||||
obj.put("auth_code", authCode);
|
obj.put("auth_code", authCode);
|
||||||
WeixinResponse response = weixinClient.post(
|
WeixinResponse response = weixinClient.post(
|
||||||
String.format(suite_get_permanent_uri,
|
String.format(suite_get_permanent_uri,
|
||||||
@ -181,7 +187,7 @@ public class SuiteApi extends QyApi {
|
|||||||
obj.put("user_info", obj.remove("auth_user_info"));
|
obj.put("user_info", obj.remove("auth_user_info"));
|
||||||
OUserInfo oInfo = JSON.toJavaObject(obj, OUserInfo.class);
|
OUserInfo oInfo = JSON.toJavaObject(obj, OUserInfo.class);
|
||||||
// 缓存微信企业号access_token
|
// 缓存微信企业号access_token
|
||||||
TokenCreator tokenCreator = new WeixinTokenSuiteCreator(suiteId, null,
|
TokenCreator tokenCreator = new WeixinTokenSuiteCreator(null,
|
||||||
suitePerCodeHolder);
|
suitePerCodeHolder);
|
||||||
Token token = new Token(obj.getString("access_token"));
|
Token token = new Token(obj.getString("access_token"));
|
||||||
token.setExpiresIn(obj.getIntValue("expires_in"));
|
token.setExpiresIn(obj.getIntValue("expires_in"));
|
||||||
@ -189,8 +195,8 @@ public class SuiteApi extends QyApi {
|
|||||||
suiteTicketHolder.getTokenStorager().caching(
|
suiteTicketHolder.getTokenStorager().caching(
|
||||||
tokenCreator.getCacheKey(), token);
|
tokenCreator.getCacheKey(), token);
|
||||||
// 缓存微信企业号永久授权码
|
// 缓存微信企业号永久授权码
|
||||||
suitePerCodeHolder.cachingPermanentCode(suiteId,
|
suitePerCodeHolder
|
||||||
obj.getString("permanent_code"));
|
.cachingPermanentCode(obj.getString("permanent_code"));
|
||||||
return oInfo;
|
return oInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,9 +214,9 @@ public class SuiteApi extends QyApi {
|
|||||||
public OUserInfo getOAuthInfo(String authCorpid) throws WeixinException {
|
public OUserInfo getOAuthInfo(String authCorpid) throws WeixinException {
|
||||||
String suite_get_authinfo_uri = getRequestUri("suite_get_authinfo_uri");
|
String suite_get_authinfo_uri = getRequestUri("suite_get_authinfo_uri");
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||||
obj.put("auth_corpid", authCorpid);
|
obj.put("auth_corpid", authCorpid);
|
||||||
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode(suiteId));
|
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode());
|
||||||
WeixinResponse response = weixinClient.post(
|
WeixinResponse response = weixinClient.post(
|
||||||
String.format(suite_get_authinfo_uri,
|
String.format(suite_get_authinfo_uri,
|
||||||
suiteTokenHolder.getAccessToken()), obj.toJSONString());
|
suiteTokenHolder.getAccessToken()), obj.toJSONString());
|
||||||
@ -235,9 +241,9 @@ public class SuiteApi extends QyApi {
|
|||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
String suite_get_agent_uri = getRequestUri("suite_get_agent_uri");
|
String suite_get_agent_uri = getRequestUri("suite_get_agent_uri");
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||||
obj.put("auth_corpid", authCorpid);
|
obj.put("auth_corpid", authCorpid);
|
||||||
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode(suiteId));
|
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode());
|
||||||
obj.put("agentid", agentid);
|
obj.put("agentid", agentid);
|
||||||
WeixinResponse response = weixinClient.post(
|
WeixinResponse response = weixinClient.post(
|
||||||
String.format(suite_get_agent_uri,
|
String.format(suite_get_agent_uri,
|
||||||
@ -272,9 +278,9 @@ public class SuiteApi extends QyApi {
|
|||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
String suite_set_agent_uri = getRequestUri("suite_set_agent_uri");
|
String suite_set_agent_uri = getRequestUri("suite_set_agent_uri");
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", suiteTicketHolder.getSuiteId());
|
||||||
obj.put("auth_corpid", authCorpid);
|
obj.put("auth_corpid", authCorpid);
|
||||||
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode(suiteId));
|
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode());
|
||||||
obj.put("agent", agentSet);
|
obj.put("agent", agentSet);
|
||||||
WeixinResponse response = weixinClient.post(
|
WeixinResponse response = weixinClient.post(
|
||||||
String.format(suite_set_agent_uri,
|
String.format(suite_set_agent_uri,
|
||||||
|
|||||||
@ -36,8 +36,8 @@ public class Party implements Serializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Party(String name) {
|
public Party(int id, String name) {
|
||||||
this(0, name, 1, 1);
|
this(id, name, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Party(int id, String name, int parentid, int order) {
|
public Party(int id, String name, int parentid, int order) {
|
||||||
|
|||||||
@ -33,7 +33,8 @@ public class User implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 非必须 成员所属部门id列表。注意,每个部门的直属员工上限为1000个
|
* 非必须 成员所属部门id列表。注意,每个部门的直属员工上限为1000个
|
||||||
*/
|
*/
|
||||||
private List<Integer> department;
|
@JSONField(name = "department")
|
||||||
|
private List<Integer> partys;
|
||||||
/**
|
/**
|
||||||
* 非必须 职位信息。长度为0~64个字符
|
* 非必须 职位信息。长度为0~64个字符
|
||||||
*/
|
*/
|
||||||
@ -123,16 +124,16 @@ public class User implements Serializable {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getDepartment() {
|
public List<Integer> getPartys() {
|
||||||
return department;
|
return partys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDepartment(List<Integer> department) {
|
public void setPartys(List<Integer> partys) {
|
||||||
this.department = department;
|
this.partys = partys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDepartment(Integer... department) {
|
public void setPartys(Integer... partys) {
|
||||||
this.department = Arrays.asList(department);
|
this.partys = Arrays.asList(partys);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPosition() {
|
public String getPosition() {
|
||||||
@ -252,8 +253,8 @@ public class User implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "User [userid=" + userid + ", name=" + name + ", department="
|
return "User [userid=" + userid + ", name=" + name + ", partys="
|
||||||
+ department + ", position=" + position + ", mobile=" + mobile
|
+ partys + ", position=" + position + ", mobile=" + mobile
|
||||||
+ ", gender=" + getFormatGender() + ", tel=" + tel + ", email="
|
+ ", gender=" + getFormatGender() + ", tel=" + tel + ", email="
|
||||||
+ email + ", weixinid=" + weixinid + ", avatar=" + avatar
|
+ email + ", weixinid=" + weixinid + ", avatar=" + avatar
|
||||||
+ ", status=" + getFormatStatus() + ", enable="
|
+ ", status=" + getFormatStatus() + ", enable="
|
||||||
|
|||||||
@ -15,44 +15,47 @@ import com.foxinmy.weixin4j.token.TokenStorager;
|
|||||||
*/
|
*/
|
||||||
public class SuitePerCodeHolder {
|
public class SuitePerCodeHolder {
|
||||||
|
|
||||||
public final TokenStorager tokenStorager;
|
private final String suiteId;
|
||||||
|
private final TokenStorager tokenStorager;
|
||||||
|
|
||||||
public SuitePerCodeHolder(TokenStorager tokenStorager) {
|
public SuitePerCodeHolder(String suiteId, TokenStorager tokenStorager) {
|
||||||
|
this.suiteId = suiteId;
|
||||||
this.tokenStorager = tokenStorager;
|
this.tokenStorager = tokenStorager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存永久授权码
|
* 缓存永久授权码
|
||||||
*
|
*
|
||||||
* @param suiteId
|
|
||||||
* @param permanentCode
|
* @param permanentCode
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public void cachingPermanentCode(String suiteId, String permanentCode)
|
public void cachingPermanentCode(String permanentCode)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
Token token = new Token(permanentCode);
|
Token token = new Token(permanentCode);
|
||||||
token.setExpiresIn(-1);
|
token.setExpiresIn(-1);
|
||||||
tokenStorager.caching(getCacheKey(suiteId), token);
|
tokenStorager.caching(getCacheKey(), token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取永久授权码的key
|
* 获取永久授权码的key
|
||||||
*
|
*
|
||||||
* @param suiteId
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String getCacheKey(String suiteId) {
|
private String getCacheKey() {
|
||||||
return String.format("qy_suite_percode_%s", suiteId);
|
return String.format("qy_suite_percode_%s", suiteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找永久二维码
|
* 查找永久二维码
|
||||||
*
|
*
|
||||||
* @param suiteId
|
|
||||||
* @return
|
* @return
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public String getPermanentCode(String suiteId) throws WeixinException {
|
public String getPermanentCode() throws WeixinException {
|
||||||
return tokenStorager.lookup(getCacheKey(suiteId)).getAccessToken();
|
return tokenStorager.lookup(getCacheKey()).getAccessToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSuiteId() {
|
||||||
|
return this.suiteId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,9 +15,14 @@ import com.foxinmy.weixin4j.token.TokenStorager;
|
|||||||
*/
|
*/
|
||||||
public class SuiteTicketHolder {
|
public class SuiteTicketHolder {
|
||||||
|
|
||||||
|
private final String suiteId;
|
||||||
|
private final String suiteSecret;
|
||||||
private final TokenStorager tokenStorager;
|
private final TokenStorager tokenStorager;
|
||||||
|
|
||||||
public SuiteTicketHolder(TokenStorager tokenStorager) {
|
public SuiteTicketHolder(String suiteId, String suiteSecret,
|
||||||
|
TokenStorager tokenStorager) {
|
||||||
|
this.suiteId = suiteId;
|
||||||
|
this.suiteSecret = suiteSecret;
|
||||||
this.tokenStorager = tokenStorager;
|
this.tokenStorager = tokenStorager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,8 +33,8 @@ public class SuiteTicketHolder {
|
|||||||
* @return
|
* @return
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public String getTicket(String suiteId) throws WeixinException {
|
public String getTicket() throws WeixinException {
|
||||||
return tokenStorager.lookup(getCacheKey(suiteId)).getAccessToken();
|
return tokenStorager.lookup(getCacheKey()).getAccessToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +43,7 @@ public class SuiteTicketHolder {
|
|||||||
* @param suiteId
|
* @param suiteId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String getCacheKey(String suiteId) {
|
private String getCacheKey() {
|
||||||
return String.format("qy_suite_ticket_%s", suiteId);
|
return String.format("qy_suite_ticket_%s", suiteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +57,15 @@ public class SuiteTicketHolder {
|
|||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
Token token = new Token(suiteTicket.getSuiteTicket());
|
Token token = new Token(suiteTicket.getSuiteTicket());
|
||||||
token.setExpiresIn(-1);
|
token.setExpiresIn(-1);
|
||||||
tokenStorager.caching(getCacheKey(suiteTicket.getSuiteId()), token);
|
tokenStorager.caching(getCacheKey(), token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSuiteId() {
|
||||||
|
return this.suiteId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSuiteSecret() {
|
||||||
|
return this.suiteSecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TokenStorager getTokenStorager() {
|
public TokenStorager getTokenStorager() {
|
||||||
|
|||||||
@ -22,38 +22,29 @@ import com.foxinmy.weixin4j.token.TokenCreator;
|
|||||||
public class WeixinSuiteTokenCreator implements TokenCreator {
|
public class WeixinSuiteTokenCreator implements TokenCreator {
|
||||||
|
|
||||||
private final WeixinHttpClient httpClient;
|
private final WeixinHttpClient httpClient;
|
||||||
private final String suiteId;
|
|
||||||
private final String suiteSecret;
|
|
||||||
private final SuiteTicketHolder ticketHolder;
|
private final SuiteTicketHolder ticketHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param suiteId
|
|
||||||
* 套件ID
|
|
||||||
* @param suiteSecret
|
|
||||||
* 套件secret
|
|
||||||
* @param stringStorager
|
* @param stringStorager
|
||||||
* 套件ticket存取器
|
* 套件ticket存取器
|
||||||
*/
|
*/
|
||||||
public WeixinSuiteTokenCreator(String suiteId, String suiteSecret,
|
public WeixinSuiteTokenCreator(SuiteTicketHolder ticketHolder) {
|
||||||
SuiteTicketHolder ticketHolder) {
|
|
||||||
this.suiteId = suiteId;
|
|
||||||
this.suiteSecret = suiteSecret;
|
|
||||||
this.ticketHolder = ticketHolder;
|
this.ticketHolder = ticketHolder;
|
||||||
this.httpClient = new WeixinHttpClient();
|
this.httpClient = new WeixinHttpClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCacheKey() {
|
public String getCacheKey() {
|
||||||
return String.format("qy_suite_token_%s", suiteId);
|
return String.format("qy_suite_token_%s", ticketHolder.getSuiteId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token createToken() throws WeixinException {
|
public Token createToken() throws WeixinException {
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", ticketHolder.getSuiteId());
|
||||||
obj.put("suite_secret", suiteSecret);
|
obj.put("suite_secret", ticketHolder.getSuiteSecret());
|
||||||
obj.put("suite_ticket", ticketHolder.getTicket(suiteId));
|
obj.put("suite_ticket", ticketHolder.getTicket());
|
||||||
WeixinResponse response = httpClient.post(URLConsts.SUITE_TOKEN_URL,
|
WeixinResponse response = httpClient.post(URLConsts.SUITE_TOKEN_URL,
|
||||||
obj.toJSONString());
|
obj.toJSONString());
|
||||||
obj = response.getAsJson();
|
obj = response.getAsJson();
|
||||||
|
|||||||
@ -22,22 +22,18 @@ import com.foxinmy.weixin4j.token.TokenCreator;
|
|||||||
public class WeixinTokenSuiteCreator implements TokenCreator {
|
public class WeixinTokenSuiteCreator implements TokenCreator {
|
||||||
|
|
||||||
private final WeixinHttpClient httpClient;
|
private final WeixinHttpClient httpClient;
|
||||||
private final String suiteId;
|
|
||||||
private final String authCorpid;
|
private final String authCorpid;
|
||||||
private final SuitePerCodeHolder perCodeHolder;
|
private final SuitePerCodeHolder perCodeHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param suiteId
|
|
||||||
* 应用套件ID
|
|
||||||
* @param suiteSecret
|
* @param suiteSecret
|
||||||
* 授权方corpid
|
* 授权方corpid
|
||||||
* @param perCodeHolder
|
* @param perCodeHolder
|
||||||
* 永久授权码
|
* 永久授权码
|
||||||
*/
|
*/
|
||||||
public WeixinTokenSuiteCreator(String suiteId, String authCorpid,
|
public WeixinTokenSuiteCreator(String authCorpid,
|
||||||
SuitePerCodeHolder perCodeHolder) {
|
SuitePerCodeHolder perCodeHolder) {
|
||||||
this.suiteId = suiteId;
|
|
||||||
this.authCorpid = authCorpid;
|
this.authCorpid = authCorpid;
|
||||||
this.perCodeHolder = perCodeHolder;
|
this.perCodeHolder = perCodeHolder;
|
||||||
this.httpClient = new WeixinHttpClient();
|
this.httpClient = new WeixinHttpClient();
|
||||||
@ -45,15 +41,15 @@ public class WeixinTokenSuiteCreator implements TokenCreator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCacheKey() {
|
public String getCacheKey() {
|
||||||
return String.format("qy_token_suite_%s", suiteId);
|
return String.format("qy_token_suite_%s", perCodeHolder.getSuiteId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Token createToken() throws WeixinException {
|
public Token createToken() throws WeixinException {
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", perCodeHolder.getSuiteId());
|
||||||
obj.put("auth_corpid", authCorpid);
|
obj.put("auth_corpid", authCorpid);
|
||||||
obj.put("permanent_code", perCodeHolder.getPermanentCode(suiteId));
|
obj.put("permanent_code", perCodeHolder.getPermanentCode());
|
||||||
WeixinResponse response = httpClient.post(URLConsts.TOKEN_SUITE_URL,
|
WeixinResponse response = httpClient.post(URLConsts.TOKEN_SUITE_URL,
|
||||||
obj.toJSONString());
|
obj.toJSONString());
|
||||||
obj = response.getAsJson();
|
obj = response.getAsJson();
|
||||||
|
|||||||
@ -30,15 +30,14 @@ public class PartyTest extends TokenTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void create() throws WeixinException {
|
public void create() throws WeixinException {
|
||||||
Party Party = new Party("苦逼组");
|
Party Party = new Party(1, "苦逼组");
|
||||||
int id = partyApi.createParty(Party);
|
int id = partyApi.createParty(Party);
|
||||||
Assert.assertTrue(id > 0);
|
Assert.assertTrue(id > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void update() throws WeixinException {
|
public void update() throws WeixinException {
|
||||||
Party Party = new Party("苦逼组111");
|
Party Party = new Party(2, "苦逼组111");
|
||||||
Party.setId(2);
|
|
||||||
JsonResult result = partyApi.updateParty(Party);
|
JsonResult result = partyApi.updateParty(Party);
|
||||||
Assert.assertEquals("updated", result.getDesc());
|
Assert.assertEquals("updated", result.getDesc());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ public class UserTest extends TokenTest {
|
|||||||
public void create() throws WeixinException {
|
public void create() throws WeixinException {
|
||||||
User user = new User("u001", "jack");
|
User user = new User("u001", "jack");
|
||||||
user.setMobile("13500000000");
|
user.setMobile("13500000000");
|
||||||
user.setDepartment(1);
|
user.setPartys(1);
|
||||||
user.pushExattr("爱好", "code");
|
user.pushExattr("爱好", "code");
|
||||||
JsonResult result = userApi.createUser(user);
|
JsonResult result = userApi.createUser(user);
|
||||||
Assert.assertEquals("created", result.getDesc());
|
Assert.assertEquals("created", result.getDesc());
|
||||||
@ -47,7 +47,7 @@ public class UserTest extends TokenTest {
|
|||||||
public void batchUpload() throws WeixinException {
|
public void batchUpload() throws WeixinException {
|
||||||
User user = new User("u001", "jack");
|
User user = new User("u001", "jack");
|
||||||
user.setMobile("13500000000");
|
user.setMobile("13500000000");
|
||||||
user.setDepartment(1);
|
user.setPartys(1);
|
||||||
String mediaId = mediaApi.batchUploadUsers(Arrays.asList(user));
|
String mediaId = mediaApi.batchUploadUsers(Arrays.asList(user));
|
||||||
System.err.println(mediaId);
|
System.err.println(mediaId);
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ public class UserTest extends TokenTest {
|
|||||||
public void update() throws WeixinException {
|
public void update() throws WeixinException {
|
||||||
User user = new User("u001", "ted");
|
User user = new User("u001", "ted");
|
||||||
user.setMobile("13500000000");
|
user.setMobile("13500000000");
|
||||||
user.setDepartment(1);
|
user.setPartys(1);
|
||||||
user.pushExattr("爱好", "code");
|
user.pushExattr("爱好", "code");
|
||||||
JsonResult result = userApi.updateUser(user);
|
JsonResult result = userApi.updateUser(user);
|
||||||
Assert.assertEquals("updated", result.getDesc());
|
Assert.assertEquals("updated", result.getDesc());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user