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

@@ -1,7 +1,6 @@
package cn.binarywang.wx.graal;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;

View File

@@ -1,7 +1,6 @@
package me.chanjar.weixin.common.util.http.apache;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;

View File

@@ -1,7 +1,6 @@
package me.chanjar.weixin.common.util.http.apache;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
@@ -12,7 +11,6 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;

View File

@@ -6,7 +6,6 @@ import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.util.StringPool;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;

View File

@@ -1,7 +1,6 @@
package me.chanjar.weixin.common.util.http.okhttp;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;

View File

@@ -0,0 +1,23 @@
package me.chanjar.weixin.common.util.json;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import java.io.Reader;
public class GsonParser {
private static final JsonParser JSON_PARSER = new JsonParser();
public static JsonObject parse(String json){
return JSON_PARSER.parse(json).getAsJsonObject();
}
public static JsonObject parse(Reader json){
return JSON_PARSER.parse(json).getAsJsonObject();
}
public static JsonObject parse(JsonReader json){
return JSON_PARSER.parse(json).getAsJsonObject();
}
}

View File

@@ -1,6 +1,5 @@
package me.chanjar.weixin.common.api;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;

View File

@@ -3,7 +3,6 @@ package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.*;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

View File

@@ -2,9 +2,7 @@ package me.chanjar.weixin.cp.api.impl;
import com.google.common.base.Joiner;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
@@ -20,6 +18,7 @@ import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.*;
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
import me.chanjar.weixin.cp.bean.WxCpMessage;
@@ -110,7 +109,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
synchronized (this.globalAgentJsapiTicketRefreshLock) {
if (this.configStorage.isAgentJsapiTicketExpired()) {
String responseContent = this.get(this.configStorage.getApiUrl(GET_AGENT_CONFIG_TICKET), null);
JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
this.configStorage.updateAgentJsapiTicket(jsonObject.get("ticket").getAsString(),
jsonObject.get("expires_in").getAsInt());
}
@@ -135,7 +134,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
synchronized (this.globalJsapiTicketRefreshLock) {
if (this.configStorage.isJsapiTicketExpired()) {
String responseContent = this.get(this.configStorage.getApiUrl(GET_JSAPI_TICKET), null);
JsonObject tmpJsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
this.configStorage.updateJsapiTicket(tmpJsonObject.get("ticket").getAsString(),
tmpJsonObject.get("expires_in").getAsInt());
}
@@ -191,8 +190,8 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
@Override
public String[] getCallbackIp() throws WxErrorException {
String responseContent = get(this.configStorage.getApiUrl(GET_CALLBACK_IP), null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
JsonArray jsonArray = tmpJsonObject.get("ip_list").getAsJsonArray();
String[] ips = new String[jsonArray.size()];
for (int i = 0; i < jsonArray.size(); i++) {
ips[i] = jsonArray.get(i).getAsString();

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.cp.api.impl;
import com.google.common.base.Joiner;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.WxType;
@@ -15,6 +14,7 @@ import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.WxCpTpService;
import me.chanjar.weixin.cp.bean.*;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
@@ -119,7 +119,7 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
jsonObject.addProperty("auth_code", authCode);
String result = post(configStorage.getApiUrl(GET_PERMANENT_CODE), jsonObject.toString());
jsonObject = new JsonParser().parse(result).getAsJsonObject();
jsonObject = GsonParser.parse(result);
WxCpTpCorp wxCpTpCorp = WxCpTpCorp.fromJson(jsonObject.get("auth_corp_info").getAsJsonObject().toString());
wxCpTpCorp.setPermanentCode(jsonObject.get("permanent_code").getAsString());
return wxCpTpCorp;

View File

@@ -1,12 +1,12 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.WxCpAgentService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpAgent;
@@ -27,7 +27,7 @@ import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Agent.*;
*/
@RequiredArgsConstructor
public class WxCpAgentServiceImpl implements WxCpAgentService {
private static final JsonParser JSON_PARSER = new JsonParser();
private final WxCpService mainService;
@@ -45,7 +45,7 @@ public class WxCpAgentServiceImpl implements WxCpAgentService {
public void set(WxCpAgent agentInfo) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_SET);
String responseContent = this.mainService.post(url, agentInfo.toJson());
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.CP));
}
@@ -55,7 +55,7 @@ public class WxCpAgentServiceImpl implements WxCpAgentService {
public List<WxCpAgent> list() throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_LIST);
String responseContent = this.mainService.get(url, null);
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.CP));
}

View File

@@ -1,14 +1,13 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonParser;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.cp.api.WxCpChatService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpAppChatMessage;
import me.chanjar.weixin.cp.bean.WxCpChat;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import org.apache.commons.lang3.StringUtils;
@@ -25,7 +24,7 @@ import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Chat.*;
*/
@RequiredArgsConstructor
public class WxCpChatServiceImpl implements WxCpChatService {
private static final JsonParser JSON_PARSER = new JsonParser();
private final WxCpService cpService;
@Override
@@ -45,7 +44,7 @@ public class WxCpChatServiceImpl implements WxCpChatService {
}
final String url = this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_CREATE);
String result = this.cpService.post(url, WxGsonBuilder.create().toJson(data));
return new JsonParser().parse(result).getAsJsonObject().get("chatid").getAsString();
return GsonParser.parse(result).get("chatid").getAsString();
}
@Override
@@ -87,7 +86,7 @@ public class WxCpChatServiceImpl implements WxCpChatService {
public WxCpChat chatGet(String chatId) throws WxErrorException {
final String url = this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_GET_CHATID + chatId);
String result = this.cpService.get(url, null);
final String chatInfo = JSON_PARSER.parse(result).getAsJsonObject().getAsJsonObject("chat_info").toString();
final String chatInfo = GsonParser.parse(result).getAsJsonObject("chat_info").toString();
return WxCpGsonBuilder.create().fromJson(chatInfo, WxCpChat.class);
}

View File

