zoukankan      html  css  js  c++  java
  • 微信 创建自定义菜单 向微信发起的post请求

    微信 创建自定义菜单 向微信发起的post请求

            Map<String, Object> res = new HashMap<String, Object>();
            try {
                String accessToken = accessTokenService.getAccessToken();
                if ("".equals(accessToken)) {
                    res.put("res", "获取微信access_token失败,请与管理员联系");
                    return res;
                }
                String action = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken;
                URL url = new URL(action);
                HttpURLConnection http = (HttpURLConnection) url.openConnection();
                http.setRequestMethod("POST");
                http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                http.setDoOutput(true);
                http.setDoInput(true);
                System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
                System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
                http.connect();
                OutputStream os = http.getOutputStream();
                os.write(data.getBytes("UTF-8"));// 传入参数
                os.flush();
                os.close();
                InputStream is = http.getInputStream();
                int size = is.available();
                byte[] jsonBytes = new byte[size];
                is.read(jsonBytes);
                String message = new String(jsonBytes, "UTF-8");
                System.out.println(message);
                res.put("res", "成功创建自定义菜单。请取消关注然后再次关注查看自定义菜单结果。");
            } catch ( Exception e) {
                e.printStackTrace();
                res.put("res", "创建自定义菜单失败,错误信息"+e.getMessage()+",请与管理员联系。");
            } 
            

    学习:

    http://www.cnblogs.com/Leo_wl/p/3248862.html

    应该可以改进吧;

  • 相关阅读:
    jquery实现京东轮播图的简单写法
    prop方法实现全选效果
    jquery实现点击小图实现大图的案例
    jquery实现淘宝精品图片切换
    html+css实现下拉菜单效果
    jquery对象和DOM对象的联系及转化
    【学习】012 垃圾回收机制算法分析
    【学习】011 JVM参数调优配置
    【学习】010 Netty异步通信框架
    【学习】009 NIO编程
  • 原文地址:https://www.cnblogs.com/stono/p/6609300.html
Copyright © 2011-2022 走看看