功能:新增微信小程序一键登录
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
# YumiNail 前后端接口文档
|
||||
# YumiNail 前后端接口文档
|
||||
|
||||
## 一、项目模块结构
|
||||
|
||||
| 模块 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| Frontend | `Frontend/` | Vue3前端项目 |
|
||||
| YumiNail-Frontend | `YumiNail-Frontend/` | YumiNail 主业务 Vue3 前端项目 |
|
||||
| YumiNail-Calendar-Frontend | `YumiNail-Calendar-Frontend/` | 美甲师日历表独立前端项目 |
|
||||
| YumiNail-Calendar-Gateway | `YumiNail-Calendar-Gateway/` | 美甲师日历表独立网关 |
|
||||
| YumiNail-Calendar-Core | `YumiNail-Calendar-Core/` | 美甲师日历表独立后端服务 |
|
||||
| YumiNail-Gateway | `YumiNail-Gateway/` | Spring Cloud Gateway网关 |
|
||||
| YumiNail-Core | `YumiNail-Core/` | 核心业务服务 |
|
||||
| MessageHub | `MessageHub/` | 消息推送服务 |
|
||||
@@ -52,6 +55,9 @@ baseURL: `http://wcy111.top:8088/api`
|
||||
|-------------|----------------|----------|------|------|
|
||||
| `/api/user/login` | UserController | `/user/login` | POST | 用户登录 |
|
||||
| `/api/user/phone-login` | UserController | `/user/phone-login` | POST | 手机号登录 |
|
||||
| `/api/user/wechat-mini/auto-login` | UserController | `/user/wechat-mini/auto-login` | POST | 小程序冷启动自动登录 |
|
||||
| `/api/user/wechat-mini/phone-login` | UserController | `/user/wechat-mini/phone-login` | POST | 小程序微信手机号一键登录 |
|
||||
| `/api/user/wechat-mini/confirm-login` | UserController | `/user/wechat-mini/confirm-login` | POST | 小程序补选门店后确认登录 |
|
||||
| `/api/user/register` | UserController | `/user/register` | POST | 用户注册 |
|
||||
| `/api/user/refresh-token` | UserController | `/user/refresh-token` | POST | 刷新Token |
|
||||
| `/api/user/logout` | UserController | `/user/logout` | POST | 用户登出 |
|
||||
@@ -67,6 +73,11 @@ baseURL: `http://wcy111.top:8088/api`
|
||||
| `/api/user/bind-phone` | UserController | `/user/bind-phone` | POST | 绑定手机号 |
|
||||
| `/api/user/phone` | UserController | `/user/phone` | PUT | 修改手机号 |
|
||||
| `/api/user/get/account/{account}` | UserController | `/user/get/account/{account}` | GET | 根据账号查询用户 |
|
||||
| `/api/user/check/account/{account}` | UserController | `/user/check/account/{account}` | GET | 检查注册账号是否可用 |
|
||||
| `/api/user/check/phone/{phone}` | UserController | `/user/check/phone/{phone}` | GET | 检查手机号是否可用 |
|
||||
| `/api/user/check/login-account/{account}` | UserController | `/user/check/login-account/{account}` | GET | 检查登录账号是否存在并返回昵称提示 |
|
||||
| `/api/user/check/login-shops/account/{account}` | UserController | `/user/check/login-shops/account/{account}` | GET | 按账号预加载可登录门店 |
|
||||
| `/api/user/check/login-shops/phone/{phone}` | UserController | `/user/check/login-shops/phone/{phone}` | GET | 按手机号预加载可登录门店 |
|
||||
| `/api/user/list/type/{type}` | UserController | `/user/list/type/{type}` | GET | 根据类型查询用户 |
|
||||
| `/api/user/send-verification-code` | UserController | `/user/send-verification-code` | POST | 发送验证码 |
|
||||
| `/api/user/deactivate` | UserController | `/user/deactivate` | DELETE | 注销账号 |
|
||||
@@ -293,9 +304,12 @@ yuminail:
|
||||
# 用户端白名单
|
||||
- /user/login
|
||||
- /user/register
|
||||
- /user/check/**
|
||||
- /user/refresh-token
|
||||
- /user/send-verification-code
|
||||
- /user/phone-login
|
||||
- /user/wechat-mini/**
|
||||
- /user/reset-password-by-phone
|
||||
- /user/get/account/**
|
||||
- /shop/list/simple
|
||||
- /health/**
|
||||
@@ -309,6 +323,22 @@ yuminail:
|
||||
- 白名单配置**不需要**带 `/api` 前缀
|
||||
- 网关在处理请求时会自动去掉 `/api` 前缀后再进行白名单匹配
|
||||
- 所有不在白名单中的接口都需要携带有效的Token
|
||||
- 小程序微信登录链路 `/user/wechat-mini/**` 需要同步加入 Gateway 本地配置、Gateway 代码默认白名单、Core 拦截器白名单、小程序请求层白名单,以及 Nacos `YumiNail-Dev` 对应 whitelist 配置
|
||||
|
||||
### 5.3 小程序微信登录配置
|
||||
|
||||
以下配置通过 Nacos `YumiNail-Dev` 命名空间维护:
|
||||
|
||||
```yaml
|
||||
yuminail:
|
||||
wechat:
|
||||
mini:
|
||||
app-id: wx1234567890abcdef
|
||||
app-secret: your-mini-program-secret
|
||||
code2session-url: https://api.weixin.qq.com/sns/jscode2session
|
||||
phone-number-url: https://api.weixin.qq.com/wxa/business/getuserphonenumber
|
||||
access-token-buffer-seconds: 60
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -412,3 +442,4 @@ public Result<Long> createProduct(@RequestBody ProductDTO productDTO) {
|
||||
3. **Token校验由网关统一处理**
|
||||
4. **权限校验由后端Controller通过注解处理**
|
||||
5. **后端Controller路径保持不变**
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
CREATE TABLE IF NOT EXISTS t_wechat_mini_binding
|
||||
(
|
||||
id BIGINT UNSIGNED NOT NULL COMMENT '微信小程序绑定主键ID(雪花ID)',
|
||||
user_id BIGINT UNSIGNED NOT NULL COMMENT '关联用户ID',
|
||||
app_id VARCHAR(64) NOT NULL COMMENT '微信小程序appId',
|
||||
openid VARCHAR(100) NOT NULL COMMENT '微信小程序openid',
|
||||
unionid VARCHAR(100) NULL COMMENT '微信开放平台unionid',
|
||||
status TINYINT UNSIGNED DEFAULT 1 NULL COMMENT '状态:1-有效,0-失效',
|
||||
create_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间',
|
||||
update_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (id)
|
||||
) COMMENT = '微信小程序账号绑定表';
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE sp_add_index_if_not_exists(
|
||||
IN p_table_name VARCHAR(64),
|
||||
IN p_index_name VARCHAR(64),
|
||||
IN p_index_sql TEXT
|
||||
)
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = p_table_name
|
||||
AND index_name = p_index_name
|
||||
) THEN
|
||||
SET @index_sql = p_index_sql;
|
||||
PREPARE stmt FROM @index_sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL sp_add_index_if_not_exists(
|
||||
't_wechat_mini_binding',
|
||||
'idx_wechat_mini_unionid',
|
||||
'CREATE INDEX idx_wechat_mini_unionid ON t_wechat_mini_binding (unionid)'
|
||||
);
|
||||
|
||||
CALL sp_add_index_if_not_exists(
|
||||
't_wechat_mini_binding',
|
||||
'uk_wechat_mini_app_openid',
|
||||
'ALTER TABLE t_wechat_mini_binding ADD CONSTRAINT uk_wechat_mini_app_openid UNIQUE (app_id, openid)'
|
||||
);
|
||||
|
||||
CALL sp_add_index_if_not_exists(
|
||||
't_wechat_mini_binding',
|
||||
'uk_wechat_mini_app_user',
|
||||
'ALTER TABLE t_wechat_mini_binding ADD CONSTRAINT uk_wechat_mini_app_user UNIQUE (app_id, user_id)'
|
||||
);
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists;
|
||||
@@ -193,6 +193,29 @@ create index idx_user_id
|
||||
on t_login_identity (user_id)
|
||||
comment '按用户查询登录标识的索引';
|
||||
|
||||
-- auto-generated definition
|
||||
create table t_wechat_mini_binding
|
||||
(
|
||||
id bigint unsigned auto_increment comment '微信小程序绑定主键ID(雪花ID)'
|
||||
primary key,
|
||||
user_id bigint unsigned not null comment '关联用户ID',
|
||||
app_id varchar(64) not null comment '微信小程序appId',
|
||||
openid varchar(100) not null comment '微信小程序openid',
|
||||
unionid varchar(100) null comment '微信开放平台unionid',
|
||||
status tinyint unsigned default 1 null comment '状态:1-有效,0-失效',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
constraint uk_wechat_mini_app_openid
|
||||
unique (app_id, openid),
|
||||
constraint uk_wechat_mini_app_user
|
||||
unique (app_id, user_id)
|
||||
)
|
||||
comment '微信小程序账号绑定表';
|
||||
|
||||
create index idx_wechat_mini_unionid
|
||||
on t_wechat_mini_binding (unionid)
|
||||
comment '按unionid查询的索引';
|
||||
|
||||
-- auto-generated definition
|
||||
create table t_nail_artist_info
|
||||
(
|
||||
@@ -1327,6 +1350,7 @@ CALL sp_drop_auto_increment_on_id_if_exists('t_coupon');
|
||||
CALL sp_drop_auto_increment_on_id_if_exists('t_coupon_tag');
|
||||
CALL sp_drop_auto_increment_on_id_if_exists('t_effect_diagram');
|
||||
CALL sp_drop_auto_increment_on_id_if_exists('t_login_identity');
|
||||
CALL sp_drop_auto_increment_on_id_if_exists('t_wechat_mini_binding');
|
||||
CALL sp_drop_auto_increment_on_id_if_exists('t_nail_artist_info');
|
||||
CALL sp_drop_auto_increment_on_id_if_exists('t_object_storage_file');
|
||||
CALL sp_drop_auto_increment_on_id_if_exists('t_order');
|
||||
|
||||
Reference in New Issue
Block a user