微信公众平台开发模式自定义菜单

 时间:2024-10-15 01:35:40

1、在设置自定义菜单之前,我们需要获取一个access_token.这个可以通过微信公众号appid和secret向公众号服务器获取api.weixin.qq.com/cgi-bin/token?appid=公众号ID&secret=公众号secret&grant_type=client_credential

微信公众平台开发模式自定义菜单

3、创建自定义菜单是通过POST协议发送一个json格式的结构体。WxAccessToken accessToken = WxAppManager.getCacheAccessToken(redis.client, app); // 获取存取的access_tokenString path = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken.access_token;URL url = new URL(path);HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();httpURLConnection.setDoOutput(true);httpURLConnection.setDoInput(true);httpURLConnection.setRequestMethod("POST");httpURLConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");httpURLConnection.connect();OutputStream outputStream = httpURLConnection.getOutputStream();outputStream.write(jsonMenu.getBytes("UTF-8"));outputStream.close();InputStream inputStream = httpURLConnection.getInputStream();JsonNode jsonIn = JsonUtil.readTree(inputStream);String errcode = jsonIn.path("errcode").asText();String errmsg = jsonIn.path("errmsg").asText();

微信公众平台开发模式自定义菜单

5、查询现有的菜单。这里使用GET请求api.weixin.qq.com/cgi-bin/menu/get?access_token=access_token

微信公众平台开发模式自定义菜单
  • Windows编辑内置域控组策略计算机加密文件系统
  • Discuz建站教程:[22]更换默认的用户组头像
  • Thecus N5500 NAS网络存储器使用手册:[1]
  • HttpWatch 工具的使用 第二篇 高级
  • 热门搜索
    家庭出身怎么写 怎么让鼻子变挺 ps怎么添加蒙版 电脑连不上网怎么解决 黑头是怎么形成的 手机刷机怎么刷 鸡蛋羹怎么做好吃 数学论文怎么写 ppt怎么做流程图 腰左侧疼是怎么回事