三方登录:支持 saas 多租户配置
This commit is contained in:
@@ -116,10 +116,11 @@ public interface ErrorCodeConstants {
|
||||
|
||||
// ========== 社交用户 1-002-018-000 ==========
|
||||
ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1_002_018_000, "社交授权失败,原因是:{}");
|
||||
ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1_002_018_001, "社交解绑失败,非当前用户绑定");
|
||||
ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_002, "社交授权失败,找不到对应的用户");
|
||||
ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_001, "社交授权失败,找不到对应的用户");
|
||||
|
||||
ErrorCode SOCIAL_APP_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_103, "获得手机号失败");
|
||||
ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败");
|
||||
ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_201, "社交客户端不存在");
|
||||
ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_201, "社交客户端已存在配置");
|
||||
|
||||
// ========== 系统敏感词 1-002-019-000 =========
|
||||
ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1_002_019_000, "系统敏感词在所有标签中都不存在");
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.socail;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.social.SocialClientConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 社交客户端")
|
||||
@RestController
|
||||
@RequestMapping("/system/social-client")
|
||||
@Validated
|
||||
public class SocialClientController {
|
||||
|
||||
@Resource
|
||||
private SocialClientService socialClientService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建社交客户端")
|
||||
@PreAuthorize("@ss.hasPermission('system:social-client:create')")
|
||||
public CommonResult<Long> createSocialClient(@Valid @RequestBody SocialClientCreateReqVO createReqVO) {
|
||||
return success(socialClientService.createSocialClient(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新社交客户端")
|
||||
@PreAuthorize("@ss.hasPermission('system:social-client:update')")
|
||||
public CommonResult<Boolean> updateSocialClient(@Valid @RequestBody SocialClientUpdateReqVO updateReqVO) {
|
||||
socialClientService.updateSocialClient(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除社交客户端")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('system:social-client:delete')")
|
||||
public CommonResult<Boolean> deleteSocialClient(@RequestParam("id") Long id) {
|
||||
socialClientService.deleteSocialClient(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得社交客户端")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:social-client:query')")
|
||||
public CommonResult<SocialClientRespVO> getSocialClient(@RequestParam("id") Long id) {
|
||||
SocialClientDO socialClient = socialClientService.getSocialClient(id);
|
||||
return success(SocialClientConvert.INSTANCE.convert(socialClient));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得社交客户端分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:social-client:query')")
|
||||
public CommonResult<PageResult<SocialClientRespVO>> getSocialClientPage(@Valid SocialClientPageReqVO pageVO) {
|
||||
PageResult<SocialClientDO> pageResult = socialClientService.getSocialClientPage(pageVO);
|
||||
return success(SocialClientConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,18 +2,25 @@ package cn.iocoder.yudao.module.system.controller.admin.socail;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserRespVO;
|
||||
import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Tag(name = "管理后台 - 社交用户")
|
||||
@@ -39,4 +46,23 @@ public class SocialUserController {
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
// ==================== 社交用户 CRUD ====================
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得社交用户")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:social-user:query')")
|
||||
public CommonResult<SocialUserRespVO> getSocialUser(@RequestParam("id") Long id) {
|
||||
SocialUserDO socialUser = socialUserService.getSocialUser(id);
|
||||
return success(SocialUserConvert.INSTANCE.convert(socialUser));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得社交用户分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:social-user:query')")
|
||||
public CommonResult<PageResult<SocialUserRespVO>> getSocialUserPage(@Valid SocialUserPageReqVO pageVO) {
|
||||
PageResult<SocialUserDO> pageResult = socialUserService.getSocialUserPage(pageVO);
|
||||
return success(SocialUserConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.socail.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.AssertTrue;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 社交客户端 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class SocialClientBaseVO {
|
||||
|
||||
@Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao商城")
|
||||
@NotNull(message = "应用名不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "31")
|
||||
@NotNull(message = "社交平台的类型不能为空")
|
||||
@InEnum(SocialTypeEnum.class)
|
||||
private Integer socialType;
|
||||
|
||||
@Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "用户类型不能为空")
|
||||
@InEnum(UserTypeEnum.class)
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "wwd411c69a39ad2e54")
|
||||
@NotNull(message = "客户端编号不能为空")
|
||||
private String clientId;
|
||||
|
||||
@Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw")
|
||||
@NotNull(message = "客户端密钥不能为空")
|
||||
private String clientSecret;
|
||||
|
||||
@Schema(description = "授权方的网页应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000045")
|
||||
private String agentId;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(CommonStatusEnum.class)
|
||||
private Integer status;
|
||||
|
||||
@SuppressWarnings("RedundantIfStatement")
|
||||
@AssertTrue(message = "agentId 不能为空")
|
||||
@JsonIgnore
|
||||
public boolean isAgentIdValid() {
|
||||
// 如果是企业微信,必须填写 agentId 属性
|
||||
if (Objects.equals(socialType, SocialTypeEnum.WECHAT_ENTERPRISE.getType())
|
||||
&& StrUtil.isEmpty(agentId)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - 社交客户端创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SocialClientCreateReqVO extends SocialClientBaseVO {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - 社交客户端分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SocialClientPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "应用名", example = "yudao商城")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "社交平台的类型", example = "31")
|
||||
private Integer socialType;
|
||||
|
||||
@Schema(description = "用户类型", example = "2")
|
||||
private Integer userType;
|
||||
|
||||
@Schema(description = "客户端编号", example = "145442115")
|
||||
private String clientId;
|
||||
|
||||
@Schema(description = "状态", example = "1")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 社交客户端 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SocialClientRespVO extends SocialClientBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27162")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 社交客户端更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SocialClientUpdateReqVO extends SocialClientBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27162")
|
||||
@NotNull(message = "编号不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 社交用户 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class SocialUserBaseVO {
|
||||
|
||||
@Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "30")
|
||||
@NotNull(message = "社交平台的类型不能为空")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "社交 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
|
||||
@NotNull(message = "社交 openid不能为空")
|
||||
private String openid;
|
||||
|
||||
@Schema(description = "社交 token", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
|
||||
private String token;
|
||||
|
||||
@Schema(description = "原始 Token 数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
|
||||
private String rawTokenInfo;
|
||||
|
||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@NotNull(message = "用户昵称不能为空")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "原始用户数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
|
||||
private String rawUserInfo;
|
||||
|
||||
@Schema(description = "最后一次的认证 code", requiredMode = Schema.RequiredMode.REQUIRED, example = "666666")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "最后一次的认证 state", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
|
||||
private String state;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 社交用户分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SocialUserPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "社交平台的类型", example = "30")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "用户昵称", example = "李四")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "社交 openid", example = "oz-Jdt0kd_jdhUxJHQdBJMlOFN7w\n")
|
||||
private String openid;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 社交用户 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SocialUserRespVO extends SocialUserBaseVO {
|
||||
|
||||
@Schema(description = "主键(自增策略)", requiredMode = Schema.RequiredMode.REQUIRED, example = "14569")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
@@ -1,12 +1,19 @@
|
||||
package cn.iocoder.yudao.module.system.convert.social;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SocialClientConvert {
|
||||
|
||||
@@ -16,4 +23,16 @@ public interface SocialClientConvert {
|
||||
|
||||
SocialWxPhoneNumberInfoRespDTO convert(WxMaPhoneNumberInfo bean);
|
||||
|
||||
SocialClientDO convert(SocialClientCreateReqVO bean);
|
||||
|
||||
SocialClientDO convert(SocialClientUpdateReqVO bean);
|
||||
|
||||
SocialClientRespVO convert(SocialClientDO bean);
|
||||
|
||||
List<SocialClientRespVO> convertList(List<SocialClientDO> list);
|
||||
|
||||
PageResult<SocialClientRespVO> convertPage(PageResult<SocialClientDO> page);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,32 @@
|
||||
package cn.iocoder.yudao.module.system.convert.social;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SocialUserConvert {
|
||||
|
||||
SocialUserConvert INSTANCE = Mappers.getMapper(SocialUserConvert.class);
|
||||
|
||||
@Mapping(target = "socialType", source = "reqVO.type")
|
||||
SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO);
|
||||
|
||||
SocialUserUnbindReqDTO convert(Long userId, Integer userType, SocialUserUnbindReqVO reqVO);
|
||||
|
||||
SocialUserRespVO convert(SocialUserDO bean);
|
||||
|
||||
List<SocialUserRespVO> convertList(List<SocialUserDO> list);
|
||||
|
||||
PageResult<SocialUserRespVO> convertPage(PageResult<SocialUserDO> page);
|
||||
|
||||
}
|
||||
|
||||
@@ -65,4 +65,12 @@ public class SocialClientDO extends TenantBaseDO {
|
||||
*/
|
||||
private String clientSecret;
|
||||
|
||||
/**
|
||||
* 代理编号
|
||||
*
|
||||
* 目前只有部分“社交类型”在使用:
|
||||
* 1. 企业微信:对应授权方的网页应用 ID
|
||||
*/
|
||||
private String agentId;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.social;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -12,4 +15,14 @@ public interface SocialClientMapper extends BaseMapperX<SocialClientDO> {
|
||||
SocialClientDO::getUserType, userType);
|
||||
}
|
||||
|
||||
default PageResult<SocialClientDO> selectPage(SocialClientPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<SocialClientDO>()
|
||||
.likeIfPresent(SocialClientDO::getName, reqVO.getName())
|
||||
.eqIfPresent(SocialClientDO::getSocialType, reqVO.getSocialType())
|
||||
.eqIfPresent(SocialClientDO::getUserType, reqVO.getUserType())
|
||||
.eqIfPresent(SocialClientDO::getClientId, reqVO.getClientId())
|
||||
.eqIfPresent(SocialClientDO::getStatus, reqVO.getStatus())
|
||||
.orderByDesc(SocialClientDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.social;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -21,4 +24,13 @@ public interface SocialUserMapper extends BaseMapperX<SocialUserDO> {
|
||||
.eq(SocialUserDO::getOpenid, openid));
|
||||
}
|
||||
|
||||
default PageResult<SocialUserDO> selectPage(SocialUserPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<SocialUserDO>()
|
||||
.eqIfPresent(SocialUserDO::getType, reqVO.getType())
|
||||
.likeIfPresent(SocialUserDO::getNickname, reqVO.getNickname())
|
||||
.likeIfPresent(SocialUserDO::getOpenid, reqVO.getOpenid())
|
||||
.betweenIfPresent(SocialUserDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(SocialUserDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package cn.iocoder.yudao.module.system.service.social;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import com.xingyuv.jushauth.model.AuthUser;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 社交应用 Service 接口
|
||||
*
|
||||
@@ -55,4 +62,44 @@ public interface SocialClientService {
|
||||
*/
|
||||
WxMaPhoneNumberInfo getWxMaPhoneNumberInfo(Integer userType, String phoneCode);
|
||||
|
||||
// =================== 客户端管理 ===================
|
||||
|
||||
/**
|
||||
* 创建社交客户端
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createSocialClient(@Valid SocialClientCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新社交客户端
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateSocialClient(@Valid SocialClientUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除社交客户端
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteSocialClient(Long id);
|
||||
|
||||
/**
|
||||
* 获得社交客户端
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 社交客户端
|
||||
*/
|
||||
SocialClientDO getSocialClient(Long id);
|
||||
|
||||
/**
|
||||
* 获得社交客户端分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 社交客户端分页
|
||||
*/
|
||||
PageResult<SocialClientDO> getSocialClientPage(SocialClientPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,16 +6,23 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
|
||||
import cn.iocoder.yudao.framework.social.core.YudaoAuthRequestFactory;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.convert.social.SocialClientConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
|
||||
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.xingyuv.jushauth.config.AuthConfig;
|
||||
@@ -41,8 +48,7 @@ import java.util.Objects;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_APP_WEIXIN_MINI_APP_PHONE_CODE_ERROR;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_USER_AUTH_FAILURE;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 社交应用 Service 实现类
|
||||
@@ -151,6 +157,9 @@ public class SocialClientServiceImpl implements SocialClientService {
|
||||
// 2.2 修改对应的 clientId + clientSecret 密钥
|
||||
newAuthConfig.setClientId(client.getClientId());
|
||||
newAuthConfig.setClientSecret(client.getClientSecret());
|
||||
if (client.getAgentId() != null) { // 如果有 agentId 则修改 agentId
|
||||
newAuthConfig.setAgentId(client.getAgentId());
|
||||
}
|
||||
// 2.3 设置会 request 里,进行后续使用
|
||||
ReflectUtil.setFieldValue(request, "config", newAuthConfig);
|
||||
}
|
||||
@@ -213,7 +222,7 @@ public class SocialClientServiceImpl implements SocialClientService {
|
||||
return service.getUserService().getPhoneNoInfo(phoneCode);
|
||||
} catch (WxErrorException e) {
|
||||
log.error("[getPhoneNoInfo][userType({}) phoneCode({}) 获得手机号失败]", userType, phoneCode, e);
|
||||
throw exception(SOCIAL_APP_WEIXIN_MINI_APP_PHONE_CODE_ERROR);
|
||||
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,4 +264,76 @@ public class SocialClientServiceImpl implements SocialClientService {
|
||||
return service;
|
||||
}
|
||||
|
||||
// =================== 客户端管理 ===================
|
||||
|
||||
@Override
|
||||
public Long createSocialClient(SocialClientCreateReqVO createReqVO) {
|
||||
// 校验重复
|
||||
validateSocialClientUnique(null, createReqVO.getUserType(), createReqVO.getSocialType());
|
||||
|
||||
// 插入
|
||||
SocialClientDO socialClient = SocialClientConvert.INSTANCE.convert(createReqVO);
|
||||
socialClientMapper.insert(socialClient);
|
||||
// 返回
|
||||
return socialClient.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSocialClient(SocialClientUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateSocialClientExists(updateReqVO.getId());
|
||||
// 校验重复
|
||||
validateSocialClientUnique(updateReqVO.getId(), updateReqVO.getUserType(), updateReqVO.getSocialType());
|
||||
|
||||
// 更新
|
||||
SocialClientDO updateObj = SocialClientConvert.INSTANCE.convert(updateReqVO);
|
||||
socialClientMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSocialClient(Long id) {
|
||||
// 校验存在
|
||||
validateSocialClientExists(id);
|
||||
// 删除
|
||||
socialClientMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateSocialClientExists(Long id) {
|
||||
if (socialClientMapper.selectById(id) == null) {
|
||||
throw exception(SOCIAL_CLIENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验社交应用是否重复,需要保证 userType + socialType 唯一
|
||||
*
|
||||
* 原因是,不同端(userType)选择某个社交登录(socialType)时,需要通过 {@link #buildAuthRequest(Integer, Integer)} 构建对应的请求
|
||||
*
|
||||
* @param id 编号
|
||||
* @param userType 用户类型
|
||||
* @param socialType 社交类型
|
||||
*/
|
||||
@VisibleForTesting
|
||||
private void validateSocialClientUnique(Long id, Integer userType, Integer socialType) {
|
||||
SocialClientDO client = socialClientMapper.selectBySocialTypeAndUserType(
|
||||
socialType, userType);
|
||||
if (client == null) {
|
||||
return;
|
||||
}
|
||||
if (id == null // 新增时,说明重复
|
||||
|| ObjUtil.notEqual(id, client.getId())) { // 更新时,如果 id 不一致,说明重复
|
||||
throw exception(SOCIAL_CLIENT_UNIQUE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocialClientDO getSocialClient(Long id) {
|
||||
return socialClientMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SocialClientDO> getSocialClientPage(SocialClientPageReqVO pageReqVO) {
|
||||
return socialClientMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package cn.iocoder.yudao.module.system.service.social;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
|
||||
@@ -19,7 +21,7 @@ public interface SocialUserService {
|
||||
/**
|
||||
* 获得指定用户的社交用户列表
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param userId 用户编号
|
||||
* @param userType 用户类型
|
||||
* @return 社交用户列表
|
||||
*/
|
||||
@@ -56,4 +58,22 @@ public interface SocialUserService {
|
||||
*/
|
||||
SocialUserRespDTO getSocialUser(Integer userType, Integer socialType, String code, String state);
|
||||
|
||||
// ==================== 社交用户 CRUD ====================
|
||||
|
||||
/**
|
||||
* 获得社交用户
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 社交用户
|
||||
*/
|
||||
SocialUserDO getSocialUser(Long id);
|
||||
|
||||
/**
|
||||
* 获得社交用户分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 社交用户分页
|
||||
*/
|
||||
PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package cn.iocoder.yudao.module.system.service.social;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper;
|
||||
@@ -113,8 +115,8 @@ public class SocialUserServiceImpl implements SocialUserService {
|
||||
*
|
||||
* @param socialType 社交平台的类型 {@link SocialTypeEnum}
|
||||
* @param userType 用户类型
|
||||
* @param code 授权码
|
||||
* @param state state
|
||||
* @param code 授权码
|
||||
* @param state state
|
||||
* @return 授权用户
|
||||
*/
|
||||
@NotNull
|
||||
@@ -146,4 +148,16 @@ public class SocialUserServiceImpl implements SocialUserService {
|
||||
return socialUser;
|
||||
}
|
||||
|
||||
// ==================== 社交用户 CRUD ====================
|
||||
|
||||
@Override
|
||||
public SocialUserDO getSocialUser(Long id) {
|
||||
return socialUserMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO) {
|
||||
return socialUserMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ DELETE FROM "system_sms_template";
|
||||
DELETE FROM "system_sms_log";
|
||||
DELETE FROM "system_sms_code";
|
||||
DELETE FROM "system_error_code";
|
||||
DELETE FROM "system_social_client";
|
||||
DELETE FROM "system_social_user";
|
||||
DELETE FROM "system_social_user_bind";
|
||||
DELETE FROM "system_tenant";
|
||||
|
||||
@@ -354,8 +354,25 @@ CREATE TABLE IF NOT EXISTS "system_error_code" (
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '错误码表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "system_social_client" (
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"name" varchar(255) NOT NULL,
|
||||
"social_type" int NOT NULL,
|
||||
"user_type" int NOT NULL,
|
||||
"client_id" varchar(255) NOT NULL,
|
||||
"client_secret" varchar(255) NOT NULL,
|
||||
"status" int NOT NULL,
|
||||
"creator" varchar(64) DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar(64) DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '社交客户端表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "system_social_user" (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"type" tinyint NOT NULL,
|
||||
"openid" varchar(64) NOT NULL,
|
||||
"token" varchar(256) DEFAULT NULL,
|
||||
@@ -374,7 +391,7 @@ CREATE TABLE IF NOT EXISTS "system_social_user" (
|
||||
) COMMENT '社交用户';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "system_social_user_bind" (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"user_id" bigint NOT NULL,
|
||||
"user_type" tinyint NOT NULL,
|
||||
"social_type" tinyint NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user