mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
code clean up for common module
This commit is contained in:
@@ -8,9 +8,13 @@ public class WxAccessToken implements Serializable {
|
||||
private static final long serialVersionUID = 8709719312922168909L;
|
||||
|
||||
private String accessToken;
|
||||
|
||||
|
||||
private int expiresIn = -1;
|
||||
|
||||
public static WxAccessToken fromJson(String json) {
|
||||
return WxGsonBuilder.create().fromJson(json, WxAccessToken.class);
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
@@ -27,8 +31,4 @@ public class WxAccessToken implements Serializable {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
|
||||
public static WxAccessToken fromJson(String json) {
|
||||
return WxGsonBuilder.create().fromJson(json, WxAccessToken.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ public class WxJsapiSignature implements Serializable {
|
||||
private static final long serialVersionUID = -1116808193154384804L;
|
||||
|
||||
private String appid;
|
||||
|
||||
|
||||
private String noncestr;
|
||||
|
||||
private long timestamp;
|
||||
@@ -51,11 +51,11 @@ public class WxJsapiSignature implements Serializable {
|
||||
}
|
||||
|
||||
public String getAppid() {
|
||||
return appid;
|
||||
return appid;
|
||||
}
|
||||
|
||||
public void setAppid(String appid) {
|
||||
this.appid = appid;
|
||||
this.appid = appid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package me.chanjar.weixin.common.bean;
|
||||
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Serializable;
|
||||
@@ -7,12 +9,10 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
|
||||
/**
|
||||
* 企业号菜单
|
||||
* @author Daniel Qian
|
||||
*
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
public class WxMenu implements Serializable {
|
||||
|
||||
@@ -21,26 +21,6 @@ public class WxMenu implements Serializable {
|
||||
private List<WxMenuButton> buttons = new ArrayList<WxMenuButton>();
|
||||
|
||||
private WxMenuRule matchRule;
|
||||
|
||||
public List<WxMenuButton> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public void setButtons(List<WxMenuButton> buttons) {
|
||||
this.buttons = buttons;
|
||||
}
|
||||
|
||||
public WxMenuRule getMatchRule() {
|
||||
return matchRule;
|
||||
}
|
||||
|
||||
public void setMatchRule(WxMenuRule matchRule) {
|
||||
this.matchRule = matchRule;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
|
||||
@@ -58,11 +38,31 @@ public class WxMenu implements Serializable {
|
||||
return WxGsonBuilder.create().fromJson(new InputStreamReader(is, StandardCharsets.UTF_8), WxMenu.class);
|
||||
}
|
||||
|
||||
public List<WxMenuButton> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public void setButtons(List<WxMenuButton> buttons) {
|
||||
this.buttons = buttons;
|
||||
}
|
||||
|
||||
public WxMenuRule getMatchRule() {
|
||||
return matchRule;
|
||||
}
|
||||
|
||||
public void setMatchRule(WxMenuRule matchRule) {
|
||||
this.matchRule = matchRule;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WxMenu{" +
|
||||
"buttons=" + buttons +
|
||||
'}';
|
||||
"buttons=" + buttons +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class WxMenuButton {
|
||||
@@ -71,7 +71,7 @@ public class WxMenu implements Serializable {
|
||||
private String name;
|
||||
private String key;
|
||||
private String url;
|
||||
|
||||
|
||||
private List<WxMenuButton> subButtons = new ArrayList<WxMenuButton>();
|
||||
|
||||
public String getType() {
|
||||
@@ -117,15 +117,15 @@ public class WxMenu implements Serializable {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WxMenuButton{" +
|
||||
"type='" + type + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", key='" + key + '\'' +
|
||||
", url='" + url + '\'' +
|
||||
", subButtons=" + subButtons +
|
||||
'}';
|
||||
"type='" + type + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", key='" + key + '\'' +
|
||||
", url='" + url + '\'' +
|
||||
", subButtons=" + subButtons +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class WxMenuRule {
|
||||
private String tagId;
|
||||
private String sex;
|
||||
@@ -134,51 +134,51 @@ public class WxMenu implements Serializable {
|
||||
private String city;
|
||||
private String clientPlatformType;
|
||||
private String language;
|
||||
|
||||
|
||||
public String getTagId() {
|
||||
return tagId;
|
||||
}
|
||||
|
||||
|
||||
public void setTagId(String tagId) {
|
||||
this.tagId = tagId;
|
||||
}
|
||||
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
|
||||
public void setSex(String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
|
||||
public String getClientPlatformType() {
|
||||
return clientPlatformType;
|
||||
}
|
||||
|
||||
|
||||
public void setClientPlatformType(String clientPlatformType) {
|
||||
this.clientPlatformType = clientPlatformType;
|
||||
}
|
||||
@@ -194,15 +194,15 @@ public class WxMenu implements Serializable {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "matchrule:{" +
|
||||
"tag_id='" + tagId + '\'' +
|
||||
", sex='" + sex + '\'' +
|
||||
", country" + country + '\'' +
|
||||
", province" + province + '\'' +
|
||||
", city" + city + '\'' +
|
||||
", client_platform_type" + clientPlatformType + '\'' +
|
||||
", language" + language + '\'' +
|
||||
"}";
|
||||
"tag_id='" + tagId + '\'' +
|
||||
", sex='" + sex + '\'' +
|
||||
", country" + country + '\'' +
|
||||
", province" + province + '\'' +
|
||||
", city" + city + '\'' +
|
||||
", client_platform_type" + clientPlatformType + '\'' +
|
||||
", language" + language + '\'' +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,19 +6,28 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 微信错误码说明,请阅读: <a href="http://mp.weixin.qq.com/wiki/10/6380dc743053a91c544ffd2b7c959166.html">全局返回码说明</a>
|
||||
* @author Daniel Qian
|
||||
*
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
public class WxError implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7869786563361406291L;
|
||||
|
||||
private int errorCode;
|
||||
|
||||
|
||||
private String errorMsg;
|
||||
|
||||
private String json;
|
||||
|
||||
|
||||
public static WxError fromJson(String json) {
|
||||
WxError error = WxGsonBuilder.create().fromJson(json, WxError.class);
|
||||
return error;
|
||||
}
|
||||
|
||||
public static Builder newBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
@@ -43,43 +52,34 @@ public class WxError implements Serializable {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public static WxError fromJson(String json) {
|
||||
WxError error = WxGsonBuilder.create().fromJson(json, WxError.class);
|
||||
return error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if(json != null){
|
||||
if (json != null) {
|
||||
return json;
|
||||
}
|
||||
return "错误: Code=" + errorCode + ", Msg=" + errorMsg;
|
||||
}
|
||||
|
||||
public static Builder newBuilder(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder{
|
||||
public static class Builder {
|
||||
private int errorCode;
|
||||
private String errorMsg;
|
||||
|
||||
|
||||
public Builder setErrorCode(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WxError build(){
|
||||
|
||||
public WxError build() {
|
||||
WxError wxError = new WxError();
|
||||
wxError.setErrorCode(this.errorCode);
|
||||
wxError.setErrorMsg(this.errorMsg);
|
||||
return wxError;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,16 @@ import java.io.Serializable;
|
||||
|
||||
public class WxMediaUploadResult implements Serializable {
|
||||
private static final long serialVersionUID = 330834334738622341L;
|
||||
|
||||
|
||||
private String type;
|
||||
private String mediaId;
|
||||
private String thumbMediaId;
|
||||
private long createdAt;
|
||||
|
||||
public static WxMediaUploadResult fromJson(String json) {
|
||||
return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class);
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -44,14 +48,10 @@ public class WxMediaUploadResult implements Serializable {
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
}
|
||||
|
||||
public static WxMediaUploadResult fromJson(String json) {
|
||||
return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WxUploadResult [type=" + type + ", media_id=" + mediaId + ", thumb_media_id=" + thumbMediaId
|
||||
+ ", created_at=" + createdAt + "]";
|
||||
+ ", created_at=" + createdAt + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user