Browse Source

修改WxCpMessage中agentId的数据类型, String-> Integer

master
cty 8 years ago
parent
commit
df47af287d
8 changed files with 294 additions and 298 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -1
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java
  3. +3
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
  4. +267
    -267
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpJedisConfigStorage.java
  5. +10
    -10
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java
  6. +4
    -4
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java
  7. +6
    -11
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java
  8. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java

+ 1
- 0
.gitignore View File

@@ -26,6 +26,7 @@ test-config.xml
/gradle/
*.bat
/gradlew
**/build/

# OSX
# Icon must end with two \r


+ 1
- 1
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java View File

@@ -45,7 +45,7 @@ public interface WxCpConfigStorage {

String getCorpSecret();

String getAgentId();
Integer getAgentId();

String getToken();



+ 3
- 3
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java View File

@@ -19,7 +19,7 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
protected volatile String token;
protected volatile String accessToken;
protected volatile String aesKey;
protected volatile String agentId;
protected volatile Integer agentId;
protected volatile long expiresTime;

protected volatile String oauth2redirectUri;
@@ -146,11 +146,11 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
}

@Override
public String getAgentId() {
public Integer getAgentId() {
return this.agentId;
}

public void setAgentId(String agentId) {
public void setAgentId(Integer agentId) {
this.agentId = agentId;
}



+ 267
- 267
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpJedisConfigStorage.java View File

@@ -1,267 +1,267 @@
package me.chanjar.weixin.cp.api;
import java.io.File;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
/**
* Jedis client implementor for wechat config storage
*
* @author gaigeshen
*/
public class WxCpJedisConfigStorage implements WxCpConfigStorage {
/* Redis keys here */
private static final String ACCESS_TOKEN_KEY = "WX_CP_ACCESS_TOKEN";
private static final String ACCESS_TOKEN_EXPIRES_TIME_KEY = "WX_CP_ACCESS_TOKEN_EXPIRES_TIME";
private static final String JS_API_TICKET_KEY = "WX_CP_JS_API_TICKET";
private static final String JS_API_TICKET_EXPIRES_TIME_KEY = "WX_CP_JS_API_TICKET_EXPIRES_TIME";
private volatile String corpId;
private volatile String corpSecret;
private volatile String token;
private volatile String aesKey;
private volatile String agentId;
private volatile String oauth2redirectUri;
private volatile String httpProxyHost;
private volatile int httpProxyPort;
private volatile String httpProxyUsername;
private volatile String httpProxyPassword;
private volatile File tmpDirFile;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
/* Redis clients pool */
private final JedisPool jedisPool;
public WxCpJedisConfigStorage(String host, int port) {
this.jedisPool = new JedisPool(host, port);
}
/**
*
* This method will be destroy jedis pool
*/
public void destroy() {
this.jedisPool.destroy();
}
@Override
public String getAccessToken() {
try (Jedis jedis = this.jedisPool.getResource()) {
return jedis.get(ACCESS_TOKEN_KEY);
}
}
@Override
public boolean isAccessTokenExpired() {
try (Jedis jedis = this.jedisPool.getResource()) {
String expiresTimeStr = jedis.get(ACCESS_TOKEN_EXPIRES_TIME_KEY);
if (expiresTimeStr != null) {
Long expiresTime = Long.parseLong(expiresTimeStr);
return System.currentTimeMillis() > expiresTime;
}
return true;
}
}
@Override
public void expireAccessToken() {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(ACCESS_TOKEN_EXPIRES_TIME_KEY, "0");
}
}
@Override
public synchronized void updateAccessToken(WxAccessToken accessToken) {
this.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
}
@Override
public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(ACCESS_TOKEN_KEY, accessToken);
jedis.set(ACCESS_TOKEN_EXPIRES_TIME_KEY,
(System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L) + "");
}
}
@Override
public String getJsapiTicket() {
try (Jedis jedis = this.jedisPool.getResource()) {
return jedis.get(JS_API_TICKET_KEY);
}
}
@Override
public boolean isJsapiTicketExpired() {
try (Jedis jedis = this.jedisPool.getResource()) {
String expiresTimeStr = jedis.get(JS_API_TICKET_EXPIRES_TIME_KEY);
if (expiresTimeStr != null) {
Long expiresTime = Long.parseLong(expiresTimeStr);
return System.currentTimeMillis() > expiresTime;
}
return true;
}
}
@Override
public void expireJsapiTicket() {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(JS_API_TICKET_EXPIRES_TIME_KEY, "0");
}
}
@Override
public synchronized void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(JS_API_TICKET_KEY, jsapiTicket);
jedis.set(JS_API_TICKET_EXPIRES_TIME_KEY,
(System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L + ""));
}
}
@Override
public String getCorpId() {
return this.corpId;
}
@Override
public String getCorpSecret() {
return this.corpSecret;
}
@Override
public String getAgentId() {
return this.agentId;
}
@Override
public String getToken() {
return this.token;
}
@Override
public String getAesKey() {
return this.aesKey;
}
@Override
public long getExpiresTime() {
try (Jedis jedis = this.jedisPool.getResource()) {
String expiresTimeStr = jedis.get(ACCESS_TOKEN_EXPIRES_TIME_KEY);
if (expiresTimeStr != null) {
Long expiresTime = Long.parseLong(expiresTimeStr);
return expiresTime;
}
return 0L;
}
}
@Override
public String getOauth2redirectUri() {
return this.oauth2redirectUri;
}
@Override
public String getHttpProxyHost() {
return this.httpProxyHost;
}
@Override
public int getHttpProxyPort() {
return this.httpProxyPort;
}
@Override
public String getHttpProxyUsername() {
return this.httpProxyUsername;
}
@Override
public String getHttpProxyPassword() {
return this.httpProxyPassword;
}
@Override
public File getTmpDirFile() {
return this.tmpDirFile;
}
@Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder;
}
public void setCorpId(String corpId) {
this.corpId = corpId;
}
public void setCorpSecret(String corpSecret) {
this.corpSecret = corpSecret;
}
public void setToken(String token) {
this.token = token;
}
public void setAesKey(String aesKey) {
this.aesKey = aesKey;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
// ============================ Setters below
public void setOauth2redirectUri(String oauth2redirectUri) {
this.oauth2redirectUri = oauth2redirectUri;
}
public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost;
}
public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort;
}
public void setHttpProxyUsername(String httpProxyUsername) {
this.httpProxyUsername = httpProxyUsername;
}
public void setHttpProxyPassword(String httpProxyPassword) {
this.httpProxyPassword = httpProxyPassword;
}
public void setTmpDirFile(File tmpDirFile) {
this.tmpDirFile = tmpDirFile;
}
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
}
package me.chanjar.weixin.cp.api;
import java.io.File;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
/**
* Jedis client implementor for wechat config storage
*
* @author gaigeshen
*/
public class WxCpJedisConfigStorage implements WxCpConfigStorage {
/* Redis keys here */
private static final String ACCESS_TOKEN_KEY = "WX_CP_ACCESS_TOKEN";
private static final String ACCESS_TOKEN_EXPIRES_TIME_KEY = "WX_CP_ACCESS_TOKEN_EXPIRES_TIME";
private static final String JS_API_TICKET_KEY = "WX_CP_JS_API_TICKET";
private static final String JS_API_TICKET_EXPIRES_TIME_KEY = "WX_CP_JS_API_TICKET_EXPIRES_TIME";
private volatile String corpId;
private volatile String corpSecret;
private volatile String token;
private volatile String aesKey;
private volatile Integer agentId;
private volatile String oauth2redirectUri;
private volatile String httpProxyHost;
private volatile int httpProxyPort;
private volatile String httpProxyUsername;
private volatile String httpProxyPassword;
private volatile File tmpDirFile;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
/* Redis clients pool */
private final JedisPool jedisPool;
public WxCpJedisConfigStorage(String host, int port) {
this.jedisPool = new JedisPool(host, port);
}
/**
*
* This method will be destroy jedis pool
*/
public void destroy() {
this.jedisPool.destroy();
}
@Override
public String getAccessToken() {
try (Jedis jedis = this.jedisPool.getResource()) {
return jedis.get(ACCESS_TOKEN_KEY);
}
}
@Override
public boolean isAccessTokenExpired() {
try (Jedis jedis = this.jedisPool.getResource()) {
String expiresTimeStr = jedis.get(ACCESS_TOKEN_EXPIRES_TIME_KEY);
if (expiresTimeStr != null) {
Long expiresTime = Long.parseLong(expiresTimeStr);
return System.currentTimeMillis() > expiresTime;
}
return true;
}
}
@Override
public void expireAccessToken() {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(ACCESS_TOKEN_EXPIRES_TIME_KEY, "0");
}
}
@Override
public synchronized void updateAccessToken(WxAccessToken accessToken) {
this.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
}
@Override
public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(ACCESS_TOKEN_KEY, accessToken);
jedis.set(ACCESS_TOKEN_EXPIRES_TIME_KEY,
(System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L) + "");
}
}
@Override
public String getJsapiTicket() {
try (Jedis jedis = this.jedisPool.getResource()) {
return jedis.get(JS_API_TICKET_KEY);
}
}
@Override
public boolean isJsapiTicketExpired() {
try (Jedis jedis = this.jedisPool.getResource()) {
String expiresTimeStr = jedis.get(JS_API_TICKET_EXPIRES_TIME_KEY);
if (expiresTimeStr != null) {
Long expiresTime = Long.parseLong(expiresTimeStr);
return System.currentTimeMillis() > expiresTime;
}
return true;
}
}
@Override
public void expireJsapiTicket() {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(JS_API_TICKET_EXPIRES_TIME_KEY, "0");
}
}
@Override
public synchronized void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(JS_API_TICKET_KEY, jsapiTicket);
jedis.set(JS_API_TICKET_EXPIRES_TIME_KEY,
(System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L + ""));
}
}
@Override
public String getCorpId() {
return this.corpId;
}
@Override
public String getCorpSecret() {
return this.corpSecret;
}
@Override
public Integer getAgentId() {
return this.agentId;
}
@Override
public String getToken() {
return this.token;
}
@Override
public String getAesKey() {
return this.aesKey;
}
@Override
public long getExpiresTime() {
try (Jedis jedis = this.jedisPool.getResource()) {
String expiresTimeStr = jedis.get(ACCESS_TOKEN_EXPIRES_TIME_KEY);
if (expiresTimeStr != null) {
Long expiresTime = Long.parseLong(expiresTimeStr);
return expiresTime;
}
return 0L;
}
}
@Override
public String getOauth2redirectUri() {
return this.oauth2redirectUri;
}
@Override
public String getHttpProxyHost() {
return this.httpProxyHost;
}
@Override
public int getHttpProxyPort() {
return this.httpProxyPort;
}
@Override
public String getHttpProxyUsername() {
return this.httpProxyUsername;
}
@Override
public String getHttpProxyPassword() {
return this.httpProxyPassword;
}
@Override
public File getTmpDirFile() {
return this.tmpDirFile;
}
@Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder;
}
public void setCorpId(String corpId) {
this.corpId = corpId;
}
public void setCorpSecret(String corpSecret) {
this.corpSecret = corpSecret;
}
public void setToken(String token) {
this.token = token;
}
public void setAesKey(String aesKey) {
this.aesKey = aesKey;
}
public void setAgentId(Integer agentId) {
this.agentId = agentId;
}
// ============================ Setters below
public void setOauth2redirectUri(String oauth2redirectUri) {
this.oauth2redirectUri = oauth2redirectUri;
}
public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost;
}
public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort;
}
public void setHttpProxyUsername(String httpProxyUsername) {
this.httpProxyUsername = httpProxyUsername;
}
public void setHttpProxyPassword(String httpProxyPassword) {
this.httpProxyPassword = httpProxyPassword;
}
public void setTmpDirFile(File tmpDirFile) {
this.tmpDirFile = tmpDirFile;
}
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
}

