+ *
* @param messageId messageId需要根据上面讲的方式构造
* @return 如果是重复消息,返回true,否则返回false
*/
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java
index 5b0f4e4e3f..e0d4d08cc4 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxMessageInMemoryDuplicateChecker.java
@@ -46,7 +46,8 @@ public WxMessageInMemoryDuplicateChecker() {
/**
* WxMsgIdInMemoryDuplicateChecker构造函数
- * @param timeToLive 一个消息ID在内存的过期时间:毫秒
+ *
+ * @param timeToLive 一个消息ID在内存的过期时间:毫秒
* @param clearPeriod 每隔多少周期检查消息ID是否过期:毫秒
*/
public WxMessageInMemoryDuplicateChecker(Long timeToLive, Long clearPeriod) {
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java
index ce69a10462..eedecb8423 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxAccessToken.java
@@ -8,9 +8,13 @@ public class WxAccessToken implements Serializable {
private static final long serialVersionUID = 8709719312922168909L;
private String accessToken;
-
+
private int expiresIn = -1;
+ public static WxAccessToken fromJson(String json) {
+ return WxGsonBuilder.create().fromJson(json, WxAccessToken.class);
+ }
+
public String getAccessToken() {
return accessToken;
}
@@ -27,8 +31,4 @@ public void setExpiresIn(int expiresIn) {
this.expiresIn = expiresIn;
}
- public static WxAccessToken fromJson(String json) {
- return WxGsonBuilder.create().fromJson(json, WxAccessToken.class);
- }
-
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java
index 74f0b1b1ab..312860dfe3 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxJsapiSignature.java
@@ -9,7 +9,7 @@ public class WxJsapiSignature implements Serializable {
private static final long serialVersionUID = -1116808193154384804L;
private String appid;
-
+
private String noncestr;
private long timestamp;
@@ -51,11 +51,11 @@ public void setUrl(String url) {
}
public String getAppid() {
- return appid;
+ return appid;
}
public void setAppid(String appid) {
- this.appid = appid;
+ this.appid = appid;
}
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxMenu.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxMenu.java
deleted file mode 100644
index d236f62b3f..0000000000
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxMenu.java
+++ /dev/null
@@ -1,208 +0,0 @@
-package me.chanjar.weixin.common.bean;
-
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Serializable;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.List;
-
-import me.chanjar.weixin.common.util.json.WxGsonBuilder;
-
-/**
- * 企业号菜单
- * @author Daniel Qian
- *
- */
-public class WxMenu implements Serializable {
-
- private static final long serialVersionUID = -7083914585539687746L;
-
- private List buttons = new ArrayList();
-
- private WxMenuRule matchRule;
-
- public List getButtons() {
- return buttons;
- }
-
- public void setButtons(List buttons) {
- this.buttons = buttons;
- }
-
- public WxMenuRule getMatchRule() {
- return matchRule;
- }
-
- public void setMatchRule(WxMenuRule matchRule) {
- this.matchRule = matchRule;
- }
-
- public String toJson() {
- return WxGsonBuilder.create().toJson(this);
- }
-
- /**
- * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
- * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
- */
- public static WxMenu fromJson(String json) {
- return WxGsonBuilder.create().fromJson(json, WxMenu.class);
- }
-
- /**
- * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
- * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
- */
- public static WxMenu fromJson(InputStream is) {
- return WxGsonBuilder.create().fromJson(new InputStreamReader(is, StandardCharsets.UTF_8), WxMenu.class);
- }
-
- @Override
- public String toString() {
- return "WxMenu{" +
- "buttons=" + buttons +
- '}';
- }
-
- public static class WxMenuButton {
-
- private String type;
- private String name;
- private String key;
- private String url;
-
- private List subButtons = new ArrayList();
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public List getSubButtons() {
- return subButtons;
- }
-
- public void setSubButtons(List subButtons) {
- this.subButtons = subButtons;
- }
-
- @Override
- public String toString() {
- return "WxMenuButton{" +
- "type='" + type + '\'' +
- ", name='" + name + '\'' +
- ", key='" + key + '\'' +
- ", url='" + url + '\'' +
- ", subButtons=" + subButtons +
- '}';
- }
- }
-
- public static class WxMenuRule {
- private String tagId;
- private String sex;
- private String country;
- private String province;
- private String city;
- private String clientPlatformType;
- private String language;
-
- public String getTagId() {
- return tagId;
- }
-
- public void setTagId(String tagId) {
- this.tagId = tagId;
- }
-
- public String getSex() {
- return sex;
- }
-
- public void setSex(String sex) {
- this.sex = sex;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCountry(String country) {
- this.country = country;
- }
-
- public String getProvince() {
- return province;
- }
-
- public void setProvince(String province) {
- this.province = province;
- }
-
- public String getCity() {
- return city;
- }
-
- public void setCity(String city) {
- this.city = city;
- }
-
- public String getClientPlatformType() {
- return clientPlatformType;
- }
-
- public void setClientPlatformType(String clientPlatformType) {
- this.clientPlatformType = clientPlatformType;
- }
-
- public String getLanguage() {
- return language;
- }
-
- public void setLanguage(String language) {
- this.language = language;
- }
-
- @Override
- public String toString() {
- return "matchrule:{" +
- "tag_id='" + tagId + '\'' +
- ", sex='" + sex + '\'' +
- ", country" + country + '\'' +
- ", province" + province + '\'' +
- ", city" + city + '\'' +
- ", client_platform_type" + clientPlatformType + '\'' +
- ", language" + language + '\'' +
- "}";
- }
- }
-
-}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenu.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenu.java
new file mode 100644
index 0000000000..7989b39a24
--- /dev/null
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenu.java
@@ -0,0 +1,69 @@
+package me.chanjar.weixin.common.bean.menu;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+import me.chanjar.weixin.common.bean.menu.WxMenuButton;
+import me.chanjar.weixin.common.util.json.WxGsonBuilder;
+
+/**
+ * 企业号菜单
+ *
+ * @author Daniel Qian
+ */
+public class WxMenu implements Serializable {
+
+ private static final long serialVersionUID = -7083914585539687746L;
+
+ private List buttons = new ArrayList();
+
+ private WxMenuRule matchRule;
+
+ /**
+ * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
+ * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
+ */
+ public static WxMenu fromJson(String json) {
+ return WxGsonBuilder.create().fromJson(json, WxMenu.class);
+ }
+
+ /**
+ * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
+ * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
+ */
+ public static WxMenu fromJson(InputStream is) {
+ return WxGsonBuilder.create().fromJson(new InputStreamReader(is, StandardCharsets.UTF_8), WxMenu.class);
+ }
+
+ public List getButtons() {
+ return buttons;
+ }
+
+ public void setButtons(List buttons) {
+ this.buttons = buttons;
+ }
+
+ public WxMenuRule getMatchRule() {
+ return matchRule;
+ }
+
+ public void setMatchRule(WxMenuRule matchRule) {
+ this.matchRule = matchRule;
+ }
+
+ public String toJson() {
+ return WxGsonBuilder.create().toJson(this);
+ }
+
+ @Override
+ public String toString() {
+ return "WxMenu{" +
+ "buttons=" + buttons +
+ '}';
+ }
+
+}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java
new file mode 100644
index 0000000000..88033400ac
--- /dev/null
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuButton.java
@@ -0,0 +1,72 @@
+package me.chanjar.weixin.common.bean.menu;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+public class WxMenuButton {
+
+ private String type;
+ private String name;
+ private String key;
+ private String url;
+ private String mediaId;
+
+ private List subButtons = new ArrayList();
+
+ @Override
+ public String toString() {
+ return ToStringBuilder.reflectionToString(this,
+ ToStringStyle.JSON_STYLE);
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public List getSubButtons() {
+ return subButtons;
+ }
+
+ public void setSubButtons(List subButtons) {
+ this.subButtons = subButtons;
+ }
+
+ public String getMediaId() {
+ return mediaId;
+ }
+
+ public void setMediaId(String mediaId) {
+ this.mediaId = mediaId;
+ }
+}
\ No newline at end of file
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java
new file mode 100644
index 0000000000..5cb9d8fedd
--- /dev/null
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java
@@ -0,0 +1,75 @@
+package me.chanjar.weixin.common.bean.menu;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+public class WxMenuRule {
+ private String tagId;
+ private String sex;
+ private String country;
+ private String province;
+ private String city;
+ private String clientPlatformType;
+ private String language;
+
+ public String getTagId() {
+ return tagId;
+ }
+
+ public void setTagId(String tagId) {
+ this.tagId = tagId;
+ }
+
+ public String getSex() {
+ return sex;
+ }
+
+ public void setSex(String sex) {
+ this.sex = sex;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String getProvince() {
+ return province;
+ }
+
+ public void setProvince(String province) {
+ this.province = province;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getClientPlatformType() {
+ return clientPlatformType;
+ }
+
+ public void setClientPlatformType(String clientPlatformType) {
+ this.clientPlatformType = clientPlatformType;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ @Override
+ public String toString() {
+ return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
+ }
+}
\ No newline at end of file
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java
index 66e22ee7f8..070ec72024 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxError.java
@@ -6,19 +6,28 @@
/**
* 微信错误码说明,请阅读: 全局返回码说明
- * @author Daniel Qian
*
+ * @author Daniel Qian
*/
public class WxError implements Serializable {
private static final long serialVersionUID = 7869786563361406291L;
private int errorCode;
-
+
private String errorMsg;
private String json;
-
+
+ public static WxError fromJson(String json) {
+ WxError error = WxGsonBuilder.create().fromJson(json, WxError.class);
+ return error;
+ }
+
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
public int getErrorCode() {
return errorCode;
}
@@ -43,40 +52,34 @@ public void setJson(String json) {
this.json = json;
}
- public static WxError fromJson(String json) {
- WxError error = WxGsonBuilder.create().fromJson(json, WxError.class);
- return error;
- }
-
@Override
public String toString() {
- return "微信错误: errcode=" + errorCode + ", errmsg=" + errorMsg + "\njson:" + json;
+ if (json != null) {
+ return json;
+ }
+ return "错误: Code=" + errorCode + ", Msg=" + errorMsg;
}
- public static Builder newBuilder(){
- return new Builder();
- }
-
- public static class Builder{
+ public static class Builder {
private int errorCode;
private String errorMsg;
-
+
public Builder setErrorCode(int errorCode) {
this.errorCode = errorCode;
return this;
}
-
+
public Builder setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
return this;
}
-
- public WxError build(){
+
+ public WxError build() {
WxError wxError = new WxError();
wxError.setErrorCode(this.errorCode);
wxError.setErrorMsg(this.errorMsg);
return wxError;
}
-
+
}
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java
index 500dc0000a..2e4b5fcd37 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMediaUploadResult.java
@@ -6,12 +6,16 @@
public class WxMediaUploadResult implements Serializable {
private static final long serialVersionUID = 330834334738622341L;
-
+
private String type;
private String mediaId;
private String thumbMediaId;
private long createdAt;
+ public static WxMediaUploadResult fromJson(String json) {
+ return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class);
+ }
+
public String getType() {
return type;
}
@@ -44,14 +48,10 @@ public void setThumbMediaId(String thumbMediaId) {
this.thumbMediaId = thumbMediaId;
}
- public static WxMediaUploadResult fromJson(String json) {
- return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class);
- }
-
@Override
public String toString() {
return "WxUploadResult [type=" + type + ", media_id=" + mediaId + ", thumb_media_id=" + thumbMediaId
- + ", created_at=" + createdAt + "]";
+ + ", created_at=" + createdAt + "]";
}
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java
index d1dc569be5..7e2e19418e 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/exception/WxErrorException.java
@@ -5,7 +5,7 @@
public class WxErrorException extends Exception {
private static final long serialVersionUID = -6357149550353160810L;
-
+
private WxError error;
public WxErrorException(WxError error) {
@@ -17,5 +17,5 @@ public WxError getError() {
return error;
}
-
+
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/Constants.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/Constants.java
index 33518f176b..f30a0ae0d0 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/Constants.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/Constants.java
@@ -26,6 +26,6 @@
public class Constants {
- public static final String Package = "me.chanjar.weixin.common.session";
+ public static final String Package = "me.chanjar.weixin.common.session";
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/InternalSession.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/InternalSession.java
index 283672af73..77d4d28291 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/InternalSession.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/InternalSession.java
@@ -8,6 +8,11 @@ public interface InternalSession {
*/
WxSession getSession();
+ /**
+ * Return the isValid flag for this session.
+ */
+ boolean isValid();
+
/**
* Set the isValid flag for this session.
*
@@ -15,11 +20,6 @@ public interface InternalSession {
*/
void setValid(boolean isValid);
- /**
- * Return the isValid flag for this session.
- */
- boolean isValid();
-
/**
* Return the session identifier for this session.
*/
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/InternalSessionManager.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/InternalSessionManager.java
index bb9a8dca58..a92e107154 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/InternalSessionManager.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/InternalSessionManager.java
@@ -7,11 +7,10 @@ public interface InternalSessionManager {
* specified session id (if any); otherwise return null.
*
* @param id The session id for the session to be returned
- *
- * @exception IllegalStateException if a new session cannot be
- * instantiated for any reason
- * @exception java.io.IOException if an input/output error occurs while
- * processing this request
+ * @throws IllegalStateException if a new session cannot be
+ * instantiated for any reason
+ * @throws java.io.IOException if an input/output error occurs while
+ * processing this request
*/
InternalSession findSession(String id);
@@ -23,10 +22,10 @@ public interface InternalSessionManager {
* null.
*
* @param sessionId The session id which should be used to create the
- * new session; if null, a new session id will be
- * generated
- * @exception IllegalStateException if a new session cannot be
- * instantiated for any reason
+ * new session; if null, a new session id will be
+ * generated
+ * @throws IllegalStateException if a new session cannot be
+ * instantiated for any reason
*/
InternalSession createSession(String sessionId);
@@ -40,8 +39,8 @@ public interface InternalSessionManager {
/**
* Remove this Session from the active Sessions for this Manager.
*
- * @param session Session to be removed
- * @param update Should the expiration statistics be updated
+ * @param session Session to be removed
+ * @param update Should the expiration statistics be updated
*/
void remove(InternalSession session, boolean update);
@@ -59,6 +58,7 @@ public interface InternalSessionManager {
* @return number of sessions active
*/
int getActiveSessions();
+
/**
* Get a session from the recycled ones or create a new empty one.
* The PersistentManager manager does not need to create session data
@@ -88,6 +88,7 @@ public interface InternalSessionManager {
* 要和{@link #setBackgroundProcessorDelay(int)}联合起来看
* 如果把这个数字设置为6(默认),那么就是说manager要等待 6 * backgroundProcessorDay的时间才会清理过期session
*
+ *
* @param processExpiresFrequency the new manager checks frequency
*/
void setProcessExpiresFrequency(int processExpiresFrequency);
@@ -97,6 +98,7 @@ public interface InternalSessionManager {
* Set the manager background processor delay
* 设置manager sleep几秒,尝试执行一次background操作(清理过期session)
*
+ *
* @param backgroundProcessorDelay
*/
void setBackgroundProcessorDelay(int backgroundProcessorDelay);
@@ -106,6 +108,7 @@ public interface InternalSessionManager {
* Set the maximum number of active Sessions allowed, or -1 for
* no limit.
* 设置最大活跃session数,默认无限
+ *
* @param max The new maximum number of sessions
*/
void setMaxActiveSessions(int max);
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/LocalStrings.properties b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/LocalStrings.properties
index ede528f739..d3ded84b8d 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/LocalStrings.properties
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/LocalStrings.properties
@@ -12,7 +12,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
applicationSession.session.ise=invalid session state
applicationSession.value.iae=null value
fileStore.saving=Saving Session {0} to file {1}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java
index b482c2b7c1..9212c619ec 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSession.java
@@ -12,17 +12,68 @@ public class StandardSession implements WxSession, InternalSession {
* The string manager for this package.
*/
protected static final StringManager sm =
- StringManager.getManager(Constants.Package);
-
+ StringManager.getManager(Constants.Package);
+ /**
+ * Type array.
+ */
+ protected static final String EMPTY_ARRAY[] = new String[0];
// ------------------------------ WxSession
protected Map attributes = new ConcurrentHashMap();
+ /**
+ * The session identifier of this Session.
+ */
+ protected String id = null;
+ /**
+ * Flag indicating whether this session is valid or not.
+ */
+ protected volatile boolean isValid = false;
+ /**
+ * We are currently processing a session expiration, so bypass
+ * certain IllegalStateException tests. NOTE: This value is not
+ * included in the serialized version of this object.
+ */
+ protected transient volatile boolean expiring = false;
+ /**
+ * The Manager with which this Session is associated.
+ */
+ protected transient InternalSessionManager manager = null;
+
+ // ------------------------------ InternalSession
+ /**
+ * The time this session was created, in milliseconds since midnight,
+ * January 1, 1970 GMT.
+ */
+ protected long creationTime = 0L;
+ /**
+ * The current accessed time for this session.
+ */
+ protected volatile long thisAccessedTime = creationTime;
+ /**
+ * The default maximum inactive interval for Sessions created by
+ * this Manager.
+ */
+ protected int maxInactiveInterval = 30 * 60;
+ /**
+ * The facade associated with this session. NOTE: This value is not
+ * included in the serialized version of this object.
+ */
+ protected transient StandardSessionFacade facade = null;
+ /**
+ * The access count for this session.
+ */
+ protected transient AtomicInteger accessCount = null;
+
+ public StandardSession(InternalSessionManager manager) {
+ this.manager = manager;
+ this.accessCount = new AtomicInteger();
+ }
@Override
public Object getAttribute(String name) {
if (!isValidInternal())
throw new IllegalStateException
- (sm.getString("sessionImpl.getAttribute.ise"));
+ (sm.getString("sessionImpl.getAttribute.ise"));
if (name == null) return null;
@@ -33,7 +84,7 @@ public Object getAttribute(String name) {
public Enumeration getAttributeNames() {
if (!isValidInternal())
throw new IllegalStateException
- (sm.getString("sessionImpl.getAttributeNames.ise"));
+ (sm.getString("sessionImpl.getAttributeNames.ise"));
Set names = new HashSet();
names.addAll(attributes.keySet());
@@ -45,7 +96,7 @@ public void setAttribute(String name, Object value) {
// Name cannot be null
if (name == null)
throw new IllegalArgumentException
- (sm.getString("sessionImpl.setAttribute.namenull"));
+ (sm.getString("sessionImpl.setAttribute.namenull"));
// Null value is the same as removeAttribute()
if (value == null) {
@@ -56,97 +107,32 @@ public void setAttribute(String name, Object value) {
// Validate our current state
if (!isValidInternal())
throw new IllegalStateException(sm.getString(
- "sessionImpl.setAttribute.ise", getIdInternal()));
+ "sessionImpl.setAttribute.ise", getIdInternal()));
attributes.put(name, value);
}
-
@Override
public void removeAttribute(String name) {
removeAttributeInternal(name);
}
-
@Override
public void invalidate() {
if (!isValidInternal())
throw new IllegalStateException
- (sm.getString("sessionImpl.invalidate.ise"));
+ (sm.getString("sessionImpl.invalidate.ise"));
// Cause this session to expire
expire();
}
- // ------------------------------ InternalSession
- /**
- * The session identifier of this Session.
- */
- protected String id = null;
-
- /**
- * Flag indicating whether this session is valid or not.
- */
- protected volatile boolean isValid = false;
-
- /**
- * We are currently processing a session expiration, so bypass
- * certain IllegalStateException tests. NOTE: This value is not
- * included in the serialized version of this object.
- */
- protected transient volatile boolean expiring = false;
-
- /**
- * The Manager with which this Session is associated.
- */
- protected transient InternalSessionManager manager = null;
-
- /**
- * Type array.
- */
- protected static final String EMPTY_ARRAY[] = new String[0];
-
- /**
- * The time this session was created, in milliseconds since midnight,
- * January 1, 1970 GMT.
- */
- protected long creationTime = 0L;
-
- /**
- * The current accessed time for this session.
- */
- protected volatile long thisAccessedTime = creationTime;
-
- /**
- * The default maximum inactive interval for Sessions created by
- * this Manager.
- */
- protected int maxInactiveInterval = 30 * 60;
-
- /**
- * The facade associated with this session. NOTE: This value is not
- * included in the serialized version of this object.
- */
- protected transient StandardSessionFacade facade = null;
-
- /**
- * The access count for this session.
- */
- protected transient AtomicInteger accessCount = null;
-
-
- public StandardSession(InternalSessionManager manager) {
- this.manager = manager;
- this.accessCount = new AtomicInteger();
- }
-
-
@Override
public WxSession getSession() {
- if (facade == null){
+ if (facade == null) {
facade = new StandardSessionFacade(this);
}
return (facade);
@@ -161,16 +147,6 @@ protected boolean isValidInternal() {
return this.isValid;
}
- /**
- * Set the isValid flag for this session.
- *
- * @param isValid The new value for the isValid flag
- */
- @Override
- public void setValid(boolean isValid) {
- this.isValid = isValid;
- }
-
@Override
public boolean isValid() {
if (!this.isValid) {
@@ -197,6 +173,16 @@ public boolean isValid() {
return this.isValid;
}
+ /**
+ * Set the isValid flag for this session.
+ *
+ * @param isValid The new value for the isValid flag
+ */
+ @Override
+ public void setValid(boolean isValid) {
+ this.isValid = isValid;
+ }
+
@Override
public String getIdInternal() {
return (this.id);
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSessionManager.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSessionManager.java
index f3a0269582..cd14a1fd4a 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSessionManager.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/StandardSessionManager.java
@@ -13,60 +13,26 @@
*/
public class StandardSessionManager implements WxSessionManager, InternalSessionManager {
- protected final Logger log = LoggerFactory.getLogger(StandardSessionManager.class);
-
protected static final StringManager sm =
- StringManager.getManager(Constants.Package);
-
+ StringManager.getManager(Constants.Package);
/**
- * The set of currently active Sessions for this Manager, keyed by
- * session identifier.
+ * The descriptive name of this Manager implementation (for logging).
*/
- protected Map sessions = new ConcurrentHashMap();
-
- @Override
- public WxSession getSession(String sessionId) {
- return getSession(sessionId, true);
- }
-
- @Override
- public WxSession getSession(String sessionId, boolean create) {
- if (sessionId == null) {
- throw new IllegalStateException
- (sm.getString("sessionManagerImpl.getSession.ise"));
- }
-
- InternalSession session = findSession(sessionId);
- if ((session != null) && !session.isValid()) {
- session = null;
- }
- if (session != null) {
- session.access();
- return session.getSession();
- }
-
- // Create a new session if requested and the response is not committed
- if (!create) {
- return (null);
- }
-
- session = createSession(sessionId);
-
- if (session == null) {
- return null;
- }
-
- session.access();
- return session.getSession();
- }
+ private static final String name = "SessionManagerImpl";
+ protected final Logger log = LoggerFactory.getLogger(StandardSessionManager.class);
+ private final Object maxActiveUpdateLock = new Object();
+ /**
+ * 后台清理线程是否已经开启
+ */
+ private final AtomicBoolean backgroundProcessStarted = new AtomicBoolean(false);
// -------------------------------------- InternalSessionManager
/**
- * The descriptive name of this Manager implementation (for logging).
+ * The set of currently active Sessions for this Manager, keyed by
+ * session identifier.
*/
- private static final String name = "SessionManagerImpl";
-
+ protected Map sessions = new ConcurrentHashMap();
/**
* The maximum number of active Sessions allowed, or -1 for no limit.
*/
@@ -84,22 +50,13 @@ public WxSession getSession(String sessionId, boolean create) {
protected int maxInactiveInterval = 30 * 60;
// Number of sessions created by this manager
- protected long sessionCounter=0;
-
- protected volatile int maxActive=0;
-
- private final Object maxActiveUpdateLock = new Object();
+ protected long sessionCounter = 0;
+ protected volatile int maxActive = 0;
/**
* Processing time during session expiration.
*/
protected long processingTime = 0;
-
- /**
- * Iteration count for background processing.
- */
- private int count = 0;
-
/**
* Frequency of the session expiration, and related manager operations.
* Manager operations will be done once for the specified amount of
@@ -107,16 +64,50 @@ public WxSession getSession(String sessionId, boolean create) {
* checks will occur).
*/
protected int processExpiresFrequency = 6;
-
/**
* background processor delay in seconds
*/
protected int backgroundProcessorDelay = 10;
-
/**
- * 后台清理线程是否已经开启
+ * Iteration count for background processing.
*/
- private final AtomicBoolean backgroundProcessStarted = new AtomicBoolean(false);
+ private int count = 0;
+
+ @Override
+ public WxSession getSession(String sessionId) {
+ return getSession(sessionId, true);
+ }
+
+ @Override
+ public WxSession getSession(String sessionId, boolean create) {
+ if (sessionId == null) {
+ throw new IllegalStateException
+ (sm.getString("sessionManagerImpl.getSession.ise"));
+ }
+
+ InternalSession session = findSession(sessionId);
+ if ((session != null) && !session.isValid()) {
+ session = null;
+ }
+ if (session != null) {
+ session.access();
+ return session.getSession();
+ }
+
+ // Create a new session if requested and the response is not committed
+ if (!create) {
+ return (null);
+ }
+
+ session = createSession(sessionId);
+
+ if (session == null) {
+ return null;
+ }
+
+ session.access();
+ return session.getSession();
+ }
@Override
public void remove(InternalSession session) {
@@ -131,7 +122,6 @@ public void remove(InternalSession session, boolean update) {
}
-
@Override
public InternalSession findSession(String id) {
@@ -145,15 +135,15 @@ public InternalSession findSession(String id) {
public InternalSession createSession(String sessionId) {
if (sessionId == null) {
throw new IllegalStateException
- (sm.getString("sessionManagerImpl.createSession.ise"));
+ (sm.getString("sessionManagerImpl.createSession.ise"));
}
if ((maxActiveSessions >= 0) &&
- (getActiveSessions() >= maxActiveSessions)) {
+ (getActiveSessions() >= maxActiveSessions)) {
rejectedSessions++;
throw new TooManyActiveSessionsException(
- sm.getString("sessionManagerImpl.createSession.tmase"),
- maxActiveSessions);
+ sm.getString("sessionManagerImpl.createSession.tmase"),
+ maxActiveSessions);
}
// Recycle or create a Session instance
@@ -216,14 +206,14 @@ public void run() {
sessions.put(session.getIdInternal(), session);
int size = getActiveSessions();
- if( size > maxActive ) {
- synchronized(maxActiveUpdateLock) {
- if( size > maxActive ) {
+ if (size > maxActive) {
+ synchronized (maxActiveUpdateLock) {
+ if (size > maxActive) {
maxActive = size;
}
}
}
-
+
}
/**
@@ -251,19 +241,19 @@ public void processExpires() {
long timeNow = System.currentTimeMillis();
InternalSession sessions[] = findSessions();
- int expireHere = 0 ;
+ int expireHere = 0;
- if(log.isDebugEnabled())
+ if (log.isDebugEnabled())
log.debug("Start expire sessions {} at {} sessioncount {}", getName(), timeNow, sessions.length);
for (int i = 0; i < sessions.length; i++) {
- if (sessions[i]!=null && !sessions[i].isValid()) {
+ if (sessions[i] != null && !sessions[i].isValid()) {
expireHere++;
}
}
long timeEnd = System.currentTimeMillis();
- if(log.isDebugEnabled())
+ if (log.isDebugEnabled())
log.debug("End expire sessions {} processingTime {} expired sessions: {}", getName(), timeEnd - timeNow, expireHere);
- processingTime += ( timeEnd - timeNow );
+ processingTime += (timeEnd - timeNow);
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/TooManyActiveSessionsException.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/TooManyActiveSessionsException.java
index bd0c0f2ba6..69fd89f80f 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/TooManyActiveSessionsException.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/session/TooManyActiveSessionsException.java
@@ -21,37 +21,34 @@
* reached and the server is refusing to create any new sessions.
*/
public class TooManyActiveSessionsException
- extends IllegalStateException
-{
- private static final long serialVersionUID = 1L;
+ extends IllegalStateException {
+ private static final long serialVersionUID = 1L;
- /**
- * The maximum number of active sessions the server will tolerate.
- */
- private final int maxActiveSessions;
+ /**
+ * The maximum number of active sessions the server will tolerate.
+ */
+ private final int maxActiveSessions;
- /**
- * Creates a new TooManyActiveSessionsException.
- *
- * @param message A description for the exception.
- * @param maxActive The maximum number of active sessions allowed by the
- * session manager.
- */
- public TooManyActiveSessionsException(String message,
- int maxActive)
- {
- super(message);
-
- maxActiveSessions = maxActive;
- }
-
- /**
- * Gets the maximum number of sessions allowed by the session manager.
- *
- * @return The maximum number of sessions allowed by the session manager.
- */
- public int getMaxActiveSessions()
- {
- return maxActiveSessions;
- }
+ /**
+ * Creates a new TooManyActiveSessionsException.
+ *
+ * @param message A description for the exception.
+ * @param maxActive The maximum number of active sessions allowed by the
+ * session manager.
+ */
+ public TooManyActiveSessionsException(String message,
+ int maxActive) {
+ super(message);
+
+ maxActiveSessions = maxActive;
+ }
+
+ /**
+ * Gets the maximum number of sessions allowed by the session manager.
+ *
+ * @return The maximum number of sessions allowed by the session manager.
+ */
+ public int getMaxActiveSessions() {
+ return maxActiveSessions;
+ }
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/StringUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/StringUtils.java
index 4234a8c8c9..49acaeeaf7 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/StringUtils.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/StringUtils.java
@@ -7,7 +7,7 @@ public class StringUtils {
/**
*
Checks if a CharSequence is whitespace, empty ("") or null.
- *
+ *
*
* StringUtils.isBlank(null) = true
* StringUtils.isBlank("") = true
@@ -16,9 +16,8 @@ public class StringUtils {
* StringUtils.isBlank(" bob ") = false
*
*
- * @param cs the CharSequence to check, may be null
+ * @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is null, empty or whitespace
- * @since 2.0
* @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
*/
public static boolean isBlank(CharSequence cs) {
@@ -36,7 +35,7 @@ public static boolean isBlank(CharSequence cs) {
/**
*
Checks if a CharSequence is not empty (""), not null and not whitespace only.
*
- * @param cs the CharSequence to check, may be null
+ * @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is
- * not empty and not null and not whitespace
- * @since 2.0
+ * not empty and not null and not whitespace
* @since 3.0 Changed signature from isNotBlank(String) to isNotBlank(CharSequence)
*/
public static boolean isNotBlank(CharSequence cs) {
@@ -57,7 +55,7 @@ public static boolean isNotBlank(CharSequence cs) {
/**
*
NOTE: This method changed in Lang version 2.0.
* It no longer trims the CharSequence.
* That functionality is available in isBlank().
*
- * @param cs the CharSequence to check, may be null
+ * @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is empty or null
* @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)
*/
@@ -80,7 +78,7 @@ public static boolean isEmpty(CharSequence cs) {
/**
*
Checks if a CharSequence is not empty ("") and not null.
The StringManager operates on a package basis. One StringManager
* per package can be created and accessed via the getManager method
* call.
- *
+ *
*
The StringManager will look for a ResourceBundle named by
* the package name given plus the suffix of "LocalStrings". In
* practice, this means that the localized information will be contained
* in a LocalStrings.properties file located in the package
* directory of the classpath.
- *
+ *
*
Please see the documentation for java.util.ResourceBundle for
* more information.
*
@@ -52,152 +46,80 @@
*/
public class StringManager {
- private static int LOCALE_CACHE_SIZE = 10;
-
- /**
- * The ResourceBundle for this StringManager.
- */
- private final ResourceBundle bundle;
- private final Locale locale;
-
- /**
- * Creates a new StringManager for a given package. This is a
- * private method and all access to it is arbitrated by the
- * static getManager method call so that only one StringManager
- * per package will be created.
- *
- * @param packageName Name of package to create StringManager for.
- */
- private StringManager(String packageName, Locale locale) {
- String bundleName = packageName + ".LocalStrings";
- ResourceBundle bnd = null;
+ private static final Map> managers =
+ new Hashtable>();
+ private static int LOCALE_CACHE_SIZE = 10;
+ /**
+ * The ResourceBundle for this StringManager.
+ */
+ private final ResourceBundle bundle;
+ private final Locale locale;
+
+ /**
+ * Creates a new StringManager for a given package. This is a
+ * private method and all access to it is arbitrated by the
+ * static getManager method call so that only one StringManager
+ * per package will be created.
+ *
+ * @param packageName Name of package to create StringManager for.
+ */
+ private StringManager(String packageName, Locale locale) {
+ String bundleName = packageName + ".LocalStrings";
+ ResourceBundle bnd = null;
+ try {
+ bnd = ResourceBundle.getBundle(bundleName, locale);
+ } catch (MissingResourceException ex) {
+ // Try from the current loader (that's the case for trusted apps)
+ // Should only be required if using a TC5 style classloader structure
+ // where common != shared != server
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if (cl != null) {
try {
- bnd = ResourceBundle.getBundle(bundleName, locale);
- } catch( MissingResourceException ex ) {
- // Try from the current loader (that's the case for trusted apps)
- // Should only be required if using a TC5 style classloader structure
- // where common != shared != server
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if( cl != null ) {
- try {
- bnd = ResourceBundle.getBundle(bundleName, locale, cl);
- } catch(MissingResourceException ex2) {
- // Ignore
- }
- }
- }
- bundle = bnd;
- // Get the actual locale, which may be different from the requested one
- if (bundle != null) {
- Locale bundleLocale = bundle.getLocale();
- if (bundleLocale.equals(Locale.ROOT)) {
- this.locale = Locale.ENGLISH;
- } else {
- this.locale = bundleLocale;
- }
- } else {
- this.locale = null;
+ bnd = ResourceBundle.getBundle(bundleName, locale, cl);
+ } catch (MissingResourceException ex2) {
+ // Ignore
}
+ }
}
-
- /**
- Get a string from the underlying resource bundle or return
- null if the String is not found.
-
- @param key to desired resource String
- @return resource String matching key from underlying
- bundle or null if not found.
- @throws IllegalArgumentException if key is null.
- */
- public String getString(String key) {
- if(key == null){
- String msg = "key may not have a null value";
-
- throw new IllegalArgumentException(msg);
- }
-
- String str = null;
-
- try {
- // Avoid NPE if bundle is null and treat it like an MRE
- if (bundle != null) {
- str = bundle.getString(key);
- }
- } catch(MissingResourceException mre) {
- //bad: shouldn't mask an exception the following way:
- // str = "[cannot find message associated with key '" + key +
- // "' due to " + mre + "]";
- // because it hides the fact that the String was missing
- // from the calling code.
- //good: could just throw the exception (or wrap it in another)
- // but that would probably cause much havoc on existing
- // code.
- //better: consistent with container pattern to
- // simply return null. Calling code can then do
- // a null check.
- str = null;
- }
-
- return str;
+ bundle = bnd;
+ // Get the actual locale, which may be different from the requested one
+ if (bundle != null) {
+ Locale bundleLocale = bundle.getLocale();
+ if (bundleLocale.equals(Locale.ROOT)) {
+ this.locale = Locale.ENGLISH;
+ } else {
+ this.locale = bundleLocale;
+ }
+ } else {
+ this.locale = null;
}
-
- /**
- * Get a string from the underlying resource bundle and format
- * it with the given set of arguments.
- *
- * @param key
- * @param args
- */
- public String getString(final String key, final Object... args) {
- String value = getString(key);
- if (value == null) {
- value = key;
- }
-
- MessageFormat mf = new MessageFormat(value);
- mf.setLocale(locale);
- return mf.format(args, new StringBuffer(), null).toString();
- }
-
- /**
- * Identify the Locale this StringManager is associated with
- */
- public Locale getLocale() {
- return locale;
- }
-
- // --------------------------------------------------------------
- // STATIC SUPPORT METHODS
- // --------------------------------------------------------------
-
- private static final Map> managers =
- new Hashtable>();
-
- /**
- * Get the StringManager for a particular package. If a manager for
- * a package already exists, it will be reused, else a new
- * StringManager will be created and returned.
- *
- * @param packageName The package name
- */
- public static final synchronized StringManager getManager(
- String packageName) {
- return getManager(packageName, Locale.getDefault());
- }
-
- /**
- * Get the StringManager for a particular package and Locale. If a manager
- * for a package/Locale combination already exists, it will be reused, else
- * a new StringManager will be created and returned.
- *
- * @param packageName The package name
- * @param locale The Locale
- */
- public static final synchronized StringManager getManager(
- String packageName, Locale locale) {
-
- Map map = managers.get(packageName);
- if (map == null) {
+ }
+
+ /**
+ * Get the StringManager for a particular package. If a manager for
+ * a package already exists, it will be reused, else a new
+ * StringManager will be created and returned.
+ *
+ * @param packageName The package name
+ */
+ public static final synchronized StringManager getManager(
+ String packageName) {
+ return getManager(packageName, Locale.getDefault());
+ }
+
+ /**
+ * Get the StringManager for a particular package and Locale. If a manager
+ * for a package/Locale combination already exists, it will be reused, else
+ * a new StringManager will be created and returned.
+ *
+ * @param packageName The package name
+ * @param locale The Locale
+ */
+ public static final synchronized StringManager getManager(
+ String packageName, Locale locale) {
+
+ Map map = managers.get(packageName);
+ if (map == null) {
/*
* Don't want the HashMap to be expanded beyond LOCALE_CACHE_SIZE.
* Expansion occurs when size() exceeds capacity. Therefore keep
@@ -206,43 +128,113 @@ public static final synchronized StringManager getManager(
* for removal needs to use one less than the maximum desired size
*
*/
- map = new LinkedHashMap(LOCALE_CACHE_SIZE, 1, true) {
- private static final long serialVersionUID = 1L;
- @Override
- protected boolean removeEldestEntry(
- Map.Entry eldest) {
- return size() > (LOCALE_CACHE_SIZE - 1);
- }
- };
- managers.put(packageName, map);
- }
+ map = new LinkedHashMap(LOCALE_CACHE_SIZE, 1, true) {
+ private static final long serialVersionUID = 1L;
- StringManager mgr = map.get(locale);
- if (mgr == null) {
- mgr = new StringManager(packageName, locale);
- map.put(locale, mgr);
+ @Override
+ protected boolean removeEldestEntry(
+ Map.Entry eldest) {
+ return size() > (LOCALE_CACHE_SIZE - 1);
}
- return mgr;
+ };
+ managers.put(packageName, map);
}
- /**
- * Retrieve the StringManager for a list of Locales. The first StringManager
- * found will be returned.
- *
- * @param requestedLocales the list of Locales
- *
- * @return the found StringManager or the default StringManager
- */
- public static StringManager getManager(String packageName,
- Enumeration requestedLocales) {
- while (requestedLocales.hasMoreElements()) {
- Locale locale = requestedLocales.nextElement();
- StringManager result = getManager(packageName, locale);
- if (result.getLocale().equals(locale)) {
- return result;
- }
- }
- // Return the default
- return getManager(packageName);
+ StringManager mgr = map.get(locale);
+ if (mgr == null) {
+ mgr = new StringManager(packageName, locale);
+ map.put(locale, mgr);
}
+ return mgr;
+ }
+
+ // --------------------------------------------------------------
+ // STATIC SUPPORT METHODS
+ // --------------------------------------------------------------
+
+ /**
+ * Retrieve the StringManager for a list of Locales. The first StringManager
+ * found will be returned.
+ *
+ * @param requestedLocales the list of Locales
+ * @return the found StringManager or the default StringManager
+ */
+ public static StringManager getManager(String packageName,
+ Enumeration requestedLocales) {
+ while (requestedLocales.hasMoreElements()) {
+ Locale locale = requestedLocales.nextElement();
+ StringManager result = getManager(packageName, locale);
+ if (result.getLocale().equals(locale)) {
+ return result;
+ }
+ }
+ // Return the default
+ return getManager(packageName);
+ }
+
+ /**
+ * Get a string from the underlying resource bundle or return
+ * null if the String is not found.
+ *
+ * @param key to desired resource String
+ * @return resource String matching key from underlying
+ * bundle or null if not found.
+ * @throws IllegalArgumentException if key is null.
+ */
+ public String getString(String key) {
+ if (key == null) {
+ String msg = "key may not have a null value";
+
+ throw new IllegalArgumentException(msg);
+ }
+
+ String str = null;
+
+ try {
+ // Avoid NPE if bundle is null and treat it like an MRE
+ if (bundle != null) {
+ str = bundle.getString(key);
+ }
+ } catch (MissingResourceException mre) {
+ //bad: shouldn't mask an exception the following way:
+ // str = "[cannot find message associated with key '" + key +
+ // "' due to " + mre + "]";
+ // because it hides the fact that the String was missing
+ // from the calling code.
+ //good: could just throw the exception (or wrap it in another)
+ // but that would probably cause much havoc on existing
+ // code.
+ //better: consistent with container pattern to
+ // simply return null. Calling code can then do
+ // a null check.
+ str = null;
+ }
+
+ return str;
+ }
+
+ /**
+ * Get a string from the underlying resource bundle and format
+ * it with the given set of arguments.
+ *
+ * @param key
+ * @param args
+ */
+ public String getString(final String key, final Object... args) {
+ String value = getString(key);
+ if (value == null) {
+ value = key;
+ }
+
+ MessageFormat mf = new MessageFormat(value);
+ mf.setLocale(locale);
+ return mf.format(args, new StringBuffer(), null).toString();
+ }
+
+ /**
+ * Identify the Locale this StringManager is associated with
+ */
+ public Locale getLocale() {
+ return locale;
+ }
}
diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java
index 1caa0a068b..109acfc072 100644
--- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java
+++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/XStreamInitializer.java
@@ -1,7 +1,5 @@
package me.chanjar.weixin.common.util.xml;
-import java.io.Writer;
-
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.core.util.QuickWriter;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
@@ -10,6 +8,8 @@
import com.thoughtworks.xstream.security.NullPermission;
import com.thoughtworks.xstream.security.PrimitiveTypePermission;
+import java.io.Writer;
+
public class XStreamInitializer {
public static XStream getInstance() {
@@ -22,6 +22,7 @@ public HierarchicalStreamWriter createWriter(Writer out) {
protected String SUFFIX_CDATA = "]]>";
protected String PREFIX_MEDIA_ID = "";
protected String SUFFIX_MEDIA_ID = "";
+
@Override
protected void writeText(QuickWriter writer, String text) {
if (text.startsWith(PREFIX_CDATA) && text.endsWith(SUFFIX_CDATA)) {
diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java
index d236c63107..b2bc7fe7d1 100644
--- a/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java
+++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxAccessTokenTest.java
@@ -14,5 +14,5 @@ public void testFromJson() {
Assert.assertTrue(wxError.getExpiresIn() == 7200);
}
-
+
}
diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java
index 51e9dab362..3fe40795f3 100644
--- a/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java
+++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxErrorTest.java
@@ -15,7 +15,7 @@ public void testFromJson() {
Assert.assertEquals(wxError.getErrorMsg(), "invalid openid");
}
-
+
public void testFromBadJson1() {
String json = "{ \"errcode\": 40003, \"errmsg\": \"invalid openid\", \"media_id\": \"12323423dsfafsf232f\" }";
@@ -24,7 +24,7 @@ public void testFromBadJson1() {
Assert.assertEquals(wxError.getErrorMsg(), "invalid openid");
}
-
+
public void testFromBadJson2() {
String json = "{\"access_token\":\"ACCESS_TOKEN\",\"expires_in\":7200}";
@@ -33,5 +33,5 @@ public void testFromBadJson2() {
Assert.assertEquals(wxError.getErrorMsg(), null);
}
-
+
}
diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxMenuTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxMenuTest.java
index 2ae12c2ccf..e2a0c2c1f8 100644
--- a/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxMenuTest.java
+++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/bean/WxMenuTest.java
@@ -1,58 +1,61 @@
package me.chanjar.weixin.common.bean;
-import me.chanjar.weixin.common.bean.WxMenu.WxMenuButton;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
+import me.chanjar.weixin.common.bean.menu.WxMenu;
+import me.chanjar.weixin.common.bean.menu.WxMenuButton;
+import me.chanjar.weixin.common.bean.menu.WxMenuRule;
+
@Test
public class WxMenuTest {
- @Test(dataProvider="wxReturnMenu")
+ @Test(dataProvider = "wxReturnMenu")
public void testFromJson(String json) {
WxMenu menu = WxMenu.fromJson(json);
Assert.assertEquals(menu.getButtons().size(), 3);
}
-
- @Test(dataProvider="wxPushMenu")
+
+ @Test(dataProvider = "wxPushMenu")
public void testToJson(String json) {
WxMenu menu = new WxMenu();
WxMenuButton button1 = new WxMenuButton();
button1.setType("click");
button1.setName("今日歌曲");
button1.setKey("V1001_TODAY_MUSIC");
-
+
WxMenuButton button2 = new WxMenuButton();
button2.setType("click");
button2.setName("歌手简介");
button2.setKey("V1001_TODAY_SINGER");
-
+
WxMenuButton button3 = new WxMenuButton();
button3.setName("菜单");
-
+
menu.getButtons().add(button1);
menu.getButtons().add(button2);
menu.getButtons().add(button3);
-
+
WxMenuButton button31 = new WxMenuButton();
button31.setType("view");
button31.setName("搜索");
button31.setUrl("http://www.soso.com/");
-
+
WxMenuButton button32 = new WxMenuButton();
button32.setType("view");
button32.setName("视频");
button32.setUrl("http://v.qq.com/");
-
+
WxMenuButton button33 = new WxMenuButton();
button33.setType("click");
button33.setName("赞一下我们");
button33.setKey("V1001_GOOD");
-
+
button3.getSubButtons().add(button31);
button3.getSubButtons().add(button32);
button3.getSubButtons().add(button33);
-
+
Assert.assertEquals(menu.toJson(), json);
}
@@ -66,7 +69,7 @@ public void testAddConditionalToJson(String json) {
menu.getButtons().add(button1);
- WxMenu.WxMenuRule wxMenuRule = new WxMenu.WxMenuRule();
+ WxMenuRule wxMenuRule = new WxMenuRule();
wxMenuRule.setTagId("2");
wxMenuRule.setSex("1");
wxMenuRule.setCountry("中国");
@@ -78,82 +81,82 @@ public void testAddConditionalToJson(String json) {
Assert.assertEquals(menu.toJson(), json);
}
-
+
@DataProvider
public Object[][] wxReturnMenu() {
- Object[][] res = menuJson();
+ Object[][] res = menuJson();
String json = "{ \"menu\" : " + res[0][0] + " }";
- return new Object[][] {
- new Object[] { json }
+ return new Object[][]{
+ new Object[]{json}
};
}
-
- @DataProvider(name="wxPushMenu")
+
+ @DataProvider(name = "wxPushMenu")
public Object[][] menuJson() {
- String json =
- "{"
- +"\"button\":["
- +"{"
- +"\"type\":\"click\","
- +"\"name\":\"今日歌曲\","
- +"\"key\":\"V1001_TODAY_MUSIC\""
- +"},"
- +"{"
- +"\"type\":\"click\","
- +"\"name\":\"歌手简介\","
- +"\"key\":\"V1001_TODAY_SINGER\""
- +"},"
- +"{"
- +"\"name\":\"菜单\","
- +"\"sub_button\":["
- +"{"
- +"\"type\":\"view\","
- +"\"name\":\"搜索\","
- +"\"url\":\"http://www.soso.com/\""
- +"},"
- +"{"
- +"\"type\":\"view\","
- +"\"name\":\"视频\","
- +"\"url\":\"http://v.qq.com/\""
- +"},"
- +"{"
- +"\"type\":\"click\","
- +"\"name\":\"赞一下我们\","
- +"\"key\":\"V1001_GOOD\""
- +"}"
- +"]"
- +"}"
- +"]"
- +"}";
- return new Object[][] {
- new Object[] { json }
+ String json =
+ "{"
+ + "\"button\":["
+ + "{"
+ + "\"type\":\"click\","
+ + "\"name\":\"今日歌曲\","
+ + "\"key\":\"V1001_TODAY_MUSIC\""
+ + "},"
+ + "{"
+ + "\"type\":\"click\","
+ + "\"name\":\"歌手简介\","
+ + "\"key\":\"V1001_TODAY_SINGER\""
+ + "},"
+ + "{"
+ + "\"name\":\"菜单\","
+ + "\"sub_button\":["
+ + "{"
+ + "\"type\":\"view\","
+ + "\"name\":\"搜索\","
+ + "\"url\":\"http://www.soso.com/\""
+ + "},"
+ + "{"
+ + "\"type\":\"view\","
+ + "\"name\":\"视频\","
+ + "\"url\":\"http://v.qq.com/\""
+ + "},"
+ + "{"
+ + "\"type\":\"click\","
+ + "\"name\":\"赞一下我们\","
+ + "\"key\":\"V1001_GOOD\""
+ + "}"
+ + "]"
+ + "}"
+ + "]"
+ + "}";
+ return new Object[][]{
+ new Object[]{json}
};
}
@DataProvider(name = "wxAddConditionalMenu")
- public Object[][] addConditionalMenuJson(){
+ public Object[][] addConditionalMenuJson() {
String json =
- "{"
- +"\"button\":["
- +"{"
- +"\"type\":\"click\","
- +"\"name\":\"今日歌曲\","
- +"\"key\":\"V1001_TODAY_MUSIC\""
- +"}"
- +"],"
- +"\"matchrule\":{"
- +"\"group_id\":\"2\","
- +"\"sex\":\"1\","
- +"\"country\":\"中国\","
- +"\"province\":\"广东\","
- +"\"city\":\"广州\","
- +"\"client_platform_type\":\"2\","
- +"\"language\":\"zh_CN\""
- +"}"
- +"}";
+ "{"
+ + "\"button\":["
+ + "{"
+ + "\"type\":\"click\","
+ + "\"name\":\"今日歌曲\","
+ + "\"key\":\"V1001_TODAY_MUSIC\""
+ + "}"
+ + "],"
+ + "\"matchrule\":{"
+ + "\"group_id\":\"2\","
+ + "\"sex\":\"1\","
+ + "\"country\":\"中国\","
+ + "\"province\":\"广东\","
+ + "\"city\":\"广州\","
+ + "\"client_platform_type\":\"2\","
+ + "\"language\":\"zh_CN\""
+ + "}"
+ + "}";
return new Object[][]{
- new Object[]{json}
+ new Object[]{json}
};
}
-
+
}
diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/session/SessionTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/session/SessionTest.java
index bcb029b191..ce2466361e 100644
--- a/weixin-java-common/src/test/java/me/chanjar/weixin/common/session/SessionTest.java
+++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/session/SessionTest.java
@@ -10,8 +10,8 @@ public class SessionTest {
@DataProvider
public Object[][] getSessionManager() {
- return new Object[][] {
- new Object[] { new StandardSessionManager() }
+ return new Object[][]{
+ new Object[]{new StandardSessionManager()}
};
}
diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/WxMessageInMemoryDuplicateCheckerTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/WxMessageInMemoryDuplicateCheckerTest.java
index 7369d63715..a3a243a428 100644
--- a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/WxMessageInMemoryDuplicateCheckerTest.java
+++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/WxMessageInMemoryDuplicateCheckerTest.java
@@ -8,7 +8,7 @@
public class WxMessageInMemoryDuplicateCheckerTest {
public void test() throws InterruptedException {
- Long[] msgIds = new Long[] { 1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l };
+ Long[] msgIds = new Long[]{1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l};
WxMessageInMemoryDuplicateChecker checker = new WxMessageInMemoryDuplicateChecker(2000l, 1000l);
// 第一次检查
diff --git a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java
index 15b08c2685..a5fa0c4199 100755
--- a/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java
+++ b/weixin-java-common/src/test/java/me/chanjar/weixin/common/util/crypto/WxCryptUtilTest.java
@@ -45,16 +45,24 @@ public void testNormal() throws ParserConfigurationException, SAXException, IOEx
Element root = document.getDocumentElement();
String cipherText = root.getElementsByTagName("Encrypt").item(0).getTextContent();
+ System.out.println(cipherText);
+
String msgSignature = root.getElementsByTagName("MsgSignature").item(0).getTextContent();
+ System.out.println(msgSignature);
+
String timestamp = root.getElementsByTagName("TimeStamp").item(0).getTextContent();
+ System.out.println(timestamp);
+
String nonce = root.getElementsByTagName("Nonce").item(0).getTextContent();
-
+ System.out.println(nonce);
+
String messageText = String.format(xmlFormat, cipherText);
-
+ System.out.println(messageText);
+
// 第三方收到企业号平台发送的消息
String plainMessage = pc.decrypt(cipherText);
-
System.out.println(plainMessage);
+
assertEquals(plainMessage, replyMsg);
}
@@ -69,7 +77,7 @@ public void testAesEncrypt2() {
}
public void testValidateSignatureError() throws ParserConfigurationException, SAXException,
- IOException {
+ IOException {
try {
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId);
String afterEncrpt = pc.encrypt(replyMsg);
diff --git a/weixin-java-common/src/test/resources/logback-test.xml b/weixin-java-common/src/test/resources/logback-test.xml
index c0d6fc3caa..2c421e49ab 100644
--- a/weixin-java-common/src/test/resources/logback-test.xml
+++ b/weixin-java-common/src/test/resources/logback-test.xml
@@ -1,5 +1,6 @@
+
+
-
diff --git a/weixin-java-cp/build.gradle b/weixin-java-cp/build.gradle
new file mode 100644
index 0000000000..f58703ca4b
--- /dev/null
+++ b/weixin-java-cp/build.gradle
@@ -0,0 +1,12 @@
+
+description = 'WeiXin Java Tools - CP'
+dependencies {
+ compile project(':weixin-java-common')
+ testCompile group: 'junit', name: 'junit', version:'4.11'
+ testCompile group: 'org.testng', name: 'testng', version:'6.8.7'
+ testCompile group: 'org.mockito', name: 'mockito-all', version:'1.9.5'
+ testCompile group: 'com.google.inject', name: 'guice', version:'3.0'
+ testCompile group: 'org.eclipse.jetty', name: 'jetty-server', version:'9.3.0.M0'
+ testCompile group: 'org.eclipse.jetty', name: 'jetty-servlet', version:'9.3.0.M0'
+}
+test.useTestNG()
diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml
index c8ab21c9e8..7b99625670 100644
--- a/weixin-java-cp/pom.xml
+++ b/weixin-java-cp/pom.xml
@@ -6,7 +6,7 @@
com.github.binarywangweixin-java-parent
- 2.0.0
+ 2.1.0weixin-java-cp
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java
index 2b2ccf1d08..4e4ab2386e 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpConfigStorage.java
@@ -7,8 +7,8 @@
/**
* 微信客户端配置存储
- * @author Daniel Qian
*
+ * @author Daniel Qian
*/
public interface WxCpConfigStorage {
@@ -36,12 +36,13 @@ public interface WxCpConfigStorage {
/**
* 应该是线程安全的
+ *
* @param jsapiTicket
*/
void updateJsapiTicket(String jsapiTicket, int expiresInSeconds);
String getCorpId();
-
+
String getCorpSecret();
String getAgentId();
@@ -61,11 +62,12 @@ public interface WxCpConfigStorage {
String getHttp_proxy_username();
String getHttp_proxy_password();
-
+
File getTmpDirFile();
/**
* http client builder
+ *
* @return ApacheHttpClientBuilder
*/
ApacheHttpClientBuilder getApacheHttpClientBuilder();
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
index 5e0ba7774a..52d0c93bbe 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpInMemoryConfigStorage.java
@@ -7,8 +7,8 @@
/**
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化
- * @author Daniel Qian
*
+ * @author Daniel Qian
*/
public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
@@ -39,6 +39,10 @@ public String getAccessToken() {
return this.accessToken;
}
+ public void setAccessToken(String accessToken) {
+ this.accessToken = accessToken;
+ }
+
public boolean isAccessTokenExpired() {
return System.currentTimeMillis() > this.expiresTime;
}
@@ -50,7 +54,7 @@ public void expireAccessToken() {
public synchronized void updateAccessToken(WxAccessToken accessToken) {
updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
}
-
+
public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) {
this.accessToken = accessToken;
this.expiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000l;
@@ -91,28 +95,32 @@ public String getCorpId() {
return this.corpId;
}
+ public void setCorpId(String corpId) {
+ this.corpId = corpId;
+ }
+
public String getCorpSecret() {
return this.corpSecret;
}
- public String getToken() {
- return this.token;
+ public void setCorpSecret(String corpSecret) {
+ this.corpSecret = corpSecret;
}
- public long getExpiresTime() {
- return this.expiresTime;
+ public String getToken() {
+ return this.token;
}
- public void setCorpId(String corpId) {
- this.corpId = corpId;
+ public void setToken(String token) {
+ this.token = token;
}
- public void setCorpSecret(String corpSecret) {
- this.corpSecret = corpSecret;
+ public long getExpiresTime() {
+ return this.expiresTime;
}
- public void setToken(String token) {
- this.token = token;
+ public void setExpiresTime(long expiresTime) {
+ this.expiresTime = expiresTime;
}
public String getAesKey() {
@@ -123,14 +131,6 @@ public void setAesKey(String aesKey) {
this.aesKey = aesKey;
}
- public void setAccessToken(String accessToken) {
- this.accessToken = accessToken;
- }
-
- public void setExpiresTime(long expiresTime) {
- this.expiresTime = expiresTime;
- }
-
public String getAgentId() {
return agentId;
}
@@ -183,21 +183,21 @@ public void setHttp_proxy_password(String http_proxy_password) {
@Override
public String toString() {
return "WxCpInMemoryConfigStorage{" +
- "corpId='" + corpId + '\'' +
- ", corpSecret='" + corpSecret + '\'' +
- ", token='" + token + '\'' +
- ", accessToken='" + accessToken + '\'' +
- ", aesKey='" + aesKey + '\'' +
- ", agentId='" + agentId + '\'' +
- ", expiresTime=" + expiresTime +
- ", http_proxy_host='" + http_proxy_host + '\'' +
- ", http_proxy_port=" + http_proxy_port +
- ", http_proxy_username='" + http_proxy_username + '\'' +
- ", http_proxy_password='" + http_proxy_password + '\'' +
- ", jsapiTicket='" + jsapiTicket + '\'' +
- ", jsapiTicketExpiresTime='" + jsapiTicketExpiresTime + '\'' +
- ", tmpDirFile='" + tmpDirFile + '\'' +
- '}';
+ "corpId='" + corpId + '\'' +
+ ", corpSecret='" + corpSecret + '\'' +
+ ", token='" + token + '\'' +
+ ", accessToken='" + accessToken + '\'' +
+ ", aesKey='" + aesKey + '\'' +
+ ", agentId='" + agentId + '\'' +
+ ", expiresTime=" + expiresTime +
+ ", http_proxy_host='" + http_proxy_host + '\'' +
+ ", http_proxy_port=" + http_proxy_port +
+ ", http_proxy_username='" + http_proxy_username + '\'' +
+ ", http_proxy_password='" + http_proxy_password + '\'' +
+ ", jsapiTicket='" + jsapiTicket + '\'' +
+ ", jsapiTicketExpiresTime='" + jsapiTicketExpiresTime + '\'' +
+ ", tmpDirFile='" + tmpDirFile + '\'' +
+ '}';
}
public File getTmpDirFile() {
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpJedisConfigStorage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpJedisConfigStorage.java
new file mode 100644
index 0000000000..8d3b6bbdb2
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpJedisConfigStorage.java
@@ -0,0 +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 http_proxy_host;
+ private volatile int http_proxy_port;
+ private volatile String http_proxy_username;
+ private volatile String http_proxy_password;
+
+ 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 getHttp_proxy_host() {
+ return this.http_proxy_host;
+ }
+
+ @Override
+ public int getHttp_proxy_port() {
+ return this.http_proxy_port;
+ }
+
+ @Override
+ public String getHttp_proxy_username() {
+ return this.http_proxy_username;
+ }
+
+ @Override
+ public String getHttp_proxy_password() {
+ return this.http_proxy_password;
+ }
+
+ @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 setHttp_proxy_host(String http_proxy_host) {
+ this.http_proxy_host = http_proxy_host;
+ }
+
+ public void setHttp_proxy_port(int http_proxy_port) {
+ this.http_proxy_port = http_proxy_port;
+ }
+
+ public void setHttp_proxy_username(String http_proxy_username) {
+ this.http_proxy_username = http_proxy_username;
+ }
+
+ public void setHttp_proxy_password(String http_proxy_password) {
+ this.http_proxy_password = http_proxy_password;
+ }
+
+ public void setTmpDirFile(File tmpDirFile) {
+ this.tmpDirFile = tmpDirFile;
+ }
+
+ public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
+ this.apacheHttpClientBuilder = apacheHttpClientBuilder;
+ }
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageHandler.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageHandler.java
index 36649c46a2..9a3920a285 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageHandler.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageHandler.java
@@ -1,7 +1,6 @@
package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.exception.WxErrorException;
-import me.chanjar.weixin.common.session.WxSession;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java
index f7e5286ba9..bdda1886cc 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java
@@ -1,13 +1,13 @@
package me.chanjar.weixin.cp.api;
+import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
+import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
+import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
import me.chanjar.weixin.common.session.InternalSession;
import me.chanjar.weixin.common.session.InternalSessionManager;
import me.chanjar.weixin.common.session.StandardSessionManager;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.util.LogExceptionHandler;
-import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
-import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
-import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import org.slf4j.Logger;
@@ -45,15 +45,13 @@
* router.route(message);
*
*
- * @author Daniel Qian
*
+ * @author Daniel Qian
*/
public class WxCpMessageRouter {
- protected final Logger log = LoggerFactory.getLogger(WxCpMessageRouter.class);
-
private static final int DEFAULT_THREAD_POOL_SIZE = 100;
-
+ protected final Logger log = LoggerFactory.getLogger(WxCpMessageRouter.class);
private final List rules = new ArrayList();
private final WxCpService wxCpService;
@@ -79,6 +77,7 @@ public WxCpMessageRouter(WxCpService wxCpService) {
* 设置自定义的 {@link ExecutorService}
* 如果不调用该方法,默认使用 Executors.newFixedThreadPool(100)
*
+ *
* @param executorService
*/
public void setExecutorService(ExecutorService executorService) {
@@ -90,6 +89,7 @@ public void setExecutorService(ExecutorService executorService) {
* 设置自定义的 {@link me.chanjar.weixin.common.api.WxMessageDuplicateChecker}
* 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker}
*
+ *
* @param messageDuplicateChecker
*/
public void setMessageDuplicateChecker(WxMessageDuplicateChecker messageDuplicateChecker) {
@@ -101,6 +101,7 @@ public void setMessageDuplicateChecker(WxMessageDuplicateChecker messageDuplicat
* 设置自定义的{@link me.chanjar.weixin.common.session.WxSessionManager}
* 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.session.StandardSessionManager}
*
+ *
* @param sessionManager
*/
public void setSessionManager(WxSessionManager sessionManager) {
@@ -112,6 +113,7 @@ public void setSessionManager(WxSessionManager sessionManager) {
* 设置自定义的{@link me.chanjar.weixin.common.api.WxErrorExceptionHandler}
* 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.util.LogExceptionHandler}
*
+ *
* @param exceptionHandler
*/
public void setExceptionHandler(WxErrorExceptionHandler exceptionHandler) {
@@ -131,6 +133,7 @@ public WxCpMessageRouterRule rule() {
/**
* 处理微信消息
+ *
* @param wxMessage
*/
public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
@@ -144,7 +147,7 @@ public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
for (final WxCpMessageRouterRule rule : rules) {
if (rule.test(wxMessage)) {
matchRules.add(rule);
- if(!rule.isReEnter()) {
+ if (!rule.isReEnter()) {
break;
}
}
@@ -158,13 +161,13 @@ public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
final List futures = new ArrayList();
for (final WxCpMessageRouterRule rule : matchRules) {
// 返回最后一个非异步的rule的执行结果
- if(rule.isAsync()) {
+ if (rule.isAsync()) {
futures.add(
- executorService.submit(new Runnable() {
- public void run() {
- rule.service(wxMessage, wxCpService, sessionManager, exceptionHandler);
- }
- })
+ executorService.submit(new Runnable() {
+ public void run() {
+ rule.service(wxMessage, wxCpService, sessionManager, exceptionHandler);
+ }
+ })
);
} else {
res = rule.service(wxMessage, wxCpService, sessionManager, exceptionHandler);
@@ -201,10 +204,10 @@ protected boolean isDuplicateMessage(WxCpXmlMessage wxMessage) {
String messageId = "";
if (wxMessage.getMsgId() == null) {
messageId = String.valueOf(wxMessage.getCreateTime())
- + "-" +String.valueOf(wxMessage.getAgentId() == null ? "" : wxMessage.getAgentId())
- + "-" + wxMessage.getFromUserName()
- + "-" + String.valueOf(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey())
- + "-" + String.valueOf(wxMessage.getEvent() == null ? "" : wxMessage.getEvent())
+ + "-" + String.valueOf(wxMessage.getAgentId() == null ? "" : wxMessage.getAgentId())
+ + "-" + wxMessage.getFromUserName()
+ + "-" + String.valueOf(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey())
+ + "-" + String.valueOf(wxMessage.getEvent() == null ? "" : wxMessage.getEvent())
;
} else {
messageId = String.valueOf(wxMessage.getMsgId());
@@ -216,11 +219,12 @@ protected boolean isDuplicateMessage(WxCpXmlMessage wxMessage) {
/**
* 对session的访问结束
+ *
* @param wxMessage
*/
protected void sessionEndAccess(WxCpXmlMessage wxMessage) {
- InternalSession session = ((InternalSessionManager)sessionManager).findSession(wxMessage.getFromUserName());
+ InternalSession session = ((InternalSessionManager) sessionManager).findSession(wxMessage.getFromUserName());
if (session != null) {
session.endAccess();
}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java
index 6d68332309..a987841c05 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouterRule.java
@@ -1,8 +1,8 @@
package me.chanjar.weixin.cp.api;
+import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
-import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
@@ -186,7 +186,6 @@ public WxCpMessageRouterRule handler(WxCpMessageHandler handler, WxCpMessageHand
/**
* 规则结束,代表如果一个消息匹配该规则,那么它将不再会进入其他规则
- *
*/
public WxCpMessageRouter end() {
this.routerBuilder.getRules().add(this);
@@ -195,7 +194,6 @@ public WxCpMessageRouter end() {
/**
* 规则结束,但是消息还会进入其他规则
- *
*/
public WxCpMessageRouter next() {
this.reEnter = true;
@@ -204,24 +202,24 @@ public WxCpMessageRouter next() {
protected boolean test(WxCpXmlMessage wxMessage) {
return
- (this.fromUser == null || this.fromUser.equals(wxMessage.getFromUserName()))
- &&
- (this.agentId == null || this.agentId.equals(wxMessage.getAgentId()))
- &&
- (this.msgType == null || this.msgType.equals(wxMessage.getMsgType()))
- &&
- (this.event == null || this.event.equals(wxMessage.getEvent()))
- &&
- (this.eventKey == null || this.eventKey.equals(wxMessage.getEventKey()))
- &&
- (this.content == null || this.content
- .equals(wxMessage.getContent() == null ? null : wxMessage.getContent().trim()))
- &&
- (this.rContent == null || Pattern
- .matches(this.rContent, wxMessage.getContent() == null ? "" : wxMessage.getContent().trim()))
- &&
- (this.matcher == null || this.matcher.match(wxMessage))
- ;
+ (this.fromUser == null || this.fromUser.equals(wxMessage.getFromUserName()))
+ &&
+ (this.agentId == null || this.agentId.equals(wxMessage.getAgentId()))
+ &&
+ (this.msgType == null || this.msgType.equals(wxMessage.getMsgType()))
+ &&
+ (this.event == null || this.event.equals(wxMessage.getEvent()))
+ &&
+ (this.eventKey == null || this.eventKey.equals(wxMessage.getEventKey()))
+ &&
+ (this.content == null || this.content
+ .equals(wxMessage.getContent() == null ? null : wxMessage.getContent().trim()))
+ &&
+ (this.rContent == null || Pattern
+ .matches(this.rContent, wxMessage.getContent() == null ? "" : wxMessage.getContent().trim()))
+ &&
+ (this.matcher == null || this.matcher.match(wxMessage))
+ ;
}
/**
@@ -231,9 +229,9 @@ protected boolean test(WxCpXmlMessage wxMessage) {
* @return true 代表继续执行别的router,false 代表停止执行别的router
*/
protected WxCpXmlOutMessage service(WxCpXmlMessage wxMessage,
- WxCpService wxCpService,
- WxSessionManager sessionManager,
- WxErrorExceptionHandler exceptionHandler) {
+ WxCpService wxCpService,
+ WxSessionManager sessionManager,
+ WxErrorExceptionHandler exceptionHandler) {
try {
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java
index 7cf9332a7e..e6f8f2ad2f 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java
@@ -1,7 +1,7 @@
package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
-import me.chanjar.weixin.common.bean.WxMenu;
+import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSession;
@@ -47,8 +47,9 @@ public interface WxCpService {
/**
* 获取access_token, 不强制刷新access_token
- * @see #getAccessToken(boolean)
+ *
* @throws WxErrorException
+ * @see #getAccessToken(boolean)
*/
String getAccessToken() throws WxErrorException;
@@ -60,6 +61,7 @@ public interface WxCpService {
* 程序员在非必要情况下尽量不要主动调用此方法
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
*
+ *
* @param forceRefresh 强制刷新
* @throws me.chanjar.weixin.common.exception.WxErrorException
*/
@@ -67,8 +69,9 @@ public interface WxCpService {
/**
* 获得jsapi_ticket,不强制刷新jsapi_ticket
- * @see #getJsapiTicket(boolean)
+ *
* @throws WxErrorException
+ * @see #getJsapiTicket(boolean)
*/
String getJsapiTicket() throws WxErrorException;
@@ -79,6 +82,7 @@ public interface WxCpService {
*
* 详情请见:http://qydev.weixin.qq.com/wiki/index.php?title=微信JS接口#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95
*
+ *
* @param forceRefresh 强制刷新
* @throws WxErrorException
*/
@@ -90,7 +94,8 @@ public interface WxCpService {
*
* 详情请见:http://qydev.weixin.qq.com/wiki/index.php?title=微信JS接口#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95
*
- * @param url url
+ *
+ * @param url url
*/
WxJsapiSignature createJsapiSignature(String url) throws WxErrorException;
@@ -111,7 +116,7 @@ public interface WxCpService {
* @throws WxErrorException
*/
WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream inputStream)
- throws WxErrorException, IOException;
+ throws WxErrorException, IOException;
/**
* @param mediaType
@@ -128,9 +133,9 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
*
*
+ * @param media_id
* @return 保存到本地的临时文件
* @throws WxErrorException
- * @param media_id
*/
File mediaDownload(String media_id) throws WxErrorException;
@@ -152,10 +157,10 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
*
* 注意: 这个方法使用WxCpConfigStorage里的agentId
*
- * @see #menuCreate(String, me.chanjar.weixin.common.bean.WxMenu)
*
* @param menu
* @throws WxErrorException
+ * @see #menuCreate(String, me.chanjar.weixin.common.bean.menu.WxMenu)
*/
void menuCreate(WxMenu menu) throws WxErrorException;
@@ -166,11 +171,11 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
*
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
*
- * @see #menuCreate(me.chanjar.weixin.common.bean.WxMenu)
*
* @param agentId 企业号应用的id
* @param menu
* @throws WxErrorException
+ * @see #menuCreate(me.chanjar.weixin.common.bean.menu.WxMenu)
*/
void menuCreate(String agentId, WxMenu menu) throws WxErrorException;
@@ -181,9 +186,9 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
*
* 注意: 这个方法使用WxCpConfigStorage里的agentId
*
- * @see #menuDelete(String)
*
* @throws WxErrorException
+ * @see #menuDelete(String)
*/
void menuDelete() throws WxErrorException;
@@ -194,10 +199,10 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
*
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
*
- * @see #menuDelete()
*
* @param agentId 企业号应用的id
* @throws WxErrorException
+ * @see #menuDelete()
*/
void menuDelete(String agentId) throws WxErrorException;
@@ -208,9 +213,9 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
*
* 注意: 这个方法使用WxCpConfigStorage里的agentId
*
- * @see #menuGet(String)
*
* @throws WxErrorException
+ * @see #menuGet(String)
*/
WxMenu menuGet() throws WxErrorException;
@@ -221,10 +226,10 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
*
* 注意: 这个方法不使用WxCpConfigStorage里的agentId,需要开发人员自己给出
*
- * @see #menuGet()
*
* @param agentId 企业号应用的id
* @throws WxErrorException
+ * @see #menuGet()
*/
WxMenu menuGet(String agentId) throws WxErrorException;
@@ -279,9 +284,10 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
*
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98.28.E8.AF.A6.E6.83.85.29
*
- * @param departId 必填。部门id
- * @param fetchChild 非必填。1/0:是否递归获取子部门下面的成员
- * @param status 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加
+ *
+ * @param departId 必填。部门id
+ * @param fetchChild 非必填。1/0:是否递归获取子部门下面的成员
+ * @param status 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加
* @throws WxErrorException
*/
List userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException;
@@ -330,7 +336,8 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
*
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98
*
- * @param userids 员工UserID列表。对应管理端的帐号
+ *
+ * @param userids 员工UserID列表。对应管理端的帐号
* @throws WxErrorException
*/
void userDelete(String[] userids) throws WxErrorException;
@@ -367,7 +374,6 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
/**
* 获得标签列表
- *
*/
List tagGet() throws WxErrorException;
@@ -386,11 +392,22 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
*/
void tagAddUsers(String tagId, List userIds, List partyIds) throws WxErrorException;
+ /**
+ *