mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-22 03:27:39 +08:00
🎨 #1659 Json解析统一优化
* 解决动态添加第一个公众号时由于configStorageMap为null报空指针异常 * Json解析统一优化 Co-authored-by: niefy <niefy@qq.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
|
@@ -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));
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
);
|
||||
|
@@ -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;
|
||||
|
@@ -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.*;
|
||||
|
@@ -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"))
|
||||
|
@@ -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()
|
||||
);
|
||||
|
@@ -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());
|
||||
}
|
||||
|
@@ -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()
|
||||
);
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
||||
/**
|
||||
|
@@ -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;
|
||||
|
||||
/**
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
||||
/**
|
||||
* 审批模板详情
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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>
|
||||
|
@@ -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.*;
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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.*;
|
||||
|
||||
|
@@ -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.*;
|
||||
|
||||
/**
|
||||
* .
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user