Exemplo n.º 1
0
  /**
   * 查询菜单
   *
   * @param token
   * @return 菜单结构json字符串
   */
  public static JSONObject getMenuJson(String token) {
    JSONObject result = null;

    if (token != null) {
      String url = MENU_GET.replace("ACCESS_TOKEN", token);
      result = WechatUtil.httpsRequest(url, "GET", null);
    }

    return result;
  }
Exemplo n.º 2
0
  public static void main(String[] args) {
    String token = WechatUtil.getToken();

    // getMenu(token);

    deleteMenu(token);

    Button sb1 = new Button("微商城", "view", null, "http://wx.vbaohui.com", null);
    Button sb2 = new Button("个人中心", "view", null, "http://wx.vbaohui.com/profile", null);
    Button btn1 = new Button("唯宝汇", "click", null, null, new Button[] {sb1, sb2});

    Button btn2 =
        new Button("有奖活动", "view", null, "http://wx.vbaohui.com/campaigns", new Button[] {});

    Button sb3 = new Button("关于我们", "view", null, "http://wx.vbaohui.com/aboutus", null);
    Button sb4 = new Button("帮助中心", "view", null, "http://wx.vbaohui.com/helps", null);
    Button btn3 = new Button("服务", "click", null, null, new Button[] {sb3, sb4});

    Menu menu = new Menu(new Button[] {btn1, btn2, btn3});
    createMenu(menu, token);
  }
Exemplo n.º 3
0
  /**
   * 创建菜单
   *
   * @param jsonMenu json格式
   * @param token
   * @return 状态 0 表示成功、其他表示失败
   */
  public static Integer createMenu(String jsonMenu, String token) {
    int result = 0;

    if (token != null) {
      // 拼装创建菜单的url
      String url = MENU_CREATE.replace("ACCESS_TOKEN", token);
      // 调用接口创建菜单
      JSONObject jsonObject = WechatUtil.httpsRequest(url, "POST", jsonMenu);

      if (null != jsonObject) {
        if (0 != jsonObject.getInt("errcode")) {
          result = jsonObject.getInt("errcode");
          log.error(
              "创建菜单失败 errcode:"
                  + jsonObject.getInt("errcode")
                  + ",errmsg:"
                  + jsonObject.getString("errmsg"));
        }
      }
    }
    return result;
  }
Exemplo n.º 4
0
 /**
  * 删除菜单
  *
  * @param token
  */
 public static void deleteMenu(String token) {
   if (token != null) {
     String url = MENU_DEL.replace("ACCESS_TOKEN", token);
     WechatUtil.httpsRequest(url, "GET", null);
   }
 }