/**
* 公众号菜单
* @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 "设置完成";
}
自定义公众号菜单(java版)
最新推荐文章于 2024-07-17 19:21:45 发布