cleanup code with findbugs plugin
This commit is contained in:
parent
9c5c411587
commit
7ca050e952
@ -1,6 +1,5 @@
|
||||
package com.foxinmy.weixin4j.api;
|
||||
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -50,21 +49,15 @@ public abstract class BaseApi {
|
||||
/**
|
||||
* 默认使用weixin4j.properties文件中的公众号信息
|
||||
*/
|
||||
public static WeixinAccount DEFAULT_WEIXIN_ACCOUNT;
|
||||
public final static WeixinAccount DEFAULT_WEIXIN_ACCOUNT;
|
||||
|
||||
/**
|
||||
* 默认token使用File的方式存储
|
||||
*/
|
||||
public static TokenStorager DEFAULT_TOKEN_STORAGER;
|
||||
public final static TokenStorager DEFAULT_TOKEN_STORAGER;
|
||||
|
||||
static {
|
||||
try {
|
||||
DEFAULT_WEIXIN_ACCOUNT = ConfigUtil.getWeixinAccount();
|
||||
} catch (MissingResourceException e) {
|
||||
System.err
|
||||
.println("'account' key not found in weixin4j.properties file.");
|
||||
; // error
|
||||
}
|
||||
DEFAULT_WEIXIN_ACCOUNT = ConfigUtil.getWeixinAccount();
|
||||
DEFAULT_TOKEN_STORAGER = new FileTokenStorager(ConfigUtil.getValue(
|
||||
"token_path", Weixin4jConst.DEFAULT_TOKEN_PATH));
|
||||
}
|
||||
|
||||
@ -4,10 +4,11 @@ import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Calendar;
|
||||
@ -331,10 +332,9 @@ public class Pay3Api {
|
||||
|
||||
BufferedReader reader = null;
|
||||
BufferedWriter writer = null;
|
||||
FileWriter fw = null;
|
||||
try {
|
||||
fw = new FileWriter(file);
|
||||
writer = new BufferedWriter(fw);
|
||||
writer = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(file), Consts.GBK));
|
||||
reader = new BufferedReader(new InputStreamReader(
|
||||
new ByteArrayInputStream(response.getContent()),
|
||||
com.foxinmy.weixin4j.model.Consts.GBK));
|
||||
@ -352,7 +352,6 @@ public class Pay3Api {
|
||||
}
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
fw.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
;
|
||||
|
||||
@ -16,7 +16,7 @@ public class StringEntity implements HttpEntity {
|
||||
}
|
||||
|
||||
public StringEntity(String body, ContentType contentType) {
|
||||
this.content = body.getBytes();
|
||||
this.content = body.getBytes(contentType.getCharset());
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.foxinmy.weixin4j.payment.mch;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -229,7 +230,10 @@ public class RedpacketRecord extends XmlResult {
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public static class RedpacketReceiver {
|
||||
public static class RedpacketReceiver implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 领取红包的Openid
|
||||
*/
|
||||
|
||||
@ -99,7 +99,15 @@ public class ConfigUtil {
|
||||
}
|
||||
|
||||
public static WeixinAccount getWeixinAccount() {
|
||||
String text = getValue("account");
|
||||
return JSON.parseObject(text, WeixinAccount.class);
|
||||
WeixinAccount account = null;
|
||||
try {
|
||||
String text = getValue("account");
|
||||
account = JSON.parseObject(text, WeixinAccount.class);
|
||||
} catch (MissingResourceException e) {
|
||||
System.err
|
||||
.println("'account' key not found in weixin4j.properties file.");
|
||||
; // error
|
||||
}
|
||||
return account;
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,11 +148,10 @@ public class ObjectId implements Comparable<ObjectId>, java.io.Serializable {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
|
||||
ObjectId other = (ObjectId) o;
|
||||
if (other == null)
|
||||
if (!(o instanceof ObjectId)) {
|
||||
return false;
|
||||
|
||||
}
|
||||
ObjectId other = (ObjectId) o;
|
||||
return _time == other._time && _machine == other._machine
|
||||
&& _inc == other._inc;
|
||||
}
|
||||
@ -310,8 +309,7 @@ public class ObjectId implements Comparable<ObjectId>, java.io.Serializable {
|
||||
}
|
||||
|
||||
ClassLoader loader = ObjectId.class.getClassLoader();
|
||||
int loaderId = loader != null
|
||||
? System.identityHashCode(loader)
|
||||
int loaderId = loader != null ? System.identityHashCode(loader)
|
||||
: 0;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@ -74,7 +74,11 @@ public class ListsuffixResultDeserializer {
|
||||
T t = XmlStream.fromXML(content, clazz);
|
||||
Map<Field, String[]> listsuffixFields = getListsuffixFields(clazz);
|
||||
if (!listsuffixFields.isEmpty()) {
|
||||
for (Field field : listsuffixFields.keySet()) {
|
||||
Iterator<Entry<Field, String[]>> it = listsuffixFields.entrySet()
|
||||
.iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<Field, String[]> entry = it.next();
|
||||
Field field = entry.getKey();
|
||||
Type type = field.getGenericType();
|
||||
Class<?> wrapperClazz = null;
|
||||
if (type instanceof ParameterizedType) {
|
||||
@ -84,7 +88,7 @@ public class ListsuffixResultDeserializer {
|
||||
continue;
|
||||
}
|
||||
ListWrapper<?> listWrapper = deserializeToListWrapper(content,
|
||||
wrapperClazz, listsuffixFields.get(field));
|
||||
wrapperClazz, entry.getValue());
|
||||
if (listWrapper != null) {
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
|
||||
@ -6,10 +6,10 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.security.KeyStore;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertificateFactory;
|
||||
@ -209,14 +209,18 @@ public class Pay2Api extends MpApi {
|
||||
.getInstance(com.foxinmy.weixin4j.model.Consts.JKS);
|
||||
ks.load(null, null);
|
||||
ks.setCertificateEntry("tenpay", cert);
|
||||
ks.store(new FileOutputStream(jksFile), jksPwd.toCharArray());
|
||||
FileOutputStream os = new FileOutputStream(jksFile);
|
||||
ks.store(os, jksPwd.toCharArray());
|
||||
os.close();
|
||||
}
|
||||
// load jks ca
|
||||
TrustManagerFactory tmf = TrustManagerFactory
|
||||
.getInstance(com.foxinmy.weixin4j.model.Consts.SunX509);
|
||||
ks = KeyStore.getInstance(com.foxinmy.weixin4j.model.Consts.JKS);
|
||||
ks.load(new FileInputStream(jksFile), jksPwd.toCharArray());
|
||||
FileInputStream is = new FileInputStream(jksFile);
|
||||
ks.load(is, jksPwd.toCharArray());
|
||||
tmf.init(ks);
|
||||
is.close();
|
||||
// load pfx ca
|
||||
KeyManagerFactory kmf = KeyManagerFactory
|
||||
.getInstance(com.foxinmy.weixin4j.model.Consts.SunX509);
|
||||
@ -373,10 +377,9 @@ public class Pay2Api extends MpApi {
|
||||
WeixinResponse response = weixinClient.get(downloadbill_uri, map);
|
||||
BufferedReader reader = null;
|
||||
BufferedWriter writer = null;
|
||||
FileWriter fw = null;
|
||||
try {
|
||||
fw = new FileWriter(file);
|
||||
writer = new BufferedWriter(fw);
|
||||
writer = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(file), Consts.GBK));
|
||||
reader = new BufferedReader(new InputStreamReader(
|
||||
new ByteArrayInputStream(response.getContent()),
|
||||
com.foxinmy.weixin4j.model.Consts.GBK));
|
||||
@ -394,7 +397,6 @@ public class Pay2Api extends MpApi {
|
||||
}
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
fw.close();
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
;
|
||||
|
||||
@ -81,7 +81,7 @@ public class AgentApi extends QyApi {
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
public static ValueFilter typeFilter;
|
||||
public final static ValueFilter typeFilter;
|
||||
static {
|
||||
typeFilter = new ValueFilter() {
|
||||
@Override
|
||||
|
||||
@ -75,7 +75,7 @@ public class BatchApi extends QyApi {
|
||||
* @param callback
|
||||
* 接收任务执行结果的回调地址等信息
|
||||
* @return 异步任务id,最大长度为64字符
|
||||
* @see {@link com.foxinmy.weixin4j.qy.api.MediaApi#batchUploadUsers(List)}
|
||||
* @see {@link com.foxinmy.weixin4j.qy.api.MediaApi#batchUploadUsers(java.util.List)}
|
||||
* @see com.foxinmy.weixin4j.qy.model.Callback
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E5.A2.9E.E9.87.8F.E6.9B.B4.E6.96.B0.E6.88.90.E5.91.98">批量更新成员</a>
|
||||
@ -113,7 +113,7 @@ public class BatchApi extends QyApi {
|
||||
* @param callback
|
||||
* 接收任务执行结果的回调地址等信息
|
||||
* @return 异步任务id,最大长度为64字符
|
||||
* @see {@link com.foxinmy.weixin4j.qy.api.MediaApi#batchUploadUsers(List)}
|
||||
* @see {@link com.foxinmy.weixin4j.qy.api.MediaApi#batchUploadUsers(java.util.List)}
|
||||
* @see com.foxinmy.weixin4j.qy.model.Callback
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E5.85.A8.E9.87.8F.E8.A6.86.E7.9B.96.E6.88.90.E5.91.98">批量覆盖成员</a>
|
||||
@ -138,7 +138,7 @@ public class BatchApi extends QyApi {
|
||||
* @param callback
|
||||
* 接收任务执行结果的回调地址等信息
|
||||
* @return 异步任务id,最大长度为64字符
|
||||
* @see {@link com.foxinmy.weixin4j.qy.api.MediaApi#batchUploadParties(List)}
|
||||
* @see {@link com.foxinmy.weixin4j.qy.api.MediaApi#batchUploadParties(java.util.List)}
|
||||
* @see com.foxinmy.weixin4j.qy.model.Callback
|
||||
* @see <a
|
||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%8E%A5%E5%8F%A3#.E5.85.A8.E9.87.8F.E8.A6.86.E7.9B.96.E9.83.A8.E9.97.A8">批量覆盖部门</a>
|
||||
|
||||
@ -16,7 +16,7 @@ import com.foxinmy.weixin4j.util.AesToken;
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class WeixinRequest implements Serializable, Cloneable {
|
||||
public class WeixinRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -9157395300510879866L;
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ public class NewsResponse implements WeixinResponse {
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class Article {
|
||||
public static class Article {
|
||||
/**
|
||||
* 图文消息标题
|
||||
*/
|
||||
|
||||
@ -67,11 +67,11 @@ public class WeixinMessageDecoder extends
|
||||
String weixinId = parameters.containsKey("weixin_id") ? parameters.get(
|
||||
"weixin_id").get(0) : null;
|
||||
AesToken aesToken = aesTokenMap.get(weixinId);
|
||||
if (aesToken == null) { //
|
||||
/*if (aesToken == null) {
|
||||
AesToken _aesToken = aesTokenMap.get(null);
|
||||
aesToken = new AesToken(weixinId, _aesToken.getToken(),
|
||||
_aesToken.getAesKey());
|
||||
}
|
||||
}*/
|
||||
String originalContent = content;
|
||||
String encryptContent = null;
|
||||
if (!content.isEmpty() && encryptType == EncryptType.AES) {
|
||||
|
||||
@ -11,7 +11,7 @@ import java.io.Serializable;
|
||||
* @since JDK 1.7
|
||||
* @see
|
||||
*/
|
||||
public class AesToken implements Serializable, Cloneable {
|
||||
public class AesToken implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6001008896414323534L;
|
||||
|
||||
|
||||
@ -72,16 +72,18 @@ public final class ClassUtil {
|
||||
return file.isDirectory() || file.getName().endsWith(".class");
|
||||
}
|
||||
});
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
classes.addAll(findClassesByFile(file,
|
||||
packageName + "." + file.getName()));
|
||||
} else {
|
||||
try {
|
||||
classes.add(Class.forName(packageName + "."
|
||||
+ file.getName().replace(".class", "")));
|
||||
} catch (ClassNotFoundException e) {
|
||||
;
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
classes.addAll(findClassesByFile(file, packageName + "."
|
||||
+ file.getName()));
|
||||
} else {
|
||||
try {
|
||||
classes.add(Class.forName(packageName + "."
|
||||
+ file.getName().replace(".class", "")));
|
||||
} catch (ClassNotFoundException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user