|
|
|
@@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
import me.chanjar.weixin.mp.api.WxMpService; |
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; |
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpUser; |
|
|
|
import org.apache.shiro.SecurityUtils; |
|
|
|
import org.apache.shiro.subject.Subject; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@@ -108,6 +109,12 @@ public class WechatLoginController extends BaseController { |
|
|
|
WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code); |
|
|
|
log.debug("accessToken: " + accessToken.getAccessToken() + ", openId: " + accessToken.getOpenId() + ", unionId: " + accessToken.getUnionId()); |
|
|
|
|
|
|
|
// 获取 用户信息 |
|
|
|
WxMpUser mpUser = wxMpService.oauth2getUserInfo(accessToken, null); |
|
|
|
if(mpUser != null) { |
|
|
|
log.debug(mpUser.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
// 保存 openId 到 cookie,一小时过期 |
|
|
|
Cookie openIdCookie = new Cookie("openId", accessToken.getOpenId()); |
|
|
|
openIdCookie.setMaxAge(60); |
|
|
|
|