mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 02:28:25 +08:00 
			
		
		
		
	将菜单相关的类转移到单独的包里方便管理,以便于某些特殊需求
This commit is contained in:
		| @ -1,208 +0,0 @@ | |||||||
| 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; |  | ||||||
| import java.nio.charset.StandardCharsets; |  | ||||||
| import java.util.ArrayList; |  | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * 企业号菜单 |  | ||||||
|  * |  | ||||||
|  * @author Daniel Qian |  | ||||||
|  */ |  | ||||||
| public class WxMenu implements Serializable { |  | ||||||
|  |  | ||||||
|   private static final long serialVersionUID = -7083914585539687746L; |  | ||||||
|  |  | ||||||
|   private List<WxMenuButton> buttons = new ArrayList<WxMenuButton>(); |  | ||||||
|  |  | ||||||
|   private WxMenuRule matchRule; |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化 |  | ||||||
|    * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu |  | ||||||
|    */ |  | ||||||
|   public static WxMenu fromJson(String json) { |  | ||||||
|     return WxGsonBuilder.create().fromJson(json, WxMenu.class); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   /** |  | ||||||
|    * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化 |  | ||||||
|    * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu |  | ||||||
|    */ |  | ||||||
|   public static WxMenu fromJson(InputStream is) { |  | ||||||
|     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 + |  | ||||||
|             '}'; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   public static class WxMenuButton { |  | ||||||
|  |  | ||||||
|     private String type; |  | ||||||
|     private String name; |  | ||||||
|     private String key; |  | ||||||
|     private String url; |  | ||||||
|  |  | ||||||
|     private List<WxMenuButton> subButtons = new ArrayList<WxMenuButton>(); |  | ||||||
|  |  | ||||||
|     public String getType() { |  | ||||||
|       return type; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setType(String type) { |  | ||||||
|       this.type = type; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public String getName() { |  | ||||||
|       return name; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setName(String name) { |  | ||||||
|       this.name = name; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public String getKey() { |  | ||||||
|       return key; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setKey(String key) { |  | ||||||
|       this.key = key; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public String getUrl() { |  | ||||||
|       return url; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setUrl(String url) { |  | ||||||
|       this.url = url; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public List<WxMenuButton> getSubButtons() { |  | ||||||
|       return subButtons; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setSubButtons(List<WxMenuButton> subButtons) { |  | ||||||
|       this.subButtons = subButtons; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public String toString() { |  | ||||||
|       return "WxMenuButton{" + |  | ||||||
|               "type='" + type + '\'' + |  | ||||||
|               ", name='" + name + '\'' + |  | ||||||
|               ", key='" + key + '\'' + |  | ||||||
|               ", url='" + url + '\'' + |  | ||||||
|               ", subButtons=" + subButtons + |  | ||||||
|               '}'; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   public static class WxMenuRule { |  | ||||||
|     private String tagId; |  | ||||||
|     private String sex; |  | ||||||
|     private String country; |  | ||||||
|     private String province; |  | ||||||
|     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; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public String getLanguage() { |  | ||||||
|       return language; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setLanguage(String language) { |  | ||||||
|       this.language = language; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public String toString() { |  | ||||||
|       return "matchrule:{" + |  | ||||||
|               "tag_id='" + tagId + '\'' + |  | ||||||
|               ", sex='" + sex + '\'' + |  | ||||||
|               ", country" + country + '\'' + |  | ||||||
|               ", province" + province + '\'' + |  | ||||||
|               ", city" + city + '\'' + |  | ||||||
|               ", client_platform_type" + clientPlatformType + '\'' + |  | ||||||
|               ", language" + language + '\'' + |  | ||||||
|               "}"; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @ -0,0 +1,69 @@ | |||||||
|  | package me.chanjar.weixin.common.bean.menu; | ||||||
|  |  | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.InputStreamReader; | ||||||
|  | import java.io.Serializable; | ||||||
|  | import java.nio.charset.StandardCharsets; | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenuButton; | ||||||
|  | import me.chanjar.weixin.common.util.json.WxGsonBuilder; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * 企业号菜单 | ||||||
|  |  * | ||||||
|  |  * @author Daniel Qian | ||||||
|  |  */ | ||||||
|  | public class WxMenu implements Serializable { | ||||||
|  |  | ||||||
|  |   private static final long serialVersionUID = -7083914585539687746L; | ||||||
|  |  | ||||||
|  |   private List<WxMenuButton> buttons = new ArrayList<WxMenuButton>(); | ||||||
|  |  | ||||||
|  |   private WxMenuRule matchRule; | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化 | ||||||
|  |    * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu | ||||||
|  |    */ | ||||||
|  |   public static WxMenu fromJson(String json) { | ||||||
|  |     return WxGsonBuilder.create().fromJson(json, WxMenu.class); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化 | ||||||
|  |    * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu | ||||||
|  |    */ | ||||||
|  |   public static WxMenu fromJson(InputStream is) { | ||||||
|  |     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 + | ||||||
|  |             '}'; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | } | ||||||
| @ -0,0 +1,62 @@ | |||||||
|  | package me.chanjar.weixin.common.bean.menu; | ||||||
|  |  | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | import org.apache.commons.lang3.builder.ToStringBuilder; | ||||||
|  | import org.apache.commons.lang3.builder.ToStringStyle; | ||||||
|  |  | ||||||
|  | public class WxMenuButton { | ||||||
|  |  | ||||||
|  |   private String type; | ||||||
|  |   private String name; | ||||||
|  |   private String key; | ||||||
|  |   private String url; | ||||||
|  |  | ||||||
|  |   private List<WxMenuButton> subButtons = new ArrayList<WxMenuButton>(); | ||||||
|  |  | ||||||
|  |   public String getType() { | ||||||
|  |     return type; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setType(String type) { | ||||||
|  |     this.type = type; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String getName() { | ||||||
|  |     return name; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setName(String name) { | ||||||
|  |     this.name = name; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String getKey() { | ||||||
|  |     return key; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setKey(String key) { | ||||||
|  |     this.key = key; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String getUrl() { | ||||||
|  |     return url; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setUrl(String url) { | ||||||
|  |     this.url = url; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public List<WxMenuButton> getSubButtons() { | ||||||
|  |     return subButtons; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setSubButtons(List<WxMenuButton> subButtons) { | ||||||
|  |     this.subButtons = subButtons; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   @Override | ||||||
|  |   public String toString() { | ||||||
|  |     return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -0,0 +1,75 @@ | |||||||
|  | package me.chanjar.weixin.common.bean.menu; | ||||||
|  |  | ||||||
|  | import org.apache.commons.lang3.builder.ToStringBuilder; | ||||||
|  | import org.apache.commons.lang3.builder.ToStringStyle; | ||||||
|  |  | ||||||
|  | public class WxMenuRule { | ||||||
|  |   private String tagId; | ||||||
|  |   private String sex; | ||||||
|  |   private String country; | ||||||
|  |   private String province; | ||||||
|  |   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; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String getLanguage() { | ||||||
|  |     return language; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setLanguage(String language) { | ||||||
|  |     this.language = language; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   @Override | ||||||
|  |   public String toString() { | ||||||
|  |     return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -2,8 +2,9 @@ package me.chanjar.weixin.common.util.json; | |||||||
|  |  | ||||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||||
| import com.google.gson.GsonBuilder; | import com.google.gson.GsonBuilder; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxAccessToken; | import me.chanjar.weixin.common.bean.WxAccessToken; | ||||||
| import me.chanjar.weixin.common.bean.WxMenu; | import me.chanjar.weixin.common.bean.menu.WxMenu; | ||||||
| import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||||
| import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | ||||||
|  |  | ||||||
|  | |||||||
| @ -8,11 +8,22 @@ | |||||||
|  */ |  */ | ||||||
| package me.chanjar.weixin.common.util.json; | package me.chanjar.weixin.common.util.json; | ||||||
|  |  | ||||||
| import com.google.gson.*; |  | ||||||
| import me.chanjar.weixin.common.bean.WxMenu; |  | ||||||
|  |  | ||||||
| import java.lang.reflect.Type; | import java.lang.reflect.Type; | ||||||
|  |  | ||||||
|  | import com.google.gson.JsonArray; | ||||||
|  | import com.google.gson.JsonDeserializationContext; | ||||||
|  | import com.google.gson.JsonDeserializer; | ||||||
|  | import com.google.gson.JsonElement; | ||||||
|  | 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.menu.WxMenu; | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenuButton; | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenuRule; | ||||||
|  |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @author Daniel Qian |  * @author Daniel Qian | ||||||
|  */ |  */ | ||||||
| @ -22,7 +33,7 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ | |||||||
|     JsonObject json = new JsonObject(); |     JsonObject json = new JsonObject(); | ||||||
|  |  | ||||||
|     JsonArray buttonArray = new JsonArray(); |     JsonArray buttonArray = new JsonArray(); | ||||||
|     for (WxMenu.WxMenuButton button : menu.getButtons()) { |     for (WxMenuButton button : menu.getButtons()) { | ||||||
|       JsonObject buttonJson = convertToJson(button); |       JsonObject buttonJson = convertToJson(button); | ||||||
|       buttonArray.add(buttonJson); |       buttonArray.add(buttonJson); | ||||||
|     } |     } | ||||||
| @ -35,7 +46,7 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ | |||||||
|     return json; |     return json; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   protected JsonObject convertToJson(WxMenu.WxMenuButton button) { |   protected JsonObject convertToJson(WxMenuButton button) { | ||||||
|     JsonObject buttonJson = new JsonObject(); |     JsonObject buttonJson = new JsonObject(); | ||||||
|     buttonJson.addProperty("type", button.getType()); |     buttonJson.addProperty("type", button.getType()); | ||||||
|     buttonJson.addProperty("name", button.getName()); |     buttonJson.addProperty("name", button.getName()); | ||||||
| @ -43,7 +54,7 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ | |||||||
|     buttonJson.addProperty("url", button.getUrl()); |     buttonJson.addProperty("url", button.getUrl()); | ||||||
|     if (button.getSubButtons() != null && button.getSubButtons().size() > 0) { |     if (button.getSubButtons() != null && button.getSubButtons().size() > 0) { | ||||||
|       JsonArray buttonArray = new JsonArray(); |       JsonArray buttonArray = new JsonArray(); | ||||||
|       for (WxMenu.WxMenuButton sub_button : button.getSubButtons()) { |       for (WxMenuButton sub_button : button.getSubButtons()) { | ||||||
|         buttonArray.add(convertToJson(sub_button)); |         buttonArray.add(convertToJson(sub_button)); | ||||||
|       } |       } | ||||||
|       buttonJson.add("sub_button", buttonArray); |       buttonJson.add("sub_button", buttonArray); | ||||||
| @ -51,7 +62,7 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ | |||||||
|     return buttonJson; |     return buttonJson; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   protected JsonObject convertToJson(WxMenu.WxMenuRule menuRule) { |   protected JsonObject convertToJson(WxMenuRule menuRule) { | ||||||
|     JsonObject matchRule = new JsonObject(); |     JsonObject matchRule = new JsonObject(); | ||||||
|     matchRule.addProperty("tag_id", menuRule.getTagId()); |     matchRule.addProperty("tag_id", menuRule.getTagId()); | ||||||
|     matchRule.addProperty("sex", menuRule.getSex()); |     matchRule.addProperty("sex", menuRule.getSex()); | ||||||
| @ -74,7 +85,7 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ | |||||||
|     JsonArray buttonsJson = menuJson.get("button").getAsJsonArray(); |     JsonArray buttonsJson = menuJson.get("button").getAsJsonArray(); | ||||||
|     for (int i = 0; i < buttonsJson.size(); i++) { |     for (int i = 0; i < buttonsJson.size(); i++) { | ||||||
|       JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject(); |       JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject(); | ||||||
|       WxMenu.WxMenuButton button = convertFromJson(buttonJson); |       WxMenuButton button = convertFromJson(buttonJson); | ||||||
|       menu.getButtons().add(button); |       menu.getButtons().add(button); | ||||||
|       if (buttonJson.get("sub_button") == null || buttonJson.get("sub_button").isJsonNull()) { |       if (buttonJson.get("sub_button") == null || buttonJson.get("sub_button").isJsonNull()) { | ||||||
|         continue; |         continue; | ||||||
| @ -88,8 +99,8 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ | |||||||
|     return menu; |     return menu; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   protected WxMenu.WxMenuButton convertFromJson(JsonObject json) { |   protected WxMenuButton convertFromJson(JsonObject json) { | ||||||
|     WxMenu.WxMenuButton button = new WxMenu.WxMenuButton(); |     WxMenuButton button = new WxMenuButton(); | ||||||
|     button.setName(GsonHelper.getString(json, "name")); |     button.setName(GsonHelper.getString(json, "name")); | ||||||
|     button.setKey(GsonHelper.getString(json, "key")); |     button.setKey(GsonHelper.getString(json, "key")); | ||||||
|     button.setUrl(GsonHelper.getString(json, "url")); |     button.setUrl(GsonHelper.getString(json, "url")); | ||||||
|  | |||||||
| @ -1,10 +1,13 @@ | |||||||
| package me.chanjar.weixin.common.bean; | package me.chanjar.weixin.common.bean; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxMenu.WxMenuButton; |  | ||||||
| import org.testng.Assert; | import org.testng.Assert; | ||||||
| import org.testng.annotations.DataProvider; | import org.testng.annotations.DataProvider; | ||||||
| import org.testng.annotations.Test; | import org.testng.annotations.Test; | ||||||
|  |  | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenu; | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenuButton; | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenuRule; | ||||||
|  |  | ||||||
| @Test | @Test | ||||||
| public class WxMenuTest { | public class WxMenuTest { | ||||||
|  |  | ||||||
| @ -66,7 +69,7 @@ public class WxMenuTest { | |||||||
|  |  | ||||||
|     menu.getButtons().add(button1); |     menu.getButtons().add(button1); | ||||||
|  |  | ||||||
|     WxMenu.WxMenuRule wxMenuRule = new WxMenu.WxMenuRule(); |     WxMenuRule wxMenuRule = new WxMenuRule(); | ||||||
|     wxMenuRule.setTagId("2"); |     wxMenuRule.setTagId("2"); | ||||||
|     wxMenuRule.setSex("1"); |     wxMenuRule.setSex("1"); | ||||||
|     wxMenuRule.setCountry("中国"); |     wxMenuRule.setCountry("中国"); | ||||||
|  | |||||||
| @ -1,7 +1,12 @@ | |||||||
| package me.chanjar.weixin.cp.api; | package me.chanjar.weixin.cp.api; | ||||||
|  |  | ||||||
|  | import java.io.File; | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxJsapiSignature; | import me.chanjar.weixin.common.bean.WxJsapiSignature; | ||||||
| import me.chanjar.weixin.common.bean.WxMenu; | import me.chanjar.weixin.common.bean.menu.WxMenu; | ||||||
| import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| import me.chanjar.weixin.common.session.WxSession; | import me.chanjar.weixin.common.session.WxSession; | ||||||
| @ -12,11 +17,6 @@ import me.chanjar.weixin.cp.bean.WxCpMessage; | |||||||
| import me.chanjar.weixin.cp.bean.WxCpTag; | import me.chanjar.weixin.cp.bean.WxCpTag; | ||||||
| import me.chanjar.weixin.cp.bean.WxCpUser; | import me.chanjar.weixin.cp.bean.WxCpUser; | ||||||
|  |  | ||||||
| import java.io.File; |  | ||||||
| import java.io.IOException; |  | ||||||
| import java.io.InputStream; |  | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 微信API的Service |  * 微信API的Service | ||||||
|  */ |  */ | ||||||
|  | |||||||
| @ -1,32 +1,13 @@ | |||||||
| package me.chanjar.weixin.cp.api; | package me.chanjar.weixin.cp.api; | ||||||
|  |  | ||||||
| import com.google.gson.JsonArray; | import java.io.File; | ||||||
| import com.google.gson.JsonElement; | import java.io.IOException; | ||||||
| import com.google.gson.JsonObject; | import java.io.InputStream; | ||||||
| import com.google.gson.JsonPrimitive; | import java.io.StringReader; | ||||||
| import com.google.gson.internal.Streams; | import java.security.NoSuchAlgorithmException; | ||||||
| import com.google.gson.reflect.TypeToken; | import java.util.List; | ||||||
| import com.google.gson.stream.JsonReader; | import java.util.UUID; | ||||||
| import me.chanjar.weixin.common.bean.WxAccessToken; |  | ||||||
| import me.chanjar.weixin.common.bean.WxJsapiSignature; |  | ||||||
| import me.chanjar.weixin.common.bean.WxMenu; |  | ||||||
| import me.chanjar.weixin.common.bean.result.WxError; |  | ||||||
| import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; |  | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; |  | ||||||
| import me.chanjar.weixin.common.session.StandardSessionManager; |  | ||||||
| import me.chanjar.weixin.common.session.WxSession; |  | ||||||
| import me.chanjar.weixin.common.session.WxSessionManager; |  | ||||||
| import me.chanjar.weixin.common.util.RandomUtils; |  | ||||||
| import me.chanjar.weixin.common.util.StringUtils; |  | ||||||
| import me.chanjar.weixin.common.util.crypto.SHA1; |  | ||||||
| import me.chanjar.weixin.common.util.fs.FileUtils; |  | ||||||
| import me.chanjar.weixin.common.util.http.*; |  | ||||||
| import me.chanjar.weixin.common.util.json.GsonHelper; |  | ||||||
| import me.chanjar.weixin.cp.bean.WxCpDepart; |  | ||||||
| import me.chanjar.weixin.cp.bean.WxCpMessage; |  | ||||||
| import me.chanjar.weixin.cp.bean.WxCpTag; |  | ||||||
| import me.chanjar.weixin.cp.bean.WxCpUser; |  | ||||||
| import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; |  | ||||||
| import org.apache.http.HttpHost; | import org.apache.http.HttpHost; | ||||||
| import org.apache.http.client.ClientProtocolException; | import org.apache.http.client.ClientProtocolException; | ||||||
| import org.apache.http.client.config.RequestConfig; | import org.apache.http.client.config.RequestConfig; | ||||||
| @ -37,13 +18,41 @@ import org.apache.http.impl.client.CloseableHttpClient; | |||||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||||
|  |  | ||||||
| import java.io.File; | import com.google.gson.JsonArray; | ||||||
| import java.io.IOException; | import com.google.gson.JsonElement; | ||||||
| import java.io.InputStream; | import com.google.gson.JsonObject; | ||||||
| import java.io.StringReader; | import com.google.gson.JsonPrimitive; | ||||||
| import java.security.NoSuchAlgorithmException; | import com.google.gson.internal.Streams; | ||||||
| import java.util.List; | import com.google.gson.reflect.TypeToken; | ||||||
| import java.util.UUID; | import com.google.gson.stream.JsonReader; | ||||||
|  |  | ||||||
|  | import me.chanjar.weixin.common.bean.WxAccessToken; | ||||||
|  | import me.chanjar.weixin.common.bean.WxJsapiSignature; | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenu; | ||||||
|  | import me.chanjar.weixin.common.bean.result.WxError; | ||||||
|  | import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | ||||||
|  | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
|  | import me.chanjar.weixin.common.session.StandardSessionManager; | ||||||
|  | import me.chanjar.weixin.common.session.WxSession; | ||||||
|  | import me.chanjar.weixin.common.session.WxSessionManager; | ||||||
|  | import me.chanjar.weixin.common.util.RandomUtils; | ||||||
|  | import me.chanjar.weixin.common.util.StringUtils; | ||||||
|  | import me.chanjar.weixin.common.util.crypto.SHA1; | ||||||
|  | import me.chanjar.weixin.common.util.fs.FileUtils; | ||||||
|  | import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; | ||||||
|  | import me.chanjar.weixin.common.util.http.DefaultApacheHttpHttpClientBuilder; | ||||||
|  | import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor; | ||||||
|  | import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; | ||||||
|  | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||||
|  | import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | ||||||
|  | import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; | ||||||
|  | import me.chanjar.weixin.common.util.http.URIUtil; | ||||||
|  | import me.chanjar.weixin.common.util.json.GsonHelper; | ||||||
|  | import me.chanjar.weixin.cp.bean.WxCpDepart; | ||||||
|  | import me.chanjar.weixin.cp.bean.WxCpMessage; | ||||||
|  | import me.chanjar.weixin.cp.bean.WxCpTag; | ||||||
|  | import me.chanjar.weixin.cp.bean.WxCpUser; | ||||||
|  | import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; | ||||||
|  |  | ||||||
| public class WxCpServiceImpl implements WxCpService { | public class WxCpServiceImpl implements WxCpService { | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,15 +1,17 @@ | |||||||
| package me.chanjar.weixin.cp.api; | package me.chanjar.weixin.cp.api; | ||||||
|  |  | ||||||
| import com.google.inject.Inject; |  | ||||||
| import me.chanjar.weixin.common.api.WxConsts; |  | ||||||
| import me.chanjar.weixin.common.bean.WxMenu; |  | ||||||
| import me.chanjar.weixin.common.bean.WxMenu.WxMenuButton; |  | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; |  | ||||||
| import org.testng.Assert; | import org.testng.Assert; | ||||||
| import org.testng.annotations.DataProvider; | import org.testng.annotations.DataProvider; | ||||||
| import org.testng.annotations.Guice; | import org.testng.annotations.Guice; | ||||||
| import org.testng.annotations.Test; | import org.testng.annotations.Test; | ||||||
|  |  | ||||||
|  | import com.google.inject.Inject; | ||||||
|  |  | ||||||
|  | import me.chanjar.weixin.common.api.WxConsts; | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenu; | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenuButton; | ||||||
|  | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 测试菜单 |  * 测试菜单 | ||||||
|  * @author Daniel Qian |  * @author Daniel Qian | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| package me.chanjar.weixin.mp.api; | package me.chanjar.weixin.mp.api; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxMenu; | import me.chanjar.weixin.common.bean.menu.WxMenu; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxMenu; | import me.chanjar.weixin.common.bean.menu.WxMenu; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | ||||||
| import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; | import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; | ||||||
|  | |||||||
| @ -1,16 +1,18 @@ | |||||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||||
|  |  | ||||||
| import com.google.inject.Inject; |  | ||||||
| import me.chanjar.weixin.common.api.WxConsts; |  | ||||||
| import me.chanjar.weixin.common.bean.WxMenu; |  | ||||||
| import me.chanjar.weixin.common.bean.WxMenu.WxMenuButton; |  | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; |  | ||||||
| import me.chanjar.weixin.mp.api.ApiTestModule; |  | ||||||
| import org.testng.Assert; | import org.testng.Assert; | ||||||
| import org.testng.annotations.DataProvider; | import org.testng.annotations.DataProvider; | ||||||
| import org.testng.annotations.Guice; | import org.testng.annotations.Guice; | ||||||
| import org.testng.annotations.Test; | import org.testng.annotations.Test; | ||||||
|  |  | ||||||
|  | import com.google.inject.Inject; | ||||||
|  |  | ||||||
|  | import me.chanjar.weixin.common.api.WxConsts; | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenu; | ||||||
|  | import me.chanjar.weixin.common.bean.menu.WxMenuButton; | ||||||
|  | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
|  | import me.chanjar.weixin.mp.api.ApiTestModule; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 测试菜单 |  * 测试菜单 | ||||||
|  * @author chanjarster |  * @author chanjarster | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 BinaryWang
					BinaryWang