zoukankan      html  css  js  c++  java
  • 微信小程序获取openid

    @Override
    public Map<String, Object> getOpenId(Map<String,Object> paramMap) {
    String code=(String)paramMap.get("code");   
    String APPID=(String)paramMap.get("appid");
    String SECRET=(String)paramMap.get("secret");
    String access_token = "";
    String openid = "";

    String aturl ="https://api.weixin.qq.com/sns/jscode2session?appid="+APPID+"&secret="+SECRET+"&js_code="+code+"&grant_type=authorization_code";
    try {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet(aturl);
    HttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    String strResult = EntityUtils.toString(response.getEntity());
    com.alibaba.fastjson.JSONObject jsonResult = JSON.parseObject(strResult);
    access_token = (String) jsonResult.get("access_token");
    openid = (String) jsonResult.get("openid");
    paramMap.clear();
    paramMap.put("openId", openid);

    } else {
    System.out.println("error");
    }

    } catch (IOException e) {
    // System.out.println("get请求提交失败:" + access_token_url + e);

    }
    return paramMap;

    }

  • 相关阅读:
    学生管理系统简化版
    图形用户界面编程——事件驱动编程
    图形界面编程
    集合框架
    多线程编程
    反射
    相关类
    异常(4.13)
    接口
    锁!代码锁
  • 原文地址:https://www.cnblogs.com/feathe/p/12145241.html
Copyright © 2011-2022 走看看