🎨 #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

@@ -2,7 +2,6 @@ package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -10,6 +9,7 @@ import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
@@ -33,7 +33,7 @@ import java.util.concurrent.locks.Lock;
@Slf4j
@AllArgsConstructor
public class WxOpenComponentServiceImpl implements WxOpenComponentService {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final Map<String, WxOpenMaService> WX_OPEN_MA_SERVICE_MAP = new ConcurrentHashMap<>();
private static final Map<String, WxMpService> WX_OPEN_MP_SERVICE_MAP = new ConcurrentHashMap<>();
private static final Map<String, WxOpenFastMaService> WX_OPEN_FAST_MA_SERVICE_MAP = new ConcurrentHashMap<>();
@@ -435,7 +435,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
@Override
public List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException {
String responseContent = get(GET_TEMPLATE_DRAFT_LIST_URL, "access_token");
JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject();
JsonObject response = GsonParser.parse(StringUtils.defaultString(responseContent, "{}"));
boolean hasDraftList = response.has("draft_list");
if (hasDraftList) {
return WxOpenGsonBuilder.create().fromJson(response.getAsJsonArray("draft_list"),
@@ -449,7 +449,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
@Override
public List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException {
String responseContent = get(GET_TEMPLATE_LIST_URL, "access_token");
JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject();
JsonObject response = GsonParser.parse(StringUtils.defaultString(responseContent, "{}"));
boolean hasTemplateList = response.has("template_list");
if (hasTemplateList) {
return WxOpenGsonBuilder.create().fromJson(response.getAsJsonArray("template_list"),

View File

@@ -1,6 +1,5 @@
package me.chanjar.weixin.open.bean;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;

View File

@@ -3,8 +3,6 @@ package me.chanjar.weixin.open.bean.ma;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import java.util.List;
/**
* @author zxfreedom
* @description

View File

@@ -11,8 +11,6 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;

View File

@@ -3,7 +3,6 @@ package me.chanjar.weixin.open.util;
import com.google.common.base.CharMatcher;
import com.google.common.io.BaseEncoding;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import org.apache.commons.codec.binary.Base64;
/**
* @author <a href="https://github.com/007gzs">007</a>

View File

@@ -2,8 +2,6 @@ package me.chanjar.weixin.open.api.impl;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
/**
* 单元测试类.
*