|
@@ -2,16 +2,14 @@ package com.miaxis.system.controller.system;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.miaxis.apple.service.IAppleService;
|
|
|
+import com.miaxis.common.core.domain.DyUserInfoResult;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.core.domain.WxUserInfo;
|
|
|
import com.miaxis.common.core.domain.entity.SysMenu;
|
|
|
import com.miaxis.common.core.domain.entity.SysUser;
|
|
|
-import com.miaxis.common.core.domain.model.LoginBody;
|
|
|
-import com.miaxis.common.core.domain.model.LoginBodyNoCode;
|
|
|
-import com.miaxis.common.core.domain.model.LoginUser;
|
|
|
+import com.miaxis.common.core.domain.model.*;
|
|
|
import com.miaxis.common.enums.StudentLoginTypeEnum;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
-import com.miaxis.common.utils.AppleUtil;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
import com.miaxis.common.utils.ServletUtils;
|
|
|
import com.miaxis.framework.web.service.SysLoginService;
|
|
@@ -22,7 +20,7 @@ import com.miaxis.system.dto.system.AppleTokenDTO;
|
|
|
import com.miaxis.system.dto.system.TokenDTO;
|
|
|
import com.miaxis.system.dto.system.UserInfoDTO;
|
|
|
import com.miaxis.system.service.ISysMenuService;
|
|
|
-import com.miaxis.common.core.domain.model.WxResult;
|
|
|
+import com.miaxis.wx.service.DyService;
|
|
|
import com.miaxis.wx.service.WxService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -36,10 +34,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
/**
|
|
@@ -69,6 +64,11 @@ public class SysLoginController
|
|
|
|
|
|
@Autowired
|
|
|
private WxService wxService;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DyService dyService;
|
|
|
+
|
|
|
private static Logger logger = LoggerFactory.getLogger(SysLoginController.class);
|
|
|
|
|
|
|
|
@@ -83,11 +83,6 @@ public class SysLoginController
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 登录方法 (含验证码)
|
|
|
*
|
|
@@ -125,8 +120,8 @@ public class SysLoginController
|
|
|
*
|
|
|
*/
|
|
|
@PostMapping("/login/code")
|
|
|
- @ApiOperation("用户授权码模式登录")
|
|
|
- public Response<TokenDTO> loginByAuthorizationCode(String authorizationCode ){
|
|
|
+ @ApiOperation("微信用户授权码模式登录")
|
|
|
+ public Response<TokenDTO> loginByWxAuthorizationCode(String authorizationCode ){
|
|
|
String wxResultStr = wxService.getWxToken(appid, appSecret, authorizationCode, "authorization_code");
|
|
|
logger.info("微信授权码登录返回值:"+wxResultStr);
|
|
|
WxResult wxResult = JSONObject.parseObject(wxResultStr,WxResult.class);
|
|
@@ -135,21 +130,55 @@ public class SysLoginController
|
|
|
if (wxResult.getErrcode() != null){
|
|
|
throw new CustomException("微信授权无效,请重新授权");
|
|
|
}
|
|
|
+
|
|
|
String userInfoStr = wxService.getUserInfo("zh_CN", wxResult.getAccess_token(), wxResult.getOpenid());
|
|
|
WxUserInfo wxUserInfo = JSONObject.parseObject(userInfoStr,WxUserInfo.class);
|
|
|
ServletUtils.getRequest().setAttribute("headImage",wxUserInfo.getHeadimgurl());
|
|
|
ServletUtils.getRequest().setAttribute("nickName",wxUserInfo.getNickname());
|
|
|
+ ServletUtils.getRequest().setAttribute("third","weixin");
|
|
|
String token = loginService.login(wxUserInfo.getOpenid(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
|
|
|
TokenDTO tokenDTO = new TokenDTO();
|
|
|
tokenDTO.setToken(token);
|
|
|
- tokenDTO.setWxResult(wxResult);
|
|
|
+ tokenDTO.setThirdResult(wxResult);
|
|
|
+ return Response.success(tokenDTO) ;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户 openid登录
|
|
|
+ *
|
|
|
+ */
|
|
|
+ @PostMapping("/login/dycode")
|
|
|
+ @ApiOperation("抖音用户授权码模式登录")
|
|
|
+ public Response<TokenDTO> loginByDyAuthorizationCode(String authorizationCode ){
|
|
|
+ String dyResultStr = dyService.getDyToken(appid, appSecret, authorizationCode, "authorization_code");
|
|
|
+ logger.info("抖音授权码登录返回值:"+dyResultStr);
|
|
|
+ DyResult dyResult = JSONObject.parseObject(dyResultStr,DyResult.class);
|
|
|
+
|
|
|
+ // 生成令牌
|
|
|
+ if (dyResult.getDyToken().getError_code() != null){
|
|
|
+ throw new CustomException("抖音授权登录无效,错误原因:"+dyResult.getDyToken().getDescription());
|
|
|
+ }
|
|
|
+ String userInfoStr = dyService.getUserInfo(dyResult.getDyToken().getAccess_token(),dyResult.getDyToken().getOpen_id());
|
|
|
+ DyUserInfoResult dyUserInfoResult = JSONObject.parseObject(userInfoStr,DyUserInfoResult.class);
|
|
|
+
|
|
|
+ ServletUtils.getRequest().setAttribute("third","douyin");
|
|
|
+ ServletUtils.getRequest().setAttribute("headImage",dyUserInfoResult.getData().getAvatar());
|
|
|
+ ServletUtils.getRequest().setAttribute("nickName",dyUserInfoResult.getData().getNickname());
|
|
|
+
|
|
|
+ String token = loginService.login(dyResult.getDyToken().getOpen_id(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
|
|
|
+ TokenDTO tokenDTO = new TokenDTO();
|
|
|
+ tokenDTO.setToken(token);
|
|
|
+ tokenDTO.setThirdResult(dyResult);
|
|
|
return Response.success(tokenDTO) ;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
@PostMapping("/login/code/test")
|
|
|
- @ApiOperation("用户授权码模式登录--测试")
|
|
|
+ @ApiOperation("微信用户授权码模式登录--测试")
|
|
|
public Response<TokenDTO> testloginByAuthorizationCode(String authorizationCode ){
|
|
|
WxUserInfo wxUserInfo = new WxUserInfo();
|
|
|
wxUserInfo.setOpenid("oN0Np5sK6JeTRa06hlE4-OkHDlDY");
|
|
@@ -158,6 +187,7 @@ public class SysLoginController
|
|
|
wxUserInfo.setHeadimgurl("https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83erGMFzKaOmz6cIaA0J1nicWSlBLdLKY46N5CNCoASiajT7Z3RIfPngPhJsjmqsSjGCFibPU4vCtfz3aw/132");
|
|
|
ServletUtils.getRequest().setAttribute("headImage",wxUserInfo.getHeadimgurl());
|
|
|
ServletUtils.getRequest().setAttribute("nickName",wxUserInfo.getNickname());
|
|
|
+ ServletUtils.getRequest().setAttribute("third","weixin");
|
|
|
String token = loginService.login(wxUserInfo.getOpenid(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
|
|
|
TokenDTO tokenDTO = new TokenDTO();
|
|
|
tokenDTO.setToken(token);
|