mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-16 20:15:06 +08:00
初步完成微信公众号登录
This commit is contained in:
@ -0,0 +1,82 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 社交用户
|
||||
* 通过 {@link SysSocialUserDO#getUserId()} 关联到对应的 {@link SysUserDO}
|
||||
*
|
||||
* @author weir
|
||||
*/
|
||||
@TableName(value = "sys_social_user", autoResultMap = true)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SysSocialUserDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 关联的用户编号
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户类型
|
||||
*
|
||||
* 枚举 {@link UserTypeEnum}
|
||||
*/
|
||||
private Integer userType;
|
||||
|
||||
/**
|
||||
* 社交平台的类型
|
||||
*
|
||||
* 枚举 {@link UserTypeEnum}
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 社交 openid
|
||||
*/
|
||||
private String openid;
|
||||
/**
|
||||
* 社交 token
|
||||
*/
|
||||
private String token;
|
||||
/**
|
||||
* 社交的全局编号
|
||||
*
|
||||
* 例如说,微信平台的 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/union-id.html
|
||||
* 如果没有 unionId 的平台,直接使用 openid 作为该字段的值
|
||||
*/
|
||||
private String unionId;
|
||||
/**
|
||||
* 原始 Token 数据,一般是 JSON 格式
|
||||
*/
|
||||
private String rawTokenInfo;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickname;
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
private String avatar;
|
||||
/**
|
||||
* 原始用户数据,一般是 JSON 格式
|
||||
*/
|
||||
private String rawUserInfo;
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.social;
|
||||
|
||||
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysSocialUserMapper extends BaseMapperX<SysSocialUserDO> {
|
||||
|
||||
default List<SysSocialUserDO> selectListByTypeAndUnionId(Integer userType, Collection<Integer> types, String unionId) {
|
||||
return selectList(new QueryWrapper<SysSocialUserDO>().eq("user_type", userType)
|
||||
.in("type", types).eq("union_id", unionId));
|
||||
}
|
||||
|
||||
default List<SysSocialUserDO> selectListByTypeAndUserId(Integer userType, Collection<Integer> types, Long userId) {
|
||||
return selectList(new QueryWrapper<SysSocialUserDO>().eq("user_type", userType)
|
||||
.in("type", types).eq("user_id", userId));
|
||||
}
|
||||
|
||||
default List<SysSocialUserDO> selectListByUserId(Integer userType, Long userId) {
|
||||
return selectList(new QueryWrapper<SysSocialUserDO>().eq("user_type", userType).eq("user_id", userId));
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,9 @@ package cn.iocoder.yudao.coreservice.modules.system.dal.redis;
|
||||
|
||||
import cn.iocoder.yudao.framework.redis.core.RedisKeyDefine;
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static cn.iocoder.yudao.framework.redis.core.RedisKeyDefine.KeyTypeEnum.STRING;
|
||||
|
||||
@ -16,4 +19,11 @@ public interface SysRedisKeyCoreConstants {
|
||||
"login_user:%s", // 参数为 sessionId
|
||||
STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC);
|
||||
|
||||
RedisKeyDefine SOCIAL_AUTH_USER = new RedisKeyDefine("社交的授权用户",
|
||||
"social_auth_user:%d:%s", // 参数为 type,code
|
||||
STRING, AuthUser.class, Duration.ofDays(1));
|
||||
|
||||
RedisKeyDefine SOCIAL_AUTH_STATE = new RedisKeyDefine("社交的 state",
|
||||
"social_auth_state:%s", // 参数为 state
|
||||
STRING, String.class, Duration.ofHours(24)); // 值为 state
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.system.dal.redis.social;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.coreservice.modules.system.dal.redis.SysRedisKeyCoreConstants.SOCIAL_AUTH_USER;
|
||||
|
||||
|
||||
/**
|
||||
* 社交 {@link AuthUser} 的 RedisDAO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Repository
|
||||
public class SysSocialAuthUserRedisDAO {
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
public AuthUser get(Integer type, AuthCallback authCallback) {
|
||||
String redisKey = formatKey(type, authCallback.getCode());
|
||||
return JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(redisKey), AuthUser.class);
|
||||
}
|
||||
|
||||
public void set(Integer type, AuthCallback authCallback, AuthUser authUser) {
|
||||
String redisKey = formatKey(type, authCallback.getCode());
|
||||
stringRedisTemplate.opsForValue().set(redisKey, JsonUtils.toJsonString(authUser), SOCIAL_AUTH_USER.getTimeout());
|
||||
}
|
||||
|
||||
private static String formatKey(Integer type, String code) {
|
||||
return String.format(SOCIAL_AUTH_USER.getKeyTemplate(), type, code);
|
||||
}
|
||||
|
||||
}
|
@ -14,4 +14,9 @@ public interface SysErrorCodeConstants {
|
||||
ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1006000001, "模板参数({})缺失");
|
||||
ErrorCode SMS_SEND_TEMPLATE_NOT_EXISTS = new ErrorCode(1006000000, "短信模板不存在");
|
||||
|
||||
|
||||
// ========== 社交模块 1006001000 ==========
|
||||
ErrorCode SOCIAL_AUTH_FAILURE = new ErrorCode(1006001000, "社交授权失败,原因是:{}");
|
||||
ErrorCode SOCIAL_UNBIND_NOT_SELF = new ErrorCode(1006001001, "社交解绑失败,非当前用户绑定");
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,63 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.system.enums.social;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 社交平台的类型枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum SysSocialTypeEnum implements IntArrayValuable {
|
||||
|
||||
GITEE(10, "GITEE"), // https://gitee.com/api/v5/oauth_doc#/
|
||||
DINGTALK(20, "DINGTALK"), // https://developers.dingtalk.com/document/app/obtain-identity-credentials
|
||||
WECHAT_ENTERPRISE(30, "WECHAT_ENTERPRISE"), // https://xkcoding.com/2019/08/06/use-justauth-integration-wechat-enterprise.html
|
||||
/**
|
||||
* 微信公众平台 - H5
|
||||
*/
|
||||
WECHAT_MP(12, "WECHAT_MP"), // https://www.cnblogs.com/juewuzhe/p/11905461.html
|
||||
/**
|
||||
* 微信开放平台 - 小程序
|
||||
*/
|
||||
WECHAT_OPEN(11, "WECHAT_OPEN"), // https://justauth.wiki/guide/oauth/wechat_open/#_2-%E7%94%B3%E8%AF%B7%E5%BC%80%E5%8F%91%E8%80%85%E8%B5%84%E8%B4%A8%E8%AE%A4%E8%AF%81
|
||||
;
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SysSocialTypeEnum::getType).toArray();
|
||||
|
||||
public static final List<Integer> WECHAT_ALL = ListUtil.toList(WECHAT_ENTERPRISE.type, WECHAT_MP.type, WECHAT_OPEN.type);
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final Integer type;
|
||||
/**
|
||||
* 类型的标识
|
||||
*/
|
||||
private final String source;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
public static SysSocialTypeEnum valueOfType(Integer type) {
|
||||
return ArrayUtil.firstMatch(o -> o.getType().equals(type), values());
|
||||
}
|
||||
|
||||
public static List<Integer> getRelationTypes(Integer type) {
|
||||
if (WECHAT_ALL.contains(type)) {
|
||||
return WECHAT_ALL;
|
||||
}
|
||||
return ListUtil.toList(type);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.system.service.social;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.enums.social.SysSocialTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 社交 Service 接口,例如说社交平台的授权登录
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface SysSocialService {
|
||||
|
||||
/**
|
||||
* 获得社交平台的授权 URL
|
||||
*
|
||||
* @param type 社交平台的类型 {@link SysSocialTypeEnum}
|
||||
* @param redirectUri 重定向 URL
|
||||
* @return 社交平台的授权 URL
|
||||
*/
|
||||
String getAuthorizeUrl(Integer type, String redirectUri);
|
||||
|
||||
/**
|
||||
* 获得授权的用户
|
||||
* 如果授权失败,则会抛出 {@link ServiceException} 异常
|
||||
*
|
||||
* @param type 社交平台的类型 {@link SysSocialTypeEnum}
|
||||
* @param code 授权码
|
||||
* @param state state
|
||||
* @return 授权用户
|
||||
*/
|
||||
@NotNull
|
||||
AuthUser getAuthUser(Integer type, String code, String state);
|
||||
|
||||
default String getAuthUserUnionId(AuthUser authUser) {
|
||||
return StrUtil.blankToDefault(authUser.getToken().getUnionId(), authUser.getUuid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 unionId 对应的某个社交平台的“所有”社交用户
|
||||
* 注意,这里的“所有”,指的是类似【微信】平台,包括了小程序、公众号、PC 网站,他们的 unionId 是一致的
|
||||
*
|
||||
* @param type 社交平台的类型 {@link SysSocialTypeEnum}
|
||||
* @param unionId 社交平台的 unionId
|
||||
* @return 社交用户列表
|
||||
*/
|
||||
List<SysSocialUserDO> getAllSocialUserList(Integer type, String unionId, UserTypeEnum userTypeEnum);
|
||||
|
||||
/**
|
||||
* 获得指定用户的社交用户列表
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @return 社交用户列表
|
||||
*/
|
||||
List<SysSocialUserDO> getSocialUserList(Long userId,UserTypeEnum userTypeEnum);
|
||||
|
||||
/**
|
||||
* 绑定社交用户
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param type 社交平台的类型 {@link SysSocialTypeEnum}
|
||||
* @param authUser 授权用户
|
||||
*/
|
||||
void bindSocialUser(Long userId, Integer type, AuthUser authUser, UserTypeEnum userTypeEnum);
|
||||
|
||||
/**
|
||||
* 取消绑定社交用户
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param type 社交平台的类型 {@link SysSocialTypeEnum}
|
||||
* @param unionId 社交平台的 unionId
|
||||
*/
|
||||
void unbindSocialUser(Long userId, Integer type, String unionId,UserTypeEnum userTypeEnum);
|
||||
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
package cn.iocoder.yudao.coreservice.modules.system.service.social.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.social.SysSocialUserMapper;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.dal.redis.social.SysSocialAuthUserRedisDAO;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.enums.social.SysSocialTypeEnum;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.xkcoding.justauth.AuthRequestFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.model.AuthCallback;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.request.AuthRequest;
|
||||
import me.zhyd.oauth.utils.AuthStateUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.SOCIAL_AUTH_FAILURE;
|
||||
import static cn.iocoder.yudao.coreservice.modules.system.enums.SysErrorCodeConstants.SOCIAL_UNBIND_NOT_SELF;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
|
||||
|
||||
/**
|
||||
* 社交 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Valid
|
||||
@Slf4j
|
||||
public class SysSocialServiceImpl implements SysSocialService {
|
||||
|
||||
@Resource
|
||||
private AuthRequestFactory authRequestFactory;
|
||||
|
||||
@Resource
|
||||
private SysSocialAuthUserRedisDAO authSocialUserRedisDAO;
|
||||
|
||||
@Resource
|
||||
private SysSocialUserMapper socialUserMapper;
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(Integer type, String redirectUri) {
|
||||
// 获得对应的 AuthRequest 实现
|
||||
AuthRequest authRequest = authRequestFactory.get(SysSocialTypeEnum.valueOfType(type).getSource());
|
||||
// 生成跳转地址
|
||||
String authorizeUri = authRequest.authorize(AuthStateUtils.createState());
|
||||
return HttpUtils.replaceUrlQuery(authorizeUri, "redirect_uri", redirectUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthUser getAuthUser(Integer type, String code, String state) {
|
||||
AuthCallback authCallback = buildAuthCallback(code, state);
|
||||
// 从缓存中获取
|
||||
AuthUser authUser = authSocialUserRedisDAO.get(type, authCallback);
|
||||
if (authUser != null) {
|
||||
return authUser;
|
||||
}
|
||||
|
||||
// 请求获取
|
||||
authUser = this.getAuthUser0(type, authCallback);
|
||||
// 缓存。原因是 code 有且可以使用一次。在社交登录时,当未绑定 User 时,需要绑定登录,此时需要 code 使用两次
|
||||
authSocialUserRedisDAO.set(type, authCallback, authUser);
|
||||
return authUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysSocialUserDO> getAllSocialUserList(Integer type, String unionId,UserTypeEnum userTypeEnum) {
|
||||
List<Integer> types = SysSocialTypeEnum.getRelationTypes(type);
|
||||
return socialUserMapper.selectListByTypeAndUnionId(userTypeEnum.getValue(), types, unionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysSocialUserDO> getSocialUserList(Long userId,UserTypeEnum userTypeEnum) {
|
||||
return socialUserMapper.selectListByUserId(userTypeEnum.getValue(), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void bindSocialUser(Long userId, Integer type, AuthUser authUser,UserTypeEnum userTypeEnum) {
|
||||
// 获得 unionId 对应的 SysSocialUserDO 列表
|
||||
String unionId = getAuthUserUnionId(authUser);
|
||||
List<SysSocialUserDO> socialUsers = this.getAllSocialUserList(type, unionId, userTypeEnum);
|
||||
|
||||
// 逻辑一:如果 userId 之前绑定过该 type 的其它账号,需要进行解绑
|
||||
this.unbindOldSocialUser(userId, type, unionId, userTypeEnum);
|
||||
|
||||
// 逻辑二:如果 socialUsers 指定的 userId 改变,需要进行更新
|
||||
// 例如说,一个微信 unionId 对应了多个社交账号,结果其中有个关联了新的 userId,则其它也要跟着修改
|
||||
// 考虑到 socialUsers 一般比较少,直接 for 循环更新即可
|
||||
socialUsers.forEach(socialUser -> {
|
||||
if (Objects.equals(socialUser.getUserId(), userId)) {
|
||||
return;
|
||||
}
|
||||
socialUserMapper.updateById(new SysSocialUserDO().setId(socialUser.getId()).setUserId(userId));
|
||||
});
|
||||
|
||||
// 逻辑三:如果 authUser 不存在于 socialUsers 中,则进行新增;否则,进行更新
|
||||
SysSocialUserDO socialUser = CollUtil.findOneByField(socialUsers, "openid", authUser.getUuid());
|
||||
SysSocialUserDO saveSocialUser = SysSocialUserDO.builder() // 新增和更新的通用属性
|
||||
.token(authUser.getToken().getAccessToken()).rawTokenInfo(toJsonString(authUser.getToken()))
|
||||
.nickname(authUser.getNickname()).avatar(authUser.getAvatar()).rawUserInfo(toJsonString(authUser.getRawUserInfo()))
|
||||
.build();
|
||||
if (socialUser == null) {
|
||||
saveSocialUser.setUserId(userId).setUserType(userTypeEnum.getValue())
|
||||
.setType(type).setOpenid(authUser.getUuid()).setUnionId(unionId);
|
||||
socialUserMapper.insert(saveSocialUser);
|
||||
} else {
|
||||
saveSocialUser.setId(socialUser.getId());
|
||||
socialUserMapper.updateById(saveSocialUser);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbindSocialUser(Long userId, Integer type, String unionId, UserTypeEnum userTypeEnum) {
|
||||
// 获得 unionId 对应的所有 SysSocialUserDO 社交用户
|
||||
List<SysSocialUserDO> socialUsers = this.getAllSocialUserList(type, unionId, userTypeEnum);
|
||||
if (CollUtil.isEmpty(socialUsers)) {
|
||||
return;
|
||||
}
|
||||
// 校验,是否解绑的是非自己的
|
||||
socialUsers.forEach(socialUser -> {
|
||||
if (!Objects.equals(socialUser.getUserId(), userId)) {
|
||||
throw exception(SOCIAL_UNBIND_NOT_SELF);
|
||||
}
|
||||
});
|
||||
|
||||
// 解绑
|
||||
socialUserMapper.deleteBatchIds(CollectionUtils.convertSet(socialUsers, SysSocialUserDO::getId));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void unbindOldSocialUser(Long userId, Integer type, String newUnionId, UserTypeEnum userTypeEnum) {
|
||||
List<Integer> types = SysSocialTypeEnum.getRelationTypes(type);
|
||||
List<SysSocialUserDO> oldSocialUsers = socialUserMapper.selectListByTypeAndUserId(
|
||||
userTypeEnum.getValue(), types, userId);
|
||||
// 如果新老的 unionId 是一致的,说明无需解绑
|
||||
if (CollUtil.isEmpty(oldSocialUsers) || Objects.equals(newUnionId, oldSocialUsers.get(0).getUnionId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 解绑
|
||||
socialUserMapper.deleteBatchIds(CollectionUtils.convertSet(oldSocialUsers, SysSocialUserDO::getId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求社交平台,获得授权的用户
|
||||
*
|
||||
* @param type 社交平台的类型
|
||||
* @param authCallback 授权回调
|
||||
* @return 授权的用户
|
||||
*/
|
||||
private AuthUser getAuthUser0(Integer type, AuthCallback authCallback) {
|
||||
AuthRequest authRequest = authRequestFactory.get(SysSocialTypeEnum.valueOfType(type).getSource());
|
||||
AuthResponse<?> authResponse = authRequest.login(authCallback);
|
||||
log.info("[getAuthUser0][请求社交平台 type({}) request({}) response({})]", type, toJsonString(authCallback),
|
||||
toJsonString(authResponse));
|
||||
if (!authResponse.ok()) {
|
||||
throw exception(SOCIAL_AUTH_FAILURE, authResponse.getMsg());
|
||||
}
|
||||
return (AuthUser) authResponse.getData();
|
||||
}
|
||||
|
||||
private static AuthCallback buildAuthCallback(String code, String state) {
|
||||
return AuthCallback.builder().code(code).state(state).build();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user