All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.chanjar.weixin.common.bean.WxMenu Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
package me.chanjar.weixin.common.bean;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import org.apache.commons.codec.Charsets;

/**
 * 企业号菜单
 * @author Daniel Qian
 *
 */
public class WxMenu implements Serializable {

  private List buttons = new ArrayList();

  public List getButtons() {
    return buttons;
  }

  public void setButtons(List buttons) {
    this.buttons = buttons;
  }
  
  public String toJson() {
    return WxGsonBuilder.create().toJson(this);
  }

  /**
   * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
   * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
   * @param json
   * @return
   */
  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
   * @param is
   * @return
   */
  public static WxMenu fromJson(InputStream is) {
    return WxGsonBuilder.create().fromJson(new InputStreamReader(is, Charsets.UTF_8), WxMenu.class);
  }

  @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 subButtons = new ArrayList();

    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 getSubButtons() {
      return subButtons;
    }

    public void setSubButtons(List subButtons) {
      this.subButtons = subButtons;
    }

    @Override
    public String toString() {
      return "WxMenuButton{" +
          "type='" + type + '\'' +
          ", name='" + name + '\'' +
          ", key='" + key + '\'' +
          ", url='" + url + '\'' +
          ", subButtons=" + subButtons +
          '}';
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy