mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 07:07:27 +08:00
fix some warnings in common modules
This commit is contained in:
parent
66cd7cda43
commit
6f297ae95a
@ -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
|
||||
*/
|
||||
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() {
|
||||
if (backgroundProcessStarted.getAndSet(true)) {
|
||||
if (this.backgroundProcessStarted.getAndSet(true)) {
|
||||
return;
|
||||
}
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@ -64,11 +64,11 @@ public class WxMessageInMemoryDuplicateChecker implements WxMessageDuplicateChec
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
Thread.sleep(clearPeriod);
|
||||
Thread.sleep(WxMessageInMemoryDuplicateChecker.this.clearPeriod);
|
||||
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;
|
||||
}
|
||||
checkBackgroundProcessStarted();
|
||||
Long timestamp = msgId2Timestamp.putIfAbsent(messageId, System.currentTimeMillis());
|
||||
Long timestamp = this.msgId2Timestamp.putIfAbsent(messageId, System.currentTimeMillis());
|
||||
return timestamp != null;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class WxAccessToken implements Serializable {
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
return this.accessToken;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
@ -24,7 +24,7 @@ public class WxAccessToken implements Serializable {
|
||||
}
|
||||
|
||||
public int getExpiresIn() {
|
||||
return expiresIn;
|
||||
return this.expiresIn;
|
||||
}
|
||||
|
||||
public void setExpiresIn(int expiresIn) {
|
||||
|
@ -39,7 +39,7 @@ public class WxCardApiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
return this.appId;
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
@ -47,7 +47,7 @@ public class WxCardApiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getCardId() {
|
||||
return cardId;
|
||||
return this.cardId;
|
||||
}
|
||||
|
||||
public void setCardId(String cardId) {
|
||||
@ -55,7 +55,7 @@ public class WxCardApiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getCardType() {
|
||||
return cardType;
|
||||
return this.cardType;
|
||||
}
|
||||
|
||||
public void setCardType(String cardType) {
|
||||
@ -63,7 +63,7 @@ public class WxCardApiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getLocationId() {
|
||||
return locationId;
|
||||
return this.locationId;
|
||||
}
|
||||
|
||||
public void setLocationId(String locationId) {
|
||||
@ -71,7 +71,7 @@ public class WxCardApiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
@ -79,7 +79,7 @@ public class WxCardApiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getOpenId() {
|
||||
return openId;
|
||||
return this.openId;
|
||||
}
|
||||
|
||||
public void setOpenId(String openId) {
|
||||
@ -87,7 +87,7 @@ public class WxCardApiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public Long getTimestamp() {
|
||||
return timestamp;
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Long timestamp) {
|
||||
@ -95,7 +95,7 @@ public class WxCardApiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getNonceStr() {
|
||||
return nonceStr;
|
||||
return this.nonceStr;
|
||||
}
|
||||
|
||||
public void setNonceStr(String nonceStr) {
|
||||
@ -103,7 +103,7 @@ public class WxCardApiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
return this.signature;
|
||||
}
|
||||
|
||||
public void setSignature(String signature) {
|
||||
|
@ -19,7 +19,7 @@ public class WxJsapiSignature implements Serializable {
|
||||
private String signature;
|
||||
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
return this.signature;
|
||||
}
|
||||
|
||||
public void setSignature(String signature) {
|
||||
@ -27,7 +27,7 @@ public class WxJsapiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getNoncestr() {
|
||||
return noncestr;
|
||||
return this.noncestr;
|
||||
}
|
||||
|
||||
public void setNoncestr(String noncestr) {
|
||||
@ -35,7 +35,7 @@ public class WxJsapiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
@ -43,7 +43,7 @@ public class WxJsapiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
@ -51,7 +51,7 @@ public class WxJsapiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getAppid() {
|
||||
return appid;
|
||||
return this.appid;
|
||||
}
|
||||
|
||||
public void setAppid(String appid) {
|
||||
|
@ -19,7 +19,7 @@ public class WxMenu implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7083914585539687746L;
|
||||
|
||||
private List<WxMenuButton> buttons = new ArrayList<WxMenuButton>();
|
||||
private List<WxMenuButton> buttons = new ArrayList<>();
|
||||
|
||||
private WxMenuRule matchRule;
|
||||
|
||||
@ -40,7 +40,7 @@ public class WxMenu implements Serializable {
|
||||
}
|
||||
|
||||
public List<WxMenuButton> getButtons() {
|
||||
return buttons;
|
||||
return this.buttons;
|
||||
}
|
||||
|
||||
public void setButtons(List<WxMenuButton> buttons) {
|
||||
@ -48,7 +48,7 @@ public class WxMenu implements Serializable {
|
||||
}
|
||||
|
||||
public WxMenuRule getMatchRule() {
|
||||
return matchRule;
|
||||
return this.matchRule;
|
||||
}
|
||||
|
||||
public void setMatchRule(WxMenuRule matchRule) {
|
||||
@ -62,7 +62,7 @@ public class WxMenu implements Serializable {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WxMenu{" +
|
||||
"buttons=" + buttons +
|
||||
"buttons=" + this.buttons +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class WxMenuButton {
|
||||
private String url;
|
||||
private String mediaId;
|
||||
|
||||
private List<WxMenuButton> subButtons = new ArrayList<WxMenuButton>();
|
||||
private List<WxMenuButton> subButtons = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -23,7 +23,7 @@ public class WxMenuButton {
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
@ -31,7 +31,7 @@ public class WxMenuButton {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
@ -39,7 +39,7 @@ public class WxMenuButton {
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
@ -47,7 +47,7 @@ public class WxMenuButton {
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
@ -55,7 +55,7 @@ public class WxMenuButton {
|
||||
}
|
||||
|
||||
public List<WxMenuButton> getSubButtons() {
|
||||
return subButtons;
|
||||
return this.subButtons;
|
||||
}
|
||||
|
||||
public void setSubButtons(List<WxMenuButton> subButtons) {
|
||||
@ -63,7 +63,7 @@ public class WxMenuButton {
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
return mediaId;
|
||||
return this.mediaId;
|
||||
}
|
||||
|
||||
public void setMediaId(String mediaId) {
|
||||
|
@ -13,7 +13,7 @@ public class WxMenuRule {
|
||||
private String language;
|
||||
|
||||
public String getTagId() {
|
||||
return tagId;
|
||||
return this.tagId;
|
||||
}
|
||||
|
||||
public void setTagId(String tagId) {
|
||||
@ -21,7 +21,7 @@ public class WxMenuRule {
|
||||
}
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
return this.sex;
|
||||
}
|
||||
|
||||
public void setSex(String sex) {
|
||||
@ -29,7 +29,7 @@ public class WxMenuRule {
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
return this.country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
@ -37,7 +37,7 @@ public class WxMenuRule {
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
return this.province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
@ -45,7 +45,7 @@ public class WxMenuRule {
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
return this.city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
@ -53,7 +53,7 @@ public class WxMenuRule {
|
||||
}
|
||||
|
||||
public String getClientPlatformType() {
|
||||
return clientPlatformType;
|
||||
return this.clientPlatformType;
|
||||
}
|
||||
|
||||
public void setClientPlatformType(String clientPlatformType) {
|
||||
@ -61,7 +61,7 @@ public class WxMenuRule {
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
return this.language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
|
@ -29,7 +29,7 @@ public class WxError implements Serializable {
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
return this.errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(int errorCode) {
|
||||
@ -37,7 +37,7 @@ public class WxError implements Serializable {
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
return this.errorMsg;
|
||||
}
|
||||
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
@ -45,7 +45,7 @@ public class WxError implements Serializable {
|
||||
}
|
||||
|
||||
public String getJson() {
|
||||
return json;
|
||||
return this.json;
|
||||
}
|
||||
|
||||
public void setJson(String json) {
|
||||
@ -54,10 +54,10 @@ public class WxError implements Serializable {
|
||||
|
||||
@Override
|
||||
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 {
|
||||
|
@ -17,7 +17,7 @@ public class WxMediaUploadResult implements Serializable {
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
@ -25,7 +25,7 @@ public class WxMediaUploadResult implements Serializable {
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
return mediaId;
|
||||
return this.mediaId;
|
||||
}
|
||||
|
||||
public void setMediaId(String mediaId) {
|
||||
@ -33,7 +33,7 @@ public class WxMediaUploadResult implements Serializable {
|
||||
}
|
||||
|
||||
public long getCreatedAt() {
|
||||
return createdAt;
|
||||
return this.createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(long createdAt) {
|
||||
@ -41,7 +41,7 @@ public class WxMediaUploadResult implements Serializable {
|
||||
}
|
||||
|
||||
public String getThumbMediaId() {
|
||||
return thumbMediaId;
|
||||
return this.thumbMediaId;
|
||||
}
|
||||
|
||||
public void setThumbMediaId(String thumbMediaId) {
|
||||
@ -50,8 +50,8 @@ public class WxMediaUploadResult implements Serializable {
|
||||
|
||||
@Override
|
||||
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() {
|
||||
return error;
|
||||
return this.error;
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,7 +18,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
*/
|
||||
protected static final String EMPTY_ARRAY[] = new String[0];
|
||||
// ------------------------------ WxSession
|
||||
protected Map<String, Object> attributes = new ConcurrentHashMap<String, Object>();
|
||||
protected Map<String, Object> attributes = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* The session identifier of this Session.
|
||||
*/
|
||||
@ -47,7 +47,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
/**
|
||||
* 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
|
||||
* this Manager.
|
||||
@ -77,7 +77,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
if (name == null) return null;
|
||||
|
||||
return (attributes.get(name));
|
||||
return (this.attributes.get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,8 +86,8 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
throw new IllegalStateException
|
||||
(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);
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
throw new IllegalStateException(sm.getString(
|
||||
"sessionImpl.setAttribute.ise", getIdInternal()));
|
||||
|
||||
attributes.put(name, value);
|
||||
this.attributes.put(name, value);
|
||||
|
||||
}
|
||||
|
||||
@ -132,10 +132,10 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
if (accessCount.get() > 0) {
|
||||
if (this.accessCount.get() > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (maxInactiveInterval > 0) {
|
||||
if (this.maxInactiveInterval > 0) {
|
||||
long timeNow = System.currentTimeMillis();
|
||||
int timeIdle;
|
||||
timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L);
|
||||
if (timeIdle >= maxInactiveInterval) {
|
||||
timeIdle = (int) ((timeNow - this.thisAccessedTime) / 1000L);
|
||||
if (timeIdle >= this.maxInactiveInterval) {
|
||||
expire();
|
||||
}
|
||||
}
|
||||
@ -193,7 +193,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
if (name == null) return;
|
||||
|
||||
// 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.
|
||||
// Do not check expiring at this point as expire should not return until
|
||||
// isValid is false
|
||||
if (!isValid)
|
||||
if (!this.isValid)
|
||||
return;
|
||||
|
||||
synchronized (this) {
|
||||
@ -210,24 +210,24 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
// Double check locking - isValid needs to be volatile
|
||||
// The check of expiring is to ensure that an infinite loop is not
|
||||
// entered as per bug 56339
|
||||
if (expiring || !isValid)
|
||||
if (this.expiring || !this.isValid)
|
||||
return;
|
||||
|
||||
if (manager == null)
|
||||
if (this.manager == null)
|
||||
return;
|
||||
|
||||
// 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
|
||||
manager.remove(this, true);
|
||||
this.manager.remove(this, true);
|
||||
|
||||
|
||||
// We have completed expire of this session
|
||||
setValid(false);
|
||||
expiring = false;
|
||||
this.expiring = false;
|
||||
|
||||
// Unbind any objects associated with this session
|
||||
String keys[] = keys();
|
||||
@ -244,7 +244,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
public void access() {
|
||||
|
||||
this.thisAccessedTime = System.currentTimeMillis();
|
||||
accessCount.incrementAndGet();
|
||||
this.accessCount.incrementAndGet();
|
||||
|
||||
}
|
||||
|
||||
@ -253,7 +253,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
public void endAccess() {
|
||||
|
||||
this.thisAccessedTime = System.currentTimeMillis();
|
||||
accessCount.decrementAndGet();
|
||||
this.accessCount.decrementAndGet();
|
||||
|
||||
}
|
||||
|
||||
@ -273,13 +273,13 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
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() {
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -14,32 +14,32 @@ public class StandardSessionFacade implements WxSession {
|
||||
}
|
||||
|
||||
public InternalSession getInternalSession() {
|
||||
return (InternalSession) session;
|
||||
return (InternalSession) this.session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String name) {
|
||||
return session.getAttribute(name);
|
||||
return this.session.getAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
return session.getAttributeNames();
|
||||
return this.session.getAttributeNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, Object value) {
|
||||
session.setAttribute(name, value);
|
||||
this.session.setAttribute(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String name) {
|
||||
session.removeAttribute(name);
|
||||
this.session.removeAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
* 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.
|
||||
*/
|
||||
@ -117,7 +117,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
@Override
|
||||
public void remove(InternalSession session, boolean update) {
|
||||
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)
|
||||
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"));
|
||||
}
|
||||
|
||||
if ((maxActiveSessions >= 0) &&
|
||||
(getActiveSessions() >= maxActiveSessions)) {
|
||||
rejectedSessions++;
|
||||
if ((this.maxActiveSessions >= 0) &&
|
||||
(getActiveSessions() >= this.maxActiveSessions)) {
|
||||
this.rejectedSessions++;
|
||||
throw new TooManyActiveSessionsException(
|
||||
sm.getString("sessionManagerImpl.createSession.tmase"),
|
||||
maxActiveSessions);
|
||||
this.maxActiveSessions);
|
||||
}
|
||||
|
||||
// Recycle or create a Session instance
|
||||
@ -155,7 +155,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
session.setMaxInactiveInterval(this.maxInactiveInterval);
|
||||
String id = sessionId;
|
||||
session.setId(id);
|
||||
sessionCounter++;
|
||||
this.sessionCounter++;
|
||||
|
||||
return (session);
|
||||
|
||||
@ -164,7 +164,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
|
||||
@Override
|
||||
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) {
|
||||
|
||||
// 当第一次有session创建的时候,开启session清理线程
|
||||
if (!backgroundProcessStarted.getAndSet(true)) {
|
||||
if (!this.backgroundProcessStarted.getAndSet(true)) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
// 每秒清理一次
|
||||
Thread.sleep(backgroundProcessorDelay * 1000l);
|
||||
Thread.sleep(StandardSessionManager.this.backgroundProcessorDelay * 1000l);
|
||||
backgroundProcess();
|
||||
} 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();
|
||||
}
|
||||
|
||||
sessions.put(session.getIdInternal(), session);
|
||||
this.sessions.put(session.getIdInternal(), session);
|
||||
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
|
||||
public InternalSession[] findSessions() {
|
||||
|
||||
return sessions.values().toArray(new InternalSession[0]);
|
||||
return this.sessions.values().toArray(new InternalSession[0]);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backgroundProcess() {
|
||||
count = (count + 1) % processExpiresFrequency;
|
||||
if (count == 0)
|
||||
this.count = (this.count + 1) % this.processExpiresFrequency;
|
||||
if (this.count == 0)
|
||||
processExpires();
|
||||
}
|
||||
|
||||
@ -243,17 +243,17 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
InternalSession sessions[] = findSessions();
|
||||
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++) {
|
||||
if (sessions[i] != null && !sessions[i].isValid()) {
|
||||
expireHere++;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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.
|
||||
*/
|
||||
public int getMaxActiveSessions() {
|
||||
return maxActiveSessions;
|
||||
return this.maxActiveSessions;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class LogExceptionHandler implements WxErrorExceptionHandler {
|
||||
@Override
|
||||
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;
|
||||
|
||||
public class ByteGroup {
|
||||
ArrayList<Byte> byteContainer = new ArrayList<Byte>();
|
||||
ArrayList<Byte> byteContainer = new ArrayList<>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public ByteGroup addBytes(byte[] bytes) {
|
||||
for (byte b : bytes) {
|
||||
byteContainer.add(b);
|
||||
this.byteContainer.add(b);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return byteContainer.size();
|
||||
return this.byteContainer.size();
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class PKCS7Encoder {
|
||||
* @return 删除补位字符后的明文
|
||||
*/
|
||||
public static byte[] decode(byte[] decrypted) {
|
||||
int pad = (int) decrypted[decrypted.length - 1];
|
||||
int pad = decrypted[decrypted.length - 1];
|
||||
if (pad < 1 || pad > 32) {
|
||||
pad = 0;
|
||||
}
|
||||
|
@ -80,10 +80,10 @@ public class WxCryptUtil {
|
||||
*/
|
||||
public static String createSign(Map<String, String> packageParams,
|
||||
String signKey) {
|
||||
SortedMap<String, String> sortedMap = new TreeMap<String, String>();
|
||||
SortedMap<String, String> sortedMap = new TreeMap<>();
|
||||
sortedMap.putAll(packageParams);
|
||||
|
||||
List<String> keys = new ArrayList<String>(packageParams.keySet());
|
||||
List<String> keys = new ArrayList<>(packageParams.keySet());
|
||||
Collections.sort(keys);
|
||||
|
||||
StringBuffer toSign = new StringBuffer();
|
||||
@ -131,7 +131,7 @@ public class WxCryptUtil {
|
||||
String nonce = genRandomStr();
|
||||
|
||||
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);
|
||||
return result;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
@ -151,7 +151,7 @@ public class WxCryptUtil {
|
||||
byte[] plainTextBytes = plainText.getBytes(CHARSET);
|
||||
byte[] bytesOfSizeInNetworkOrder = number2BytesInNetworkOrder(
|
||||
plainTextBytes.length);
|
||||
byte[] appIdBytes = appidOrCorpid.getBytes(CHARSET);
|
||||
byte[] appIdBytes = this.appidOrCorpid.getBytes(CHARSET);
|
||||
|
||||
// randomStr + networkBytesOrder + text + appid
|
||||
byteCollector.addBytes(randomStringBytes);
|
||||
@ -169,8 +169,8 @@ public class WxCryptUtil {
|
||||
try {
|
||||
// 设置加密模式为AES的CBC模式
|
||||
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);
|
||||
|
||||
// 加密
|
||||
@ -207,7 +207,7 @@ public class WxCryptUtil {
|
||||
|
||||
try {
|
||||
// 验证安全签名
|
||||
String signature = SHA1.gen(token, timeStamp, nonce, cipherText);
|
||||
String signature = SHA1.gen(this.token, timeStamp, nonce, cipherText);
|
||||
if (!signature.equals(msgSignature)) {
|
||||
throw new RuntimeException("加密消息签名校验失败");
|
||||
}
|
||||
@ -231,9 +231,9 @@ public class WxCryptUtil {
|
||||
try {
|
||||
// 设置解密模式为AES的CBC模式
|
||||
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(
|
||||
Arrays.copyOfRange(aesKey, 0, 16));
|
||||
Arrays.copyOfRange(this.aesKey, 0, 16));
|
||||
cipher.init(Cipher.DECRYPT_MODE, key_spec, iv);
|
||||
|
||||
// 使用BASE64对密文进行解码
|
||||
@ -264,7 +264,7 @@ public class WxCryptUtil {
|
||||
}
|
||||
|
||||
// appid不相同的情况
|
||||
if (!from_appid.equals(appidOrCorpid)) {
|
||||
if (!from_appid.equals(this.appidOrCorpid)) {
|
||||
throw new RuntimeException("AppID不正确");
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ public class InputStreamResponseHandler implements ResponseHandler<InputStream>
|
||||
|
||||
public static final ResponseHandler<InputStream> INSTANCE = new InputStreamResponseHandler();
|
||||
|
||||
@Override
|
||||
public InputStream handleResponse(final HttpResponse response) throws IOException {
|
||||
final StatusLine statusLine = response.getStatusLine();
|
||||
final HttpEntity entity = response.getEntity();
|
||||
|
@ -70,7 +70,7 @@ public class MediaDownloadRequestExecutor implements RequestExecutor<File, Strin
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
|
||||
} finally {
|
||||
|
@ -35,7 +35,7 @@ public class URIUtil {
|
||||
private static String getHex(byte buf[]) {
|
||||
StringBuilder o = new StringBuilder(buf.length * 3);
|
||||
for (int i = 0; i < buf.length; i++) {
|
||||
int n = (int) buf[i] & 0xff;
|
||||
int n = buf[i] & 0xff;
|
||||
o.append("%");
|
||||
if (n < 0x10) {
|
||||
o.append("0");
|
||||
|
@ -19,6 +19,7 @@ public class Utf8ResponseHandler implements ResponseHandler<String> {
|
||||
|
||||
public static final ResponseHandler<String> INSTANCE = new Utf8ResponseHandler();
|
||||
|
||||
@Override
|
||||
public String handleResponse(final HttpResponse response) throws IOException {
|
||||
final StatusLine statusLine = response.getStatusLine();
|
||||
final HttpEntity entity = response.getEntity();
|
||||
|
@ -18,6 +18,7 @@ import java.lang.reflect.Type;
|
||||
*/
|
||||
public class WxAccessTokenAdapter implements JsonDeserializer<WxAccessToken> {
|
||||
|
||||
@Override
|
||||
public WxAccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
WxAccessToken accessToken = new WxAccessToken();
|
||||
JsonObject accessTokenJsonObject = json.getAsJsonObject();
|
||||
|
@ -18,6 +18,7 @@ import java.lang.reflect.Type;
|
||||
*/
|
||||
public class WxErrorAdapter implements JsonDeserializer<WxError> {
|
||||
|
||||
@Override
|
||||
public WxError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
WxError wxError = new WxError();
|
||||
JsonObject wxErrorJsonObject = json.getAsJsonObject();
|
||||
|
@ -18,6 +18,7 @@ import java.lang.reflect.Type;
|
||||
*/
|
||||
public class WxMediaUploadResultAdapter implements JsonDeserializer<WxMediaUploadResult> {
|
||||
|
||||
@Override
|
||||
public WxMediaUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
WxMediaUploadResult uploadResult = new WxMediaUploadResult();
|
||||
JsonObject uploadResultJsonObject = json.getAsJsonObject();
|
||||
|
@ -29,6 +29,7 @@ import me.chanjar.weixin.common.bean.menu.WxMenuRule;
|
||||
*/
|
||||
public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializer<WxMenu> {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(WxMenu menu, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject json = new JsonObject();
|
||||
|
||||
@ -75,6 +76,7 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ
|
||||
return matchRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
/*
|
||||
* 操蛋的微信
|
||||
|
@ -47,7 +47,7 @@ import java.util.*;
|
||||
public class StringManager {
|
||||
|
||||
private static final Map<String, Map<Locale, StringManager>> managers =
|
||||
new Hashtable<String, Map<Locale, StringManager>>();
|
||||
new Hashtable<>();
|
||||
private static int LOCALE_CACHE_SIZE = 10;
|
||||
/**
|
||||
* 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
|
||||
if (bundle != null) {
|
||||
Locale bundleLocale = bundle.getLocale();
|
||||
if (this.bundle != null) {
|
||||
Locale bundleLocale = this.bundle.getLocale();
|
||||
if (bundleLocale.equals(Locale.ROOT)) {
|
||||
this.locale = Locale.ENGLISH;
|
||||
} else {
|
||||
@ -192,8 +192,8 @@ public class StringManager {
|
||||
|
||||
try {
|
||||
// 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) {
|
||||
//bad: shouldn't mask an exception the following way:
|
||||
@ -227,7 +227,7 @@ public class StringManager {
|
||||
}
|
||||
|
||||
MessageFormat mf = new MessageFormat(value);
|
||||
mf.setLocale(locale);
|
||||
mf.setLocale(this.locale);
|
||||
return mf.format(args, new StringBuffer(), null).toString();
|
||||
}
|
||||
|
||||
@ -235,6 +235,6 @@ public class StringManager {
|
||||
* Identify the Locale this StringManager is associated with
|
||||
*/
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
return this.locale;
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ public class XStreamInitializer {
|
||||
|
||||
@Override
|
||||
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);
|
||||
} 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);
|
||||
} else {
|
||||
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";
|
||||
|
||||
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);
|
||||
|
||||
@ -56,31 +56,31 @@ public class WxCryptUtilTest {
|
||||
String nonce = root.getElementsByTagName("Nonce").item(0).getTextContent();
|
||||
System.out.println(nonce);
|
||||
|
||||
String messageText = String.format(xmlFormat, cipherText);
|
||||
String messageText = String.format(this.xmlFormat, cipherText);
|
||||
System.out.println(messageText);
|
||||
|
||||
// 第三方收到企业号平台发送的消息
|
||||
String plainMessage = pc.decrypt(cipherText);
|
||||
System.out.println(plainMessage);
|
||||
|
||||
assertEquals(plainMessage, replyMsg);
|
||||
assertEquals(plainMessage, this.replyMsg);
|
||||
}
|
||||
|
||||
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() {
|
||||
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,
|
||||
IOException {
|
||||
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();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
StringReader sr = new StringReader(afterEncrpt);
|
||||
@ -91,8 +91,8 @@ public class WxCryptUtilTest {
|
||||
NodeList nodelist1 = root.getElementsByTagName("Encrypt");
|
||||
|
||||
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) {
|
||||
assertEquals(e.getMessage(), "加密消息签名校验失败");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user