🎨 weixin-java-pay模块去除jackson依赖,调整相关代码

This commit is contained in:
cofe 2021-01-08 17:07:32 +08:00 committed by GitHub
parent 1eec0f4bfa
commit fd58b3f212
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 11 deletions

View File

@ -70,12 +70,6 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
</dependency> </dependency>
<dependency>
<!-- 待优化去掉 -->
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.0.pr1</version>
</dependency>
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>

View File

@ -1,16 +1,17 @@
package com.github.binarywang.wxpay.v3.auth; package com.github.binarywang.wxpay.v3.auth;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.binarywang.wxpay.v3.Credentials; import com.github.binarywang.wxpay.v3.Credentials;
import com.github.binarywang.wxpay.v3.Validator; import com.github.binarywang.wxpay.v3.Validator;
import com.github.binarywang.wxpay.v3.WxPayV3HttpClientBuilder; import com.github.binarywang.wxpay.v3.WxPayV3HttpClientBuilder;
import com.github.binarywang.wxpay.v3.util.AesUtils; import com.github.binarywang.wxpay.v3.util.AesUtils;
import com.github.binarywang.wxpay.v3.util.PemUtils; import com.github.binarywang.wxpay.v3.util.PemUtils;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxRuntimeException; import me.chanjar.weixin.common.error.WxRuntimeException;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
@ -158,15 +159,15 @@ public class AutoUpdateCertificatesVerifier implements Verifier {
*/ */
private List<X509Certificate> deserializeToCerts(byte[] apiV3Key, String body) throws GeneralSecurityException, IOException { private List<X509Certificate> deserializeToCerts(byte[] apiV3Key, String body) throws GeneralSecurityException, IOException {
AesUtils aesUtils = new AesUtils(apiV3Key); AesUtils aesUtils = new AesUtils(apiV3Key);
ObjectMapper mapper = new ObjectMapper(); final JsonObject json = GsonParser.parse(body);
JsonNode dataNode = mapper.readTree(body).get("data"); final JsonArray dataNode = json.getAsJsonArray("data");
if (dataNode == null) { if (dataNode == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
List<X509Certificate> newCertList = new ArrayList<>(); List<X509Certificate> newCertList = new ArrayList<>();
for (int i = 0, count = dataNode.size(); i < count; i++) { for (int i = 0, count = dataNode.size(); i < count; i++) {
JsonNode encryptCertificateNode = dataNode.get(i).get("encrypt_certificate"); final JsonObject encryptCertificateNode = ((JsonObject) dataNode.get(i)).getAsJsonObject("encrypt_certificate");
//解密 //解密
String cert = aesUtils.decryptToString( String cert = aesUtils.decryptToString(
encryptCertificateNode.get("associated_data").toString().replaceAll("\"", "") encryptCertificateNode.get("associated_data").toString().replaceAll("\"", "")