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

}

微信小程序获取openid

上一篇:Java岗 面试考点精讲(基础篇02期)(下)


下一篇:小程序获取unionid的方法