微信小程序獲取openId等信息

/**

*獲取小程序的appId,secret

*/

public static final String PAR_OPEN_APPID="";

 

public static final String PAR_OPEN_APP_SECRET="";

 

/**

*小程序訪問獲取基本信息的地址

*/

public static final String CODE_SESSION="https://api.weixin.qq.com/sns/jscode2session";

 

 

/**

*獲取小程序openId等信息

*/

 

參數:@RequestParam(value="code",required=true)String code

 

Map<String,String>param=Maps.newHashMap();

param.put("appid",WechatAccountConfig.PAR_OPEN_APPID);

param.put("secret",WechatAccountConfig.PAR_OPEN_APP_SECRET);

param.put("js_code",code);

param.put("grant_type","authorization_code");

String result=HttpClientUtil.doGet(WechatAccountConfig.CODE_SESSION,param);

JSONObject  jsonObject=JSONObject.parseObject(result);

 

// unionid只有申請開放者平臺讓公衆號與小程序綁定纔有

String  uniodId=jsonObject.getString("unionid");

String  sessionKey=jsonObject.getString("session_key");

String  openId=jsonObject.getString("openid");

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章