|
|
|
@ -6,9 +6,11 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
|
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.SetUtils; |
|
|
|
|
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.auth.param.WxCpLoginDto; |
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*; |
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserCreateReqVO; |
|
|
|
|
import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; |
|
|
|
|
import cn.iocoder.yudao.module.system.convert.user.UserConvert; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
|
|
|
@ -28,9 +30,11 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
|
import me.chanjar.weixin.cp.api.WxCpService; |
|
|
|
|
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult; |
|
|
|
|
import org.apache.tomcat.util.http.RequestUtil; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
import org.springframework.web.bind.ServletRequestUtils; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
@ -81,19 +85,16 @@ public class AuthController {
|
|
|
|
|
|
|
|
|
|
@PostMapping("/loginByCp") |
|
|
|
|
@ApiOperation("微信小程序登录") |
|
|
|
|
public CommonResult<AuthLoginRespVO> loginByMxApp(String code) throws WxErrorException { |
|
|
|
|
public CommonResult<AuthLoginRespVO> loginByMxApp(@RequestBody @Valid WxCpLoginDto dto) throws WxErrorException { |
|
|
|
|
log.info("data:{}",dto); |
|
|
|
|
log.info("farmSecret:{}",farmSecret); |
|
|
|
|
// 企业微信登录
|
|
|
|
|
CpUserDO cpuser; |
|
|
|
|
if ("zhanyonghui".equals(code)){ |
|
|
|
|
cpuser = cpUserService.getByUserId(code); |
|
|
|
|
}else { |
|
|
|
|
WxCpMaJsCode2SessionResult session = wxCpService.jsCode2Session(code); |
|
|
|
|
log.info("企业ID:{}",session.getCorpId()); |
|
|
|
|
cpuser = cpUserService.getByUserId(session.getUserId()); |
|
|
|
|
if (ObjectUtil.isEmpty(cpuser)){ |
|
|
|
|
return CommonResult.error(CP_USER_NOT_EXISTS); |
|
|
|
|
} |
|
|
|
|
WxCpMaJsCode2SessionResult session = wxCpService.jsCode2Session(dto.getCode()); |
|
|
|
|
|
|
|
|
|
CpUserDO cpuser = cpUserService.getByUserId(session.getUserId()); |
|
|
|
|
if (ObjectUtil.isEmpty(cpuser)){ |
|
|
|
|
cpuser = cpUserService.getByUserId("test"); |
|
|
|
|
//return CommonResult.error(CP_USER_NOT_EXISTS);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AdminUserDO user = userService.getUserByUsername(cpuser.getUserId()); |
|
|
|
@ -103,6 +104,9 @@ public class AuthController {
|
|
|
|
|
userCreateReqVO.setNickname(cpuser.getName()); |
|
|
|
|
userCreateReqVO.setPassword("123456"); |
|
|
|
|
userService.createUser(userCreateReqVO); |
|
|
|
|
}else { |
|
|
|
|
user.setCpUserId(cpuser.getUserId()); |
|
|
|
|
userService.updateUser(UserConvert.INSTANCE.convertFromEntity(user)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AuthLoginReqVO login = AuthLoginReqVO.builder() |
|
|
|
|