微信小程序获取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;

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM