更新
This commit is contained in:
parent
3dccc64d94
commit
5e66db1455
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.app.company.controller;
|
package cn.iocoder.yudao.module.app.company.controller;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
||||||
import cn.iocoder.yudao.module.company.entity.Company;
|
import cn.iocoder.yudao.module.company.entity.Company;
|
||||||
import cn.iocoder.yudao.module.company.service.CompanyService;
|
import cn.iocoder.yudao.module.company.service.CompanyService;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
@ -0,0 +1,106 @@
|
|||||||
|
package cn.iocoder.yudao.module.jx.controller.app;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||||
|
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
|
import cn.iocoder.yudao.module.jx.domain.DriveSchoolCoach;
|
||||||
|
import cn.iocoder.yudao.module.jx.domain.DriveSchoolInfo;
|
||||||
|
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolCoachMapper;
|
||||||
|
import cn.iocoder.yudao.module.jx.service.IDriveSchoolInfoService;
|
||||||
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||||
|
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
||||||
|
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 认证")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/jx/auth")
|
||||||
|
@Validated
|
||||||
|
@Slf4j
|
||||||
|
public class AppJxAuthController {
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AdminUserService userService;
|
||||||
|
@Resource
|
||||||
|
private PermissionService permissionService;
|
||||||
|
@Resource
|
||||||
|
private DriveSchoolCoachMapper driveSchoolCoachMapper;
|
||||||
|
@Resource
|
||||||
|
private IDriveSchoolInfoService driveSchoolInfoService;
|
||||||
|
@Resource
|
||||||
|
private AdminUserApi userApi;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Jx用户信息
|
||||||
|
*
|
||||||
|
* @return 用户信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/getJxInfo")
|
||||||
|
public CommonResult getJxInfo()
|
||||||
|
{
|
||||||
|
// 获取当前用户信息
|
||||||
|
// Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||||
|
// AdminUserRespDTO sysUser = userApi.getUser(userId);
|
||||||
|
// Long deptId = sysUser.getDeptId();
|
||||||
|
|
||||||
|
LoginUser user = SecurityFrameworkUtils.getLoginUser();
|
||||||
|
// 获取当前登录用户角色编码
|
||||||
|
Set<String> roles = permissionService.getRolePermission(user.getId());
|
||||||
|
//获取驾校的
|
||||||
|
Long userId = user.getId();
|
||||||
|
AdminUserDO sysUser = userService.getUser(userId);
|
||||||
|
Long deptId = sysUser.getDeptId();
|
||||||
|
|
||||||
|
String phonenumber = sysUser.getMobile();
|
||||||
|
//根据手机号查询驾校教练
|
||||||
|
DriveSchoolCoach driveSchoolCoach = driveSchoolCoachMapper.selectByPhonenumber(phonenumber);
|
||||||
|
|
||||||
|
if (ObjectUtils.isNotEmpty(driveSchoolCoach)){
|
||||||
|
sysUser.setAvatar(driveSchoolCoach.getImage());
|
||||||
|
}
|
||||||
|
DriveSchoolInfo driveSchoolInfo = driveSchoolInfoService.getSchoolInfoByDeptId(deptId);
|
||||||
|
|
||||||
|
Map<String,Object> result = new HashMap<>();
|
||||||
|
result.put("user", sysUser);
|
||||||
|
result.put("roles", roles);
|
||||||
|
result.put("schoolInfo", driveSchoolInfo);
|
||||||
|
|
||||||
|
return CommonResult.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取App用户信息
|
||||||
|
*
|
||||||
|
* @return 用户信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/getAppInfo")
|
||||||
|
public CommonResult<?> getAppInfo()
|
||||||
|
{
|
||||||
|
LoginUser user = SecurityFrameworkUtils.getLoginUser();
|
||||||
|
// 获取当前登录用户角色编码
|
||||||
|
Set<String> roles = permissionService.getRolePermission(user.getId());
|
||||||
|
Map<String,Object> result = new HashMap<>();
|
||||||
|
result.put("user", user);
|
||||||
|
result.put("role", roles);
|
||||||
|
return success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -62,13 +62,28 @@ public class LoginController {
|
|||||||
@PostMapping("/wxLogin")
|
@PostMapping("/wxLogin")
|
||||||
@TenantIgnore
|
@TenantIgnore
|
||||||
public CommonResult<?> wxLogin(@RequestBody WxLoginBody wxLoginBody) {
|
public CommonResult<?> wxLogin(@RequestBody WxLoginBody wxLoginBody) {
|
||||||
|
// appId
|
||||||
|
String appId = wxConfig.getRepairAppId();
|
||||||
|
//appSecret
|
||||||
|
String appSecret = wxConfig.getRepairAppSecret();
|
||||||
|
//code
|
||||||
|
String appCode = SystemEnum.REPAIR.getCode();
|
||||||
|
if (StrUtil.isNotEmpty(wxLoginBody.getType())) {
|
||||||
|
switch (wxLoginBody.getType()) {
|
||||||
|
case "jx":
|
||||||
|
appId = wxConfig.getJxAppId();
|
||||||
|
appSecret = wxConfig.getJxAppSecret();
|
||||||
|
appCode = SystemEnum.SCHOOL.getCode();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
String code = wxLoginBody.getCode();
|
String code = wxLoginBody.getCode();
|
||||||
//秘钥
|
//秘钥
|
||||||
String encryptedIv = wxLoginBody.getEncryptedIv();
|
String encryptedIv = wxLoginBody.getEncryptedIv();
|
||||||
//加密数据
|
//加密数据
|
||||||
String encryptedData = wxLoginBody.getEncryptedData();
|
String encryptedData = wxLoginBody.getEncryptedData();
|
||||||
//想微信服务器发送请求获取用户信息
|
//想微信服务器发送请求获取用户信息
|
||||||
String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxConfig.getRepairAppId() + "&secret=" + wxConfig.getRepairAppSecret() + "&js_code=" + code + "&grant_type=authorization_code";
|
String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appId + "&secret=" + appSecret + "&js_code=" + code + "&grant_type=authorization_code";
|
||||||
String res = restTemplate.getForObject(url, String.class);
|
String res = restTemplate.getForObject(url, String.class);
|
||||||
JSONObject jsonObject = JSONObject.parseObject(res);
|
JSONObject jsonObject = JSONObject.parseObject(res);
|
||||||
//获取session_key和openid
|
//获取session_key和openid
|
||||||
@ -86,7 +101,7 @@ public class LoginController {
|
|||||||
if (StringUtils.hasText(decryptResult)) {
|
if (StringUtils.hasText(decryptResult)) {
|
||||||
//如果解析成功,获取token
|
//如果解析成功,获取token
|
||||||
//查用户(未注册的话自动注册)
|
//查用户(未注册的话自动注册)
|
||||||
AdminUserDO adminUserDO = wechatService.wechatLogin(SystemEnum.REPAIR.getCode(),decryptResult,openId,wxLoginBody.getInviteId());
|
AdminUserDO adminUserDO = wechatService.wechatLogin(appCode,decryptResult,openId,wxLoginBody.getInviteId());
|
||||||
//登录生成token
|
//登录生成token
|
||||||
AuthLoginRespVO loginVO = loginService.wxLoginByUserId(adminUserDO.getId(),adminUserDO.getUsername());
|
AuthLoginRespVO loginVO = loginService.wxLoginByUserId(adminUserDO.getId(),adminUserDO.getUsername());
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
@ -19,6 +19,11 @@ public class WxLoginBody {
|
|||||||
*/
|
*/
|
||||||
private String encryptedData;
|
private String encryptedData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小程序类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
//邀请码
|
//邀请码
|
||||||
private String inviteId;
|
private String inviteId;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user