+ 10
- 10
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java View File

@@ -160,7 +160,7 @@ public interface WxCpService {
*
* @param menu
* @throws WxErrorException
* @see #menuCreate(String, me.chanjar.weixin.common.bean.menu.WxMenu)
* @see #menuCreate(Integer, WxMenu)
*/
void menuCreate(WxMenu menu) throws WxErrorException;

@@ -177,7 +177,7 @@ public interface WxCpService {
* @throws WxErrorException
* @see #menuCreate(me.chanjar.weixin.common.bean.menu.WxMenu)
*/
void menuCreate(String agentId, WxMenu menu) throws WxErrorException;
void menuCreate(Integer agentId, WxMenu menu) throws WxErrorException;

/**
* <pre>
@@ -188,7 +188,7 @@ public interface WxCpService {
* </pre>
*
* @throws WxErrorException
* @see #menuDelete(String)
* @see #menuDelete(Integer)
*/
void menuDelete() throws WxErrorException;

@@ -204,7 +204,7 @@ public interface WxCpService {
* @throws WxErrorException
* @see #menuDelete()
*/
void menuDelete(String agentId) throws WxErrorException;
void menuDelete(Integer agentId) throws WxErrorException;

/**
* <pre>
@@ -215,7 +215,7 @@ public interface WxCpService {
* </pre>
*
* @throws WxErrorException
* @see #menuGet(String)
* @see #menuGet(Integer)
*/
WxMenu menuGet() throws WxErrorException;

@@ -231,7 +231,7 @@ public interface WxCpService {
* @throws WxErrorException
* @see #menuGet()
*/
WxMenu menuGet(String agentId) throws WxErrorException;
WxMenu menuGet(Integer agentId) throws WxErrorException;

/**
* <pre>
@@ -396,12 +396,12 @@ public interface WxCpService {
* <pre>
* 构造oauth2授权的url连接
* </pre>
*
*
* @param state
* @return url
*/
String oauth2buildAuthorizationUrl(String state);
/**
* <pre>
* 构造oauth2授权的url连接
@@ -425,7 +425,7 @@ public interface WxCpService {
*
* @param code
* @return [userid, deviceid]
* @see #oauth2getUserInfo(String, String)
* @see #oauth2getUserInfo(Integer, String)
*/
String[] oauth2getUserInfo(String code) throws WxErrorException;

@@ -443,7 +443,7 @@ public interface WxCpService {
* @return [userid, deviceid]
* @see #oauth2getUserInfo(String)
*/
String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException;
String[] oauth2getUserInfo(Integer agentId, String code) throws WxErrorException;


/**


+ 4
- 4
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java View File

@@ -191,7 +191,7 @@ public class WxCpServiceImpl implements WxCpService {
}

@Override
public void menuCreate(String agentId, WxMenu menu) throws WxErrorException {
public void menuCreate(Integer agentId, WxMenu menu) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid="
+ this.configStorage.getAgentId();
post(url, menu.toJson());
@@ -203,7 +203,7 @@ public class WxCpServiceImpl implements WxCpService {
}

@Override
public void menuDelete(String agentId) throws WxErrorException {
public void menuDelete(Integer agentId) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete?agentid=" + agentId;
get(url, null);
}
@@ -214,7 +214,7 @@ public class WxCpServiceImpl implements WxCpService {
}

@Override
public WxMenu menuGet(String agentId) throws WxErrorException {
public WxMenu menuGet(Integer agentId) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=" + agentId;
try {
String resultContent = get(url, null);
@@ -487,7 +487,7 @@ this.configStorage.getOauth2redirectUri(),
}

@Override
public String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException {
public String[] oauth2getUserInfo(Integer agentId, String code) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?"
+ "code=" + code
+ "&agentid=" + agentId;


+ 6
- 11
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpMessage.java View File

@@ -1,17 +1,12 @@
package me.chanjar.weixin.cp.bean;

import me.chanjar.weixin.cp.bean.messagebuilder.*;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import me.chanjar.weixin.cp.bean.messagebuilder.FileBuilder;
import me.chanjar.weixin.cp.bean.messagebuilder.ImageBuilder;
import me.chanjar.weixin.cp.bean.messagebuilder.NewsBuilder;
import me.chanjar.weixin.cp.bean.messagebuilder.TextBuilder;
import me.chanjar.weixin.cp.bean.messagebuilder.VideoBuilder;
import me.chanjar.weixin.cp.bean.messagebuilder.VoiceBuilder;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

/**
* 消息
*
@@ -23,7 +18,7 @@ public class WxCpMessage implements Serializable {
private String toUser;
private String toParty;
private String toTag;
private String agentId;
private Integer agentId;
private String msgType;
private String content;
private String mediaId;
@@ -101,11 +96,11 @@ public class WxCpMessage implements Serializable {
this.toTag = toTag;
}

public String getAgentId() {
public Integer getAgentId() {
return this.agentId;
}

public void setAgentId(String agentId) {
public void setAgentId(Integer agentId) {
this.agentId = agentId;
}



+ 2
- 2
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/BaseBuilder.java View File

@@ -5,13 +5,13 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;

public class BaseBuilder<T> {
protected String msgType;
protected String agentId;
protected Integer agentId;
protected String toUser;
protected String toParty;
protected String toTag;
protected String safe;

public T agentId(String agentId) {
public T agentId(Integer agentId) {
this.agentId = agentId;
return (T) this;
}


Loading…
Cancel
Save