From 6e1d7fcef0baa8c403fa39c9fb3330ca81dd2955 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 11 Aug 2019 11:26:36 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E8=A7=84=E8=8C=83=E5=8C=96=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quality-checks/google_checks.xml | 1 - .../cp/api/impl/BaseWxCpServiceImpl.java | 32 ++++++++++--------- .../cp/api/impl/BaseWxCpTpServiceImpl.java | 8 +++-- .../cp/api/impl/WxCpAgentServiceImpl.java | 4 +-- .../cp/api/impl/WxCpChatServiceImpl.java | 20 +++++++----- .../impl/WxCpExternalContactServiceImpl.java | 16 +++++----- .../cp/api/impl/WxCpMediaServiceImpl.java | 7 ++-- .../weixin/cp/api/impl/WxCpOaServiceImpl.java | 27 +++++++++------- 8 files changed, 64 insertions(+), 51 deletions(-) diff --git a/quality-checks/google_checks.xml b/quality-checks/google_checks.xml index b7a7e96cf..1f76bfaf0 100644 --- a/quality-checks/google_checks.xml +++ b/quality-checks/google_checks.xml @@ -27,7 +27,6 @@ - diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java index c7f10f6b3..326717b1a 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java @@ -36,34 +36,36 @@ import java.util.Map; import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.*; /** + * . + * * @author chanjarster */ @Slf4j public abstract class BaseWxCpServiceImpl implements WxCpService, RequestHttp { - private WxCpUserService userService = new WxCpUserServiceImpl(this); - private WxCpChatService chatService = new WxCpChatServiceImpl(this); + private WxCpUserService userService = new WxCpUserServiceImpl(this); + private WxCpChatService chatService = new WxCpChatServiceImpl(this); private WxCpDepartmentService departmentService = new WxCpDepartmentServiceImpl(this); - private WxCpMediaService mediaService = new WxCpMediaServiceImpl(this); - private WxCpMenuService menuService = new WxCpMenuServiceImpl(this); - private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this); - private WxCpTagService tagService = new WxCpTagServiceImpl(this); - private WxCpAgentService agentService = new WxCpAgentServiceImpl(this); - private WxCpOaService oaService = new WxCpOaServiceImpl(this); - private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this); + private WxCpMediaService mediaService = new WxCpMediaServiceImpl(this); + private WxCpMenuService menuService = new WxCpMenuServiceImpl(this); + private WxCpOAuth2Service oauth2Service = new WxCpOAuth2ServiceImpl(this); + private WxCpTagService tagService = new WxCpTagServiceImpl(this); + private WxCpAgentService agentService = new WxCpAgentServiceImpl(this); + private WxCpOaService oaService = new WxCpOaServiceImpl(this); + private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this); private WxCpExternalContactService externalContactService = new WxCpExternalContactServiceImpl(this); /** - * 全局的是否正在刷新access token的锁 + * 全局的是否正在刷新access token的锁. */ protected final Object globalAccessTokenRefreshLock = new Object(); /** - * 全局的是否正在刷新jsapi_ticket的锁 + * 全局的是否正在刷新jsapi_ticket的锁. */ protected final Object globalJsapiTicketRefreshLock = new Object(); /** - * 全局的是否正在刷新agent的jsapi_ticket的锁 + * 全局的是否正在刷新agent的jsapi_ticket的锁. */ protected final Object globalAgentJsapiTicketRefreshLock = new Object(); @@ -72,7 +74,7 @@ public abstract class BaseWxCpServiceImpl implements WxCpService, RequestH private WxSessionManager sessionManager = new StandardSessionManager(); /** - * 临时文件目录 + * 临时文件目录. */ private File tmpDirFile; private int retrySleepMillis = 1000; @@ -183,8 +185,8 @@ public abstract class BaseWxCpServiceImpl implements WxCpService, RequestH params.put("js_code", jsCode); params.put("grant_type", "authorization_code"); - String result = this.get(this.configStorage.getApiUrl(JSCODE_TO_SESSION), Joiner.on("&").withKeyValueSeparator("=").join(params)); - return WxCpMaJsCode2SessionResult.fromJson(result); + final String url = this.configStorage.getApiUrl(JSCODE_TO_SESSION); + return WxCpMaJsCode2SessionResult.fromJson(this.get(url, Joiner.on("&").withKeyValueSeparator("=").join(params))); } @Override diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java index 92c6ac298..a0585af12 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java @@ -26,6 +26,8 @@ import java.util.HashMap; import java.util.Map; /** + * . + * * @author zhenjun cai */ @Slf4j @@ -73,7 +75,7 @@ public abstract class BaseWxCpTpServiceImpl implements WxCpTpService, Requ @Override public String getSuiteTicket(boolean forceRefresh) throws WxErrorException { -// suite ticket由微信服务器推送,不能强制刷新 +// suite ticket由微信服务器推送,不能强制刷新 // if (forceRefresh) { // this.configStorage.expireSuiteTicket(); // } @@ -93,8 +95,8 @@ public abstract class BaseWxCpTpServiceImpl implements WxCpTpService, Requ params.put("js_code", jsCode); params.put("grant_type", "authorization_code"); - String result = this.get(configStorage.getApiUrl(WxCpApiPathConsts.Tp.JSCODE_TO_SESSION), Joiner.on("&").withKeyValueSeparator("=").join(params)); - return WxCpMaJsCode2SessionResult.fromJson(result); + final String url = configStorage.getApiUrl(WxCpApiPathConsts.Tp.JSCODE_TO_SESSION); + return WxCpMaJsCode2SessionResult.fromJson(this.get(url, Joiner.on("&").withKeyValueSeparator("=").join(params))); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java index 6a9b77469..fd2beb4ad 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java @@ -36,8 +36,8 @@ public class WxCpAgentServiceImpl implements WxCpAgentService { throw new IllegalArgumentException("缺少agentid参数"); } - String responseContent = this.mainService.get(String.format(this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_GET), agentId), null); - return WxCpAgent.fromJson(responseContent); + final String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_GET), agentId); + return WxCpAgent.fromJson(this.mainService.get(url, null)); } @Override diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java index bd5baf01d..b1f374c07 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java @@ -43,13 +43,14 @@ public class WxCpChatServiceImpl implements WxCpChatService { if (StringUtils.isNotBlank(chatId)) { data.put("chatid", chatId); } - String result = this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_CREATE), WxGsonBuilder.create().toJson(data)); + 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(); } @Override public String create(String name, String owner, List users, String chatId) throws WxErrorException { - return chatCreate(name, owner, users, chatId); + return this.chatCreate(name, owner, users, chatId); } @Override @@ -72,24 +73,27 @@ public class WxCpChatServiceImpl implements WxCpChatService { data.put("del_user_list", usersToDelete); } - this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_UPDATE), WxGsonBuilder.create().toJson(data)); + final String url = this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_UPDATE); + this.cpService.post(url, WxGsonBuilder.create().toJson(data)); } @Override - public void update(String chatId, String name, String owner, List usersToAdd, List usersToDelete) throws WxErrorException { + public void update(String chatId, String name, String owner, List usersToAdd, List usersToDelete) + throws WxErrorException { chatUpdate(chatId, name, owner, usersToAdd, usersToDelete); } @Override public WxCpChat chatGet(String chatId) throws WxErrorException { - String result = this.cpService.get(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_GET_CHATID + chatId), null); - return WxCpGsonBuilder.create() - .fromJson(JSON_PARSER.parse(result).getAsJsonObject().getAsJsonObject("chat_info").toString(), WxCpChat.class); + 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(); + return WxCpGsonBuilder.create().fromJson(chatInfo, WxCpChat.class); } @Override public WxCpChat get(String chatId) throws WxErrorException { - return chatGet(chatId); + return this.chatGet(chatId); } @Override diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java index 189100083..8a5b7d56e 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java @@ -20,22 +20,22 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic @Override public WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException { - String responseContent = this.mainService.get(this.mainService.getWxCpConfigStorage().getApiUrl(GET_EXTERNAL_CONTACT + userId), null); - + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_EXTERNAL_CONTACT + userId); + String responseContent = this.mainService.get(url, null); return WxCpUserExternalContactInfo.fromJson(responseContent); } @Override public List listExternalContacts(String userId) throws WxErrorException { - String responseContent = this.mainService.get(this.mainService.getWxCpConfigStorage().getApiUrl(LIST_EXTERNAL_CONTACT + userId), null); - WxCpUserExternalContactList list = WxCpUserExternalContactList.fromJson(responseContent); - return list.getExternalUserId(); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_EXTERNAL_CONTACT + userId); + String responseContent = this.mainService.get(url, null); + return WxCpUserExternalContactList.fromJson(responseContent).getExternalUserId(); } @Override public List listFollowUser() throws WxErrorException { - String responseContent = this.mainService.get(this.mainService.getWxCpConfigStorage().getApiUrl(GET_FOLLOW_USER_LIST), null); - WxCpUserWithExternalPermission list = WxCpUserWithExternalPermission.fromJson(responseContent); - return list.getFollowUser(); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_FOLLOW_USER_LIST); + String responseContent = this.mainService.get(url, null); + return WxCpUserWithExternalPermission.fromJson(responseContent).getFollowUser(); } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java index 05e13cfc8..55579ff05 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java @@ -6,6 +6,7 @@ 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; @@ -59,8 +60,8 @@ public class WxCpMediaServiceImpl implements WxCpMediaService { @Override public String uploadImg(File file) throws WxErrorException { - final WxMediaUploadResult result = this.mainService - .execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()), this.mainService.getWxCpConfigStorage().getApiUrl(IMG_UPLOAD), file); - return result.getUrl(); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(IMG_UPLOAD); + return this.mainService.execute(MediaUploadRequestExecutor.create(this.mainService.getRequestHttp()), url, file) + .getUrl(); } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java index 5d7d758c0..b8449ced1 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java @@ -22,6 +22,8 @@ import java.util.List; import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*; /** + * . + * * @author Element * @date 2019-04-06 11:20 */ @@ -60,7 +62,8 @@ public class WxCpOaServiceImpl implements WxCpOaService { jsonObject.add("useridlist", jsonArray); - String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_DATA), jsonObject.toString()); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_DATA); + String responseContent = this.mainService.post(url, jsonObject.toString()); JsonElement tmpJsonElement = new JsonParser().parse(responseContent); return WxCpGsonBuilder.create() .fromJson( @@ -89,7 +92,8 @@ public class WxCpOaServiceImpl implements WxCpOaService { jsonObject.addProperty("datetime", datetime.getTime() / 1000L); jsonObject.add("useridlist", jsonArray); - String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_OPTION), jsonObject.toString()); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CHECKIN_OPTION); + String responseContent = this.mainService.post(url, jsonObject.toString()); JsonElement tmpJsonElement = new JsonParser().parse(responseContent); return WxCpGsonBuilder.create() @@ -109,12 +113,14 @@ public class WxCpOaServiceImpl implements WxCpOaService { jsonObject.addProperty("next_spnum", nextSpnum); } - String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_DATA), jsonObject.toString()); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_DATA); + String responseContent = this.mainService.post(url, jsonObject.toString()); return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDataResult.class); } @Override - public List getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit) throws WxErrorException { + public List getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit) + throws WxErrorException { JsonObject jsonObject = new JsonObject(); if (offset == null) { @@ -141,14 +147,13 @@ public class WxCpOaServiceImpl implements WxCpOaService { jsonObject.addProperty("end_time", endtimestamp); } - String responseContent = this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(GET_DIAL_RECORD), jsonObject.toString()); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_DIAL_RECORD); + String responseContent = this.mainService.post(url, jsonObject.toString()); JsonElement tmpJsonElement = new JsonParser().parse(responseContent); - return WxCpGsonBuilder.create() - .fromJson( - tmpJsonElement.getAsJsonObject().get("record"), - new TypeToken>() { - }.getType() - ); + return WxCpGsonBuilder.create().fromJson(tmpJsonElement.getAsJsonObject().get("record"), + new TypeToken>() { + }.getType() + ); } }