微信公众号开发——获取openId
/**
*
* 获取用户openID
* @param course
* @return
* @throws UnsupportedEncodingException
*/
@RequestMapping(value = "/obtainOpenid" , method = )
public String obtainOpenid(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException{
ServletRequestAttributes attributes = (ServletRequestAttributes) ();
request = ();
// 获取openid
("text/html");
("UTF-8");
("UTF-8");
//String code = ("code");//获取code
String code = ();
Map<String, String> params = new HashMap<String, String>();
("appid", );
("secret",);
("grant_type", "authorization_code");
("code", code);
String result = (
"/sns/oauth2/access_token", params);
JSONObject jsonObject = (result);
String openid = ("openid").toString();
return openid ;
}