252 lines
11 KiB
Plaintext
252 lines
11 KiB
Plaintext
|
syntax = "v1"
|
|||
|
|
|||
|
info(
|
|||
|
title: "Portal-Api-Gateway (PGW)"
|
|||
|
desc: "netpute web portal api gateway"
|
|||
|
author: "daniel wang"
|
|||
|
email: "daniel.wang@30cm.net"
|
|||
|
version: "0.0.1"
|
|||
|
)
|
|||
|
|
|||
|
type MemberLoginHeader {
|
|||
|
DeviceID string `header:"device_id"`
|
|||
|
IpAddress string `header:"ip_address"`
|
|||
|
Brewser string `header:"brewser"`
|
|||
|
}
|
|||
|
|
|||
|
// -------------------------------------------
|
|||
|
|
|||
|
type CreateAccountRequest {
|
|||
|
Account string `json:"account" validate:"required"` // 帳號名稱(line code 輸入在這邊)
|
|||
|
Token string `json:"token" validate:"required"` // 密碼或平台token,密碼請 sha256 轉碼,如果三方token 請隨便給一個 sha256 字串
|
|||
|
TokenCheck string `json:"token_check" validate:"required"` // 密碼或平台token,token 請保持原樣,填在這邊,不用管 token
|
|||
|
Platform string `json:"platform" validate:"oneof=platform google line"` // 平台名稱 (platform) 平台、google、line
|
|||
|
AccountType string `json:"account_type" validate:"oneof=phone email platform"` // 帳號類型 phone(手機)、email(信箱)、platform(自定義帳號) -> (如果為第三方都寫 platform)
|
|||
|
MemberLoginHeader
|
|||
|
}
|
|||
|
|
|||
|
type LoginReq {
|
|||
|
Account string `json:"account" validate:"required"` // 帳號名稱
|
|||
|
Token string `json:"token"` // 密碼或平台token,密碼請 sha256 轉碼
|
|||
|
Platform string `json:"platform" validate:"oneof=platform google line"` // 平台名稱 platform, google
|
|||
|
AccountType string `json:"account_type" validate:"oneof=phone email platform"` // 帳號類型 1 手機 2 信箱 3 自定義帳號
|
|||
|
MemberLoginHeader
|
|||
|
}
|
|||
|
|
|||
|
type LoginTokenResp {
|
|||
|
UID string `json:"uid"` // Account
|
|||
|
AccessToken string `json:"access_token"` // 訪問令牌 預設 5 分鐘過期
|
|||
|
RefreshToken string `json:"refresh_token"` // 刷新令牌 (預設一天過期,只能用一次),當呼叫更新token api 時,會自動把舊的失效,變成新的 refresh_token ,前端要記得過其實協助刷新,刷新不過表示全失效了(重新登入)
|
|||
|
TokenType string `json:"token_type"` // Bearer
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
type ForgetPasswordCodeReq {
|
|||
|
Account string `json:"account" validate:"required"` // 帳號名稱
|
|||
|
AccountType string `json:"account_type" validate:"oneof=phone email"` // 帳號類型 (phone) 手機 (email) 信箱
|
|||
|
}
|
|||
|
|
|||
|
type PreVerifyForgetPasswdReq {
|
|||
|
Identifier string `json:"identifier" validate:"required"` // 聯繫方式,可以是 email 或 phone
|
|||
|
VerifyCode string `json:"verify_code" validate:"required,len=6"` // 驗證碼,長度為6
|
|||
|
}
|
|||
|
|
|||
|
type UpdateTokenReq {
|
|||
|
UID string `json:"uid" validate:"required"` // 誰要更新
|
|||
|
Token string `json:"token" validate:"required"` // access token -> 已過期要被更新的
|
|||
|
RefreshToken string `json:"refresh_token" validate:"required"` // refresh token -> 重點,要驗證他的
|
|||
|
// MemberLoginHeader
|
|||
|
}
|
|||
|
|
|||
|
type UpdatePasswordReq {
|
|||
|
Account string `json:"account" validate:"required"` // 帳號名稱
|
|||
|
VerifyCode string `json:"verify_code" validate:"required,len=6"` // 驗證碼,長度為6
|
|||
|
Token string `json:"token" validate:"required,len=64"` // 密碼或平台token,密碼請 sha256 轉碼
|
|||
|
TokenCheck string `json:"token_check" validate:"required,len=64"` // 密碼或平台token,密碼請 sha256 轉碼
|
|||
|
}
|
|||
|
|
|||
|
@server(
|
|||
|
group: member
|
|||
|
prefix: /api/v1
|
|||
|
schemes: https
|
|||
|
timeout: 10s
|
|||
|
)
|
|||
|
service gateway {
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary:"創建新會員"
|
|||
|
description: "創建一個全新的帳號,創完成之後會自動登入"
|
|||
|
)
|
|||
|
@handler AccountCreate
|
|||
|
post /member (CreateAccountRequest) returns (LoginTokenResp)
|
|||
|
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-401 (BaseResponse) // 輸入的帳號密碼未經驗證-> 帳號密碼錯誤的意思 */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary:"登入"
|
|||
|
description: "會員登入"
|
|||
|
)
|
|||
|
@handler Login
|
|||
|
post /member/login (LoginReq) returns (LoginTokenResp)
|
|||
|
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary:"發送忘記密碼驗證"
|
|||
|
description: "發送忘記密碼驗證(三分鐘內只能發一次信)"
|
|||
|
)
|
|||
|
@handler ForgetPasswordCode
|
|||
|
post /member/forget-password-code (ForgetPasswordCodeReq) returns (RespOK)
|
|||
|
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-401 (BaseResponse) // 無效的驗證碼 */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary:"更新密碼(要發送驗證碼才可以的流程)"
|
|||
|
description: "更新密碼(要發送驗證碼才可以的流程)"
|
|||
|
)
|
|||
|
@handler UpdatePassword
|
|||
|
put /member/update-password (UpdatePasswordReq) returns (RespOK)
|
|||
|
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-401 (BaseResponse) // 無效的驗證碼 */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary:"預先驗證驗證碼"
|
|||
|
description: "忘記密碼的時候看 ui. 流程要預先驗證一次才給送,"
|
|||
|
)
|
|||
|
@handler PreVerifyUpdatePasswordCode
|
|||
|
put /member/pre-verify (PreVerifyForgetPasswdReq) returns (RespOK)
|
|||
|
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-401 (BaseResponse) // 無效的 Refresh Token */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary:"更新 Access Token"
|
|||
|
description: "用 RefreshToken 換取 AccessToken"
|
|||
|
)
|
|||
|
@handler RefreshAccessToken
|
|||
|
put /member/refresh_access_token (UpdateTokenReq) returns (LoginTokenResp)
|
|||
|
}
|
|||
|
|
|||
|
// ------------------- 要登入之後才可以做的事情 ------------------------
|
|||
|
|
|||
|
type UserInfo {
|
|||
|
Platform string `json:"platform"` // 用戶平台 platform, google, line
|
|||
|
UID string `json:"uid"` // 用戶 UID
|
|||
|
AvatarURL string `json:"avatar_url"` // 頭像 URL(可選)
|
|||
|
FullName string `json:"full_name"` // 用戶全名
|
|||
|
Nickname string `json:"nickname"` // 暱稱(可選)
|
|||
|
GenderCode string `json:"gender_code"` // 性別代碼 mail, femail ,sec
|
|||
|
Birthdate string `json:"birthdate"` // 生日 (格式: 19930417)
|
|||
|
PhoneNumber string `json:"phone_number"` // 電話
|
|||
|
Address string `json:"address"` // 地址
|
|||
|
Email string `json:"email"` // 驗證後的信箱
|
|||
|
AlarmCategory string `json:"alarm_category"` // 告警狀態
|
|||
|
UserStatus string `json:"user_status"` // 用戶狀態
|
|||
|
PreferredLanguage string `json:"preferred_language"` // 使用語言
|
|||
|
Currency string `json:"currency"` // 使用幣種
|
|||
|
UpdateAt string `json:"update_at"`
|
|||
|
CreateAt string `json:"create_at"`
|
|||
|
}
|
|||
|
|
|||
|
type BindingUserInfoReq {
|
|||
|
VerifyHeader
|
|||
|
PreferredLanguage string `json:"preferred_language,optional" validate:"oneof=zh-tw en-us"` // 使用語言
|
|||
|
Currency string `json:"currency,optional" validate:"oneof=TWD USD"`
|
|||
|
AvatarURL string `json:"avatar_url,optional"` // 頭像 URL(可選)
|
|||
|
Nickname string `json:"nickname,optional"`
|
|||
|
FullName string `json:"full_name,optional"` // 用戶全名
|
|||
|
GenderCode string `json:"gender_code" validate:"oneof=secret male female"` // 性別代碼
|
|||
|
Birthday string `json:"birthday,optional" validate:"rfc3339"` // 生日 (格式: unix)
|
|||
|
Address string `json:"address,optional"` // 地址
|
|||
|
}
|
|||
|
|
|||
|
type VerificationCodeRequest {
|
|||
|
VerifyHeader
|
|||
|
Identifier string `json:"identifier" validate:"required"` // 聯繫方式,可以是 email 或 phone
|
|||
|
CodeType string `json:"code_type" validate:"oneof=email phone forget_password"` // 驗證碼類型
|
|||
|
}
|
|||
|
|
|||
|
type CheckoutVerifyReq {
|
|||
|
VerifyHeader
|
|||
|
Account string `json:"account" validate:"required"` // 帳號名稱
|
|||
|
CodeType string `json:"code_type" validate:"oneof=email phone"` // 驗證碼類型 1 信箱 2 手機
|
|||
|
VerifyCode string `json:"verify_code" validate:"required,len=6"` // 驗證碼,長度為6
|
|||
|
UID string `json:"uid" validate:"required"`
|
|||
|
}
|
|||
|
|
|||
|
type ModifyPasswdReq {
|
|||
|
VerifyHeader
|
|||
|
NewToken string `json:"token" validate:"required,len=64"` // 密碼或平台token,密碼請 sha256 轉碼
|
|||
|
NewTokenCheck string `json:"token_check" validate:"required,len=64"` // 密碼或平台token,密碼請 sha256 轉碼
|
|||
|
}
|
|||
|
|
|||
|
@server(
|
|||
|
group: member
|
|||
|
prefix: /api/v1
|
|||
|
schemes: https
|
|||
|
timeout: 10s
|
|||
|
middleware: AuthMiddleware
|
|||
|
)
|
|||
|
|
|||
|
service gateway {
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-401 (BaseResponse) // 無效的Token */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary: "會員登出"
|
|||
|
)
|
|||
|
@handler Logout
|
|||
|
get /member/logout (VerifyHeader) returns (RespOK)
|
|||
|
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-401 (BaseResponse) // 無效的Token */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary: "取得會員資訊"
|
|||
|
)
|
|||
|
@handler Info
|
|||
|
get /member/info (VerifyHeader) returns (UserInfo)
|
|||
|
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-403 (BaseResponse) // 無效的Token */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary: "更新會員詳細資訊"
|
|||
|
)
|
|||
|
@handler ModifyMemberInfo
|
|||
|
put /member/info (BindingUserInfoReq) returns (UserInfo)
|
|||
|
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-401 (BaseResponse) // 無效的Token */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary: "發送邀請 - 綁定會員"
|
|||
|
description: "可以依照類別(手機驗證,email驗證),同一個類型十分鐘內只能發送一次"
|
|||
|
)
|
|||
|
@handler SendVerifyCode
|
|||
|
post /member/verify (VerificationCodeRequest) returns (RespOK)
|
|||
|
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-401 (BaseResponse) // 無效的驗證碼 */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary: "確認邀請 - 綁定會員"
|
|||
|
description: "確認驗證碼是否有效"
|
|||
|
)
|
|||
|
@handler CheckVerifyCode
|
|||
|
post /member/check-verify-code (CheckoutVerifyReq) returns (RespOK)
|
|||
|
|
|||
|
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
|||
|
/* @respdoc-401 (BaseResponse) // 無效的驗證碼 */
|
|||
|
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
|||
|
@doc(
|
|||
|
summary: "修改密碼"
|
|||
|
description: "修改密碼"
|
|||
|
)
|
|||
|
@handler ModifyPasswdHandler
|
|||
|
put /member/modify-passwd (ModifyPasswdReq) returns (RespOK)
|
|||
|
}
|