瀏覽代碼

🎨 规范化部分代码格式

master
Binary Wang 5 年之前
父節點
當前提交
6e1d7fcef0
共有 8 個檔案被更改,包括 64 行新增51 行删除
  1. +0
    -1
      quality-checks/google_checks.xml
  2. +17
    -15
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java
  3. +5
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpTpServiceImpl.java
  4. +2
    -2
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java
  5. +12
    -8
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpChatServiceImpl.java
  6. +8
    -8
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java
  7. +4
    -3
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMediaServiceImpl.java
  8. +16
    -11
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java

+ 0
- 1
quality-checks/google_checks.xml 查看文件

@@ -27,7 +27,6 @@
<property name="max" value="120"/> <property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module> </module>
<module name="AvoidStarImport"/>
<module name="OneTopLevelClass"/> <module name="OneTopLevelClass"/>
<module name="NoLineWrap"/> <module name="NoLineWrap"/>
<module name="EmptyBlock"> <module name="EmptyBlock">


+ 17
- 15
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.*; import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.*;


/** /**
* .
*
* @author chanjarster * @author chanjarster
*/ */
@Slf4j @Slf4j
public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestHttp<H, P> { public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestHttp<H, P> {
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 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); private WxCpExternalContactService externalContactService = new WxCpExternalContactServiceImpl(this);


/** /**
* 全局的是否正在刷新access token的锁
* 全局的是否正在刷新access token的锁.
*/ */
protected final Object globalAccessTokenRefreshLock = new Object(); protected final Object globalAccessTokenRefreshLock = new Object();


/** /**
* 全局的是否正在刷新jsapi_ticket的锁
* 全局的是否正在刷新jsapi_ticket的锁.
*/ */
protected final Object globalJsapiTicketRefreshLock = new Object(); protected final Object globalJsapiTicketRefreshLock = new Object();


/** /**
* 全局的是否正在刷新agent的jsapi_ticket的锁
* 全局的是否正在刷新agent的jsapi_ticket的锁.
*/ */
protected final Object globalAgentJsapiTicketRefreshLock = new Object(); protected final Object globalAgentJsapiTicketRefreshLock = new Object();


@@ -72,7 +74,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
private WxSessionManager sessionManager = new StandardSessionManager(); private WxSessionManager sessionManager = new StandardSessionManager();


/** /**
* 临时文件目录
* 临时文件目录.
*/ */
private File tmpDirFile; private File tmpDirFile;
private int retrySleepMillis = 1000; private int retrySleepMillis = 1000;
@@ -183,8 +185,8 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
params.put("js_code", jsCode); params.put("js_code", jsCode);
params.put("grant_type", "authorization_code"); 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 @Override


+ 5
- 3
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; import java.util.Map;


/** /**
* .
*
* @author zhenjun cai * @author zhenjun cai
*/ */
@Slf4j @Slf4j
@@ -73,7 +75,7 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ


@Override @Override
public String getSuiteTicket(boolean forceRefresh) throws WxErrorException { public String getSuiteTicket(boolean forceRefresh) throws WxErrorException {
// suite ticket由微信服务器推送,不能强制刷新
// suite ticket由微信服务器推送,不能强制刷新
// if (forceRefresh) { // if (forceRefresh) {
// this.configStorage.expireSuiteTicket(); // this.configStorage.expireSuiteTicket();
// } // }
@@ -93,8 +95,8 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
params.put("js_code", jsCode); params.put("js_code", jsCode);
params.put("grant_type", "authorization_code"); 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)));
} }






+ 2
- 2
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参数"); 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 @Override


+ 12
- 8
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)) { if (StringUtils.isNotBlank(chatId)) {
data.put("chatid", 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(); return new JsonParser().parse(result).getAsJsonObject().get("chatid").getAsString();
} }


@Override @Override
public String create(String name, String owner, List<String> users, String chatId) throws WxErrorException { public String create(String name, String owner, List<String> users, String chatId) throws WxErrorException {
return chatCreate(name, owner, users, chatId);
return this.chatCreate(name, owner, users, chatId);
} }


@Override @Override
@@ -72,24 +73,27 @@ public class WxCpChatServiceImpl implements WxCpChatService {
data.put("del_user_list", usersToDelete); 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 @Override
public void update(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete) throws WxErrorException {
public void update(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete)
throws WxErrorException {
chatUpdate(chatId, name, owner, usersToAdd, usersToDelete); chatUpdate(chatId, name, owner, usersToAdd, usersToDelete);
} }


@Override @Override
public WxCpChat chatGet(String chatId) throws WxErrorException { 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 @Override
public WxCpChat get(String chatId) throws WxErrorException { public WxCpChat get(String chatId) throws WxErrorException {
return chatGet(chatId);
return this.chatGet(chatId);
} }


@Override @Override


+ 8
- 8
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java 查看文件

@@ -20,22 +20,22 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic


@Override @Override
public WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException { 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); return WxCpUserExternalContactInfo.fromJson(responseContent);
} }


@Override @Override
public List<String> listExternalContacts(String userId) throws WxErrorException { public List<String> 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 @Override
public List<String> listFollowUser() throws WxErrorException { public List<String> 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();
} }
} }

+ 4
- 3
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.fs.FileUtils;
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor; import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; 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.WxCpMediaService;
import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts; import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
@@ -59,8 +60,8 @@ public class WxCpMediaServiceImpl implements WxCpMediaService {


@Override @Override
public String uploadImg(File file) throws WxErrorException { 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();
} }
} }

+ 16
- 11
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.*; import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;


/** /**
* .
*
* @author Element * @author Element
* @date 2019-04-06 11:20 * @date 2019-04-06 11:20
*/ */
@@ -60,7 +62,8 @@ public class WxCpOaServiceImpl implements WxCpOaService {


jsonObject.add("useridlist", jsonArray); 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); JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.create() return WxCpGsonBuilder.create()
.fromJson( .fromJson(
@@ -89,7 +92,8 @@ public class WxCpOaServiceImpl implements WxCpOaService {
jsonObject.addProperty("datetime", datetime.getTime() / 1000L); jsonObject.addProperty("datetime", datetime.getTime() / 1000L);
jsonObject.add("useridlist", jsonArray); 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); JsonElement tmpJsonElement = new JsonParser().parse(responseContent);


return WxCpGsonBuilder.create() return WxCpGsonBuilder.create()
@@ -109,12 +113,14 @@ public class WxCpOaServiceImpl implements WxCpOaService {
jsonObject.addProperty("next_spnum", nextSpnum); 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); return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDataResult.class);
} }


@Override @Override
public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit) throws WxErrorException {
public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit)
throws WxErrorException {
JsonObject jsonObject = new JsonObject(); JsonObject jsonObject = new JsonObject();


if (offset == null) { if (offset == null) {
@@ -141,14 +147,13 @@ public class WxCpOaServiceImpl implements WxCpOaService {
jsonObject.addProperty("end_time", endtimestamp); 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); JsonElement tmpJsonElement = new JsonParser().parse(responseContent);


return WxCpGsonBuilder.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("record"),
new TypeToken<List<WxCpDialRecord>>() {
}.getType()
);
return WxCpGsonBuilder.create().fromJson(tmpJsonElement.getAsJsonObject().get("record"),
new TypeToken<List<WxCpDialRecord>>() {
}.getType()
);
} }
} }

Loading…
取消
儲存