@@ -61,7 +61,7 @@ public class WxConsts { | |||||
/** | /** | ||||
* 群发反馈消息代码所对应的文字描述 | * 群发反馈消息代码所对应的文字描述 | ||||
*/ | */ | ||||
public static final Map<String, String> MASS_ST_2_DESC = new HashMap<String, String>(); | |||||
public static final Map<String, String> MASS_ST_2_DESC = new HashMap<>(); | |||||
/////////////////////// | /////////////////////// | ||||
// 微信端推送过来的事件类型 | // 微信端推送过来的事件类型 | ||||
/////////////////////// | /////////////////////// | ||||
@@ -25,7 +25,7 @@ public class WxMessageInMemoryDuplicateChecker implements WxMessageDuplicateChec | |||||
/** | /** | ||||
* 消息id->消息时间戳的map | * 消息id->消息时间戳的map | ||||
*/ | */ | ||||
private final ConcurrentHashMap<String, Long> msgId2Timestamp = new ConcurrentHashMap<String, Long>(); | |||||
private final ConcurrentHashMap<String, Long> msgId2Timestamp = new ConcurrentHashMap<>(); | |||||
/** | /** | ||||
* 后台清理线程是否已经开启 | * 后台清理线程是否已经开启 | ||||
@@ -56,7 +56,7 @@ public class WxMessageInMemoryDuplicateChecker implements WxMessageDuplicateChec | |||||
} | } | ||||
protected void checkBackgroundProcessStarted() { | protected void checkBackgroundProcessStarted() { | ||||
if (backgroundProcessStarted.getAndSet(true)) { | |||||
if (this.backgroundProcessStarted.getAndSet(true)) { | |||||
return; | return; | ||||
} | } | ||||
Thread t = new Thread(new Runnable() { | Thread t = new Thread(new Runnable() { | ||||
@@ -64,11 +64,11 @@ public class WxMessageInMemoryDuplicateChecker implements WxMessageDuplicateChec | |||||
public void run() { | public void run() { | ||||
try { | try { | ||||
while (true) { | while (true) { | ||||
Thread.sleep(clearPeriod); | |||||
Thread.sleep(WxMessageInMemoryDuplicateChecker.this.clearPeriod); | |||||
Long now = System.currentTimeMillis(); | Long now = System.currentTimeMillis(); | ||||
for (Map.Entry<String, Long> entry : msgId2Timestamp.entrySet()) { | |||||
if (now - entry.getValue() > timeToLive) { | |||||
msgId2Timestamp.entrySet().remove(entry); | |||||
for (Map.Entry<String, Long> entry : WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet()) { | |||||
if (now - entry.getValue() > WxMessageInMemoryDuplicateChecker.this.timeToLive) { | |||||
WxMessageInMemoryDuplicateChecker.this.msgId2Timestamp.entrySet().remove(entry); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -87,7 +87,7 @@ public class WxMessageInMemoryDuplicateChecker implements WxMessageDuplicateChec | |||||
return false; | return false; | ||||
} | } | ||||
checkBackgroundProcessStarted(); | checkBackgroundProcessStarted(); | ||||
Long timestamp = msgId2Timestamp.putIfAbsent(messageId, System.currentTimeMillis()); | |||||
Long timestamp = this.msgId2Timestamp.putIfAbsent(messageId, System.currentTimeMillis()); | |||||
return timestamp != null; | return timestamp != null; | ||||
} | } | ||||
@@ -16,7 +16,7 @@ public class WxAccessToken implements Serializable { | |||||
} | } | ||||
public String getAccessToken() { | public String getAccessToken() { | ||||
return accessToken; | |||||
return this.accessToken; | |||||
} | } | ||||
public void setAccessToken(String accessToken) { | public void setAccessToken(String accessToken) { | ||||
@@ -24,7 +24,7 @@ public class WxAccessToken implements Serializable { | |||||
} | } | ||||
public int getExpiresIn() { | public int getExpiresIn() { | ||||
return expiresIn; | |||||
return this.expiresIn; | |||||
} | } | ||||
public void setExpiresIn(int expiresIn) { | public void setExpiresIn(int expiresIn) { | ||||
@@ -39,7 +39,7 @@ public class WxCardApiSignature implements Serializable { | |||||
} | } | ||||
public String getAppId() { | public String getAppId() { | ||||
return appId; | |||||
return this.appId; | |||||
} | } | ||||
public void setAppId(String appId) { | public void setAppId(String appId) { | ||||
@@ -47,7 +47,7 @@ public class WxCardApiSignature implements Serializable { | |||||
} | } | ||||
public String getCardId() { | public String getCardId() { | ||||
return cardId; | |||||
return this.cardId; | |||||
} | } | ||||
public void setCardId(String cardId) { | public void setCardId(String cardId) { | ||||
@@ -55,7 +55,7 @@ public class WxCardApiSignature implements Serializable { | |||||
} | } | ||||
public String getCardType() { | public String getCardType() { | ||||
return cardType; | |||||
return this.cardType; | |||||
} | } | ||||
public void setCardType(String cardType) { | public void setCardType(String cardType) { | ||||
@@ -63,7 +63,7 @@ public class WxCardApiSignature implements Serializable { | |||||
} | } | ||||
public String getLocationId() { | public String getLocationId() { | ||||
return locationId; | |||||
return this.locationId; | |||||
} | } | ||||
public void setLocationId(String locationId) { | public void setLocationId(String locationId) { | ||||
@@ -71,7 +71,7 @@ public class WxCardApiSignature implements Serializable { | |||||
} | } | ||||
public String getCode() { | public String getCode() { | ||||
return code; | |||||
return this.code; | |||||
} | } | ||||
public void setCode(String code) { | public void setCode(String code) { | ||||
@@ -79,7 +79,7 @@ public class WxCardApiSignature implements Serializable { | |||||
} | } | ||||
public String getOpenId() { | public String getOpenId() { | ||||
return openId; | |||||
return this.openId; | |||||
} | } | ||||
public void setOpenId(String openId) { | public void setOpenId(String openId) { | ||||
@@ -87,7 +87,7 @@ public class WxCardApiSignature implements Serializable { | |||||
} | } | ||||
public Long getTimestamp() { | public Long getTimestamp() { | ||||
return timestamp; | |||||
return this.timestamp; | |||||
} | } | ||||
public void setTimestamp(Long timestamp) { | public void setTimestamp(Long timestamp) { | ||||
@@ -95,7 +95,7 @@ public class WxCardApiSignature implements Serializable { | |||||
} | } | ||||
public String getNonceStr() { | public String getNonceStr() { | ||||
return nonceStr; | |||||
return this.nonceStr; | |||||
} | } | ||||
public void setNonceStr(String nonceStr) { | public void setNonceStr(String nonceStr) { | ||||
@@ -103,7 +103,7 @@ public class WxCardApiSignature implements Serializable { | |||||
} | } | ||||
public String getSignature() { | public String getSignature() { | ||||
return signature; | |||||
return this.signature; | |||||
} | } | ||||
public void setSignature(String signature) { | public void setSignature(String signature) { | ||||
@@ -19,7 +19,7 @@ public class WxJsapiSignature implements Serializable { | |||||
private String signature; | private String signature; | ||||
public String getSignature() { | public String getSignature() { | ||||
return signature; | |||||
return this.signature; | |||||
} | } | ||||
public void setSignature(String signature) { | public void setSignature(String signature) { | ||||
@@ -27,7 +27,7 @@ public class WxJsapiSignature implements Serializable { | |||||
} | } | ||||
public String getNoncestr() { | public String getNoncestr() { | ||||
return noncestr; | |||||
return this.noncestr; | |||||
} | } | ||||
public void setNoncestr(String noncestr) { | public void setNoncestr(String noncestr) { | ||||
@@ -35,7 +35,7 @@ public class WxJsapiSignature implements Serializable { | |||||
} | } | ||||
public long getTimestamp() { | public long getTimestamp() { | ||||
return timestamp; | |||||
return this.timestamp; | |||||
} | } | ||||
public void setTimestamp(long timestamp) { | public void setTimestamp(long timestamp) { | ||||
@@ -43,7 +43,7 @@ public class WxJsapiSignature implements Serializable { | |||||
} | } | ||||
public String getUrl() { | public String getUrl() { | ||||
return url; | |||||
return this.url; | |||||
} | } | ||||
public void setUrl(String url) { | public void setUrl(String url) { | ||||
@@ -51,7 +51,7 @@ public class WxJsapiSignature implements Serializable { | |||||
} | } | ||||
public String getAppid() { | public String getAppid() { | ||||
return appid; | |||||
return this.appid; | |||||
} | } | ||||
public void setAppid(String appid) { | public void setAppid(String appid) { | ||||
@@ -19,7 +19,7 @@ public class WxMenu implements Serializable { | |||||
private static final long serialVersionUID = -7083914585539687746L; | private static final long serialVersionUID = -7083914585539687746L; | ||||
private List<WxMenuButton> buttons = new ArrayList<WxMenuButton>(); | |||||
private List<WxMenuButton> buttons = new ArrayList<>(); | |||||
private WxMenuRule matchRule; | private WxMenuRule matchRule; | ||||
@@ -40,7 +40,7 @@ public class WxMenu implements Serializable { | |||||
} | } | ||||
public List<WxMenuButton> getButtons() { | public List<WxMenuButton> getButtons() { | ||||
return buttons; | |||||
return this.buttons; | |||||
} | } | ||||
public void setButtons(List<WxMenuButton> buttons) { | public void setButtons(List<WxMenuButton> buttons) { | ||||
@@ -48,7 +48,7 @@ public class WxMenu implements Serializable { | |||||
} | } | ||||
public WxMenuRule getMatchRule() { | public WxMenuRule getMatchRule() { | ||||
return matchRule; | |||||
return this.matchRule; | |||||
} | } | ||||
public void setMatchRule(WxMenuRule matchRule) { | public void setMatchRule(WxMenuRule matchRule) { | ||||
@@ -62,7 +62,7 @@ public class WxMenu implements Serializable { | |||||
@Override | @Override | ||||
public String toString() { | public String toString() { | ||||
return "WxMenu{" + | return "WxMenu{" + | ||||
"buttons=" + buttons + | |||||
"buttons=" + this.buttons + | |||||
'}'; | '}'; | ||||
} | } | ||||
@@ -14,7 +14,7 @@ public class WxMenuButton { | |||||
private String url; | private String url; | ||||
private String mediaId; | private String mediaId; | ||||
private List<WxMenuButton> subButtons = new ArrayList<WxMenuButton>(); | |||||
private List<WxMenuButton> subButtons = new ArrayList<>(); | |||||
@Override | @Override | ||||
public String toString() { | public String toString() { | ||||
@@ -23,7 +23,7 @@ public class WxMenuButton { | |||||
} | } | ||||
public String getType() { | public String getType() { | ||||
return type; | |||||
return this.type; | |||||
} | } | ||||
public void setType(String type) { | public void setType(String type) { | ||||
@@ -31,7 +31,7 @@ public class WxMenuButton { | |||||
} | } | ||||
public String getName() { | public String getName() { | ||||
return name; | |||||
return this.name; | |||||
} | } | ||||
public void setName(String name) { | public void setName(String name) { | ||||
@@ -39,7 +39,7 @@ public class WxMenuButton { | |||||
} | } | ||||
public String getKey() { | public String getKey() { | ||||
return key; | |||||
return this.key; | |||||
} | } | ||||
public void setKey(String key) { | public void setKey(String key) { | ||||
@@ -47,7 +47,7 @@ public class WxMenuButton { | |||||
} | } | ||||
public String getUrl() { | public String getUrl() { | ||||
return url; | |||||
return this.url; | |||||
} | } | ||||
public void setUrl(String url) { | public void setUrl(String url) { | ||||
@@ -55,7 +55,7 @@ public class WxMenuButton { | |||||
} | } | ||||
public List<WxMenuButton> getSubButtons() { | public List<WxMenuButton> getSubButtons() { | ||||
return subButtons; | |||||
return this.subButtons; | |||||
} | } | ||||
public void setSubButtons(List<WxMenuButton> subButtons) { | public void setSubButtons(List<WxMenuButton> subButtons) { | ||||
@@ -63,7 +63,7 @@ public class WxMenuButton { | |||||
} | } | ||||
public String getMediaId() { | public String getMediaId() { | ||||
return mediaId; | |||||
return this.mediaId; | |||||
} | } | ||||
public void setMediaId(String mediaId) { | public void setMediaId(String mediaId) { | ||||
@@ -13,7 +13,7 @@ public class WxMenuRule { | |||||
private String language; | private String language; | ||||
public String getTagId() { | public String getTagId() { | ||||
return tagId; | |||||
return this.tagId; | |||||
} | } | ||||
public void setTagId(String tagId) { | public void setTagId(String tagId) { | ||||
@@ -21,7 +21,7 @@ public class WxMenuRule { | |||||
} | } | ||||
public String getSex() { | public String getSex() { | ||||
return sex; | |||||
return this.sex; | |||||
} | } | ||||
public void setSex(String sex) { | public void setSex(String sex) { | ||||
@@ -29,7 +29,7 @@ public class WxMenuRule { | |||||
} | } | ||||
public String getCountry() { | public String getCountry() { | ||||
return country; | |||||
return this.country; | |||||
} | } | ||||
public void setCountry(String country) { | public void setCountry(String country) { | ||||
@@ -37,7 +37,7 @@ public class WxMenuRule { | |||||
} | } | ||||
public String getProvince() { | public String getProvince() { | ||||
return province; | |||||
return this.province; | |||||
} | } | ||||
public void setProvince(String province) { | public void setProvince(String province) { | ||||
@@ -45,7 +45,7 @@ public class WxMenuRule { | |||||
} | } | ||||
public String getCity() { | public String getCity() { | ||||
return city; | |||||
return this.city; | |||||
} | } | ||||
public void setCity(String city) { | public void setCity(String city) { | ||||
@@ -53,7 +53,7 @@ public class WxMenuRule { | |||||
} | } | ||||
public String getClientPlatformType() { | public String getClientPlatformType() { | ||||
return clientPlatformType; | |||||
return this.clientPlatformType; | |||||
} | } | ||||
public void setClientPlatformType(String clientPlatformType) { | public void setClientPlatformType(String clientPlatformType) { | ||||
@@ -61,7 +61,7 @@ public class WxMenuRule { | |||||
} | } | ||||
public String getLanguage() { | public String getLanguage() { | ||||
return language; | |||||
return this.language; | |||||
} | } | ||||
public void setLanguage(String language) { | public void setLanguage(String language) { | ||||
@@ -29,7 +29,7 @@ public class WxError implements Serializable { | |||||
} | } | ||||
public int getErrorCode() { | public int getErrorCode() { | ||||
return errorCode; | |||||
return this.errorCode; | |||||
} | } | ||||
public void setErrorCode(int errorCode) { | public void setErrorCode(int errorCode) { | ||||
@@ -37,7 +37,7 @@ public class WxError implements Serializable { | |||||
} | } | ||||
public String getErrorMsg() { | public String getErrorMsg() { | ||||
return errorMsg; | |||||
return this.errorMsg; | |||||
} | } | ||||
public void setErrorMsg(String errorMsg) { | public void setErrorMsg(String errorMsg) { | ||||
@@ -45,7 +45,7 @@ public class WxError implements Serializable { | |||||
} | } | ||||
public String getJson() { | public String getJson() { | ||||
return json; | |||||
return this.json; | |||||
} | } | ||||
public void setJson(String json) { | public void setJson(String json) { | ||||
@@ -54,10 +54,10 @@ public class WxError implements Serializable { | |||||
@Override | @Override | ||||
public String toString() { | public String toString() { | ||||
if (json != null) { | |||||
return json; | |||||
if (this.json != null) { | |||||
return this.json; | |||||
} | } | ||||
return "错误: Code=" + errorCode + ", Msg=" + errorMsg; | |||||
return "错误: Code=" + this.errorCode + ", Msg=" + this.errorMsg; | |||||
} | } | ||||
public static class Builder { | public static class Builder { | ||||
@@ -17,7 +17,7 @@ public class WxMediaUploadResult implements Serializable { | |||||
} | } | ||||
public String getType() { | public String getType() { | ||||
return type; | |||||
return this.type; | |||||
} | } | ||||
public void setType(String type) { | public void setType(String type) { | ||||
@@ -25,7 +25,7 @@ public class WxMediaUploadResult implements Serializable { | |||||
} | } | ||||
public String getMediaId() { | public String getMediaId() { | ||||
return mediaId; | |||||
return this.mediaId; | |||||
} | } | ||||
public void setMediaId(String mediaId) { | public void setMediaId(String mediaId) { | ||||
@@ -33,7 +33,7 @@ public class WxMediaUploadResult implements Serializable { | |||||
} | } | ||||
public long getCreatedAt() { | public long getCreatedAt() { | ||||
return createdAt; | |||||
return this.createdAt; | |||||
} | } | ||||
public void setCreatedAt(long createdAt) { | public void setCreatedAt(long createdAt) { | ||||
@@ -41,7 +41,7 @@ public class WxMediaUploadResult implements Serializable { | |||||
} | } | ||||
public String getThumbMediaId() { | public String getThumbMediaId() { | ||||
return thumbMediaId; | |||||
return this.thumbMediaId; | |||||
} | } | ||||
public void setThumbMediaId(String thumbMediaId) { | public void setThumbMediaId(String thumbMediaId) { | ||||
@@ -50,8 +50,8 @@ public class WxMediaUploadResult implements Serializable { | |||||
@Override | @Override | ||||
public String toString() { | public String toString() { | ||||
return "WxUploadResult [type=" + type + ", media_id=" + mediaId + ", thumb_media_id=" + thumbMediaId | |||||
+ ", created_at=" + createdAt + "]"; | |||||
return "WxUploadResult [type=" + this.type + ", media_id=" + this.mediaId + ", thumb_media_id=" + this.thumbMediaId | |||||
+ ", created_at=" + this.createdAt + "]"; | |||||
} | } | ||||
} | } |
@@ -14,7 +14,7 @@ public class WxErrorException extends Exception { | |||||
} | } | ||||
public WxError getError() { | public WxError getError() { | ||||
return error; | |||||
return this.error; | |||||
} | } | ||||
@@ -18,7 +18,7 @@ public class StandardSession implements WxSession, InternalSession { | |||||
*/ | */ | ||||
protected static final String EMPTY_ARRAY[] = new String[0]; | protected static final String EMPTY_ARRAY[] = new String[0]; | ||||
// ------------------------------ WxSession | // ------------------------------ WxSession | ||||
protected Map<String, Object> attributes = new ConcurrentHashMap<String, Object>(); | |||||
protected Map<String, Object> attributes = new ConcurrentHashMap<>(); | |||||
/** | /** | ||||
* The session identifier of this Session. | * The session identifier of this Session. | ||||
*/ | */ | ||||
@@ -47,7 +47,7 @@ public class StandardSession implements WxSession, InternalSession { | |||||
/** | /** | ||||
* The current accessed time for this session. | * The current accessed time for this session. | ||||
*/ | */ | ||||
protected volatile long thisAccessedTime = creationTime; | |||||
protected volatile long thisAccessedTime = this.creationTime; | |||||
/** | /** | ||||
* The default maximum inactive interval for Sessions created by | * The default maximum inactive interval for Sessions created by | ||||
* this Manager. | * this Manager. | ||||
@@ -77,7 +77,7 @@ public class StandardSession implements WxSession, InternalSession { | |||||
if (name == null) return null; | if (name == null) return null; | ||||
return (attributes.get(name)); | |||||
return (this.attributes.get(name)); | |||||
} | } | ||||
@Override | @Override | ||||
@@ -86,8 +86,8 @@ public class StandardSession implements WxSession, InternalSession { | |||||
throw new IllegalStateException | throw new IllegalStateException | ||||
(sm.getString("sessionImpl.getAttributeNames.ise")); | (sm.getString("sessionImpl.getAttributeNames.ise")); | ||||
Set<String> names = new HashSet<String>(); | |||||
names.addAll(attributes.keySet()); | |||||
Set<String> names = new HashSet<>(); | |||||
names.addAll(this.attributes.keySet()); | |||||
return Collections.enumeration(names); | return Collections.enumeration(names); | ||||
} | } | ||||
@@ -109,7 +109,7 @@ public class StandardSession implements WxSession, InternalSession { | |||||
throw new IllegalStateException(sm.getString( | throw new IllegalStateException(sm.getString( | ||||
"sessionImpl.setAttribute.ise", getIdInternal())); | "sessionImpl.setAttribute.ise", getIdInternal())); | ||||
attributes.put(name, value); | |||||
this.attributes.put(name, value); | |||||
} | } | ||||
@@ -132,10 +132,10 @@ public class StandardSession implements WxSession, InternalSession { | |||||
@Override | @Override | ||||
public WxSession getSession() { | public WxSession getSession() { | ||||
if (facade == null) { | |||||
facade = new StandardSessionFacade(this); | |||||
if (this.facade == null) { | |||||
this.facade = new StandardSessionFacade(this); | |||||
} | } | ||||
return (facade); | |||||
return (this.facade); | |||||
} | } | ||||
@@ -157,15 +157,15 @@ public class StandardSession implements WxSession, InternalSession { | |||||
return true; | return true; | ||||
} | } | ||||
if (accessCount.get() > 0) { | |||||
if (this.accessCount.get() > 0) { | |||||
return true; | return true; | ||||
} | } | ||||
if (maxInactiveInterval > 0) { | |||||
if (this.maxInactiveInterval > 0) { | |||||
long timeNow = System.currentTimeMillis(); | long timeNow = System.currentTimeMillis(); | ||||
int timeIdle; | int timeIdle; | ||||
timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L); | |||||
if (timeIdle >= maxInactiveInterval) { | |||||
timeIdle = (int) ((timeNow - this.thisAccessedTime) / 1000L); | |||||
if (timeIdle >= this.maxInactiveInterval) { | |||||
expire(); | expire(); | ||||
} | } | ||||
} | } | ||||
@@ -193,7 +193,7 @@ public class StandardSession implements WxSession, InternalSession { | |||||
if (name == null) return; | if (name == null) return; | ||||
// Remove this attribute from our collection | // Remove this attribute from our collection | ||||
attributes.remove(name); | |||||
this.attributes.remove(name); | |||||
} | } | ||||
@@ -202,7 +202,7 @@ public class StandardSession implements WxSession, InternalSession { | |||||
// Check to see if session has already been invalidated. | // Check to see if session has already been invalidated. | ||||
// Do not check expiring at this point as expire should not return until | // Do not check expiring at this point as expire should not return until | ||||
// isValid is false | // isValid is false | ||||
if (!isValid) | |||||
if (!this.isValid) | |||||
return; | return; | ||||
synchronized (this) { | synchronized (this) { | ||||
@@ -210,24 +210,24 @@ public class StandardSession implements WxSession, InternalSession { | |||||
// Double check locking - isValid needs to be volatile | // Double check locking - isValid needs to be volatile | ||||
// The check of expiring is to ensure that an infinite loop is not | // The check of expiring is to ensure that an infinite loop is not | ||||
// entered as per bug 56339 | // entered as per bug 56339 | ||||
if (expiring || !isValid) | |||||
if (this.expiring || !this.isValid) | |||||
return; | return; | ||||
if (manager == null) | |||||
if (this.manager == null) | |||||
return; | return; | ||||
// Mark this session as "being expired" | // Mark this session as "being expired" | ||||
expiring = true; | |||||
this.expiring = true; | |||||
accessCount.set(0); | |||||
this.accessCount.set(0); | |||||
// Remove this session from our manager's active sessions | // Remove this session from our manager's active sessions | ||||
manager.remove(this, true); | |||||
this.manager.remove(this, true); | |||||
// We have completed expire of this session | // We have completed expire of this session | ||||
setValid(false); | setValid(false); | ||||
expiring = false; | |||||
this.expiring = false; | |||||
// Unbind any objects associated with this session | // Unbind any objects associated with this session | ||||
String keys[] = keys(); | String keys[] = keys(); | ||||
@@ -244,7 +244,7 @@ public class StandardSession implements WxSession, InternalSession { | |||||
public void access() { | public void access() { | ||||
this.thisAccessedTime = System.currentTimeMillis(); | this.thisAccessedTime = System.currentTimeMillis(); | ||||
accessCount.incrementAndGet(); | |||||
this.accessCount.incrementAndGet(); | |||||
} | } | ||||
@@ -253,7 +253,7 @@ public class StandardSession implements WxSession, InternalSession { | |||||
public void endAccess() { | public void endAccess() { | ||||
this.thisAccessedTime = System.currentTimeMillis(); | this.thisAccessedTime = System.currentTimeMillis(); | ||||
accessCount.decrementAndGet(); | |||||
this.accessCount.decrementAndGet(); | |||||
} | } | ||||
@@ -273,13 +273,13 @@ public class StandardSession implements WxSession, InternalSession { | |||||
@Override | @Override | ||||
public void setId(String id) { | public void setId(String id) { | ||||
if ((this.id != null) && (manager != null)) | |||||
manager.remove(this); | |||||
if ((this.id != null) && (this.manager != null)) | |||||
this.manager.remove(this); | |||||
this.id = id; | this.id = id; | ||||
if (manager != null) | |||||
manager.add(this); | |||||
if (this.manager != null) | |||||
this.manager.add(this); | |||||
} | } | ||||
/** | /** | ||||
@@ -289,7 +289,7 @@ public class StandardSession implements WxSession, InternalSession { | |||||
*/ | */ | ||||
protected String[] keys() { | protected String[] keys() { | ||||
return attributes.keySet().toArray(EMPTY_ARRAY); | |||||
return this.attributes.keySet().toArray(EMPTY_ARRAY); | |||||
} | } | ||||
@@ -300,31 +300,31 @@ public class StandardSession implements WxSession, InternalSession { | |||||
StandardSession session = (StandardSession) o; | StandardSession session = (StandardSession) o; | ||||
if (creationTime != session.creationTime) return false; | |||||
if (expiring != session.expiring) return false; | |||||
if (isValid != session.isValid) return false; | |||||
if (maxInactiveInterval != session.maxInactiveInterval) return false; | |||||
if (thisAccessedTime != session.thisAccessedTime) return false; | |||||
if (!accessCount.equals(session.accessCount)) return false; | |||||
if (!attributes.equals(session.attributes)) return false; | |||||
if (!facade.equals(session.facade)) return false; | |||||
if (!id.equals(session.id)) return false; | |||||
return manager.equals(session.manager); | |||||
if (this.creationTime != session.creationTime) return false; | |||||
if (this.expiring != session.expiring) return false; | |||||
if (this.isValid != session.isValid) return false; | |||||
if (this.maxInactiveInterval != session.maxInactiveInterval) return false; | |||||
if (this.thisAccessedTime != session.thisAccessedTime) return false; | |||||
if (!this.accessCount.equals(session.accessCount)) return false; | |||||
if (!this.attributes.equals(session.attributes)) return false; | |||||
if (!this.facade.equals(session.facade)) return false; | |||||
if (!this.id.equals(session.id)) return false; | |||||
return this.manager.equals(session.manager); | |||||
} | } | ||||
@Override | @Override | ||||
public int hashCode() { | public int hashCode() { | ||||
int result = attributes.hashCode(); | |||||
result = 31 * result + id.hashCode(); | |||||
result = 31 * result + (isValid ? 1 : 0); | |||||
result = 31 * result + (expiring ? 1 : 0); | |||||
result = 31 * result + manager.hashCode(); | |||||
result = 31 * result + (int) (creationTime ^ (creationTime >>> 32)); | |||||
result = 31 * result + (int) (thisAccessedTime ^ (thisAccessedTime >>> 32)); | |||||
result = 31 * result + maxInactiveInterval; | |||||
result = 31 * result + facade.hashCode(); | |||||
result = 31 * result + accessCount.hashCode(); | |||||
int result = this.attributes.hashCode(); | |||||
result = 31 * result + this.id.hashCode(); | |||||
result = 31 * result + (this.isValid ? 1 : 0); | |||||
result = 31 * result + (this.expiring ? 1 : 0); | |||||
result = 31 * result + this.manager.hashCode(); | |||||
result = 31 * result + (int) (this.creationTime ^ (this.creationTime >>> 32)); | |||||
result = 31 * result + (int) (this.thisAccessedTime ^ (this.thisAccessedTime >>> 32)); | |||||
result = 31 * result + this.maxInactiveInterval; | |||||
result = 31 * result + this.facade.hashCode(); | |||||
result = 31 * result + this.accessCount.hashCode(); | |||||
return result; | return result; | ||||
} | } | ||||
@@ -14,32 +14,32 @@ public class StandardSessionFacade implements WxSession { | |||||
} | } | ||||
public InternalSession getInternalSession() { | public InternalSession getInternalSession() { | ||||
return (InternalSession) session; | |||||
return (InternalSession) this.session; | |||||
} | } | ||||
@Override | @Override | ||||
public Object getAttribute(String name) { | public Object getAttribute(String name) { | ||||
return session.getAttribute(name); | |||||
return this.session.getAttribute(name); | |||||
} | } | ||||
@Override | @Override | ||||
public Enumeration<String> getAttributeNames() { | public Enumeration<String> getAttributeNames() { | ||||
return session.getAttributeNames(); | |||||
return this.session.getAttributeNames(); | |||||
} | } | ||||
@Override | @Override | ||||
public void setAttribute(String name, Object value) { | public void setAttribute(String name, Object value) { | ||||
session.setAttribute(name, value); | |||||
this.session.setAttribute(name, value); | |||||
} | } | ||||
@Override | @Override | ||||
public void removeAttribute(String name) { | public void removeAttribute(String name) { | ||||
session.removeAttribute(name); | |||||
this.session.removeAttribute(name); | |||||
} | } | ||||
@Override | @Override | ||||
public void invalidate() { | public void invalidate() { | ||||
session.invalidate(); | |||||
this.session.invalidate(); | |||||
} | } | ||||
} | } |
@@ -32,7 +32,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | |||||
* The set of currently active Sessions for this Manager, keyed by | * The set of currently active Sessions for this Manager, keyed by | ||||
* session identifier. | * session identifier. | ||||
*/ | */ | ||||
protected Map<String, InternalSession> sessions = new ConcurrentHashMap<String, InternalSession>(); | |||||
protected Map<String, InternalSession> sessions = new ConcurrentHashMap<>(); | |||||
/** | /** | ||||
* The maximum number of active Sessions allowed, or -1 for no limit. | * The maximum number of active Sessions allowed, or -1 for no limit. | ||||
*/ | */ | ||||
@@ -117,7 +117,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | |||||
@Override | @Override | ||||
public void remove(InternalSession session, boolean update) { | public void remove(InternalSession session, boolean update) { | ||||
if (session.getIdInternal() != null) { | if (session.getIdInternal() != null) { | ||||
sessions.remove(session.getIdInternal()); | |||||
this.sessions.remove(session.getIdInternal()); | |||||
} | } | ||||
} | } | ||||
@@ -127,7 +127,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | |||||
if (id == null) | if (id == null) | ||||
return (null); | return (null); | ||||
return sessions.get(id); | |||||
return this.sessions.get(id); | |||||
} | } | ||||
@@ -138,12 +138,12 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | |||||
(sm.getString("sessionManagerImpl.createSession.ise")); | (sm.getString("sessionManagerImpl.createSession.ise")); | ||||
} | } | ||||
if ((maxActiveSessions >= 0) && | |||||
(getActiveSessions() >= maxActiveSessions)) { | |||||
rejectedSessions++; | |||||
if ((this.maxActiveSessions >= 0) && | |||||
(getActiveSessions() >= this.maxActiveSessions)) { | |||||
this.rejectedSessions++; | |||||
throw new TooManyActiveSessionsException( | throw new TooManyActiveSessionsException( | ||||
sm.getString("sessionManagerImpl.createSession.tmase"), | sm.getString("sessionManagerImpl.createSession.tmase"), | ||||
maxActiveSessions); | |||||
this.maxActiveSessions); | |||||
} | } | ||||
// Recycle or create a Session instance | // Recycle or create a Session instance | ||||
@@ -155,7 +155,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | |||||
session.setMaxInactiveInterval(this.maxInactiveInterval); | session.setMaxInactiveInterval(this.maxInactiveInterval); | ||||
String id = sessionId; | String id = sessionId; | ||||
session.setId(id); | session.setId(id); | ||||
sessionCounter++; | |||||
this.sessionCounter++; | |||||
return (session); | return (session); | ||||
@@ -164,7 +164,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | |||||
@Override | @Override | ||||
public int getActiveSessions() { | public int getActiveSessions() { | ||||
return sessions.size(); | |||||
return this.sessions.size(); | |||||
} | } | ||||
@@ -185,17 +185,17 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | |||||
public void add(InternalSession session) { | public void add(InternalSession session) { | ||||
// 当第一次有session创建的时候,开启session清理线程 | // 当第一次有session创建的时候,开启session清理线程 | ||||
if (!backgroundProcessStarted.getAndSet(true)) { | |||||
if (!this.backgroundProcessStarted.getAndSet(true)) { | |||||
Thread t = new Thread(new Runnable() { | Thread t = new Thread(new Runnable() { | ||||
@Override | @Override | ||||
public void run() { | public void run() { | ||||
while (true) { | while (true) { | ||||
try { | try { | ||||
// 每秒清理一次 | // 每秒清理一次 | ||||
Thread.sleep(backgroundProcessorDelay * 1000l); | |||||
Thread.sleep(StandardSessionManager.this.backgroundProcessorDelay * 1000l); | |||||
backgroundProcess(); | backgroundProcess(); | ||||
} catch (InterruptedException e) { | } catch (InterruptedException e) { | ||||
log.error("SessionManagerImpl.backgroundProcess error", e); | |||||
StandardSessionManager.this.log.error("SessionManagerImpl.backgroundProcess error", e); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -204,12 +204,12 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | |||||
t.start(); | t.start(); | ||||
} | } | ||||
sessions.put(session.getIdInternal(), session); | |||||
this.sessions.put(session.getIdInternal(), session); | |||||
int size = getActiveSessions(); | int size = getActiveSessions(); | ||||
if (size > maxActive) { | |||||
synchronized (maxActiveUpdateLock) { | |||||
if (size > maxActive) { | |||||
maxActive = size; | |||||
if (size > this.maxActive) { | |||||
synchronized (this.maxActiveUpdateLock) { | |||||
if (size > this.maxActive) { | |||||
this.maxActive = size; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -223,14 +223,14 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | |||||
@Override | @Override | ||||
public InternalSession[] findSessions() { | public InternalSession[] findSessions() { | ||||
return sessions.values().toArray(new InternalSession[0]); | |||||
return this.sessions.values().toArray(new InternalSession[0]); | |||||
} | } | ||||
@Override | @Override | ||||
public void backgroundProcess() { | public void backgroundProcess() { | ||||
count = (count + 1) % processExpiresFrequency; | |||||
if (count == 0) | |||||
this.count = (this.count + 1) % this.processExpiresFrequency; | |||||
if (this.count == 0) | |||||
processExpires(); | processExpires(); | ||||
} | } | ||||
@@ -243,17 +243,17 @@ public class StandardSessionManager implements WxSessionManager, InternalSession | |||||
InternalSession sessions[] = findSessions(); | InternalSession sessions[] = findSessions(); | ||||
int expireHere = 0; | int expireHere = 0; | ||||
if (log.isDebugEnabled()) | |||||
log.debug("Start expire sessions {} at {} sessioncount {}", getName(), timeNow, sessions.length); | |||||
if (this.log.isDebugEnabled()) | |||||
this.log.debug("Start expire sessions {} at {} sessioncount {}", getName(), timeNow, sessions.length); | |||||
for (int i = 0; i < sessions.length; i++) { | for (int i = 0; i < sessions.length; i++) { | ||||
if (sessions[i] != null && !sessions[i].isValid()) { | if (sessions[i] != null && !sessions[i].isValid()) { | ||||
expireHere++; | expireHere++; | ||||
} | } | ||||
} | } | ||||
long timeEnd = System.currentTimeMillis(); | long timeEnd = System.currentTimeMillis(); | ||||
if (log.isDebugEnabled()) | |||||
log.debug("End expire sessions {} processingTime {} expired sessions: {}", getName(), timeEnd - timeNow, expireHere); | |||||
processingTime += (timeEnd - timeNow); | |||||
if (this.log.isDebugEnabled()) | |||||
this.log.debug("End expire sessions {} processingTime {} expired sessions: {}", getName(), timeEnd - timeNow, expireHere); | |||||
this.processingTime += (timeEnd - timeNow); | |||||
} | } | ||||
@@ -40,7 +40,7 @@ public class TooManyActiveSessionsException | |||||
int maxActive) { | int maxActive) { | ||||
super(message); | super(message); | ||||
maxActiveSessions = maxActive; | |||||
this.maxActiveSessions = maxActive; | |||||
} | } | ||||
/** | /** | ||||
@@ -49,6 +49,6 @@ public class TooManyActiveSessionsException | |||||
* @return The maximum number of sessions allowed by the session manager. | * @return The maximum number of sessions allowed by the session manager. | ||||
*/ | */ | ||||
public int getMaxActiveSessions() { | public int getMaxActiveSessions() { | ||||
return maxActiveSessions; | |||||
return this.maxActiveSessions; | |||||
} | } | ||||
} | } |
@@ -13,7 +13,7 @@ public class LogExceptionHandler implements WxErrorExceptionHandler { | |||||
@Override | @Override | ||||
public void handle(WxErrorException e) { | public void handle(WxErrorException e) { | ||||
log.error("Error happens", e); | |||||
this.log.error("Error happens", e); | |||||
} | } | ||||
@@ -3,24 +3,24 @@ package me.chanjar.weixin.common.util.crypto; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
public class ByteGroup { | public class ByteGroup { | ||||
ArrayList<Byte> byteContainer = new ArrayList<Byte>(); | |||||
ArrayList<Byte> byteContainer = new ArrayList<>(); | |||||
public byte[] toBytes() { | public byte[] toBytes() { | ||||
byte[] bytes = new byte[byteContainer.size()]; | |||||
for (int i = 0; i < byteContainer.size(); i++) { | |||||
bytes[i] = byteContainer.get(i); | |||||
byte[] bytes = new byte[this.byteContainer.size()]; | |||||
for (int i = 0; i < this.byteContainer.size(); i++) { | |||||
bytes[i] = this.byteContainer.get(i); | |||||
} | } | ||||
return bytes; | return bytes; | ||||
} | } | ||||
public ByteGroup addBytes(byte[] bytes) { | public ByteGroup addBytes(byte[] bytes) { | ||||
for (byte b : bytes) { | for (byte b : bytes) { | ||||
byteContainer.add(b); | |||||
this.byteContainer.add(b); | |||||
} | } | ||||
return this; | return this; | ||||
} | } | ||||
public int size() { | public int size() { | ||||
return byteContainer.size(); | |||||
return this.byteContainer.size(); | |||||
} | } | ||||
} | } |
@@ -47,7 +47,7 @@ public class PKCS7Encoder { | |||||
* @return 删除补位字符后的明文 | * @return 删除补位字符后的明文 | ||||
*/ | */ | ||||
public static byte[] decode(byte[] decrypted) { | public static byte[] decode(byte[] decrypted) { | ||||
int pad = (int) decrypted[decrypted.length - 1]; | |||||
int pad = decrypted[decrypted.length - 1]; | |||||
if (pad < 1 || pad > 32) { | if (pad < 1 || pad > 32) { | ||||
pad = 0; | pad = 0; | ||||
} | } | ||||
@@ -80,10 +80,10 @@ public class WxCryptUtil { | |||||
*/ | */ | ||||
public static String createSign(Map<String, String> packageParams, | public static String createSign(Map<String, String> packageParams, | ||||
String signKey) { | String signKey) { | ||||
SortedMap<String, String> sortedMap = new TreeMap<String, String>(); | |||||
SortedMap<String, String> sortedMap = new TreeMap<>(); | |||||
sortedMap.putAll(packageParams); | sortedMap.putAll(packageParams); | ||||
List<String> keys = new ArrayList<String>(packageParams.keySet()); | |||||
List<String> keys = new ArrayList<>(packageParams.keySet()); | |||||
Collections.sort(keys); | Collections.sort(keys); | ||||
StringBuffer toSign = new StringBuffer(); | StringBuffer toSign = new StringBuffer(); | ||||
@@ -131,7 +131,7 @@ public class WxCryptUtil { | |||||
String nonce = genRandomStr(); | String nonce = genRandomStr(); | ||||
try { | try { | ||||
String signature = SHA1.gen(token, timeStamp, nonce, encryptedXml); | |||||
String signature = SHA1.gen(this.token, timeStamp, nonce, encryptedXml); | |||||
String result = generateXml(encryptedXml, signature, timeStamp, nonce); | String result = generateXml(encryptedXml, signature, timeStamp, nonce); | ||||
return result; | return result; | ||||
} catch (NoSuchAlgorithmException e) { | } catch (NoSuchAlgorithmException e) { | ||||
@@ -151,7 +151,7 @@ public class WxCryptUtil { | |||||
byte[] plainTextBytes = plainText.getBytes(CHARSET); | byte[] plainTextBytes = plainText.getBytes(CHARSET); | ||||
byte[] bytesOfSizeInNetworkOrder = number2BytesInNetworkOrder( | byte[] bytesOfSizeInNetworkOrder = number2BytesInNetworkOrder( | ||||
plainTextBytes.length); | plainTextBytes.length); | ||||
byte[] appIdBytes = appidOrCorpid.getBytes(CHARSET); | |||||
byte[] appIdBytes = this.appidOrCorpid.getBytes(CHARSET); | |||||
// randomStr + networkBytesOrder + text + appid | // randomStr + networkBytesOrder + text + appid | ||||
byteCollector.addBytes(randomStringBytes); | byteCollector.addBytes(randomStringBytes); | ||||
@@ -169,8 +169,8 @@ public class WxCryptUtil { | |||||
try { | try { | ||||
// 设置加密模式为AES的CBC模式 | // 设置加密模式为AES的CBC模式 | ||||
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); | Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); | ||||
SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES"); | |||||
IvParameterSpec iv = new IvParameterSpec(aesKey, 0, 16); | |||||
SecretKeySpec keySpec = new SecretKeySpec(this.aesKey, "AES"); | |||||
IvParameterSpec iv = new IvParameterSpec(this.aesKey, 0, 16); | |||||
cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv); | cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv); | ||||
// 加密 | // 加密 | ||||
@@ -207,7 +207,7 @@ public class WxCryptUtil { | |||||
try { | try { | ||||
// 验证安全签名 | // 验证安全签名 | ||||
String signature = SHA1.gen(token, timeStamp, nonce, cipherText); | |||||
String signature = SHA1.gen(this.token, timeStamp, nonce, cipherText); | |||||
if (!signature.equals(msgSignature)) { | if (!signature.equals(msgSignature)) { | ||||
throw new RuntimeException("加密消息签名校验失败"); | throw new RuntimeException("加密消息签名校验失败"); | ||||
} | } | ||||
@@ -231,9 +231,9 @@ public class WxCryptUtil { | |||||
try { | try { | ||||
// 设置解密模式为AES的CBC模式 | // 设置解密模式为AES的CBC模式 | ||||
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); | Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); | ||||
SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES"); | |||||
SecretKeySpec key_spec = new SecretKeySpec(this.aesKey, "AES"); | |||||
IvParameterSpec iv = new IvParameterSpec( | IvParameterSpec iv = new IvParameterSpec( | ||||
Arrays.copyOfRange(aesKey, 0, 16)); | |||||
Arrays.copyOfRange(this.aesKey, 0, 16)); | |||||
cipher.init(Cipher.DECRYPT_MODE, key_spec, iv); | cipher.init(Cipher.DECRYPT_MODE, key_spec, iv); | ||||
// 使用BASE64对密文进行解码 | // 使用BASE64对密文进行解码 | ||||
@@ -264,7 +264,7 @@ public class WxCryptUtil { | |||||
} | } | ||||
// appid不相同的情况 | // appid不相同的情况 | ||||
if (!from_appid.equals(appidOrCorpid)) { | |||||
if (!from_appid.equals(this.appidOrCorpid)) { | |||||
throw new RuntimeException("AppID不正确"); | throw new RuntimeException("AppID不正确"); | ||||
} | } | ||||
@@ -14,6 +14,7 @@ public class InputStreamResponseHandler implements ResponseHandler<InputStream> | |||||
public static final ResponseHandler<InputStream> INSTANCE = new InputStreamResponseHandler(); | public static final ResponseHandler<InputStream> INSTANCE = new InputStreamResponseHandler(); | ||||
@Override | |||||
public InputStream handleResponse(final HttpResponse response) throws IOException { | public InputStream handleResponse(final HttpResponse response) throws IOException { | ||||
final StatusLine statusLine = response.getStatusLine(); | final StatusLine statusLine = response.getStatusLine(); | ||||
final HttpEntity entity = response.getEntity(); | final HttpEntity entity = response.getEntity(); | ||||
@@ -70,7 +70,7 @@ public class MediaDownloadRequestExecutor implements RequestExecutor<File, Strin | |||||
return null; | return null; | ||||
} | } | ||||
String[] name_ext = fileName.split("\\."); | String[] name_ext = fileName.split("\\."); | ||||
File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1], tmpDirFile); | |||||
File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1], this.tmpDirFile); | |||||
return localFile; | return localFile; | ||||
} finally { | } finally { | ||||
@@ -35,7 +35,7 @@ public class URIUtil { | |||||
private static String getHex(byte buf[]) { | private static String getHex(byte buf[]) { | ||||
StringBuilder o = new StringBuilder(buf.length * 3); | StringBuilder o = new StringBuilder(buf.length * 3); | ||||
for (int i = 0; i < buf.length; i++) { | for (int i = 0; i < buf.length; i++) { | ||||
int n = (int) buf[i] & 0xff; | |||||
int n = buf[i] & 0xff; | |||||
o.append("%"); | o.append("%"); | ||||
if (n < 0x10) { | if (n < 0x10) { | ||||
o.append("0"); | o.append("0"); | ||||
@@ -19,6 +19,7 @@ public class Utf8ResponseHandler implements ResponseHandler<String> { | |||||
public static final ResponseHandler<String> INSTANCE = new Utf8ResponseHandler(); | public static final ResponseHandler<String> INSTANCE = new Utf8ResponseHandler(); | ||||
@Override | |||||
public String handleResponse(final HttpResponse response) throws IOException { | public String handleResponse(final HttpResponse response) throws IOException { | ||||
final StatusLine statusLine = response.getStatusLine(); | final StatusLine statusLine = response.getStatusLine(); | ||||
final HttpEntity entity = response.getEntity(); | final HttpEntity entity = response.getEntity(); | ||||
@@ -18,6 +18,7 @@ import java.lang.reflect.Type; | |||||
*/ | */ | ||||
public class WxAccessTokenAdapter implements JsonDeserializer<WxAccessToken> { | public class WxAccessTokenAdapter implements JsonDeserializer<WxAccessToken> { | ||||
@Override | |||||
public WxAccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | public WxAccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||||
WxAccessToken accessToken = new WxAccessToken(); | WxAccessToken accessToken = new WxAccessToken(); | ||||
JsonObject accessTokenJsonObject = json.getAsJsonObject(); | JsonObject accessTokenJsonObject = json.getAsJsonObject(); | ||||
@@ -18,6 +18,7 @@ import java.lang.reflect.Type; | |||||
*/ | */ | ||||
public class WxErrorAdapter implements JsonDeserializer<WxError> { | public class WxErrorAdapter implements JsonDeserializer<WxError> { | ||||
@Override | |||||
public WxError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | public WxError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||||
WxError wxError = new WxError(); | WxError wxError = new WxError(); | ||||
JsonObject wxErrorJsonObject = json.getAsJsonObject(); | JsonObject wxErrorJsonObject = json.getAsJsonObject(); | ||||
@@ -18,6 +18,7 @@ import java.lang.reflect.Type; | |||||
*/ | */ | ||||
public class WxMediaUploadResultAdapter implements JsonDeserializer<WxMediaUploadResult> { | public class WxMediaUploadResultAdapter implements JsonDeserializer<WxMediaUploadResult> { | ||||
@Override | |||||
public WxMediaUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | public WxMediaUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||||
WxMediaUploadResult uploadResult = new WxMediaUploadResult(); | WxMediaUploadResult uploadResult = new WxMediaUploadResult(); | ||||
JsonObject uploadResultJsonObject = json.getAsJsonObject(); | JsonObject uploadResultJsonObject = json.getAsJsonObject(); | ||||
@@ -29,6 +29,7 @@ import me.chanjar.weixin.common.bean.menu.WxMenuRule; | |||||
*/ | */ | ||||
public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializer<WxMenu> { | public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializer<WxMenu> { | ||||
@Override | |||||
public JsonElement serialize(WxMenu menu, Type typeOfSrc, JsonSerializationContext context) { | public JsonElement serialize(WxMenu menu, Type typeOfSrc, JsonSerializationContext context) { | ||||
JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
@@ -75,6 +76,7 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ | |||||
return matchRule; | return matchRule; | ||||
} | } | ||||
@Override | |||||
public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||||
/* | /* | ||||
* 操蛋的微信 | * 操蛋的微信 | ||||
@@ -47,7 +47,7 @@ import java.util.*; | |||||
public class StringManager { | public class StringManager { | ||||
private static final Map<String, Map<Locale, StringManager>> managers = | private static final Map<String, Map<Locale, StringManager>> managers = | ||||
new Hashtable<String, Map<Locale, StringManager>>(); | |||||
new Hashtable<>(); | |||||
private static int LOCALE_CACHE_SIZE = 10; | private static int LOCALE_CACHE_SIZE = 10; | ||||
/** | /** | ||||
* The ResourceBundle for this StringManager. | * The ResourceBundle for this StringManager. | ||||
@@ -81,10 +81,10 @@ public class StringManager { | |||||
} | } | ||||
} | } | ||||
} | } | ||||
bundle = bnd; | |||||
this.bundle = bnd; | |||||
// Get the actual locale, which may be different from the requested one | // Get the actual locale, which may be different from the requested one | ||||
if (bundle != null) { | |||||
Locale bundleLocale = bundle.getLocale(); | |||||
if (this.bundle != null) { | |||||
Locale bundleLocale = this.bundle.getLocale(); | |||||
if (bundleLocale.equals(Locale.ROOT)) { | if (bundleLocale.equals(Locale.ROOT)) { | ||||
this.locale = Locale.ENGLISH; | this.locale = Locale.ENGLISH; | ||||
} else { | } else { | ||||
@@ -192,8 +192,8 @@ public class StringManager { | |||||
try { | try { | ||||
// Avoid NPE if bundle is null and treat it like an MRE | // Avoid NPE if bundle is null and treat it like an MRE | ||||
if (bundle != null) { | |||||
str = bundle.getString(key); | |||||
if (this.bundle != null) { | |||||
str = this.bundle.getString(key); | |||||
} | } | ||||
} catch (MissingResourceException mre) { | } catch (MissingResourceException mre) { | ||||
//bad: shouldn't mask an exception the following way: | //bad: shouldn't mask an exception the following way: | ||||
@@ -227,7 +227,7 @@ public class StringManager { | |||||
} | } | ||||
MessageFormat mf = new MessageFormat(value); | MessageFormat mf = new MessageFormat(value); | ||||
mf.setLocale(locale); | |||||
mf.setLocale(this.locale); | |||||
return mf.format(args, new StringBuffer(), null).toString(); | return mf.format(args, new StringBuffer(), null).toString(); | ||||
} | } | ||||
@@ -235,6 +235,6 @@ public class StringManager { | |||||
* Identify the Locale this StringManager is associated with | * Identify the Locale this StringManager is associated with | ||||
*/ | */ | ||||
public Locale getLocale() { | public Locale getLocale() { | ||||
return locale; | |||||
return this.locale; | |||||
} | } | ||||
} | } |
@@ -25,9 +25,9 @@ public class XStreamInitializer { | |||||
@Override | @Override | ||||
protected void writeText(QuickWriter writer, String text) { | protected void writeText(QuickWriter writer, String text) { | ||||
if (text.startsWith(PREFIX_CDATA) && text.endsWith(SUFFIX_CDATA)) { | |||||
if (text.startsWith(this.PREFIX_CDATA) && text.endsWith(this.SUFFIX_CDATA)) { | |||||
writer.write(text); | writer.write(text); | ||||
} else if (text.startsWith(PREFIX_MEDIA_ID) && text.endsWith(SUFFIX_MEDIA_ID)) { | |||||
} else if (text.startsWith(this.PREFIX_MEDIA_ID) && text.endsWith(this.SUFFIX_MEDIA_ID)) { | |||||
writer.write(text); | writer.write(text); | ||||
} else { | } else { | ||||
super.writeText(writer, text); | super.writeText(writer, text); | ||||
@@ -34,8 +34,8 @@ public class WxCryptUtilTest { | |||||
String afterAesEncrypt2 = "jn1L23DB+6ELqJ+6bruv23M2GmYfkv0xBh2h+XTBOKVKcgDFHle6gqcZ1cZrk3e1qjPQ1F4RsLWzQRG9udbKWesxlkupqcEcW7ZQweImX9+wLMa0GaUzpkycA8+IamDBxn5loLgZpnS7fVAbExOkK5DYHBmv5tptA9tklE/fTIILHR8HLXa5nQvFb3tYPKAlHF3rtTeayNf0QuM+UW/wM9enGIDIJHF7CLHiDNAYxr+r+OrJCmPQyTy8cVWlu9iSvOHPT/77bZqJucQHQ04sq7KZI27OcqpQNSto2OdHCoTccjggX5Z9Mma0nMJBU+jLKJ38YB1fBIz+vBzsYjrTmFQ44YfeEuZ+xRTQwr92vhA9OxchWVINGC50qE/6lmkwWTwGX9wtQpsJKhP+oS7rvTY8+VdzETdfakjkwQ5/Xka042OlUb1/slTwo4RscuQ+RdxSGvDahxAJ6+EAjLt9d8igHngxIbf6YyqqROxuxqIeIch3CssH/LqRs+iAcILvApYZckqmA7FNERspKA5f8GoJ9sv8xmGvZ9Yrf57cExWtnX8aCMMaBropU/1k+hKP5LVdzbWCG0hGwx/dQudYR/eXp3P0XxjlFiy+9DMlaFExWUZQDajPkdPrEeOwofJb"; | String afterAesEncrypt2 = "jn1L23DB+6ELqJ+6bruv23M2GmYfkv0xBh2h+XTBOKVKcgDFHle6gqcZ1cZrk3e1qjPQ1F4RsLWzQRG9udbKWesxlkupqcEcW7ZQweImX9+wLMa0GaUzpkycA8+IamDBxn5loLgZpnS7fVAbExOkK5DYHBmv5tptA9tklE/fTIILHR8HLXa5nQvFb3tYPKAlHF3rtTeayNf0QuM+UW/wM9enGIDIJHF7CLHiDNAYxr+r+OrJCmPQyTy8cVWlu9iSvOHPT/77bZqJucQHQ04sq7KZI27OcqpQNSto2OdHCoTccjggX5Z9Mma0nMJBU+jLKJ38YB1fBIz+vBzsYjrTmFQ44YfeEuZ+xRTQwr92vhA9OxchWVINGC50qE/6lmkwWTwGX9wtQpsJKhP+oS7rvTY8+VdzETdfakjkwQ5/Xka042OlUb1/slTwo4RscuQ+RdxSGvDahxAJ6+EAjLt9d8igHngxIbf6YyqqROxuxqIeIch3CssH/LqRs+iAcILvApYZckqmA7FNERspKA5f8GoJ9sv8xmGvZ9Yrf57cExWtnX8aCMMaBropU/1k+hKP5LVdzbWCG0hGwx/dQudYR/eXp3P0XxjlFiy+9DMlaFExWUZQDajPkdPrEeOwofJb"; | ||||
public void testNormal() throws ParserConfigurationException, SAXException, IOException { | public void testNormal() throws ParserConfigurationException, SAXException, IOException { | ||||
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId); | |||||
String encryptedXml = pc.encrypt(replyMsg); | |||||
WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId); | |||||
String encryptedXml = pc.encrypt(this.replyMsg); | |||||
System.out.println(encryptedXml); | System.out.println(encryptedXml); | ||||
@@ -56,31 +56,31 @@ public class WxCryptUtilTest { | |||||
String nonce = root.getElementsByTagName("Nonce").item(0).getTextContent(); | String nonce = root.getElementsByTagName("Nonce").item(0).getTextContent(); | ||||
System.out.println(nonce); | System.out.println(nonce); | ||||
String messageText = String.format(xmlFormat, cipherText); | |||||
String messageText = String.format(this.xmlFormat, cipherText); | |||||
System.out.println(messageText); | System.out.println(messageText); | ||||
// 第三方收到企业号平台发送的消息 | // 第三方收到企业号平台发送的消息 | ||||
String plainMessage = pc.decrypt(cipherText); | String plainMessage = pc.decrypt(cipherText); | ||||
System.out.println(plainMessage); | System.out.println(plainMessage); | ||||
assertEquals(plainMessage, replyMsg); | |||||
assertEquals(plainMessage, this.replyMsg); | |||||
} | } | ||||
public void testAesEncrypt() { | public void testAesEncrypt() { | ||||
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId); | |||||
assertEquals(pc.encrypt(randomStr, replyMsg), afterAesEncrypt); | |||||
WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId); | |||||
assertEquals(pc.encrypt(this.randomStr, this.replyMsg), this.afterAesEncrypt); | |||||
} | } | ||||
public void testAesEncrypt2() { | public void testAesEncrypt2() { | ||||
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId); | |||||
assertEquals(pc.encrypt(randomStr, replyMsg2), afterAesEncrypt2); | |||||
WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId); | |||||
assertEquals(pc.encrypt(this.randomStr, this.replyMsg2), this.afterAesEncrypt2); | |||||
} | } | ||||
public void testValidateSignatureError() throws ParserConfigurationException, SAXException, | public void testValidateSignatureError() throws ParserConfigurationException, SAXException, | ||||
IOException { | IOException { | ||||
try { | try { | ||||
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId); | |||||
String afterEncrpt = pc.encrypt(replyMsg); | |||||
WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId); | |||||
String afterEncrpt = pc.encrypt(this.replyMsg); | |||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||||
DocumentBuilder db = dbf.newDocumentBuilder(); | DocumentBuilder db = dbf.newDocumentBuilder(); | ||||
StringReader sr = new StringReader(afterEncrpt); | StringReader sr = new StringReader(afterEncrpt); | ||||
@@ -91,8 +91,8 @@ public class WxCryptUtilTest { | |||||
NodeList nodelist1 = root.getElementsByTagName("Encrypt"); | NodeList nodelist1 = root.getElementsByTagName("Encrypt"); | ||||
String encrypt = nodelist1.item(0).getTextContent(); | String encrypt = nodelist1.item(0).getTextContent(); | ||||
String fromXML = String.format(xmlFormat, encrypt); | |||||
pc.decrypt("12345", timestamp, nonce, fromXML); // 这里签名错误 | |||||
String fromXML = String.format(this.xmlFormat, encrypt); | |||||
pc.decrypt("12345", this.timestamp, this.nonce, fromXML); // 这里签名错误 | |||||
} catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
assertEquals(e.getMessage(), "加密消息签名校验失败"); | assertEquals(e.getMessage(), "加密消息签名校验失败"); | ||||
return; | return; | ||||