✨ Introducing new features. 支持钉钉和企微登录实现

This commit is contained in:
lbw committed 2023-12-03 23:44:09 +08:00
1 parent 3fbc34e7d2
commit a6457abe8e
4 files changed
+185

No files matched your search

+2
View File
@@ -1146,6 +1146,8 @@ CREATE TABLE `sys_user` (
`qq_openid` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'QQ openId',
`gitee_login` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '码云标识',
`osc_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '开源中国标识',
`wx_cp_userid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '企业微信唯一ID',
`wx_ding_userid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '钉钉唯一ID',
`tenant_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '所属租户ID',
PRIMARY KEY (`user_id`) USING BTREE,
KEY `user_wx_openid` (`wx_openid`) USING BTREE,
@@ -167,6 +167,18 @@ public class SysUser implements Serializable {
@Schema(description = "开源中国唯一标识")
private String oscId;
/**
* 企微微信 userid
*/
@Schema(description = "企微微信 userid")
private String wxCpUserid;
/**
* 钉钉 userid
*/
@Schema(description = "钉钉 userid")
private String wxDingUserid;
/**
* 昵称
*/
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.admin.handler;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
import com.pig4cloud.pigx.admin.api.entity.SysUser;
import com.pig4cloud.pigx.admin.mapper.SysSocialDetailsMapper;
import com.pig4cloud.pigx.admin.service.SysUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author lengleng
* @date 2023-10-14
*
* 钉钉登录
*/
@Slf4j
@Component("DINGTALK")
@AllArgsConstructor
public class DingTalkLoginHandler extends AbstractLoginHandler {
private final SysUserService sysUserService;
private final SysSocialDetailsMapper sysSocialDetailsMapper;
/**
* QQ登录传入code
* <p>
* 通过code 调用qq 获取唯一标识
* @param code
* @return
*/
@Override
public String identify(String code) {
// 企微唯一标识
return "LengLeng";
}
/**
* openId 获取用户信息
* @param openId
* @return
*/
@Override
public UserInfo info(String openId) {
SysUser user = sysUserService.getOne(Wrappers.<SysUser>query().lambda().eq(SysUser::getWxCpUserid, openId));
if (user == null) {
log.info("钉钉未绑定:{}", openId);
return null;
}
return sysUserService.findUserInfo(user);
}
/**
* 绑定逻辑
* @param user 用户实体
* @param identify 渠道返回唯一标识
* @return
*/
@Override
public Boolean bind(SysUser user, String identify) {
user.setWxCpUserid(identify);
sysUserService.updateById(user);
return true;
}
}
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.admin.handler;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
import com.pig4cloud.pigx.admin.api.entity.SysUser;
import com.pig4cloud.pigx.admin.mapper.SysSocialDetailsMapper;
import com.pig4cloud.pigx.admin.service.SysUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author lengleng
* @date 2023-10-14
*
* 企业微信登录
*/
@Slf4j
@Component("CP")
@AllArgsConstructor
public class WeChatCPLoginHandler extends AbstractLoginHandler {
private final SysUserService sysUserService;
private final SysSocialDetailsMapper sysSocialDetailsMapper;
/**
* QQ登录传入code
* <p>
* 通过code 调用qq 获取唯一标识
* @param code
* @return
*/
@Override
public String identify(String code) {
return "LengLeng";
}
/**
* openId 获取用户信息
* @param openId
* @return
*/
@Override
public UserInfo info(String openId) {
SysUser user = sysUserService.getOne(Wrappers.<SysUser>query().lambda().eq(SysUser::getWxCpUserid, openId));
if (user == null) {
log.info("企业微信未绑定:{}", openId);
return null;
}
return sysUserService.findUserInfo(user);
}
/**
* 绑定逻辑
* @param user 用户实体
* @param identify 渠道返回唯一标识
* @return
*/
@Override
public Boolean bind(SysUser user, String identify) {
user.setWxCpUserid(identify);
sysUserService.updateById(user);
return true;
}
}