mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-17 05:48:12 +08:00
🎨 #1659 Json解析统一优化
* 解决动态添加第一个公众号时由于configStorageMap为null报空指针异常 * Json解析统一优化 Co-authored-by: niefy <niefy@qq.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package cn.binarywang.wx.miniapp.bean.cloud;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user