|
@@ -2,15 +2,17 @@ package com.miaxis.system.controller.system;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
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.WxResult;
|
|
|
import com.miaxis.common.enums.UserLoginTypeEnum;
|
|
|
+import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
import com.miaxis.common.utils.ServletUtils;
|
|
|
-import com.miaxis.feign.dto.WxResult;
|
|
|
import com.miaxis.feign.service.IWxService;
|
|
|
import com.miaxis.framework.web.service.SysLoginService;
|
|
|
import com.miaxis.framework.web.service.SysPermissionService;
|
|
@@ -19,8 +21,13 @@ 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.tms.dto.TmsCoachInfoOpenidDTO;
|
|
|
+import com.miaxis.tms.service.ITmsCoachInfoService;
|
|
|
+import com.miaxis.tms.vo.TmsCoachInfoVo;
|
|
|
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;
|
|
@@ -55,6 +62,14 @@ public class SysLoginController
|
|
|
@Autowired
|
|
|
private IWxService wxService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ITmsCoachInfoService coachInfoService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(SysLoginController.class);
|
|
|
+
|
|
|
|
|
|
@Value("${app.appid}")
|
|
|
private String appid;
|
|
@@ -62,6 +77,14 @@ public class SysLoginController
|
|
|
@Value("${app.secret}")
|
|
|
private String secret;
|
|
|
|
|
|
+
|
|
|
+ @Value("${coachApp.appid}")
|
|
|
+ private String coachAppid;
|
|
|
+
|
|
|
+ @Value("${coachApp.secret}")
|
|
|
+ private String coachSecret;
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 登录方法 (含验证码)
|
|
|
*
|
|
@@ -136,6 +159,39 @@ public class SysLoginController
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @PostMapping("/login/code")
|
|
|
+ @ApiOperation("教练管家app微信用户授权码模式登录")
|
|
|
+ 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);
|
|
|
+
|
|
|
+ // 生成令牌
|
|
|
+ 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());
|
|
|
+
|
|
|
+ System.out.println(wxUserInfo.getNickname());
|
|
|
+ System.out.println(wxUserInfo.getHeadimgurl());
|
|
|
+ System.out.println(wxUserInfo.getOpenid());
|
|
|
+
|
|
|
+ TmsCoachInfoOpenidDTO coachInfoOpenidDTO = new TmsCoachInfoOpenidDTO();
|
|
|
+ coachInfoOpenidDTO.setCity(city);
|
|
|
+ coachInfoOpenidDTO.setOpenid(wxUserInfo.getOpenid());
|
|
|
+
|
|
|
+
|
|
|
+ TmsCoachInfoVo tmsCoachInfoVo = coachInfoService.getCoachInfoByOpenid(coachInfoOpenidDTO);
|
|
|
+ return Response.success(tmsCoachInfoVo) ;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取用户信息
|
|
|
*
|