新增 user 模块
调整新的项目结构,将 service 和 dao 模块,从 application 拆除,独立成 service-impl 模块 增加 sdk 模块,用于提供一个封装过的功能。例如说,认证和授权~
This commit is contained in:
22
user/user-service-api/pom.xml
Normal file
22
user/user-service-api/pom.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>user</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>user-service-api</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>common-framework</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.iocoder.mall.user.service.api;
|
||||
|
||||
import cn.iocoder.common.framework.exception.ServiceException;
|
||||
|
||||
public interface MobileCodeService {
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @param mobile 手机号
|
||||
*/
|
||||
void send(String mobile) throws ServiceException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.user.service.api;
|
||||
|
||||
|
||||
import cn.iocoder.common.framework.exception.ServiceException;
|
||||
import cn.iocoder.mall.user.service.api.dto.OAuth2AccessTokenBO;
|
||||
import cn.iocoder.mall.user.service.api.dto.OAuth2AuthenticationDTO;
|
||||
|
||||
public interface OAuth2Service {
|
||||
|
||||
/**
|
||||
* 使用手机号 + 验证码,获取访问令牌等信息
|
||||
*
|
||||
* 如果手机未注册,并且验证码正确,进行自动注册。
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @param code 验证码
|
||||
* @return 授权信息
|
||||
*/
|
||||
OAuth2AccessTokenBO getAccessToken(String mobile, String code)
|
||||
throws ServiceException;
|
||||
|
||||
/**
|
||||
* 校验访问令牌,获取身份信息( 不包括 accessToken 等等 )
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
* @return 授权信息
|
||||
*/
|
||||
OAuth2AuthenticationDTO checkToken(String accessToken)
|
||||
throws ServiceException;
|
||||
|
||||
// @see 刷新 token
|
||||
|
||||
// @see 移除 token
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.iocoder.mall.user.service.api;
|
||||
|
||||
import cn.iocoder.common.framework.exception.ServiceException;
|
||||
import cn.iocoder.mall.user.service.api.dto.UserDTO;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
/**
|
||||
* 创建用户。一般在用户注册时,调用该方法
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @param code 手机验证码
|
||||
* @return 用户
|
||||
*/
|
||||
UserDTO createUser(String mobile, String code) throws ServiceException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.iocoder.mall.user.service.api.constant;
|
||||
|
||||
public class ThirdPlatformConstant {
|
||||
|
||||
public static final int QQ = 1;
|
||||
|
||||
public static final int WEIBO = 2;
|
||||
|
||||
// WECHAT 可能分成好几个
|
||||
|
||||
// ....
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package cn.iocoder.mall.user.service.api.constant;
|
||||
|
||||
/**
|
||||
* 错误码枚举类
|
||||
*
|
||||
* 用户中心,使用 1-001-000-000 段
|
||||
*/
|
||||
public enum UserErrorCodeEnum {
|
||||
|
||||
// ========== OAUTH2 模块 ==========
|
||||
OAUTH2_UNKNOWN(1001001000, "未知错误"), // 预留
|
||||
OAUTH2_INVALID_GRANT_BAD_CREDENTIALS(1001001001, "密码不正确"), // 暂时没用到
|
||||
OAUTH2_INVALID_GRANT_USERNAME_NOT_FOUND(1001001002, "账号不存在"), // 暂时没用到
|
||||
OAUTH2_INVALID_GRANT(1001001010, ""), // 预留
|
||||
OAUTH_INVALID_TOKEN_NOT_FOUND(1001001011, "访问令牌不存在"),
|
||||
OAUTH_INVALID_TOKEN_EXPIRED(1001001012, "访问令牌已过期"),
|
||||
OAUTH_INVALID_TOKEN_INVALID(1001001013, "访问令牌已失效"),
|
||||
OAUTH_INVALID_TOKEN(1001001020, ""), // 预留
|
||||
|
||||
// ========== 用户模块 ==========
|
||||
USER_MOBILE_NOT_REGISTERED(1001002000, "手机号未注册用户"),
|
||||
USER_MOBILE_ALREADY_REGISTERED(1001002001, "手机号已经注册用户"),
|
||||
|
||||
// ========== 手机验证码模块 ==========
|
||||
MOBILE_CODE_NOT_FOUND(1001003000, "验证码不存在"),
|
||||
MOBILE_CODE_EXPIRED(1001003001, "验证码已过期"),
|
||||
MOBILE_CODE_USED(1001003002, "验证码已使用"),
|
||||
MOBILE_CODE_NOT_CORRECT(1001003003, "验证码不正确"),
|
||||
MOBILE_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY(1001003004, "超过每日短信发送数量"),
|
||||
MOBILE_CODE_SEND_TOO_FAST(1001003005, "短信发送过于频率")
|
||||
;
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
||||
UserErrorCodeEnum(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.iocoder.mall.user.service.api.dto;
|
||||
|
||||
public class MobileCodeDTO {
|
||||
|
||||
private String code;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public MobileCodeDTO setCode(String code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.iocoder.mall.user.service.api.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class OAuth2AccessTokenBO implements Serializable {
|
||||
|
||||
/**
|
||||
* 访问令牌
|
||||
*/
|
||||
private String accessToken;
|
||||
/**
|
||||
* 刷新令牌
|
||||
*/
|
||||
private String refreshToken;
|
||||
/**
|
||||
* 过期时间,单位:秒。
|
||||
*/
|
||||
private Integer expiresIn;
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public OAuth2AccessTokenBO setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
|
||||
public OAuth2AccessTokenBO setRefreshToken(String refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getExpiresIn() {
|
||||
return expiresIn;
|
||||
}
|
||||
|
||||
public OAuth2AccessTokenBO setExpiresIn(Integer expiresIn) {
|
||||
this.expiresIn = expiresIn;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.mall.user.service.api.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class OAuth2AuthenticationDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Long uid;
|
||||
|
||||
public Long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public OAuth2AuthenticationDTO setUid(Long uid) {
|
||||
this.uid = uid;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.iocoder.mall.user.service.api.dto;
|
||||
|
||||
public class UserDTO {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
private Long uid;
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String mobile;
|
||||
|
||||
public Long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public UserDTO setUid(Long uid) {
|
||||
this.uid = uid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public UserDTO setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user