🎨 #1659 Json解析统一优化

* 解决动态添加第一个公众号时由于configStorageMap为null报空指针异常

* Json解析统一优化

Co-authored-by: niefy <niefy@qq.com>
This commit is contained in:
niefy
2020-07-06 17:01:37 +08:00
committed by GitHub
parent 8121a521d3
commit 0adca9650d
114 changed files with 229 additions and 337 deletions

View File

@@ -8,7 +8,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.annotation.Required;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.util.Map;

View File

@@ -2,7 +2,6 @@ package com.github.binarywang.wxpay.bean.profitsharing;
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.*;
import me.chanjar.weixin.common.annotation.Required;

View File

@@ -1,11 +1,11 @@
package com.github.binarywang.wxpay.bean.result;
import com.google.common.collect.Lists;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.*;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Document;
@@ -149,10 +149,10 @@ public class WxPayRefundQueryResult extends BaseWxPayResult implements Serializa
return;
}
JsonElement tmpJsonElement = new JsonParser().parse(this.promotionDetailString);
JsonObject tmpJson = GsonParser.parse(this.promotionDetailString);
final List<WxPayRefundPromotionDetail> promotionDetail = WxGsonBuilder.create()
.fromJson(tmpJsonElement.getAsJsonObject().get("promotion_detail"),
.fromJson(tmpJson.get("promotion_detail"),
new TypeToken<List<WxPayRefundPromotionDetail>>() {
}.getType()
);

View File

@@ -1,13 +1,13 @@
package com.github.binarywang.wxpay.bean.result;
import com.google.common.collect.Lists;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Document;
@@ -138,10 +138,10 @@ public class WxPayRefundResult extends BaseWxPayResult implements Serializable {
return;
}
JsonElement tmpJsonElement = new JsonParser().parse(this.promotionDetailString);
JsonObject tmpJson = GsonParser.parse(this.promotionDetailString);
final List<WxPayRefundPromotionDetail> promotionDetail = WxGsonBuilder.create()
.fromJson(tmpJsonElement.getAsJsonObject().get("promotion_detail"),
.fromJson(tmpJson.get("promotion_detail"),
new TypeToken<List<WxPayRefundPromotionDetail>>() {
}.getType()
);

View File

@@ -5,8 +5,6 @@ import com.github.binarywang.wxpay.bean.payscore.WxPayScoreRequest;
import com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult;
import com.github.binarywang.wxpay.exception.WxPayException;
import java.net.URISyntaxException;
/**
* <pre>
* 支付分相关服务类.

View File

@@ -1,8 +1,6 @@
package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.bean.profitsharing.*;
import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingResult;
import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingRequest;
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.ProfitSharingService;

View File

@@ -3,8 +3,8 @@ package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.bean.WxPayApiData;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import jodd.util.Base64;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpStatus;
@@ -38,7 +38,6 @@ import java.nio.charset.StandardCharsets;
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
private final static JsonParser JSON_PARSER = new JsonParser();
@Override
public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException {
@@ -104,7 +103,7 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
return responseString;
} else {
//有错误提示信息返回
JsonObject jsonObject = JSON_PARSER.parse(responseString).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseString);
throw new WxPayException(jsonObject.get("message").getAsString());
}
} catch (Exception e) {
@@ -132,7 +131,7 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
return responseString;
} else {
//有错误提示信息返回
JsonObject jsonObject = JSON_PARSER.parse(responseString).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseString);
throw new WxPayException(jsonObject.get("message").getAsString());
}
} catch (Exception e) {

View File

@@ -10,8 +10,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Slf4j
public class WxPayCredentials implements Credentials {

View File

@@ -9,8 +9,7 @@ import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Slf4j
public class WxPayValidator implements Validator {
private Verifier verifier;

View File

@@ -2,8 +2,6 @@ package com.github.binarywang.wxpay.bean.entpay;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
/**
* .
*

View File

@@ -1,9 +1,6 @@
package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.bean.profitsharing.*;
import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingRequest;
import com.github.binarywang.wxpay.bean.profitsharing.Receiver;
import com.github.binarywang.wxpay.bean.profitsharing.ReceiverList;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;