@@ -1,15 +1,14 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.util.List;
@@ -32,8 +31,8 @@ public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
public Long create(WxCpDepart depart) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_CREATE);
String responseContent = this.mainService.post(url, depart.toJson());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("id"));
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
return GsonHelper.getAsLong(tmpJsonObject.get("id"));
}
@Override
@@ -56,9 +55,9 @@ public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
}
String responseContent = this.mainService.get(url, null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(tmpJsonElement.getAsJsonObject().get("department"),
.fromJson(tmpJsonObject.get("department"),
new TypeToken<List<WxCpDepart>>() {
}.getType()
);

View File

@@ -6,10 +6,8 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.cp.api.WxCpMediaService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import java.io.File;
import java.io.IOException;

View File

@@ -5,7 +5,6 @@ import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpMenuService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Menu.*;

View File

@@ -1,24 +1,18 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.WxCpOAuth2Service;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo;
import me.chanjar.weixin.cp.bean.WxCpUserDetail;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import static me.chanjar.weixin.common.api.WxConsts.OAuth2Scope.*;
import static me.chanjar.weixin.common.api.WxConsts.OAuth2Scope.SNSAPI_PRIVATEINFO;
import static me.chanjar.weixin.common.api.WxConsts.OAuth2Scope.SNSAPI_USERINFO;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.OAuth2.*;
/**
@@ -74,8 +68,7 @@ public class WxCpOAuth2ServiceImpl implements WxCpOAuth2Service {
@Override
public WxCpOauth2UserInfo getUserInfo(Integer agentId, String code) throws WxErrorException {
String responseText = this.mainService.get(String.format(this.mainService.getWxCpConfigStorage().getApiUrl(GET_USER_INFO), code, agentId), null);
JsonElement je = new JsonParser().parse(responseText);
JsonObject jo = je.getAsJsonObject();
JsonObject jo = GsonParser.parse(responseText);
return WxCpOauth2UserInfo.builder()
.userId(GsonHelper.getString(jo, "UserId"))

View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.WxCpOaService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.oa.*;
@@ -64,10 +64,10 @@ public class WxCpOaServiceImpl implements WxCpOaService {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_DATA);
String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJson = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("checkindata"),
tmpJson.get("checkindata"),
new TypeToken<List<WxCpCheckinData>>() {
}.getType()
);
@@ -94,11 +94,11 @@ public class WxCpOaServiceImpl implements WxCpOaService {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_OPTION);
String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJson = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("info"),
tmpJson.get("info"),
new TypeToken<List<WxCpCheckinOption>>() {
}.getType()
);
@@ -202,9 +202,9 @@ public class WxCpOaServiceImpl implements WxCpOaService {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_DIAL_RECORD);
String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJson = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create().fromJson(tmpJsonElement.getAsJsonObject().get("record"),
return WxCpGsonBuilder.create().fromJson(tmpJson.get("record"),
new TypeToken<List<WxCpDialRecord>>() {
}.getType()
);

View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -88,7 +88,7 @@ public class WxCpServiceImpl extends WxCpServiceApacheHttpClientImpl {
// 拿到锁之后再次判断一下最新的token是否过期避免重刷
if (getWxCpConfigStorage().isAgentJsapiTicketExpired()) {
String responseContent = this.get(getWxCpConfigStorage().getApiUrl(GET_AGENT_CONFIG_TICKET), null);
JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
getWxCpConfigStorage().updateAgentJsapiTicket(jsonObject.get("ticket").getAsString(),
jsonObject.get("expires_in").getAsInt());
}
@@ -112,7 +112,7 @@ public class WxCpServiceImpl extends WxCpServiceApacheHttpClientImpl {
// 拿到锁之后再次判断一下最新的token是否过期避免重刷
if (getWxCpConfigStorage().isJsapiTicketExpired()) {
String responseContent = this.get(getWxCpConfigStorage().getApiUrl(GET_JSAPI_TICKET), null);
JsonObject tmpJsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
getWxCpConfigStorage().updateJsapiTicket(tmpJsonObject.get("ticket").getAsString(),
tmpJsonObject.get("expires_in").getAsInt());
}

View File

@@ -4,6 +4,7 @@ import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpTagService;
import me.chanjar.weixin.cp.bean.WxCpTag;
@@ -49,8 +50,8 @@ public class WxCpTagServiceImpl implements WxCpTagService {
private String create(JsonObject param) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(TAG_CREATE);
String responseContent = this.mainService.post(url, param.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("tagid").getAsString();
JsonObject jsonObject = GsonParser.parse(responseContent);
return jsonObject.get("tagid").getAsString();
}
@Override
@@ -72,10 +73,10 @@ public class WxCpTagServiceImpl implements WxCpTagService {
public List<WxCpTag> listAll() throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(TAG_LIST);
String responseContent = this.mainService.get(url, null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJson = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("taglist"),
tmpJson.get("taglist"),
new TypeToken<List<WxCpTag>>() {
}.getType()
);
@@ -85,10 +86,10 @@ public class WxCpTagServiceImpl implements WxCpTagService {
public List<WxCpUser> listUsersByTagId(String tagId) throws WxErrorException {
String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(TAG_GET), tagId);
String responseContent = this.mainService.get(url, null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJson = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"),
tmpJson.get("userlist"),
new TypeToken<List<WxCpUser>>() {
}.getType()
);

View File

@@ -5,7 +5,6 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpTaskCardService;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import java.util.HashMap;
import java.util.List;

View File

@@ -2,13 +2,13 @@ package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.HttpType;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import org.apache.http.Consts;
@@ -76,7 +76,7 @@ public class WxCpTpServiceApacheHttpClientImpl extends BaseWxCpTpServiceImpl<Clo
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
jsonObject = new JsonParser().parse(resultContent).getAsJsonObject();
jsonObject = GsonParser.parse(resultContent);
String suiteAccussToken = jsonObject.get("suite_access_token").getAsString();
Integer expiresIn = jsonObject.get("expires_in").getAsInt();
this.configStorage.updateSuiteAccessToken(suiteAccussToken, expiresIn);

View File

@@ -5,6 +5,7 @@ import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpUserService;
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
@@ -84,9 +85,9 @@ public class WxCpUserServiceImpl implements WxCpUserService {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(USER_LIST + departId);
String responseContent = this.mainService.get(url, params);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject jsonObject = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(tmpJsonElement.getAsJsonObject().get("userlist"),
.fromJson(jsonObject.get("userlist"),
new TypeToken<List<WxCpUser>>() {
}.getType()
);
@@ -107,10 +108,10 @@ public class WxCpUserServiceImpl implements WxCpUserService {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(USER_SIMPLE_LIST + departId);
String responseContent = this.mainService.get(url, params);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJson = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"),
tmpJson.get("userlist"),
new TypeToken<List<WxCpUser>>() {
}.getType()
);
@@ -158,14 +159,14 @@ public class WxCpUserServiceImpl implements WxCpUserService {
}
String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJson = GsonParser.parse(responseContent);
Map<String, String> result = Maps.newHashMap();
if (tmpJsonElement.getAsJsonObject().get("openid") != null) {
result.put("openid", tmpJsonElement.getAsJsonObject().get("openid").getAsString());
if (tmpJson.get("openid") != null) {
result.put("openid", tmpJson.get("openid").getAsString());
}
if (tmpJsonElement.getAsJsonObject().get("appid") != null) {
result.put("appid", tmpJsonElement.getAsJsonObject().get("appid").getAsString());
if (tmpJson.get("appid") != null) {
result.put("appid", tmpJson.get("appid").getAsString());
}
return result;
@@ -177,8 +178,8 @@ public class WxCpUserServiceImpl implements WxCpUserService {
jsonObject.addProperty("openid", openid);
String url = this.mainService.getWxCpConfigStorage().getApiUrl(USER_CONVERT_TO_USERID);
String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("userid").getAsString();
JsonObject tmpJson = GsonParser.parse(responseContent);
return tmpJson.get("userid").getAsString();
}
@Override
@@ -187,8 +188,8 @@ public class WxCpUserServiceImpl implements WxCpUserService {
jsonObject.addProperty("mobile", mobile);
String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_USER_ID);
String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("userid").getAsString();
JsonObject tmpJson = GsonParser.parse(responseContent);
return tmpJson.get("userid").getAsString();
}
@Override

View File

@@ -1,12 +1,7 @@
package me.chanjar.weixin.cp.bean;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Splitter;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

View File

@@ -8,16 +8,7 @@ import com.thoughtworks.xstream.annotations.XStreamConverter;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.util.XmlUtils;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.cp.bean.outxmlbuilder.ImageBuilder;
import me.chanjar.weixin.cp.bean.outxmlbuilder.NewsBuilder;
import me.chanjar.weixin.cp.bean.outxmlbuilder.TextBuilder;
import me.chanjar.weixin.cp.bean.outxmlbuilder.VideoBuilder;
import me.chanjar.weixin.cp.bean.outxmlbuilder.VoiceBuilder;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
/**

View File

@@ -8,13 +8,6 @@ import com.thoughtworks.xstream.annotations.XStreamConverter;
import lombok.Data;
import me.chanjar.weixin.common.util.XmlUtils;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.cp.bean.outxmlbuilder.ImageBuilder;
import me.chanjar.weixin.cp.bean.outxmlbuilder.NewsBuilder;
import me.chanjar.weixin.cp.bean.outxmlbuilder.TextBuilder;
import me.chanjar.weixin.cp.bean.outxmlbuilder.VideoBuilder;
import me.chanjar.weixin.cp.bean.outxmlbuilder.VoiceBuilder;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
/**

View File

@@ -1,6 +1,5 @@
package me.chanjar.weixin.cp.bean;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;

View File

@@ -1,15 +1,12 @@
package me.chanjar.weixin.cp.bean.oa;
import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateContent;
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateControls;
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateTitle;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* 审批模板详情

View File

@@ -3,7 +3,6 @@ package me.chanjar.weixin.cp.bean.oa.templatedata;
import lombok.Data;
import java.io.Serializable;
import java.util.Map;
/**
* @author Administrator

View File

@@ -5,7 +5,6 @@ import lombok.Data;
import me.chanjar.weixin.cp.bean.oa.templatedata.TemplateDateRange;
import java.io.Serializable;
import java.util.Map;
/**
* @author gyv12345@163.com

View File

@@ -8,7 +8,6 @@ import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.*;
/**
* <pre>

View File

@@ -2,21 +2,17 @@ package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonObject;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpTpService;
import me.chanjar.weixin.cp.bean.WxCpTpAuthInfo;
import me.chanjar.weixin.cp.bean.WxCpTpCorp;
import me.chanjar.weixin.cp.bean.WxCpTpPermanentCodeInfo;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import org.testng.annotations.Test;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tp.GET_AUTH_INFO;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Tp.GET_PERMANENT_CODE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;
import static org.testng.Assert.*;

View File

@@ -9,14 +9,12 @@ import me.chanjar.weixin.cp.bean.WxCpAgent;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.constant.WxCpConsts;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.contentOf;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;

View File

@@ -15,7 +15,6 @@ import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.Gender;
import me.chanjar.weixin.cp.bean.WxCpInviteResult;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
import static org.testng.Assert.*;

View File

@@ -3,7 +3,6 @@ package me.chanjar.weixin.cp.bean;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.*;
/**
* .

View File

@@ -8,7 +8,6 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
public class WxCpOAuth2Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;

View File

@@ -7,7 +7,6 @@ import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.api.WxOcrService;
@@ -20,6 +19,7 @@ import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import org.apache.commons.lang3.StringUtils;
@@ -37,7 +37,7 @@ import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ErrorCode.*;
*/
@Slf4j
public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestHttp<H, P> {
private static final JsonParser JSON_PARSER = new JsonParser();
private WxMaConfig wxMaConfig;
private final WxMaMsgService kefuService = new WxMaMsgServiceImpl(this);
@@ -94,7 +94,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
throw new WxErrorException(error);
}
return JSON_PARSER.parse(responseContent).getAsJsonObject().get("unionid").getAsString();
return GsonParser.parse(responseContent).get("unionid").getAsString();
}
@Override

View File

@@ -10,10 +10,10 @@ import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitPage;
import cn.binarywang.wx.miniapp.bean.analysis.WxMaVisitTrend;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.lang.reflect.Type;
@@ -26,7 +26,7 @@ import java.util.List;
*/
@AllArgsConstructor
public class WxMaAnalysisServiceImpl implements WxMaAnalysisService {
private static final JsonParser JSON_PARSER = new JsonParser();
private WxMaService wxMaService;
@Override
@@ -106,7 +106,7 @@ public class WxMaAnalysisServiceImpl implements WxMaAnalysisService {
*/
private <T> List<T> getAnalysisResultAsList(String url, Date beginDate, Date endDate, Type returnType) throws WxErrorException {
String responseContent = this.wxMaService.post(url, toJson(beginDate, endDate));
JsonObject response = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject response = GsonParser.parse(responseContent);
boolean hasList = response.has("list");
if (hasList) {
return WxMaGsonBuilder.create().fromJson(response.getAsJsonArray("list"), returnType);

View File

@@ -11,11 +11,11 @@ import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import org.apache.commons.lang3.StringUtils;
@@ -31,7 +31,7 @@ import java.util.*;
@Slf4j
@RequiredArgsConstructor
public class WxMaCloudServiceImpl implements WxMaCloudService {
private static final JsonParser JSON_PARSER = new JsonParser();
private final WxMaService wxMaService;
@Override
@@ -44,7 +44,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
public String invokeCloudFunction(String env, String name, String body) throws WxErrorException {
String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv();
final String response = this.wxMaService.post(String.format(INVOKE_CLOUD_FUNCTION_URL, cloudEnv, name), body);
return JSON_PARSER.parse(response).getAsJsonObject().get("resp_data").getAsString();
return GsonParser.parse(response).get("resp_data").getAsString();
}
@Override
@@ -59,8 +59,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
params.addProperty("query", query);
String responseContent = wxMaService.post(DATABASE_ADD_URL, params.toString());
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
}
@@ -84,8 +83,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
params.addProperty("query", query);
String responseContent = wxMaService.post(DATABASE_ADD_URL, params.toString());
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
}
@@ -102,7 +100,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
@Override
public JsonArray databaseAdd(String env, String query) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_ADD_URL, ImmutableMap.of("env", env, "query", query));
return JSON_PARSER.parse(response).getAsJsonObject().get("id_list").getAsJsonArray();
return GsonParser.parse(response).get("id_list").getAsJsonArray();
}
@Override
@@ -116,8 +114,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
params.addProperty("query", query);
String responseContent = wxMaService.post(DATABASE_DELETE_URL, params.toString());
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
}
@@ -133,7 +130,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
@Override
public int databaseDelete(String env, String query) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_DELETE_URL, ImmutableMap.of("env", env, "query", query));
return JSON_PARSER.parse(response).getAsJsonObject().get("deleted").getAsInt();
return GsonParser.parse(response).get("deleted").getAsInt();
}
@Override
@@ -214,7 +211,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
@Override
public JsonArray databaseAggregate(String env, String query) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_AGGREGATE_URL, ImmutableMap.of("env", env, "query", query));
return JSON_PARSER.parse(response).getAsJsonObject().get("data").getAsJsonArray();
return GsonParser.parse(response).get("data").getAsJsonArray();
}
@Override
@@ -228,7 +225,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
params.addProperty("query", query);
String responseContent = wxMaService.post(DATABASE_COUNT_URL, params.toString());
return JSON_PARSER.parse(responseContent).getAsJsonObject().get("count").getAsLong();
return GsonParser.parse(responseContent).get("count").getAsLong();
}
@Override
@@ -240,7 +237,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
@Override
public Long databaseCount(String env, String query) throws WxErrorException {
String response = this.wxMaService.post(DATABASE_COUNT_URL, ImmutableMap.of("env", env, "query", query));
return JSON_PARSER.parse(response).getAsJsonObject().get("count").getAsLong();
return GsonParser.parse(response).get("count").getAsLong();
}
@Override
@@ -283,7 +280,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
params.addProperty("conflict_mode", conflictMode);
String response = this.wxMaService.post(DATABASE_MIGRATE_IMPORT_URL, params.toString());
return JSON_PARSER.parse(response).getAsJsonObject().get("job_id").getAsLong();
return GsonParser.parse(response).get("job_id").getAsLong();
}
@Override
@@ -301,7 +298,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
params.addProperty("query", query);
String response = this.wxMaService.post(DATABASE_MIGRATE_EXPORT_URL, params.toString());
return JSON_PARSER.parse(response).getAsJsonObject().get("job_id").getAsLong();
return GsonParser.parse(response).get("job_id").getAsLong();
}
@Override

