|
|
@@ -6,6 +6,7 @@ import cn.binarywang.wx.miniapp.config.WxMaConfig;
|
|
|
import cn.dev33.satoken.context.SaHolder;
|
|
|
import cn.dev33.satoken.stp.StpLogic;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.useragent.UserAgent;
|
|
|
@@ -29,6 +30,7 @@ import cn.tr.module.sys.user.dto.SysUserDTO;
|
|
|
import cn.tr.module.sys.user.service.ISysUserService;
|
|
|
import cn.tr.plugin.security.bo.UserLoginInfoBO;
|
|
|
import cn.tr.plugin.security.utils.SaTokenUtils;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -60,15 +62,13 @@ public class WxAppletOauth2UserOperator extends AbstractOAuth2PswUserOperator {
|
|
|
@Autowired
|
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
@Override
|
|
|
public String auth(OAuth2PswReqDTO source) {
|
|
|
String appId = source.getAppId();
|
|
|
String wxAppletCode = source.getWxAppletCode();
|
|
|
String username = source.getUsername();
|
|
|
Date loginTime = new Date();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
//获取Request对象
|
|
|
HttpServletRequest request = ServletUtils.getRequest();
|
|
|
String ip = ServletUtils.getClientIP(request);
|
|
|
@@ -81,18 +81,17 @@ public class WxAppletOauth2UserOperator extends AbstractOAuth2PswUserOperator {
|
|
|
if (StrUtil.isEmpty(wxAppletCode)) {
|
|
|
throw new IllegalArgumentException("微信登陆码不能为空");
|
|
|
}
|
|
|
- try {
|
|
|
- WxMaJscode2SessionResult sessionInfo = wxMaService.getUserService().getSessionInfo(wxAppletCode);
|
|
|
-// WxMaJscode2SessionResult sessionInfo=new WxMaJscode2SessionResult();
|
|
|
-// sessionInfo.setOpenid("0d3DO5000LXJjU1dib300i6FX31DO50t");
|
|
|
-// sessionInfo.setUnionid("123");
|
|
|
- String openid = sessionInfo.getOpenid();
|
|
|
-// String sessionKey = sessionInfo.getSessionKey();
|
|
|
|
|
|
+// WxMaJscode2SessionResult sessionInfo = wxMaService.getUserService().getSessionInfo(wxAppletCode);
|
|
|
+ WxMaJscode2SessionResult sessionInfo=new WxMaJscode2SessionResult();
|
|
|
+ sessionInfo.setOpenid("0d3DO5000LXJjU1dib300i6FX31DO50t");
|
|
|
+ sessionInfo.setUnionid("123");
|
|
|
+ String openid = sessionInfo.getOpenid();
|
|
|
//根据openid查询用户信息 (通过数据库进行查询)
|
|
|
BizWxUserDTO wxUser = wxUserService.getUserByOpenidAndAppid(openid, appId);
|
|
|
if (wxUser == null) {
|
|
|
wxUser = new BizWxUserDTO();
|
|
|
+ wxUser.setId(IdUtil.getSnowflake().nextIdStr());
|
|
|
wxUser.setOpenId(openid);
|
|
|
wxUser.setAppId(appId);
|
|
|
wxUser.setNickname(username);
|
|
|
@@ -134,11 +133,6 @@ public class WxAppletOauth2UserOperator extends AbstractOAuth2PswUserOperator {
|
|
|
.build();
|
|
|
setSessionUser(tokenValue,loginInfo);
|
|
|
return tokenValue;
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- throw new ServiceException(TRExcCode.WX_LOGIN_FAIL, "微信登录失败:" + e.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|