自定义公众号菜单(java版)

  /**
     * 公众号菜单
     * @return
     */
    @GetMapping(value = "/setMenu",produces = "text/html;charset=utf-8")
    public String setMenu() {
        String accessToken = getToken();//上期有提到
        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        //一级菜单
        JSONObject menu1 = new JSONObject();
        menu1.put("type", "view");
        menu1.put("name", "知识星球");
        menu1.put("url", "https://www.photosir.com/videoTeaching.html");
        jsonArray.add(menu1);
        //一级菜单
        JSONObject menu2 = new JSONObject();
        menu2.put("type", "miniprogram");
        menu2.put("name", "悟空传图");
        menu2.put("url", "http://mp.weixin.qq.com");
        menu2.put("appid", "公众号appid");
        menu2.put("pagepath", "小程序配置路径");
        jsonArray.add(menu2);
        //一级菜单
        JSONObject menu3 = new JSONObject();
        menu3.put("name", "商业合作");
        JSONArray jsonArray2 = new JSONArray();
        //二级菜单
        JSONObject menu4 = new JSONObject();
        menu4.put("type", "view");
        menu4.put("name", "官网");
        menu4.put("url", "https://www.photosir.com/");
        jsonArray2.add(menu4);
        JSONObject menu5 = new JSONObject();
        menu5.put("type", "view");
        menu5.put("name", "联系我们");
        menu5.put("url", "https://www.photosir.com/contact.html");
        jsonArray2.add(menu5);
        menu3.put("sub_button", jsonArray2);
        jsonArray.add(menu3);
        jsonObject.put("button", jsonArray);
        String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken;
        String result = HttpUtil.postData(url, jsonObject.toJSONString());
        System.out.println(result);
        return "设置完成";
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

佛係老李

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值