|
@@ -90,6 +90,28 @@ public class WXLoginController {
|
|
|
return "redirect:"+url;
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping("getMpOpenIdByCode")
|
|
|
+ public String getOpenIdByCode(String code){
|
|
|
+ //获取access_token
|
|
|
+ String url = "https://api.weixin.qq.com/sns/jscode2session" +
|
|
|
+ "?appid=" + ConstantUtil.MPAPPID +
|
|
|
+ "&secret=" + ConstantUtil.MPAPPSECRET +
|
|
|
+ "&js_code=" + code +
|
|
|
+ "&grant_type=authorization_code";
|
|
|
+ String result = HttpClientUtil.doGet(url);
|
|
|
+ System.out.println("请求获取access_token:" + result);
|
|
|
+ //返回结果的json对象
|
|
|
+ JSONObject resultObject = JSON.parseObject(result);
|
|
|
+ //请求获取userInfo
|
|
|
+ String infoUrl = "https://api.weixin.qq.com/sns/userinfo" +
|
|
|
+ "?access_token=" + resultObject.getString("access_token") +
|
|
|
+ "&openid=" + resultObject.getString("openid") +
|
|
|
+ "&lang=zh_CN";
|
|
|
+ String resultInfo = HttpClientUtil.doGet(infoUrl);
|
|
|
+
|
|
|
+ return resultInfo;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 回调方法
|
|
|
*
|