mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-29 09:38:19 +08:00
🎨 优化代码
This commit is contained in:
@ -17,6 +17,7 @@ import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
import me.chanjar.weixin.common.enums.WxType;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxRuntimeException;
|
||||
import me.chanjar.weixin.common.util.DataUtils;
|
||||
import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
@ -155,7 +156,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
String response = doGetAccessTokenRequest();
|
||||
return extractAccessToken(response);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new WxRuntimeException(e);
|
||||
} finally {
|
||||
if (locked) {
|
||||
lock.unlock();
|
||||
@ -222,7 +223,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
} while (retryTimes++ < this.maxRetryTimes);
|
||||
|
||||
log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
|
||||
throw new RuntimeException("微信服务端异常,超出重试次数");
|
||||
throw new WxRuntimeException("微信服务端异常,超出重试次数");
|
||||
}
|
||||
|
||||
private <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
|
||||
@ -267,7 +268,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
throw new WxRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -354,7 +355,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
|
||||
return this;
|
||||
}
|
||||
|
||||
throw new RuntimeException(String.format("无法找到对应【%s】的小程序配置信息,请核实!", miniappId));
|
||||
throw new WxRuntimeException(String.format("无法找到对应【%s】的小程序配置信息,请核实!", miniappId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -8,6 +8,7 @@ import com.google.gson.annotations.SerializedName;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.common.error.WxRuntimeException;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
@ -174,7 +175,7 @@ public class WxMaMessage implements Serializable {
|
||||
return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8), wxMaConfig,
|
||||
timestamp, nonce, msgSignature);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new WxRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,7 +189,7 @@ public class WxMaMessage implements Serializable {
|
||||
String plainText = new WxMaCryptUtils(config).decrypt(encryptedMessage.getEncrypt());
|
||||
return fromJson(plainText);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new WxRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +197,7 @@ public class WxMaMessage implements Serializable {
|
||||
try {
|
||||
return fromEncryptedJson(IOUtils.toString(inputStream, StandardCharsets.UTF_8), config);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new WxRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.binarywang.wx.miniapp.config.impl;
|
||||
|
||||
import com.github.jedis.lock.JedisLock;
|
||||
import me.chanjar.weixin.common.error.WxRuntimeException;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.io.File;
|
||||
@ -232,10 +233,10 @@ public abstract class AbstractWxMaRedisConfig extends WxMaDefaultConfigImpl {
|
||||
public void lock() {
|
||||
try (Jedis jedis = getConfiguredJedis()) {
|
||||
if (!lock.acquire(jedis)) {
|
||||
throw new RuntimeException("acquire timeouted");
|
||||
throw new WxRuntimeException("acquire timeouted");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("lock failed", e);
|
||||
throw new WxRuntimeException("lock failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +244,7 @@ public abstract class AbstractWxMaRedisConfig extends WxMaDefaultConfigImpl {
|
||||
public void lockInterruptibly() throws InterruptedException {
|
||||
try (Jedis jedis = getConfiguredJedis()) {
|
||||
if (!lock.acquire(jedis)) {
|
||||
throw new RuntimeException("acquire timeouted");
|
||||
throw new WxRuntimeException("acquire timeouted");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -253,7 +254,7 @@ public abstract class AbstractWxMaRedisConfig extends WxMaDefaultConfigImpl {
|
||||
try (Jedis jedis = getConfiguredJedis()) {
|
||||
return lock.acquire(jedis);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("lock failed", e);
|
||||
throw new WxRuntimeException("lock failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,7 +274,7 @@ public abstract class AbstractWxMaRedisConfig extends WxMaDefaultConfigImpl {
|
||||
|
||||
@Override
|
||||
public Condition newCondition() {
|
||||
throw new RuntimeException("unsupported method");
|
||||
throw new WxRuntimeException("unsupported method");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import me.chanjar.weixin.common.error.WxRuntimeException;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
@ -47,7 +48,7 @@ public class WxMaCryptUtils extends me.chanjar.weixin.common.util.crypto.WxCrypt
|
||||
|
||||
return new String(PKCS7Encoder.decode(cipher.doFinal(Base64.decodeBase64(encryptedData))), UTF_8);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("AES解密失败!", e);
|
||||
throw new WxRuntimeException("AES解密失败!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +79,7 @@ public class WxMaCryptUtils extends me.chanjar.weixin.common.util.crypto.WxCrypt
|
||||
cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(Base64.decodeBase64(ivStr.getBytes(UTF_8))));
|
||||
return new String(cipher.doFinal(Base64.decodeBase64(encryptedData.getBytes(UTF_8))), UTF_8);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("AES解密失败!", e);
|
||||
throw new WxRuntimeException("AES解密失败!", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxRuntimeException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -23,7 +24,7 @@ public class ApiTestModule implements Module {
|
||||
public void configure(Binder binder) {
|
||||
try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(TEST_CONFIG_XML)) {
|
||||
if (inputStream == null) {
|
||||
throw new RuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成");
|
||||
throw new WxRuntimeException("测试配置文件【" + TEST_CONFIG_XML + "】未找到,请参照test-config-sample.xml文件生成");
|
||||
}
|
||||
TestConfig config = TestConfig.fromXml(inputStream);
|
||||
config.setAccessTokenLock(new ReentrantLock());
|
||||
|
||||
Reference in New Issue
Block a user