View File

@@ -9,6 +9,7 @@ import java.nio.file.Path;
import java.util.List;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.StringUtils;
import cn.binarywang.wx.miniapp.api.WxMaCodeService;
@@ -20,7 +21,6 @@ import cn.binarywang.wx.miniapp.bean.code.WxMaCodeSubmitAuditRequest;
import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
@@ -34,7 +34,7 @@ import me.chanjar.weixin.common.util.json.GsonHelper;
*/
@AllArgsConstructor
public class WxMaCodeServiceImpl implements WxMaCodeService {
private static final JsonParser JSON_PARSER = new JsonParser();
private WxMaService wxMaService;
@Override
@@ -73,7 +73,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
@Override
public List<WxMaCategory> getCategory() throws WxErrorException {
String responseContent = this.wxMaService.get(GET_CATEGORY_URL, null);
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
boolean hasCategoryList = jsonObject.has("category_list");
if (hasCategoryList) {
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("category_list"),
@@ -87,7 +87,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
@Override
public List<String> getPage() throws WxErrorException {
String responseContent = this.wxMaService.get(GET_PAGE_URL, null);
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
boolean hasPageList = jsonObject.has("page_list");
if (hasPageList) {
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("page_list"),
@@ -101,7 +101,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
@Override
public long submitAudit(WxMaCodeSubmitAuditRequest auditRequest) throws WxErrorException {
String responseContent = this.wxMaService.post(SUBMIT_AUDIT_URL, auditRequest.toJson());
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
return GsonHelper.getLong(jsonObject, "auditid");
}

View File

@@ -2,14 +2,13 @@ package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaJsapiService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.RandomUtils;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.util.concurrent.locks.Lock;
@@ -22,7 +21,7 @@ import java.util.concurrent.locks.Lock;
*/
@AllArgsConstructor
public class WxMaJsapiServiceImpl implements WxMaJsapiService {
private static final JsonParser JSON_PARSER = new JsonParser();
private WxMaService wxMaService;
@@ -42,8 +41,7 @@ public class WxMaJsapiServiceImpl implements WxMaJsapiService {
if (this.wxMaService.getWxMaConfig().isCardApiTicketExpired()) {
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=wx_card", null);
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.wxMaService.getWxMaConfig().updateCardApiTicket(jsapiTicket, expiresInSeconds);
@@ -70,8 +68,7 @@ public class WxMaJsapiServiceImpl implements WxMaJsapiService {
if (this.wxMaService.getWxMaConfig().isJsapiTicketExpired()) {
String responseContent = this.wxMaService.get(GET_JSAPI_TICKET_URL + "?type=jsapi", null);
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.wxMaService.getWxMaConfig().updateJsapiTicket(jsapiTicket, expiresInSeconds);

View File

@@ -14,6 +14,7 @@ import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.io.Serializable;
import java.util.HashMap;
@@ -29,7 +30,6 @@ import java.util.Map;
*/
@AllArgsConstructor
public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
private static final JsonParser JSON_PARSER = new JsonParser();
private WxMaService wxMaService;
@@ -38,7 +38,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
Map<String, Object> map = new HashMap<>(2);
map.put("goodsInfo", goods);
String responseContent = this.wxMaService.post(ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -51,7 +51,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
map.put("auditId", auditId);
map.put("goodsId", goodsId);
String responseContent = this.wxMaService.post(RESET_AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -63,7 +63,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
Map<String, Integer> map = new HashMap<>(2);
map.put("goodsId", goodsId);
String responseContent = this.wxMaService.post(AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -75,7 +75,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
Map<String, Integer> map = new HashMap<>(2);
map.put("goodsId", goodsId);
String responseContent = this.wxMaService.post(DELETE_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -87,7 +87,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
Map<String, Object> map = new HashMap<>(2);
map.put("goodsInfo", goods);
String responseContent = this.wxMaService.post(UPDATE_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -99,7 +99,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
Map<String, Object> map = new HashMap<>(2);
map.put("goods_ids", goodsIds);
String responseContent = this.wxMaService.post(GET_GOODS_WARE_HOUSE, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -110,7 +110,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
public WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException {
ImmutableMap<String, ? extends Serializable> params = ImmutableMap.of("status", status, "offset", offset, "limit", limit);
String responseContent = wxMaService.get(GET_APPROVED_GOODS, Joiner.on("&").withKeyValueSeparator("=").join(params));
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

View File

@@ -6,12 +6,12 @@ import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.util.ArrayList;
import java.util.HashMap;
@@ -28,13 +28,12 @@ import java.util.Map;
@Slf4j
@AllArgsConstructor
public class WxMaLiveServiceImpl implements WxMaLiveService {
private static final JsonParser JSON_PARSER = new JsonParser();
private final WxMaService wxMaService;
@Override
public Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException {
String responseContent = this.wxMaService.post(CREATE_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -95,7 +94,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
map.put("roomId", roomId);
map.put("ids", goodsIds);
String responseContent = this.wxMaService.post(ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -104,12 +103,12 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
if (map == null) {
map = new HashMap<>(2);
map = new HashMap(2);
}
map.put("start", start);
map.put("limit", limit);
String responseContent = wxMaService.post(GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

View File

@@ -6,18 +6,18 @@ import cn.binarywang.wx.miniapp.bean.*;
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@AllArgsConstructor
public class WxMaMsgServiceImpl implements WxMaMsgService {
private static final JsonParser JSON_PARSER = new JsonParser();
private WxMaService wxMaService;
@Override
@@ -29,7 +29,7 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
@Override
public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException {
String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson());
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -38,7 +38,7 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
@Override
public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException {
String responseContent = this.wxMaService.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson());
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -47,7 +47,7 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
@Override
public void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException {
String responseContent = this.wxMaService.post(UNIFORM_MSG_SEND_URL, uniformMessage.toJson());
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
@@ -56,7 +56,7 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
@Override
public JsonObject createUpdatableMessageActivityId() throws WxErrorException {
final String responseContent = this.wxMaService.get(ACTIVITY_ID_CREATE_URL, null);
return JSON_PARSER.parse(responseContent).getAsJsonObject();
return GsonParser.parse(responseContent);
}
@Override

View File

@@ -6,10 +6,10 @@ import cn.binarywang.wx.miniapp.bean.template.WxMaPubTemplateTitleListResult;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
@@ -36,7 +36,7 @@ public class WxMaSubscribeServiceImpl implements WxMaSubscribeService {
public List<PubTemplateKeyword> getPubTemplateKeyWordsById(String id) throws WxErrorException {
String responseText = this.wxMaService.get(GET_PUB_TEMPLATE_KEY_WORDS_BY_ID_URL,
Joiner.on("&").withKeyValueSeparator("=").join(ImmutableMap.of("tid", id)));
return WxMaGsonBuilder.create().fromJson(new JsonParser().parse(responseText).getAsJsonObject()
return WxMaGsonBuilder.create().fromJson(GsonParser.parse(responseText)
.getAsJsonArray("data"), new TypeToken<List<PubTemplateKeyword>>() {
}.getType());
}
@@ -46,13 +46,13 @@ public class WxMaSubscribeServiceImpl implements WxMaSubscribeService {
String responseText = this.wxMaService.post(TEMPLATE_ADD_URL, ImmutableMap.of("tid", id,
"kidList", keywordIdList.toArray(),
"sceneDesc", sceneDesc));
return new JsonParser().parse(responseText).getAsJsonObject().get("priTmplId").getAsString();
return GsonParser.parse(responseText).get("priTmplId").getAsString();
}
@Override
public List<TemplateInfo> getTemplateList() throws WxErrorException {
String responseText = this.wxMaService.get(TEMPLATE_LIST_URL, null);
return WxMaGsonBuilder.create().fromJson(new JsonParser().parse(responseText).getAsJsonObject()
return WxMaGsonBuilder.create().fromJson(GsonParser.parse(responseText)
.getAsJsonArray("data"), new TypeToken<List<TemplateInfo>>() {
}.getType());
}
@@ -66,7 +66,7 @@ public class WxMaSubscribeServiceImpl implements WxMaSubscribeService {
@Override
public List<CategoryData> getCategory() throws WxErrorException {
String responseText = this.wxMaService.get(GET_CATEGORY_URL, null);
return WxMaGsonBuilder.create().fromJson(new JsonParser().parse(responseText).getAsJsonObject()
return WxMaGsonBuilder.create().fromJson(GsonParser.parse(responseText)
.getAsJsonArray("data"), new TypeToken<List<CategoryData>>() {
}.getType());
}

View File

@@ -5,9 +5,9 @@ import java.util.List;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;
/**
* 微信运动步数信息.
@@ -16,7 +16,7 @@ import lombok.Data;
*/
@Data
public class WxMaRunStepInfo implements Serializable {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final long serialVersionUID = -7496372171398607044L;
/**
@@ -30,7 +30,7 @@ public class WxMaRunStepInfo implements Serializable {
private Integer step;
public static List<WxMaRunStepInfo> fromJson(String json) {
JsonObject jsonObject = JSON_PARSER.parse(json).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(json);
return WxMaGsonBuilder.create().fromJson(jsonObject.get("stepInfoList").toString(),
new TypeToken<List<WxMaRunStepInfo>>() {
}.getType());

View File

@@ -1,6 +1,5 @@
package cn.binarywang.wx.miniapp.bean.cloud;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@@ -2,12 +2,12 @@ package cn.binarywang.wx.miniapp.bean.express;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.io.Serializable;
import java.util.List;
@@ -24,7 +24,7 @@ import java.util.List;
@AllArgsConstructor
public class WxMaExpressAccount implements Serializable {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final long serialVersionUID = -4991983596742569736L;
/**
@@ -95,7 +95,7 @@ public class WxMaExpressAccount implements Serializable {
private List<WxMaExpressDelivery.ServiceType> serviceType;
public static List<WxMaExpressAccount> fromJsonList(String json) {
JsonObject jsonObject = JSON_PARSER.parse(json).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(json);
return WxMaGsonBuilder.create().fromJson(jsonObject.get("list").toString(),
new TypeToken<List<WxMaExpressAccount>>() {
}.getType());

View File

@@ -2,12 +2,12 @@ package cn.binarywang.wx.miniapp.bean.express;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.io.Serializable;
import java.util.List;
@@ -23,7 +23,7 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
public class WxMaExpressDelivery implements Serializable {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final long serialVersionUID = -8394544895730223810L;
/**
@@ -63,7 +63,7 @@ public class WxMaExpressDelivery implements Serializable {
private List<ServiceType> serviceType;
public static List<WxMaExpressDelivery> fromJson(String json) {
JsonObject jsonObject = JSON_PARSER.parse(json).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(json);
return WxMaGsonBuilder.create().fromJson(jsonObject.get("data").toString(),
new TypeToken<List<WxMaExpressDelivery>>() {
}.getType());

View File

@@ -1,7 +1,6 @@
package cn.binarywang.wx.miniapp.bean.express;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -22,7 +21,7 @@ import java.util.List;
@AllArgsConstructor
public class WxMaExpressPrinter implements Serializable {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final long serialVersionUID = 7164449984700322531L;
/**

View File

@@ -2,12 +2,12 @@ package cn.binarywang.wx.miniapp.bean.express.result;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.util.json.GsonParser;
import java.io.Serializable;
import java.util.List;
@@ -24,7 +24,7 @@ import java.util.Map;
@NoArgsConstructor
@AllArgsConstructor
public class WxMaExpressOrderInfoResult implements Serializable {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final long serialVersionUID = -9166603059965942285L;
/**
@@ -66,7 +66,7 @@ public class WxMaExpressOrderInfoResult implements Serializable {
}
public static List<WxMaExpressOrderInfoResult> toList(String json) {
JsonObject jsonObject = JSON_PARSER.parse(json).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(json);
return WxMaGsonBuilder.create().fromJson(jsonObject.get("order_list").toString(),
new TypeToken<List<WxMaExpressOrderInfoResult>>() {
}.getType());

View File

@@ -1,8 +1,6 @@
package cn.binarywang.wx.miniapp.bean.template;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.io.Serializable;

View File

@@ -1,9 +1,7 @@
package cn.binarywang.wx.miniapp.bean.template;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.io.Serializable;

View File

@@ -1,9 +1,7 @@
package cn.binarywang.wx.miniapp.bean.template;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.io.Serializable;

View File

@@ -1,6 +1,5 @@
package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.*;
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import org.testng.annotations.*;
@@ -12,8 +11,6 @@ import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import com.google.inject.Inject;
import me.chanjar.weixin.common.error.WxErrorException;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.text.SimpleDateFormat;
import java.util.Date;

View File

@@ -1,19 +1,13 @@
package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.bean.WxMaShareInfo;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import cn.binarywang.wx.miniapp.test.ApiTestModule;
import cn.binarywang.wx.miniapp.test.TestConfig;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import me.chanjar.weixin.common.error.WxErrorException;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
/**
* 测试分享相关的接口

View File

@@ -5,7 +5,6 @@ import java.util.List;
import org.testng.annotations.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.*;
/**
* <pre>

View File

@@ -1,13 +1,11 @@
package cn.binarywang.wx.miniapp.config.impl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import lombok.SneakyThrows;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.TransportMode;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

View File

@@ -4,7 +4,6 @@ import me.chanjar.weixin.common.api.WxConsts;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.*;
public class WxMaXmlOutMessageTest {

View File

@@ -2,7 +2,7 @@ package cn.binarywang.wx.miniapp.util.json;
import cn.binarywang.wx.miniapp.bean.WxMaTemplateData;
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage;
import com.google.gson.JsonParser;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -33,7 +33,7 @@ public class WxMaUniformMessageGsonAdapterTest {
.addData(new WxMaTemplateData("keyword3", "2014年9月22日", "#173177"))
.addData(new WxMaTemplateData("remark", "欢迎再次购买!", "#173177"));
assertThat(message.toJson()).isEqualTo(new JsonParser().parse("{\n" +
assertThat(message.toJson()).isEqualTo(GsonParser.parse("{\n" +
" \"touser\":\"OPENID\",\n" +
" \"mp_template_msg\":{\n" +
" \"appid\":\"APPID\",\n" +
@@ -66,7 +66,7 @@ public class WxMaUniformMessageGsonAdapterTest {
" }\n" +
" }\n" +
" }\n" +
"}").getAsJsonObject().toString());
"}").toString());
}
@Test
@@ -84,7 +84,7 @@ public class WxMaUniformMessageGsonAdapterTest {
.addData(new WxMaTemplateData("keyword3", "腾讯微信总部"))
.addData(new WxMaTemplateData("keyword4", "广州市海珠区新港中路397号"));
assertThat(message.toJson()).isEqualTo(new JsonParser().parse("{\n" +
assertThat(message.toJson()).isEqualTo(GsonParser.parse("{\n" +
" \"touser\":\"OPENID\",\n" +
" \"weapp_template_msg\":{\n" +
" \"template_id\":\"TEMPLATE_ID\",\n" +
@@ -106,6 +106,6 @@ public class WxMaUniformMessageGsonAdapterTest {
" },\n" +
" \"emphasis_keyword\":\"keyword1.DATA\"\n" +
" }\n" +
"}").getAsJsonObject().toString());
"}").toString());
}
}

View File

@@ -3,9 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@@ -23,6 +21,7 @@ import me.chanjar.weixin.common.util.DataUtils;
import me.chanjar.weixin.common.util.RandomUtils;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.api.*;
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
@@ -48,7 +47,7 @@ import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.*;
*/
@Slf4j
public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestHttp<H, P> {
private static final JsonParser JSON_PARSER = new JsonParser();
protected WxSessionManager sessionManager = new StandardSessionManager();
private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this);
@@ -111,7 +110,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
if (this.getWxMpConfigStorage().isTicketExpired(type)) {
String responseContent = execute(SimpleGetRequestExecutor.create(this),
GET_TICKET_URL.getUrl(this.getWxMpConfigStorage()) + type.getCode(), null);
JsonObject tmpJsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.getWxMpConfigStorage().updateTicket(type, jsapiTicket, expiresInSeconds);
@@ -166,8 +165,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
o.addProperty("action", "long2short");
o.addProperty("long_url", longUrl);
String responseContent = this.post(SHORTURL_API_URL, o.toString());
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("short_url").getAsString();
return GsonParser.parse(responseContent).get("short_url").getAsString();
}
@Override
@@ -245,8 +243,8 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
@Override
public String[] getCallbackIP() throws WxErrorException {
String responseContent = this.get(GET_CALLBACK_IP_URL, null);
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
JsonArray ipList = tmpJsonObject.get("ip_list").getAsJsonArray();
String[] ipArray = new String[ipList.size()];
for (int i = 0; i < ipList.size(); i++) {
ipArray[i] = ipList.get(i).getAsString();
@@ -434,9 +432,13 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
@Override
public void addConfigStorage(String mpId, WxMpConfigStorage configStorages) {
synchronized (this) {
if (this.configStorageMap == null) {
this.setWxMpConfigStorage(configStorages);
} else {
this.configStorageMap.put(mpId, configStorages);
}
}
}
@Override
public void removeConfigStorage(String mpId) {

View File

@@ -1,10 +1,10 @@
package me.chanjar.weixin.mp.api.impl;
import com.google.gson.JsonParser;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.api.WxMpAiOpenService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.enums.AiLangType;
@@ -23,7 +23,7 @@ import static me.chanjar.weixin.mp.enums.WxMpApiUrl.AiOpen.*;
*/
@RequiredArgsConstructor
public class WxMpAiOpenServiceImpl implements WxMpAiOpenService {
private static final JsonParser JSON_PARSER = new JsonParser();
private final WxMpService wxMpService;
@Override
@@ -53,7 +53,7 @@ public class WxMpAiOpenServiceImpl implements WxMpAiOpenService {
throw new WxErrorException(error);
}
return JSON_PARSER.parse(response).getAsJsonObject().get("to_content").getAsString();
return GsonParser.parse(response).get("to_content").getAsString();
}
@Override
@@ -69,6 +69,6 @@ public class WxMpAiOpenServiceImpl implements WxMpAiOpenService {
throw new WxErrorException(error);
}
return JSON_PARSER.parse(response).getAsJsonObject().get("result").getAsString();
return GsonParser.parse(response).get("result").getAsString();
}
}

View File

@@ -9,6 +9,7 @@ import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.RandomUtils;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.api.WxMpCardService;
import me.chanjar.weixin.mp.api.WxMpService;
@@ -58,8 +59,7 @@ public class WxMpCardServiceImpl implements WxMpCardService {
if (this.getWxMpService().getWxMpConfigStorage().isTicketExpired(type)) {
String responseContent = this.wxMpService.execute(SimpleGetRequestExecutor
.create(this.getWxMpService().getRequestHttp()), WxMpApiUrl.Card.CARD_GET_TICKET, null);
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
String cardApiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
this.getWxMpService().getWxMpConfigStorage().updateTicket(type, cardApiTicket, expiresInSeconds);
@@ -99,8 +99,7 @@ public class WxMpCardServiceImpl implements WxMpCardService {
JsonObject param = new JsonObject();
param.addProperty("encrypt_code", encryptCode);
String responseContent = this.wxMpService.post(WxMpApiUrl.Card.CARD_CODE_DECRYPT, param.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
JsonPrimitive jsonPrimitive = tmpJsonObject.getAsJsonPrimitive("code");
return jsonPrimitive.getAsString();
}
@@ -159,7 +158,7 @@ public class WxMpCardServiceImpl implements WxMpCardService {
String responseContent = this.wxMpService.post(WxMpApiUrl.Card.CARD_GET, param.toString());
// 判断返回值
JsonObject json = (new JsonParser()).parse(responseContent).getAsJsonObject();
JsonObject json = GsonParser.parse(responseContent);
String errcode = json.get("errcode").getAsString();
if (!"0".equals(errcode)) {
String errmsg = json.get("errmsg").getAsString();

View File

@@ -6,7 +6,6 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpDeviceService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.device.*;
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Device.*;

View File

@@ -1,12 +1,11 @@
package me.chanjar.weixin.mp.api.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.api.WxMpMarketingService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.marketing.WxMpAdLeadFilter;
@@ -38,8 +37,8 @@ public class WxMpMarketingServiceImpl implements WxMpMarketingService {
json.addProperty("name", name);
json.addProperty("description", description);
String responseContent = wxMpService.post(USER_ACTION_SETS_ADD, json.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("data").getAsJsonObject().get("user_action_set_id").getAsLong();
JsonObject tmpJson = GsonParser.parse(responseContent);
return tmpJson.get("data").getAsJsonObject().get("user_action_set_id").getAsLong();
}
@Override

View File

@@ -11,7 +11,6 @@ import me.chanjar.weixin.mp.bean.result.WxMpMassGetResult;
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
import me.chanjar.weixin.mp.bean.result.WxMpMassSpeedGetResult;
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.*;

View File

@@ -13,7 +13,6 @@ import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.api.WxMpMaterialService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.material.*;
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import me.chanjar.weixin.mp.util.requestexecuter.material.*;
import me.chanjar.weixin.mp.util.requestexecuter.media.MediaImgUploadRequestExecutor;

View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.mp.api.impl;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.api.WxMpMenuService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
@@ -38,7 +38,7 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
log.debug("创建菜单:{},结果:{}", menuJson, result);
if (menu.getMatchRule() != null) {
return new JsonParser().parse(result).getAsJsonObject().get("menuid").getAsString();
return GsonParser.parse(result).get("menuid").getAsString();
}
return null;
@@ -46,8 +46,7 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
@Override
public String menuCreate(String json) throws WxErrorException {
JsonParser jsonParser = new JsonParser();
JsonObject jsonObject = jsonParser.parse(json).getAsJsonObject();
JsonObject jsonObject = GsonParser.parse(json);
WxMpApiUrl.Menu url = MENU_CREATE;
if (jsonObject.get("matchrule") != null) {
url = MENU_ADDCONDITIONAL;
@@ -55,7 +54,7 @@ public class WxMpMenuServiceImpl implements WxMpMenuService {
String result = this.wxMpService.post(url, json);
if (jsonObject.get("matchrule") != null) {
return jsonParser.parse(result).getAsJsonObject().get("menuid").getAsString();
return GsonParser.parse(result).get("menuid").getAsString();
}
return null;

View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.mp.api.impl;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.BeanUtils;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpStoreService;
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
@@ -47,7 +47,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
return WxMpStoreBaseInfo.fromJson(new JsonParser().parse(response).getAsJsonObject()
return WxMpStoreBaseInfo.fromJson(GsonParser.parse(response)
.get("business").getAsJsonObject().get("base_info").toString());
}
@@ -117,7 +117,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
}
return WxMpGsonBuilder.create().fromJson(
new JsonParser().parse(response).getAsJsonObject().get("category_list"),
GsonParser.parse(response).get("category_list"),
new TypeToken<List<String>>() {
}.getType());
}

View File

@@ -1,17 +1,16 @@
package me.chanjar.weixin.mp.api.impl;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpTemplateMsgService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
import java.util.List;
@@ -26,14 +25,14 @@ import static me.chanjar.weixin.mp.enums.WxMpApiUrl.TemplateMsg.*;
*/
@RequiredArgsConstructor
public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
private static final JsonParser JSON_PARSER = new JsonParser();
private final WxMpService wxMpService;
@Override
public String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErrorException {
String responseContent = this.wxMpService.post(MESSAGE_TEMPLATE_SEND, templateMessage.toJson());
final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
final JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() == 0) {
return jsonObject.get("msgid").getAsString();
}
@@ -62,7 +61,7 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("template_id_short", shortTemplateId);
String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString());
final JsonObject result = JSON_PARSER.parse(responseContent).getAsJsonObject();
final JsonObject result = GsonParser.parse(responseContent);
if (result.get("errcode").getAsInt() == 0) {
return result.get("template_id").getAsString();
}

View File

@@ -7,7 +7,6 @@ import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpUserBlacklistService;
import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult;
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.util.HashMap;

View File

@@ -9,7 +9,6 @@ import me.chanjar.weixin.mp.bean.WxMpUserQuery;
import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.util.HashMap;

View File

@@ -2,12 +2,12 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpUserTagService;
import me.chanjar.weixin.mp.bean.tag.WxTagListUser;
@@ -134,7 +134,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
String responseContent = this.wxMpService.post(TAGS_GETIDLIST, json.toString());
return WxMpGsonBuilder.create().fromJson(
new JsonParser().parse(responseContent).getAsJsonObject().get("tagid_list"),
GsonParser.parse(responseContent).get("tagid_list"),
new TypeToken<List<Long>>() {
}.getType());
}

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.mp.bean.card;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.Serializable;

View File

@@ -1,6 +1,5 @@
package me.chanjar.weixin.mp.bean.card;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;

View File

@@ -1,6 +1,5 @@
package me.chanjar.weixin.mp.bean.card;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;

View File

@@ -6,7 +6,6 @@ import me.chanjar.weixin.mp.bean.result.WxMpResult;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.Serializable;
import java.util.List;
@Data

View File

@@ -2,8 +2,6 @@ package me.chanjar.weixin.mp.bean.comment;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.common.util.xml.IntegerArrayConverter;
import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.Serializable;

View File

@@ -6,6 +6,7 @@ import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
@@ -116,7 +117,7 @@ public class WxDataCubeArticleResult extends WxDataCubeBaseResult {
public static List<WxDataCubeArticleResult> fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
GsonParser.parse(json).get("list"),
new TypeToken<List<WxDataCubeArticleResult>>() {
}.getType());
}

View File

@@ -6,6 +6,7 @@ import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
@@ -42,7 +43,7 @@ public class WxDataCubeArticleTotal extends WxDataCubeBaseResult {
public static List<WxDataCubeArticleTotal> fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
GsonParser.parse(json).get("list"),
new TypeToken<List<WxDataCubeArticleTotal>>() {
}.getType());
}

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.mp.bean.datacube;
import java.io.Serializable;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
@@ -18,7 +17,6 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
@Data
public abstract class WxDataCubeBaseResult implements Serializable {
private static final long serialVersionUID = 8780389911053297600L;
protected static final JsonParser JSON_PARSER = new JsonParser();
/**
* ref_date.

View File

@@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.util.List;
@@ -57,7 +58,7 @@ public class WxDataCubeInterfaceResult extends WxDataCubeBaseResult {
public static List<WxDataCubeInterfaceResult> fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
GsonParser.parse(json).get("list"),
new TypeToken<List<WxDataCubeInterfaceResult>>() {
}.getType());
}

View File

@@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.util.List;
@@ -70,7 +71,7 @@ public class WxDataCubeMsgResult extends WxDataCubeBaseResult {
public static List<WxDataCubeMsgResult> fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
GsonParser.parse(json).get("list"),
new TypeToken<List<WxDataCubeMsgResult>>() {
}.getType());
}

View File

@@ -4,10 +4,9 @@ import java.io.Serializable;
import java.util.Date;
import java.util.List;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
@@ -20,7 +19,7 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
*/
@Data
public class WxDataCubeUserCumulate implements Serializable {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final long serialVersionUID = -3570981300225093657L;
@@ -30,7 +29,7 @@ public class WxDataCubeUserCumulate implements Serializable {
public static List<WxDataCubeUserCumulate> fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
GsonParser.parse(json).get("list"),
new TypeToken<List<WxDataCubeUserCumulate>>() {
}.getType());
}

View File

@@ -4,10 +4,9 @@ import java.io.Serializable;
import java.util.Date;
import java.util.List;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
@@ -20,7 +19,7 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
public class WxDataCubeUserSummary implements Serializable {
private static final long serialVersionUID = -2336654489906694173L;
private static final JsonParser JSON_PARSER = new JsonParser();
private Date refDate;
@@ -32,7 +31,7 @@ public class WxDataCubeUserSummary implements Serializable {
public static List<WxDataCubeUserSummary> fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("list"),
GsonParser.parse(json).get("list"),
new TypeToken<List<WxDataCubeUserSummary>>() {
}.getType());
}

View File

@@ -3,7 +3,6 @@ package me.chanjar.weixin.mp.bean.kefu.result;
import java.io.Serializable;
import java.util.List;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.mp.bean.kefu.result;
import java.io.Serializable;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;

View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.mp.bean.marketing;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.Serializable;
@@ -15,7 +15,6 @@ import java.util.List;
@Data
public class WxMpAdLeadResult implements Serializable {
private static final long serialVersionUID = -1526796632563660821L;
protected static final JsonParser JSON_PARSER = new JsonParser();
@SerializedName("page_info")
private WxMpAdLeadPageInfo pageInfo;
@@ -25,7 +24,7 @@ public class WxMpAdLeadResult implements Serializable {
public static WxMpAdLeadResult fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("data"),
GsonParser.parse(json).get("data"),
new TypeToken<WxMpAdLeadResult>() {
}.getType());
}

View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.mp.bean.marketing;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.io.Serializable;
@@ -16,7 +16,6 @@ import java.util.List;
@Data
public class WxMpUserActionSet implements Serializable {
private static final long serialVersionUID = 1979861770645159905L;
protected static final JsonParser JSON_PARSER = new JsonParser();
/**
* user_action_set_id
@@ -48,7 +47,7 @@ public class WxMpUserActionSet implements Serializable {
public static List<WxMpUserActionSet> fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
JSON_PARSER.parse(json).getAsJsonObject().get("data").getAsJsonObject().get("list"),
GsonParser.parse(json).get("data").getAsJsonObject().get("list"),
new TypeToken<List<WxMpUserActionSet>>() {
}.getType());
}

View File

@@ -3,9 +3,9 @@ package me.chanjar.weixin.mp.bean.tag;
import java.io.Serializable;
import java.util.List;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
@@ -37,13 +37,13 @@ public class WxUserTag implements Serializable {
public static WxUserTag fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
new JsonParser().parse(json).getAsJsonObject().get("tag"),
GsonParser.parse(json).get("tag"),
WxUserTag.class);
}
public static List<WxUserTag> listFromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
new JsonParser().parse(json).getAsJsonObject().get("tags"),
GsonParser.parse(json).get("tags"),
new TypeToken<List<WxUserTag>>() {
}.getType());
}

View File

@@ -3,10 +3,10 @@ package me.chanjar.weixin.mp.bean.template;
import java.io.Serializable;
import java.util.List;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
/**
@@ -19,7 +19,7 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
*/
@Data
public class WxMpTemplate implements Serializable {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final long serialVersionUID = -7366474522571199372L;
/**
@@ -60,7 +60,7 @@ public class WxMpTemplate implements Serializable {
private String example;
public static List<WxMpTemplate> fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(JSON_PARSER.parse(json).getAsJsonObject().get("template_list"),
return WxMpGsonBuilder.create().fromJson(GsonParser.parse(json).get("template_list"),
new TypeToken<List<WxMpTemplate>>() {
}.getType());
}

View File

@@ -1,8 +1,8 @@
package me.chanjar.weixin.mp.bean.wifi;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.util.List;
@@ -17,7 +17,7 @@ import java.util.List;
public class WxMpWifiShopDataResult {
public static WxMpWifiShopDataResult fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
new JsonParser().parse(json).getAsJsonObject().get("data"),
GsonParser.parse(json).get("data"),
WxMpWifiShopDataResult.class);
}

View File

@@ -1,8 +1,8 @@
package me.chanjar.weixin.mp.bean.wifi;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import java.util.List;
@@ -18,7 +18,7 @@ import java.util.List;
public class WxMpWifiShopListResult {
public static WxMpWifiShopListResult fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(
new JsonParser().parse(json).getAsJsonObject().get("data"),
GsonParser.parse(json).get("data"),
WxMpWifiShopListResult.class);
}

View File

@@ -20,7 +20,6 @@ package me.chanjar.weixin.mp.util.crypto;
import com.google.common.base.CharMatcher;
import com.google.common.io.BaseEncoding;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import org.apache.commons.codec.binary.Base64;
public class WxMpCryptUtil extends me.chanjar.weixin.common.util.crypto.WxCryptUtil {

View File

@@ -9,8 +9,6 @@ import me.chanjar.weixin.mp.bean.marketing.WxMpUserAction;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
/**
* 测试类.
*

View File

@@ -9,7 +9,6 @@ import me.chanjar.weixin.mp.bean.WxMpUserQuery;
import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.mp.bean.membercard;
import org.testng.annotations.Test;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

View File

@@ -5,7 +5,6 @@ import org.testng.annotations.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.*;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>

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

Some files were not shown because too many files have changed in this diff Show More