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