|
@@ -1,5 +1,6 @@
|
|
|
package com.miaxis.system.controller.system;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
|
import com.miaxis.common.core.domain.entity.SysMenu;
|
|
|
import com.miaxis.common.core.domain.entity.SysUser;
|
|
@@ -7,6 +8,7 @@ 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.enums.StudentLoginTypeEnum;
|
|
|
+import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
import com.miaxis.common.utils.ServletUtils;
|
|
|
import com.miaxis.framework.web.service.SysLoginService;
|
|
@@ -16,8 +18,12 @@ import com.miaxis.system.dto.common.RouterDTO;
|
|
|
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.WxService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -50,6 +56,24 @@ public class SysLoginController
|
|
|
private TokenService tokenService;
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WxService wxService;
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(SysLoginController.class);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${app.appId}")
|
|
|
+ private String appid;
|
|
|
+
|
|
|
+ @Value("${app.appSecret}")
|
|
|
+ private String appSecret;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -84,48 +108,60 @@ public class SysLoginController
|
|
|
tokenDTO.setToken(token);
|
|
|
return Response.success(tokenDTO);
|
|
|
}
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 用户 jscode登录
|
|
|
-// *
|
|
|
-// */
|
|
|
-// @PostMapping("/login/jscode")
|
|
|
-// @ApiOperation("用户jscode登录")
|
|
|
-// public Response<TokenDTO> getInfo(String jscode){
|
|
|
-// String result = wxService.getWxInfo(appid, secret, jscode,"authorization_code");
|
|
|
-// JSONObject jsonString = JSONObject.parseObject(result);
|
|
|
-// WxResult wxResult = JSONObject.toJavaObject(jsonString, WxResult.class);
|
|
|
-// TokenDTO tokenDTO = new TokenDTO();
|
|
|
-// // 生成令牌
|
|
|
-// if (wxResult.getOpenid() != null){
|
|
|
-// // 生成令牌
|
|
|
-// String token = loginService.login(wxResult.getOpenid(),null, StudentLoginTypeEnum.OPENID_LOGIN.getCode());
|
|
|
-// tokenDTO.setToken(token);
|
|
|
-// return Response.success(tokenDTO) ;
|
|
|
-// }
|
|
|
-// else{
|
|
|
-// return Response.error(500,wxResult.getErrmsg());
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
- * 用户 jscode登录
|
|
|
+ * 用户 openid登录
|
|
|
*
|
|
|
*/
|
|
|
- @PostMapping("/login/jscode-test")
|
|
|
- @ApiOperation("用户jscode登录(测试,固定openid)")
|
|
|
- public Response<TokenDTO> getInfoTest(String jscode){
|
|
|
+ @PostMapping("/login/code")
|
|
|
+ @ApiOperation("用户授权码模式登录")
|
|
|
+ public Response<TokenDTO> loginByAuthorizationCode(String authorizationCode ){
|
|
|
+ String wxResultStr = wxService.getWxToken(appid, appSecret, authorizationCode, "authorization_code");
|
|
|
+ logger.info("微信授权码登录返回值:"+wxResultStr);
|
|
|
+ WxResult wxResult = JSONObject.parseObject(wxResultStr,WxResult.class);
|
|
|
+
|
|
|
+ // 生成令牌
|
|
|
+ if (wxResult.getErrcode() != null){
|
|
|
+ throw new CustomException("微信授权无效,请重新授权");
|
|
|
+ }
|
|
|
+ String token = loginService.login(wxResult.getOpenid(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
|
|
|
TokenDTO tokenDTO = new TokenDTO();
|
|
|
- // 生成令牌
|
|
|
- String token = loginService.login("oO7PJ5CPQJo62kZWA3uiUX2KG2s4",null, StudentLoginTypeEnum.OPENID_LOGIN.getCode());
|
|
|
tokenDTO.setToken(token);
|
|
|
+ tokenDTO.setWxResult(wxResult);
|
|
|
return Response.success(tokenDTO) ;
|
|
|
|
|
|
|
|
|
+
|
|
|
+ }
|
|
|
+ @PostMapping("/login/code/test")
|
|
|
+ @ApiOperation("用户授权码模式登录--测试")
|
|
|
+ public Response<TokenDTO> testloginByAuthorizationCode(String authorizationCode ){
|
|
|
+ String token = loginService.login("oN0Np5sK6JeTRa06hlE4-OkHDlDY",null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
|
|
|
+ TokenDTO tokenDTO = new TokenDTO();
|
|
|
+ tokenDTO.setToken(token);
|
|
|
+ return Response.success(tokenDTO) ;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 用户 jscode登录
|
|
|
+// *
|
|
|
+// */
|
|
|
+// @PostMapping("/login/jscode-test")
|
|
|
+// @ApiOperation("用户jscode登录(测试,固定openid)")
|
|
|
+// public Response<TokenDTO> getInfoTest(String jscode){
|
|
|
+// TokenDTO tokenDTO = new TokenDTO();
|
|
|
+// // 生成令牌
|
|
|
+// String token = loginService.login("oO7PJ5CPQJo62kZWA3uiUX2KG2s4",null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
|
|
|
+// tokenDTO.setToken(token);
|
|
|
+// return Response.success(tokenDTO) ;
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取用户信息
|