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

 时间: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 工具的使用 第二篇 高级
  • 热门搜索
    310什么意思 鲍鱼什么意思 致铅球运动员 一杠三星是什么级别 spoon是什么意思 绿萝的养殖方法 plain是什么意思 condition是什么意思 11月11日是什么节日 除权除息是什么意思