Search in sources :

Example 1 with WxMenuButton

use of me.chanjar.weixin.common.bean.menu.WxMenuButton in project weixin-java-mp-demo-springboot by binarywang.

the class WxMenuController method menuCreateSample.

@GetMapping("/create")
public String menuCreateSample() throws WxErrorException {
    WxMenu menu = new WxMenu();
    WxMenuButton button1 = new WxMenuButton();
    button1.setType(MenuButtonType.CLICK);
    button1.setName("今日歌曲");
    button1.setKey("V1001_TODAY_MUSIC");
    // WxMenuButton button2 = new WxMenuButton();
    // button2.setType(WxConsts.BUTTON_MINIPROGRAM);
    // button2.setName("小程序");
    // button2.setAppId("wx286b93c14bbf93aa");
    // button2.setPagePath("pages/lunar/index.html");
    // button2.setUrl("http://mp.weixin.qq.com");
    WxMenuButton button3 = new WxMenuButton();
    button3.setName("菜单");
    menu.getButtons().add(button1);
    // menu.getButtons().add(button2);
    menu.getButtons().add(button3);
    WxMenuButton button31 = new WxMenuButton();
    button31.setType(MenuButtonType.VIEW);
    button31.setName("搜索");
    button31.setUrl("http://www.soso.com/");
    WxMenuButton button32 = new WxMenuButton();
    button32.setType(MenuButtonType.VIEW);
    button32.setName("视频");
    button32.setUrl("http://v.qq.com/");
    WxMenuButton button33 = new WxMenuButton();
    button33.setType(MenuButtonType.CLICK);
    button33.setName("赞一下我们");
    button33.setKey("V1001_GOOD");
    button3.getSubButtons().add(button31);
    button3.getSubButtons().add(button32);
    button3.getSubButtons().add(button33);
    return this.wxService.getMenuService().menuCreate(menu);
}
Also used : WxMenu(me.chanjar.weixin.common.bean.menu.WxMenu) WxMenuButton(me.chanjar.weixin.common.bean.menu.WxMenuButton)

Example 2 with WxMenuButton

use of me.chanjar.weixin.common.bean.menu.WxMenuButton in project weixin-java-mp-demo-springboot by binarywang.

the class WxMenuController method menuCreateSample.

