zoukankan      html  css  js  c++  java
  • Java 微信登录授权后获取微信用户信息昵称乱码问题解决

    String getUserInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token="+access_token+"&openid="+openid+"&lang=zh_CN";
    URL url1 = new URL(getUserInfoUrl);
    HttpURLConnection urlConnection = (HttpURLConnection)url1.openConnection();


    // 将返回的输入流转换成字符串
    InputStream inputStream = urlConnection.getInputStream();

    // 指定编码格式
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"UTF-8");
    BufferedReader in = new BufferedReader(inputStreamReader);
    String jsonUserStr =in.readLine().toString();
    out.println("jsonUserStr = "+jsonUserStr);


    // 释放资源
    inputStream.close();
    inputStream = null;
    urlConnection.disconnect();


    JSONObject jsonUserObject = new JSONObject(jsonUserStr);

  • 相关阅读:
    二叉搜索树
    splay模板
    树状数组模板
    K尾相等数
    寻找最大数
    布线问题(最小生成树)
    开心的小明
    独木舟上的旅行(二)
    The Triangle(记忆化搜索)
    喷水装置(二)
  • 原文地址:https://www.cnblogs.com/libra0920/p/5671193.html
Copyright © 2011-2022 走看看