mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-17 13:49:26 +08:00
1.WxMenuRule增加language字段
2.更改了WxMenu的toJson方法使menurule转换成正确的字符串 3.WxMenuTest中增加了相应的测试用例
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
package me.chanjar.weixin.common.bean;
|
||||
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
import org.apache.commons.codec.Charsets;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.codec.Charsets;
|
||||
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
|
||||
/**
|
||||
* 企业号菜单
|
||||
* @author Daniel Qian
|
||||
@@ -136,6 +135,7 @@ public class WxMenu implements Serializable {
|
||||
private String province;
|
||||
private String city;
|
||||
private String clientPlatformType;
|
||||
private String language;
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
@@ -184,8 +184,16 @@ public class WxMenu implements Serializable {
|
||||
public void setClientPlatformType(String clientPlatformType) {
|
||||
this.clientPlatformType = clientPlatformType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "matchrule:{" +
|
||||
"group_id='" + groupId + '\'' +
|
||||
@@ -194,6 +202,7 @@ public class WxMenu implements Serializable {
|
||||
", province" + province + '\'' +
|
||||
", city" + city + '\'' +
|
||||
", client_platform_type" + clientPlatformType + '\'' +
|
||||
", language" + language + '\'' +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
*/
|
||||
package me.chanjar.weixin.common.util.json;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
@@ -19,9 +16,10 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxMenu;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Daniel Qian
|
||||
@@ -40,8 +38,7 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ
|
||||
json.add("button", buttonArray);
|
||||
|
||||
if (menu.getMatchRule() != null) {
|
||||
Gson gson = new Gson();
|
||||
json.add("matchrule", gson.toJsonTree(menu.getMatchRule()));
|
||||
json.add("matchrule", convertToJson(menu.getMatchRule()));
|
||||
}
|
||||
|
||||
return json;
|
||||
@@ -63,6 +60,18 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ
|
||||
return buttonJson;
|
||||
}
|
||||
|
||||
protected JsonObject convertToJson(WxMenu.WxMenuRule menuRule){
|
||||
JsonObject matchRule = new JsonObject();
|
||||
matchRule.addProperty("group_id",menuRule.getGroupId());
|
||||
matchRule.addProperty("sex",menuRule.getSex());
|
||||
matchRule.addProperty("country",menuRule.getCountry());
|
||||
matchRule.addProperty("province",menuRule.getProvince());
|
||||
matchRule.addProperty("city",menuRule.getCity());
|
||||
matchRule.addProperty("client_platform_type",menuRule.getClientPlatformType());
|
||||
matchRule.addProperty("language",menuRule.getLanguage());
|
||||
return matchRule;
|
||||
}
|
||||
|
||||
public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
/*
|
||||
* 操蛋的微信
|
||||
|
||||
Reference in New Issue
Block a user