mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
fix some warnings in common modules
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user