@GetMapping("/create")
public String menuCreateSample(@PathVariable String appid) throws WxErrorException, MalformedURLException {
    WxMenu menu = new WxMenu();
    WxMenuButton button1 = new WxMenuButton();
    button1.setType(MenuButtonType.CLICK);
    button1.setName("今日歌曲");
    button1.setKey("V1001_TODAY_MUSIC");
    // WxMenuButton button2 = new WxMenuButton();
    // button2.setType(WxConsts.BUTTON_MINIPROGRAM);
    // button2.setName("小程序");
    // button2.setAppId("wx286b93c14bbf93aa");
    // button2.setPagePath("pages/lunar/index.html");
    // button2.setUrl("http://mp.weixin.qq.com");
    WxMenuButton button3 = new WxMenuButton();
    button3.setName("菜单");
    menu.getButtons().add(button1);
    // menu.getButtons().add(button2);
    menu.getButtons().add(button3);
    WxMenuButton button31 = new WxMenuButton();
    button31.setType(MenuButtonType.VIEW);
    button31.setName("搜索");
    button31.setUrl("http://www.soso.com/");
    WxMenuButton button32 = new WxMenuButton();
    button32.setType(MenuButtonType.VIEW);
    button32.setName("视频");
    button32.setUrl("http://v.qq.com/");
    WxMenuButton button33 = new WxMenuButton();
    button33.setType(MenuButtonType.CLICK);
    button33.setName("赞一下我们");
    button33.setKey("V1001_GOOD");
    WxMenuButton button34 = new WxMenuButton();
    button34.setType(MenuButtonType.VIEW);
    button34.setName("获取用户信息");
    ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    if (servletRequestAttributes != null) {
        HttpServletRequest request = servletRequestAttributes.getRequest();
        URL requestURL = new URL(request.getRequestURL().toString());
        String url = this.wxService.switchoverTo(appid).getOAuth2Service().buildAuthorizationUrl(String.format("%s://%s/wx/redirect/%s/greet", requestURL.getProtocol(), requestURL.getHost(), appid), WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
        button34.setUrl(url);
    }
    button3.getSubButtons().add(button31);
    button3.getSubButtons().add(button32);
    button3.getSubButtons().add(button33);
    button3.getSubButtons().add(button34);
    this.wxService.switchover(appid);
    return this.wxService.getMenuService().menuCreate(menu);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WxMenu(me.chanjar.weixin.common.bean.menu.WxMenu) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) WxMenuButton(me.chanjar.weixin.common.bean.menu.WxMenuButton) URL(java.net.URL)

Example 3 with WxMenuButton

use of me.chanjar.weixin.common.bean.menu.WxMenuButton in project fw-cloud-framework by liuweijw.

the class WxMenuController method menuCreateSample.

@GetMapping("/create")
public String menuCreateSample() throws WxErrorException {
    WxMenu menu = new WxMenu();
    WxMenuButton button1 = new WxMenuButton();
    button1.setType(MenuButtonType.CLICK);
    button1.setName("今日歌曲");
    button1.setKey("V1001_TODAY_MUSIC");
    // WxMenuButton button2 = new WxMenuButton();
    // button2.setType(WxConsts.BUTTON_MINIPROGRAM);
    // button2.setName("小程序");
    // button2.setAppId("wx286b93c14bbf93aa");
    // button2.setPagePath("pages/lunar/index.html");
    // button2.setUrl("http://mp.weixin.qq.com");
    WxMenuButton button3 = new WxMenuButton();
    button3.setName("菜单");
    menu.getButtons().add(button1);
    // menu.getButtons().add(button2);
    menu.getButtons().add(button3);
    WxMenuButton button31 = new WxMenuButton();
    button31.setType(MenuButtonType.VIEW);
    button31.setName("搜索");
    button31.setUrl("http://www.soso.com/");
    WxMenuButton button32 = new WxMenuButton();
    button32.setType(MenuButtonType.VIEW);
    button32.setName("视频");
    button32.setUrl("http://v.qq.com/");
    WxMenuButton button33 = new WxMenuButton();
    button33.setType(MenuButtonType.CLICK);
    button33.setName("赞一下我们");
    button33.setKey("V1001_GOOD");
    button3.getSubButtons().add(button31);
    button3.getSubButtons().add(button32);
    button3.getSubButtons().add(button33);
    return this.wxService.getMenuService().menuCreate(menu);
}
Also used : WxMenu(me.chanjar.weixin.common.bean.menu.WxMenu) WxMenuButton(me.chanjar.weixin.common.bean.menu.WxMenuButton) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with WxMenuButton

use of me.chanjar.weixin.common.bean.menu.WxMenuButton in project summer by foxsugar.

the class WxMenuController method menuCreateSample.

@GetMapping("/createSample")
public String menuCreateSample() throws WxErrorException {
    WxMenu menu = new WxMenu();
    WxMenuButton button1 = new WxMenuButton();
    button1.setName("游戏中心");
    WxMenuButton button11 = new WxMenuButton();
    button11.setType(MenuButtonType.VIEW);
    button11.setName("下载游戏");
    // button11.setUrl("http://"+ serverConfig.getDomain() +"/agent/#/download");
    button11.setKey("DOWNLOAD_GAME");
    WxMenuButton button12 = new WxMenuButton();
    button12.setType(MenuButtonType.CLICK);
    button12.setName("在线客服");
    button12.setKey("KEFU_ONLINE");
    button1.getSubButtons().add(button11);
    button1.getSubButtons().add(button12);
    // button2
    WxMenuButton button2 = new WxMenuButton();
    button2.setName("代理");
    WxMenuButton button21 = new WxMenuButton();
    button21.setType(MenuButtonType.VIEW);
    // button21.setType(MenuButtonType.CLICK);
    button21.setName("进入后台");
    // button21.setKey("LOGIN_AGENT");
    button21.setUrl("http://" + serverConfig.getDomain() + "/game/wechat/authorize?returnUrl=loginAgent");
    // button11.setKey("DOWNLOAD_GAME");
    WxMenuButton button22 = new WxMenuButton();
    button22.setType(MenuButtonType.CLICK);
    button22.setName("专属链接");
    button22.setKey("LINK");
    WxMenuButton button23 = new WxMenuButton();
    button23.setType(MenuButtonType.CLICK);
    button23.setName("结算");
    button23.setKey("CLEAR");
    button2.getSubButtons().add(button21);
    button2.getSubButtons().add(button22);
    button2.getSubButtons().add(button23);
    // button3
    WxMenuButton button3 = new WxMenuButton();
    button3.setName("充值");
    button3.setType(MenuButtonType.VIEW);
    button3.setUrl("http://" + serverConfig.getDomain() + "/game/wechat/authorize?returnUrl=charge");
    menu.getButtons().add(button1);
    menu.getButtons().add(button2);
    menu.getButtons().add(button3);
    return this.wxService.getMenuService().menuCreate(menu);
}
Also used : WxMenu(me.chanjar.weixin.common.bean.menu.WxMenu) WxMenuButton(me.chanjar.weixin.common.bean.menu.WxMenuButton)

Aggregations

WxMenu (me.chanjar.weixin.common.bean.menu.WxMenu)4 WxMenuButton (me.chanjar.weixin.common.bean.menu.WxMenuButton)4 URL (java.net.URL)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1