mingyang-admin-iot-app/rpc/app.proto

226 lines
4.7 KiB
Protocol Buffer

syntax = "proto3";
package app;
option go_package = "./app";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
// 账户类型枚举(手机/邮箱)
enum AccountType {
UNKNOWN = 0;
MOBILE = 1;
EMAIL = 2;
}
// 验证码类型枚举
enum VerifyCodeType {
REGISTER = 0;
LOGIN = 1;
RESET_PASSWORD = 2;
BIND_PHONE = 3;
BIND_EMAIL = 4;
UPDATE_PHONE = 5;
UPDATE_EMAIL = 6;
WITHDRAW = 7;
CHANGE_PAY_PASSWORD = 8;
}
// AuthInfoResp 是认证信息的响应
message AuthInfoResp {
uint64 user_id = 1;
string type = 2;
RegisteredClaims claims = 3;
}
message AuthReq {
string token = 1;
google.protobuf.Timestamp time = 2;
}
// 认证令牌
message AuthToken {
string access_token = 1;
string refresh_token = 2;
string token_type = 3;
google.protobuf.Timestamp access_token_expires = 4;
google.protobuf.Timestamp refresh_token_expires = 5;
}
message BaseIDResp {
uint64 id = 1;
string msg = 2;
}
message BaseMsg {
string msg = 1;
}
message BaseResp {
string msg = 1;
}
message BaseUUIDResp {
string id = 1;
string msg = 2;
}
// ClaimStrings 用于表示 JWT 中的 audience 字段
message ClaimStrings {
repeated string values = 1;
}
// base message
message Empty {}
message IDReq {
uint64 id = 1;
}
message IDsReq {
repeated uint64 ids = 1;
}
message LoginRequest {
optional string username = 1;
optional string password = 2;
optional string clientIp = 3;
optional string loginTyp = 4;
optional string loginPlatform = 5;
}
message LoginResponse {
UserInfo user = 1;
AuthToken auth_token = 2;
}
// NumericDate 使用 timestamp 表示 JWT 中的时间字段
message NumericDate {
google.protobuf.Timestamp timestamp = 1;
}
message PageInfoReq {
uint64 page = 1;
uint64 page_size = 2;
}
message PageUserRequest {
uint64 page = 1;
uint64 page_size = 2;
optional string username = 3;
optional string email = 4;
optional string mobile = 5;
optional string status = 6;
optional string clientIp = 7;
}
message PageUserResponse {
uint64 total = 1;
repeated UserInfo data = 2;
}
message RegisterUserRequest {
optional string email = 1;
optional string password = 2;
optional string username = 3;
optional string name = 4;
optional string mobile = 5;
optional string captcha = 6;
optional uint32 verificationType = 7;
optional string nickName = 9;
optional string registrationSource = 10;
optional string gender = 11;
}
message RegisterUserResponse {
UserInfo user = 1;
AuthToken auth_token = 2;
bool email_verification_required = 3;
bool phone_verification_required = 4;
}
// RegisteredClaims 是 JWT 声明集的结构化版本
message RegisteredClaims {
// iss (Issuer) - 签发者
string issuer = 1;
// sub (Subject) - 主题
string subject = 2;
// aud (Audience) - 受众
ClaimStrings audience = 3;
// exp (Expiration Time) - 过期时间
NumericDate expires_at = 4;
// nbf (Not Before) - 生效时间
NumericDate not_before = 5;
// iat (Issued At) - 签发时间
NumericDate issued_at = 6;
// jti (JWT ID) - JWT ID
string id = 7;
}
message UUIDReq {
string id = 1;
}
message UUIDsReq {
repeated string ids = 1;
}
message UserInfo {
optional uint64 id = 1;
optional string username = 2;
optional string email = 3;
optional string mobile = 4;
optional string password_hash = 5;
optional string salt = 6;
string nickName = 7;
optional string avatar = 8;
optional string gender = 9;
optional string account_status = 10;
optional uint32 is_verified = 11;
optional int64 last_login_at = 12;
optional string last_login_ip = 13;
optional int64 login_attempts = 14;
optional int64 locked_until = 15;
optional string recovery_token = 16;
optional int64 recovery_token_expiry = 17;
optional google.protobuf.Struct metadata = 20;
optional string registration_source = 21;
optional int64 birthday_at = 22;
optional int64 created_at = 23;
optional int64 updated_at = 24;
}
message VerifyCodeReq {
VerifyCodeType type = 1;
AccountType account_type = 2;
string value = 3;
}
message VerifyCodeResp {
string captchaCode = 1;
uint32 expire = 2;
}
// App 服务定义
service App {
// 校验token
// group: auth
rpc AuthToken(AuthReq) returns (AuthInfoResp);
// 获取验证码
// group: code
rpc GetVerifyCode(VerifyCodeReq) returns (VerifyCodeResp);
// 用户注册
// group: user
rpc RegisterUser(RegisterUserRequest) returns (RegisterUserResponse);
// 用户登录
// group: user
rpc LoginUser(LoginRequest) returns (LoginResponse);
// 分页查询用户信息
// group: user
rpc ListUsers(PageUserRequest) returns (PageUserResponse);
// group: base
rpc InitDatabase(Empty) returns (BaseResp);
}