优化代码,替换掉ToStringBuilder.reflectionToString相关代码

This commit is contained in:
Binary Wang
2018-11-02 11:18:56 +08:00
parent cd28a5b487
commit eab7dd398a
138 changed files with 670 additions and 731 deletions

View File

@@ -1,5 +1,9 @@
package cn.binarywang.wx.miniapp.api.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaTemplateService;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateAddResult;
@@ -10,15 +14,11 @@ import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class WxMaTemplateServiceImpl implements WxMaTemplateService {
private WxMaService wxMaService;
public WxMaTemplateServiceImpl(WxMaService wxMaService){
public WxMaTemplateServiceImpl(WxMaService wxMaService) {
this.wxMaService = wxMaService;
}
@@ -31,9 +31,9 @@ public class WxMaTemplateServiceImpl implements WxMaTemplateService {
String responseText = this.wxMaService.post(TEMPLATE_LIBRARY_LIST_URL, WxGsonBuilder.create().toJson(params));
WxError wxError = WxError.fromJson(responseText);
if(wxError.getErrorCode() == 0){
if (wxError.getErrorCode() == 0) {
return WxMaTemplateLibraryListResult.fromJson(responseText);
}else {
} else {
throw new WxErrorException(wxError);
}
}
@@ -46,9 +46,9 @@ public class WxMaTemplateServiceImpl implements WxMaTemplateService {
String responseText = this.wxMaService.post(TEMPLATE_LIBRARY_KEYWORD_URL, WxGsonBuilder.create().toJson(params));
WxError wxError = WxError.fromJson(responseText);
if(wxError.getErrorCode() == 0){
if (wxError.getErrorCode() == 0) {
return WxMaTemplateLibraryGetResult.fromJson(responseText);
}else {
} else {
throw new WxErrorException(wxError);
}
}
@@ -62,9 +62,9 @@ public class WxMaTemplateServiceImpl implements WxMaTemplateService {
String responseText = this.wxMaService.post(TEMPLATE_ADD_URL, WxGsonBuilder.create().toJson(params));
WxError wxError = WxError.fromJson(responseText);
if(wxError.getErrorCode() == 0){
if (wxError.getErrorCode() == 0) {
return WxMaTemplateAddResult.fromJson(responseText);
}else {
} else {
throw new WxErrorException(wxError);
}
}
@@ -78,9 +78,9 @@ public class WxMaTemplateServiceImpl implements WxMaTemplateService {
String responseText = this.wxMaService.post(TEMPLATE_LIST_URL, WxGsonBuilder.create().toJson(params));
WxError wxError = WxError.fromJson(responseText);
if(wxError.getErrorCode() == 0){
if (wxError.getErrorCode() == 0) {
return WxMaTemplateListResult.fromJson(responseText);
}else {
} else {
throw new WxErrorException(wxError);
}
}
@@ -92,9 +92,9 @@ public class WxMaTemplateServiceImpl implements WxMaTemplateService {
String responseText = this.wxMaService.post(TEMPLATE_DEL_URL, WxGsonBuilder.create().toJson(params));
WxError wxError = WxError.fromJson(responseText);
if(wxError.getErrorCode() == 0){
if (wxError.getErrorCode() == 0) {
return true;
}else {
} else {
throw new WxErrorException(wxError);
}
}

View File

@@ -6,8 +6,6 @@ import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
@@ -168,7 +166,7 @@ public class WxMaMessage implements Serializable {
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
return this.toJson();
}
public String toJson() {

View File

@@ -1,14 +1,13 @@
package cn.binarywang.wx.miniapp.config;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.io.File;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
/**
* 基于内存的微信配置provider在实际生产环境中应该将这些配置持久化
*
@@ -224,7 +223,7 @@ public class WxMaInMemoryConfig implements WxMaConfig {
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
return WxMaGsonBuilder.create().toJson(this);
}
@Override