|
@@ -17,6 +17,7 @@ import com.miaxis.feign.service.IWxService;
|
|
|
import com.miaxis.framework.web.service.SysLoginService;
|
|
|
import com.miaxis.framework.web.service.SysPermissionService;
|
|
|
import com.miaxis.framework.web.service.TokenService;
|
|
|
+import com.miaxis.service.IAppleService;
|
|
|
import com.miaxis.system.dto.common.RouterDTO;
|
|
|
import com.miaxis.system.dto.system.TokenDTO;
|
|
|
import com.miaxis.system.dto.system.UserInfoDTO;
|
|
@@ -35,6 +36,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -46,9 +48,8 @@ import java.util.Set;
|
|
|
* @author miaxis
|
|
|
*/
|
|
|
@RestController
|
|
|
-@Api(tags={"【系统-登录验证】"})
|
|
|
-public class SysLoginController
|
|
|
-{
|
|
|
+@Api(tags = {"【系统-登录验证】"})
|
|
|
+public class SysLoginController {
|
|
|
@Autowired
|
|
|
private SysLoginService loginService;
|
|
|
|
|
@@ -67,7 +68,8 @@ public class SysLoginController
|
|
|
@Autowired
|
|
|
private ITmsCoachInfoService coachInfoService;
|
|
|
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private IAppleService appleService;
|
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SysLoginController.class);
|
|
@@ -95,14 +97,15 @@ public class SysLoginController
|
|
|
*/
|
|
|
@PostMapping("/login")
|
|
|
@ApiOperation("系统-登录方法")
|
|
|
- public Response<TokenDTO> login(@RequestBody LoginBody loginBody)
|
|
|
- { TokenDTO tokenDTO = new TokenDTO();
|
|
|
+ public Response<TokenDTO> login(@RequestBody LoginBody loginBody) {
|
|
|
+ TokenDTO tokenDTO = new TokenDTO();
|
|
|
// 生成令牌
|
|
|
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
|
|
|
loginBody.getUuid());
|
|
|
tokenDTO.setToken(token);
|
|
|
return Response.success(tokenDTO);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 登录方法 (不含验证码)
|
|
|
*
|
|
@@ -111,8 +114,8 @@ public class SysLoginController
|
|
|
*/
|
|
|
@PostMapping("/login/noCode")
|
|
|
@ApiOperation("登录方法(不含验证码)")
|
|
|
- public Response<TokenDTO> loginNoCode(@RequestBody LoginBodyNoCode loginBodyNoCode)
|
|
|
- { TokenDTO tokenDTO = new TokenDTO();
|
|
|
+ public Response<TokenDTO> loginNoCode(@RequestBody LoginBodyNoCode loginBodyNoCode) {
|
|
|
+ TokenDTO tokenDTO = new TokenDTO();
|
|
|
// 生成令牌
|
|
|
String token = loginService.login(loginBodyNoCode.getUsername(), loginBodyNoCode.getPassword());
|
|
|
tokenDTO.setToken(token);
|
|
@@ -121,24 +124,22 @@ public class SysLoginController
|
|
|
|
|
|
/**
|
|
|
* 用户 jscode登录
|
|
|
- *
|
|
|
*/
|
|
|
@PostMapping("/login/jscode")
|
|
|
@ApiOperation("用户jscode登录")
|
|
|
- public Response<TokenDTO> getInfo(String jscode){
|
|
|
- String result = wxService.getWxInfo(appid, secret, jscode,"authorization_code");
|
|
|
+ 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){
|
|
|
+ if (wxResult.getOpenid() != null) {
|
|
|
// 生成令牌
|
|
|
- String token = loginService.login(wxResult.getOpenid(),null, UserLoginTypeEnum.OPENID_LOGIN.getCode());
|
|
|
+ String token = loginService.login(wxResult.getOpenid(), null, UserLoginTypeEnum.OPENID_LOGIN.getCode());
|
|
|
tokenDTO.setToken(token);
|
|
|
- return Response.success(tokenDTO) ;
|
|
|
- }
|
|
|
- else{
|
|
|
- return Response.error(500,wxResult.getErrmsg());
|
|
|
+ return Response.success(tokenDTO);
|
|
|
+ } else {
|
|
|
+ return Response.error(500, wxResult.getErrmsg());
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -146,16 +147,15 @@ public class SysLoginController
|
|
|
|
|
|
/**
|
|
|
* 用户 jscode登录
|
|
|
- *
|
|
|
*/
|
|
|
@PostMapping("/login/jscode-test")
|
|
|
@ApiOperation("用户jscode登录(测试,固定openid)")
|
|
|
- public Response<TokenDTO> getInfoTest(String jscode){
|
|
|
+ public Response<TokenDTO> getInfoTest(String jscode) {
|
|
|
TokenDTO tokenDTO = new TokenDTO();
|
|
|
- // 生成令牌
|
|
|
- String token = loginService.login("oO7PJ5CPQJo62kZWA3uiUX2KG2s4",null, UserLoginTypeEnum.OPENID_LOGIN.getCode());
|
|
|
+ // 生成令牌
|
|
|
+ String token = loginService.login("oO7PJ5CPQJo62kZWA3uiUX2KG2s4", null, UserLoginTypeEnum.OPENID_LOGIN.getCode());
|
|
|
tokenDTO.setToken(token);
|
|
|
- return Response.success(tokenDTO) ;
|
|
|
+ return Response.success(tokenDTO);
|
|
|
|
|
|
|
|
|
}
|
|
@@ -163,21 +163,21 @@ public class SysLoginController
|
|
|
|
|
|
@PostMapping("/login/code")
|
|
|
@ApiOperation("教练管家app微信用户授权码模式登录")
|
|
|
- public Response loginByWxAuthorizationCode(String authorizationCode,String city){
|
|
|
+ public Response loginByWxAuthorizationCode(String authorizationCode, String city) {
|
|
|
String wxResultStr = wxService.getWxToken(coachAppid, coachSecret, authorizationCode, "authorization_code");
|
|
|
- logger.info("微信授权码登录返回值:"+wxResultStr);
|
|
|
- WxResult wxResult = JSONObject.parseObject(wxResultStr,WxResult.class);
|
|
|
+ logger.info("微信授权码登录返回值:" + wxResultStr);
|
|
|
+ WxResult wxResult = JSONObject.parseObject(wxResultStr, WxResult.class);
|
|
|
|
|
|
// 生成令牌
|
|
|
- if (wxResult.getErrcode() != null){
|
|
|
+ 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("openid",wxUserInfo.getOpenid());
|
|
|
+ WxUserInfo wxUserInfo = JSONObject.parseObject(userInfoStr, WxUserInfo.class);
|
|
|
+ ServletUtils.getRequest().setAttribute("headImage", wxUserInfo.getHeadimgurl());
|
|
|
+ ServletUtils.getRequest().setAttribute("nickName", wxUserInfo.getNickname());
|
|
|
+ ServletUtils.getRequest().setAttribute("openid", wxUserInfo.getOpenid());
|
|
|
|
|
|
System.out.println(wxUserInfo.getNickname());
|
|
|
System.out.println(wxUserInfo.getHeadimgurl());
|
|
@@ -189,15 +189,51 @@ public class SysLoginController
|
|
|
|
|
|
TmsCoachInfoVo tmsCoachInfoVo = coachInfoService.getCoachInfoByOpenid(coachInfoOpenidDTO);
|
|
|
|
|
|
- Map<String,Object> resultMap = new HashMap();
|
|
|
- if(tmsCoachInfoVo==null){
|
|
|
- resultMap.put("openid",wxUserInfo.getOpenid());
|
|
|
- resultMap.put("coach",null);
|
|
|
+ Map<String, Object> resultMap = new HashMap();
|
|
|
+ if (tmsCoachInfoVo == null) {
|
|
|
+ resultMap.put("openid", wxUserInfo.getOpenid());
|
|
|
+ resultMap.put("coach", null);
|
|
|
return Response.success(resultMap);
|
|
|
} else {
|
|
|
- resultMap.put("openid",null);
|
|
|
- resultMap.put("coach",tmsCoachInfoVo);
|
|
|
- return Response.success(resultMap) ;
|
|
|
+ resultMap.put("openid", null);
|
|
|
+ resultMap.put("coach", tmsCoachInfoVo);
|
|
|
+ return Response.success(resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/login/code/ios")
|
|
|
+ @ApiOperation("教练管家Ios登录")
|
|
|
+ public Response iosLogin(String identityToken, String userId, String city) throws Exception {
|
|
|
+
|
|
|
+ try {
|
|
|
+ JSONObject appleUser = appleService.getAppleUserInfo(identityToken);
|
|
|
+ String sub = appleUser.getString("sub");
|
|
|
+
|
|
|
+ System.out.println("sub = " + sub);
|
|
|
+ System.out.println("userId = " + userId);
|
|
|
+
|
|
|
+
|
|
|
+ TmsCoachInfoOpenidDTO coachInfoOpenidDTO = new TmsCoachInfoOpenidDTO();
|
|
|
+ coachInfoOpenidDTO.setCity(city);
|
|
|
+ coachInfoOpenidDTO.setOpenid(sub);
|
|
|
+
|
|
|
+ TmsCoachInfoVo tmsCoachInfoVo = coachInfoService.getCoachInfoByOpenid(coachInfoOpenidDTO);
|
|
|
+
|
|
|
+ Map<String, Object> resultMap = new HashMap();
|
|
|
+ if (tmsCoachInfoVo == null) {
|
|
|
+ resultMap.put("openid", sub);
|
|
|
+ resultMap.put("coach", null);
|
|
|
+ return Response.success(resultMap);
|
|
|
+ } else {
|
|
|
+ resultMap.put("openid", null);
|
|
|
+ resultMap.put("coach", tmsCoachInfoVo);
|
|
|
+ return Response.success(resultMap);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("获取苹果用户信息失败");
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -210,13 +246,12 @@ public class SysLoginController
|
|
|
*/
|
|
|
@GetMapping("getInfo")
|
|
|
@ApiOperation("获取用户信息")
|
|
|
- public Response<UserInfoDTO> getInfo()
|
|
|
- {
|
|
|
+ public Response<UserInfoDTO> getInfo() {
|
|
|
SecurityUtils.getLoginUser();
|
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
UserInfoDTO userInfoDTO = new UserInfoDTO();
|
|
|
SysUser user = loginUser.getUser();
|
|
|
- if (user != null){
|
|
|
+ if (user != null) {
|
|
|
userInfoDTO.setUser(user);
|
|
|
// 角色集合
|
|
|
Set<String> roles = permissionService.getRolePermission(user);
|
|
@@ -236,8 +271,7 @@ public class SysLoginController
|
|
|
*/
|
|
|
@GetMapping("getRouters")
|
|
|
@ApiOperation("获取路由信息")
|
|
|
- public Response<List<RouterDTO>> getRouters()
|
|
|
- {
|
|
|
+ public Response<List<RouterDTO>> getRouters() {
|
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
// 用户信息
|
|
|
SysUser user = loginUser.getUser();
|