This commit is contained in:
dzc committed 2026-04-17 15:52:11 +08:00
1 parent c36a043751
commit e6eb95f057
4 files changed
+91 -50

No files matched your search

@@ -110,6 +110,12 @@ public class AppUser extends Model<AppUser> {
@Schema(description = "第三方登录扩展字段")
private String loginExtJson;
/**
* openId
*/
@Schema(description = "openId")
private String openid;
/**
* 创建人
*/
@@ -164,10 +170,4 @@ public class AppUser extends Model<AppUser> {
@Schema(description = "锁定标记")
private String lockFlag;
/**
* openId
*/
@Schema(description = "openId")
private String openid;
}
@@ -0,0 +1,18 @@
package com.bsd.pjcloud.thirdparty.dto;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class ThirdIsVerifyDeviceTo {
@NotEmpty(message = "用户手机号不能为空")
private String mobile;
/**
* 会校验`mobile`是否属于`userId`
*/
private Long userId;
}
@@ -1,6 +1,8 @@
package com.bsd.pjcloud.thirdparty.controller;
import cn.hutool.core.util.ObjectUtil;
import com.bsd.pjcloud.admin.api.dto.UserInfo;
import com.bsd.pjcloud.admin.api.dto.UserTokenDTO;
import com.bsd.pjcloud.admin.api.entity.SysUser;
import com.bsd.pjcloud.admin.api.entity.UserTrustedDeviceEntity;
@@ -13,10 +15,7 @@ import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.core.util.WebUtils;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.thirdparty.dto.DeviceVerifyDTO;
import com.bsd.pjcloud.thirdparty.dto.SHJNSSODTO;
import com.bsd.pjcloud.thirdparty.dto.UrlTokenDTO;
import com.bsd.pjcloud.thirdparty.dto.ZZDUserDTO;
import com.bsd.pjcloud.thirdparty.dto.*;
import com.bsd.pjcloud.thirdparty.service.SmsService;
import com.bsd.pjcloud.thirdparty.service.ThirdPartyOAuth2Service;
import com.bsd.pjcloud.thirdparty.service.ThirdPartyUserService;
@@ -43,8 +42,8 @@ import java.util.concurrent.TimeUnit;
@RestController
@RequiredArgsConstructor
@RequestMapping("/thirdPartyOAth2" )
@Tag(description = "thirdPartyOAth2" , name = "第三方单点接口" )
@RequestMapping("/thirdPartyOAth2")
@Tag(description = "thirdPartyOAth2", name = "第三方单点接口")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ThirdPartyOAth2Cotroller {
@@ -72,10 +71,10 @@ public class ThirdPartyOAth2Cotroller {
//
// }
@Operation(summary = "诗画token" )
@GetMapping("/sh/sso" )
public R getThirdPartyshsso(@RequestParam("accountId") String accountId,@RequestParam("sessionId") String sessionId) {
return R.ok(thirdPartyOAuth2Service.shjnsso(accountId,sessionId));
@Operation(summary = "诗画token")
@GetMapping("/sh/sso")
public R getThirdPartyshsso(@RequestParam("accountId") String accountId, @RequestParam("sessionId") String sessionId) {
return R.ok(thirdPartyOAuth2Service.shjnsso(accountId, sessionId));
}
@@ -92,7 +91,7 @@ public class ThirdPartyOAth2Cotroller {
@Transactional(rollbackFor = Exception.class)
public R zzdsso(@RequestBody UrlTokenDTO urlTokenDTO) {
String token = urlTokenDTO.getToken();
if (StringUtils.isBlank(token)){
if (StringUtils.isBlank(token)) {
return R.failed("token不能为空");
}
@@ -134,13 +133,13 @@ public class ThirdPartyOAth2Cotroller {
R<Map> r;
//1.根据手机号或者钉钉号先查询是否有这个人
R<List<SysUser>> userByMobileOrEmployeeCode = remoteUserService.getUserByMobileOrEmployeeCode(employeeCode, mobile);
List<SysUser> sysUserList = userByMobileOrEmployeeCode.getData();
if(!CollectionUtils.isEmpty(sysUserList)){
List<SysUser> sysUserList = userByMobileOrEmployeeCode.getData();
if (!CollectionUtils.isEmpty(sysUserList)) {
//登录成功生成token
UserTokenDTO userTokenDTO = new UserTokenDTO();
userTokenDTO.setSysUser(sysUserList.get(0));
r = remoteTokenService.generateToken(userTokenDTO);
}else {
} else {
//2.根据浙政钉的员工钉钉号查询是否有这个人
// List<ThirdPartyUserEntity> thirdPartyUserEntityList = thirdPartyUserService.getUserByEmployeeCode(employeeCode);
// UserDTO userDTO = new UserDTO();
@@ -191,13 +190,12 @@ public class ThirdPartyOAth2Cotroller {
HashMap<String, Object> objectObjectHashMap = new HashMap<>();
Object accessToken = r.getData().get("accessToken");
Object refreshToken = r.getData().get("refreshToken");
objectObjectHashMap.put("refreshToken",refreshToken);
objectObjectHashMap.put("accessToken",accessToken);
objectObjectHashMap.put("refreshToken", refreshToken);
objectObjectHashMap.put("accessToken", accessToken);
return R.ok(objectObjectHashMap);
}
/**
* 诗画sdk获取参数
*
@@ -210,31 +208,31 @@ public class ThirdPartyOAth2Cotroller {
@SysLog("诗画江南单点登录")
@Transactional
@GlobalTransactional
public R shjnsso(@RequestBody @Valid SHJNSSODTO shjnsso,HttpServletRequest httpServletRequest) {
public R shjnsso(@RequestBody @Valid SHJNSSODTO shjnsso, HttpServletRequest httpServletRequest) {
//检查设备指纹
ZZDUserDTO zzdUserDTO = thirdPartyOAuth2Service.shjnsso(shjnsso.getAccountId(), shjnsso.getSessionId());
if (null==zzdUserDTO){
ZZDUserDTO zzdUserDTO = thirdPartyOAuth2Service.shjnsso(shjnsso.getAccountId(), shjnsso.getSessionId());
if (null == zzdUserDTO) {
throw new RuntimeException("");
}
ZZDUserDTO.Ext ext = zzdUserDTO.getExt();
String mobile = zzdUserDTO.getMobile();
R<List<SysUser>> userByMobileOrEmployeeCode = remoteUserService.getUserByMobileOrEmployeeCode(null, mobile);
List<SysUser> sysUserList = userByMobileOrEmployeeCode.getData();
if(!CollectionUtils.isEmpty(sysUserList)){
List<SysUser> sysUserList = userByMobileOrEmployeeCode.getData();
if (!CollectionUtils.isEmpty(sysUserList)) {
SysUser sysUser = sysUserList.get(0);
//判断当前用户设备是否信任
String md5 = DeviceFingerprintUtil.generate(httpServletRequest);
R<UserTrustedDeviceEntity> userTrustedDeviceR = remoteUserTrustedDeviceService.getUserTrustedDeviceByIdAndMD5(sysUser.getPhone(), md5);
UserTrustedDeviceEntity userTrustedDevice = userTrustedDeviceR.getData();
if (userTrustedDevice == null || userTrustedDevice.getExpireTime().isBefore(LocalDateTime.now())){
return R.failed(-1,"请先信任设备");
if (userTrustedDevice == null || userTrustedDevice.getExpireTime().isBefore(LocalDateTime.now())) {
return R.failed(-1, "请先信任设备");
}
//登录成功生成token
UserTokenDTO userTokenDTO = new UserTokenDTO();
userTokenDTO.setSysUser(sysUser);
return remoteTokenService.generateToken(userTokenDTO);
}else {
} else {
//自动注册
// UserDTO userDTO = new UserDTO();
//// userDTO.setDeptId(1865990541445263361L);
@@ -256,6 +254,7 @@ public class ThirdPartyOAth2Cotroller {
}
}
@Inner(value = false)
@GetMapping("/getAuthToken/{token}")
public R info(@PathVariable(name = "token") String token) {
@@ -281,7 +280,7 @@ public class ThirdPartyOAth2Cotroller {
@PostMapping("/verify-device")
@SysLog("设备验证")
@Inner(value = false)
public R verifyDevice(@RequestBody DeviceVerifyDTO dto,HttpServletRequest httpServletRequest) {
public R verifyDevice(@RequestBody DeviceVerifyDTO dto, HttpServletRequest httpServletRequest) {
// 1. 校验验证码
String redisKey = "smsCode_" + dto.getMobilePhone();
String storedCode = (String) redisTemplate.opsForValue().get(redisKey);
@@ -289,18 +288,18 @@ public class ThirdPartyOAth2Cotroller {
return R.failed("验证码错误");
}
// 验证成功后移除验证码(可选)
redisTemplate.delete(redisKey);
// 验证成功后移除验证码(可选)
redisTemplate.delete(redisKey);
// 2. 记录信任设备
//查询之前的是否有过期的数据,有就更新
String generate = DeviceFingerprintUtil.generate(httpServletRequest);
R<UserTrustedDeviceEntity> userTrustedDeviceR = remoteUserTrustedDeviceService.getUserTrustedDeviceByIdAndMD5(dto.getMobilePhone(), generate);
if (userTrustedDeviceR.getData() != null){
if (userTrustedDeviceR.getData() != null) {
userTrustedDeviceR.getData().setExpireTime(LocalDateTime.now().plusMonths(3));
remoteUserTrustedDeviceService.updateById(userTrustedDeviceR.getData());
}else {
} else {
UserTrustedDeviceEntity userTrustedDevice = new UserTrustedDeviceEntity();
userTrustedDevice.setMobilePhone(dto.getMobilePhone());
userTrustedDevice.setExpireTime(LocalDateTime.now().plusMonths(3));
@@ -311,31 +310,50 @@ public class ThirdPartyOAth2Cotroller {
return R.ok();
}
@PostMapping("/is-verify-device")
@SysLog("判断该设备是否被验证")
@Inner(value = false)
public R<Boolean> isVerifyDevice(@RequestBody ThirdIsVerifyDeviceTo body, HttpServletRequest httpServletRequest) {
if (ObjectUtil.isNotEmpty(body.getUserId())) {
UserInfo userInfo = remoteUserService.getInnerByUserId(body.getUserId()).getData();
if (ObjectUtil.isEmpty(userInfo)) {
throw new RuntimeException("用户不存在");
}
if (ObjectUtil.notEqual(userInfo.getSysUser().getPhone(), body.getMobile())) {
throw new RuntimeException("手机号和登录的账号不一致");
}
}
String generate = DeviceFingerprintUtil.generate(httpServletRequest);
UserTrustedDeviceEntity userTrustedDevice = remoteUserTrustedDeviceService.getUserTrustedDeviceByIdAndMD5(body.getMobile(), generate).getData();
return R.ok(ObjectUtil.isNotEmpty(userTrustedDevice));
}
/**
* 诗画浦江端
*
* @param mobilePhone
* @param httpServletRequest
* @param type 短信区分标识 if null 诗画登录短信 1 访客登录短信
* @param type 短信区分标识 if null 诗画登录短信 1 访客登录短信
* @return
*/
@PostMapping("/loginSms")
@Operation(summary = "发送登录短信")
@SysLog("发送登录短信")
@Inner(value = false)
public R loginSms(@RequestParam String mobilePhone,HttpServletRequest httpServletRequest,
@RequestParam(value = "type",required = false)Integer type) {
Map<String, String> stringHashMap = new LinkedHashMap<>();
public R loginSms(@RequestParam String mobilePhone, HttpServletRequest httpServletRequest,
@RequestParam(value = "type", required = false) Integer type) {
Map<String, String> stringHashMap = new LinkedHashMap<>();
String s = SmsCodeUtil.generateNumberCode(6);
stringHashMap.put("code",s);
stringHashMap.put("date","5");
smsService.sendSms(mobilePhone, "20657",stringHashMap, WebUtils.getIP());
stringHashMap.put("code", s);
stringHashMap.put("date", "5");
smsService.sendSms(mobilePhone, "20657", stringHashMap, WebUtils.getIP());
// null 适配之前诗画的,=1访客,先else
if (null==type){
redisTemplate.opsForValue().set(CacheConstants.SMS_CODE_KEY +mobilePhone,s, 5, TimeUnit.MINUTES);
}else {
stringRedisTemplate.opsForValue().set(CacheConstants.SMS_VISITOR_CODE_KEY +mobilePhone,s, 5, TimeUnit.MINUTES);
if (null == type) {
redisTemplate.opsForValue().set(CacheConstants.SMS_CODE_KEY + mobilePhone, s, 5, TimeUnit.MINUTES);
} else {
stringRedisTemplate.opsForValue().set(CacheConstants.SMS_VISITOR_CODE_KEY + mobilePhone, s, 5, TimeUnit.MINUTES);
}
// redisTemplate.opsForValue().set(CacheConstants.SMS_CODE_KEY +mobilePhone,s, 5, TimeUnit.MINUTES);
@@ -343,7 +361,4 @@ public class ThirdPartyOAth2Cotroller {
}
}
@@ -204,6 +204,14 @@ public class WalletManageController {
PjcloudUser user = SecurityUtils.getUser();
return R.ok(walletManageService.isUseDoor(user.getId()));
}
@GetMapping("/app/topup-wallet")
@Operation(summary = "创建充值钱包")
public R<String> createTopupWallet() {
PjcloudUser user = SecurityUtils.getUser();
walletManageService.createWallet(user.getId());
return R.ok();
}
/* ************************************* end app end ************************************* */
@Operation(summary = "分页查询", description = "分页查询")