captcha/captcha.proto
syntax = "proto3";
package jsgenerate_kb2022.captcha;
option go_package = "gateway/protocol/captcha";
import "google/api/annotations.proto";
// Captcha 模塊用於提供驗證碼服務
service Captcha{
// 創建一個默認的驗證碼,數字 或 英文字符
rpc Generate(GenerateRequest) returns (CaptchaResponse){
option (google.api.http) = {
post: "/api/v1/captcha/generate"
body: "*"
};
}
// 創建一個數學驗證碼,簡單的數學 加減乘除法
rpc Math (MathRequest) returns (CaptchaResponse){
option (google.api.http) = {
post: "/api/v1/captcha/math"
body: "*"
};
}
// 驗證驗證碼
rpc Verify (VerifyRequest) returns (VerifyResponse){
option (google.api.http) = {
post: "/api/v1/captcha/verify"
body: "*"
};
}
}
message CaptchaResponse{
// 驗證碼,綁定的 id
string id=1;
// 驗證碼圖像的 base64 值,可以直接設置到 img 標籤的 src 屬性
string image=2;
}
message GenerateRequest{
// 要生成驗證碼長度,最小爲 4,最大爲 10
uint32 length = 1;
// 生成圖像寬度,最小爲 50
uint32 width = 2;
// 生成圖像高度,最小爲 40
uint32 height = 3;
}
message MathRequest{
// 生成圖像寬度,最小爲 50
uint32 width = 2;
// 生成圖像高度,最小爲 40
uint32 height = 3;
}
message VerifyRequest{
// 驗證碼 id
string id = 1;
// 用戶輸入的驗證碼值
string val = 2;
// 如果爲 true 則在驗證後刪除此驗證碼。可以通過將此參數設置爲 false 來使用 ajax 驗證用戶輸入的驗證碼是否正確,來自動爲用戶顯示輸入內容是否正確
bool clear = 3;
}
message VerifyResponse{
// 如果驗證碼正常 返回 true 否則返回 false
bool ok = 1;
}