This commit is contained in:
桀尼龟 2025-02-21 17:05:27 +08:00
parent c2cfcd7899
commit 70348b930d
8 changed files with 2994 additions and 2168 deletions

File diff suppressed because it is too large Load Diff

View File

@ -58,6 +58,42 @@ service Account {
rpc Register (RegistRequest) returns (RegisterResponse) {}// rpc Register (RegistRequest) returns (RegisterResponse) {}//
rpc UserList (UserListRequest) returns (UserListResponse) {}// rpc UserList (UserListRequest) returns (UserListResponse) {}//
rpc CheckRealName (CheckRealNameRequest) returns (CheckRealNameResponse) {}// rpc CheckRealName (CheckRealNameRequest) returns (CheckRealNameResponse) {}//
rpc GenerateSliderCaptcha(GenerateSliderCaptchaRequest) returns (GenerateSliderCaptchaResponse) {}// +
rpc VerifySliderCaptcha(VerifySliderCaptchaRequest) returns (VerifySliderCaptchaResponse) {}//
rpc SendNationMsg (SendNationMsgRequest) returns (SendMsgStatusResponse) {} // --
}
message SendNationMsgRequest {
string Domain = 1 [json_name = "domain",(validator.field) = {string_not_empty: true,human_error: "70001"} ];
string TelNum = 2 [json_name = "telNum",(validator.field) = {string_not_empty: true,human_error: "70001"}];
string Project = 3 [json_name = "project"];
uint32 signNo = 4;
uint32 mId = 5;
string scope = 6;//
}
message VerifySliderCaptchaResponse {
string nonceStr = 1;
}
message VerifySliderCaptchaRequest {
string nonceStr = 1;
float blockX = 2;
}
message GenerateSliderCaptchaResponse {
string nonceStr = 1;
string canvasSrc = 2;
string blockSrc = 3;
uint64 blockY = 4;
uint64 faceY = 5;
uint64 blockX = 6;
}
message GenerateSliderCaptchaRequest {
uint64 canvasWidth = 1;
uint64 canvasHeight = 2;
uint64 blockWidth = 3;
uint64 blockHeight = 4;
uint64 blockRadius = 5;
uint64 place = 6;
} }
message CheckRealNameResponse{ message CheckRealNameResponse{
uint64 id =1; uint64 id =1;
@ -91,6 +127,7 @@ message UserListInfo{
string subNum = 14; string subNum = 14;
string notPassRemarks = 15; string notPassRemarks = 15;
string telNum = 16; string telNum = 16;
string telAreaCode = 17;
} }
message UserListRequest{ message UserListRequest{
string domain = 1; string domain = 1;
@ -355,11 +392,13 @@ message ListByIDsRequest {
message SendMsgRequest { message SendMsgRequest {
string Domain = 1 [json_name = "domain",(validator.field) = {string_not_empty: true,human_error: "70001"} ]; string Domain = 1 [json_name = "domain",(validator.field) = {string_not_empty: true,human_error: "70001"} ];
string TelNum = 2 [json_name = "telNum",(validator.field) = {regex: "^1\\d{10}$",human_error: "70002"}]; string TelNum = 2 [json_name = "telNum"];
//string TelNum = 2 [json_name = "telNum",(validator.field) = {regex: "^1\\d{10}$",human_error: "70002"}];
string Project = 3 [json_name = "project"]; string Project = 3 [json_name = "project"];
uint32 signNo = 4; uint32 signNo = 4;
uint32 mId = 5; uint32 mId = 5;
string scope = 6; // string scope = 6; //
string zone = 7; //
} }
message SendCustomMsgRequest { message SendCustomMsgRequest {
@ -375,9 +414,10 @@ message SendCustomMsgRequest {
message CheckMsgRequest { message CheckMsgRequest {
string Domain = 1 [json_name = "domain",(validator.field) = {string_not_empty: true,human_error: "70001"} ]; string Domain = 1 [json_name = "domain",(validator.field) = {string_not_empty: true,human_error: "70001"} ];
string TelNum = 2 [json_name = "telNum",(validator.field) = {regex: "^1\\d{10}$",human_error: "70002"}]; string TelNum = 2 [json_name = "telNum"];
string Code = 3 [json_name = "code",(validator.field) = {string_not_empty: true,human_error: "70003"} ]; string Code = 3 [json_name = "code",(validator.field) = {string_not_empty: true,human_error: "70003"} ];
string scope = 4;// string scope = 4;//
string zone = 5; //
} }
message SendMsgStatusResponse { message SendMsgStatusResponse {
@ -545,11 +585,12 @@ message RegistRequest {
message LoginRequest { message LoginRequest {
string Domain = 1 [json_name = "domain",(validator.field) = {string_not_empty: true,human_error: "70001"} ]; string Domain = 1 [json_name = "domain",(validator.field) = {string_not_empty: true,human_error: "70001"} ];
string TelNum = 2 [json_name = "telNum",(validator.field) = {regex: "^1\\d{10}$",human_error: "70002"}]; string TelNum = 2 [json_name = "telNum"];
string Code = 3 [json_name = "code"]; string Code = 3 [json_name = "code"];
string Password = 4 [json_name = "password"]; string Password = 4 [json_name = "password"];
string Ip = 5 [json_name = "ip"]; string Ip = 5 [json_name = "ip"];
bool passCheckIp = 6 ; bool passCheckIp = 6 ;
string telAreaCode = 7;
} }
message TokenInfo { message TokenInfo {

View File

@ -17,6 +17,27 @@ var _ = proto.Marshal
var _ = fmt.Errorf var _ = fmt.Errorf
var _ = math.Inf var _ = math.Inf
func (this *SendNationMsgRequest) Validate() error {
if this.Domain == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Domain", fmt.Errorf(`70001`))
}
if this.TelNum == "" {
return github_com_mwitkow_go_proto_validators.FieldError("TelNum", fmt.Errorf(`70001`))
}
return nil
}
func (this *VerifySliderCaptchaResponse) Validate() error {
return nil
}
func (this *VerifySliderCaptchaRequest) Validate() error {
return nil
}
func (this *GenerateSliderCaptchaResponse) Validate() error {
return nil
}
func (this *GenerateSliderCaptchaRequest) Validate() error {
return nil
}
func (this *CheckRealNameResponse) Validate() error { func (this *CheckRealNameResponse) Validate() error {
return nil return nil
} }
@ -191,16 +212,10 @@ func (this *ListByIDsRequest) Validate() error {
} }
return nil return nil
} }
var _regex_SendMsgRequest_TelNum = regexp.MustCompile(`^1\d{10}$`)
func (this *SendMsgRequest) Validate() error { func (this *SendMsgRequest) Validate() error {
if this.Domain == "" { if this.Domain == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Domain", fmt.Errorf(`70001`)) return github_com_mwitkow_go_proto_validators.FieldError("Domain", fmt.Errorf(`70001`))
} }
if !_regex_SendMsgRequest_TelNum.MatchString(this.TelNum) {
return github_com_mwitkow_go_proto_validators.FieldError("TelNum", fmt.Errorf(`70002`))
}
return nil return nil
} }
@ -215,16 +230,10 @@ func (this *SendCustomMsgRequest) Validate() error {
} }
return nil return nil
} }
var _regex_CheckMsgRequest_TelNum = regexp.MustCompile(`^1\d{10}$`)
func (this *CheckMsgRequest) Validate() error { func (this *CheckMsgRequest) Validate() error {
if this.Domain == "" { if this.Domain == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Domain", fmt.Errorf(`70001`)) return github_com_mwitkow_go_proto_validators.FieldError("Domain", fmt.Errorf(`70001`))
} }
if !_regex_CheckMsgRequest_TelNum.MatchString(this.TelNum) {
return github_com_mwitkow_go_proto_validators.FieldError("TelNum", fmt.Errorf(`70002`))
}
if this.Code == "" { if this.Code == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Code", fmt.Errorf(`70003`)) return github_com_mwitkow_go_proto_validators.FieldError("Code", fmt.Errorf(`70003`))
} }
@ -353,16 +362,10 @@ func (this *RequestStatus) Validate() error {
func (this *RegistRequest) Validate() error { func (this *RegistRequest) Validate() error {
return nil return nil
} }
var _regex_LoginRequest_TelNum = regexp.MustCompile(`^1\d{10}$`)
func (this *LoginRequest) Validate() error { func (this *LoginRequest) Validate() error {
if this.Domain == "" { if this.Domain == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Domain", fmt.Errorf(`70001`)) return github_com_mwitkow_go_proto_validators.FieldError("Domain", fmt.Errorf(`70001`))
} }
if !_regex_LoginRequest_TelNum.MatchString(this.TelNum) {
return github_com_mwitkow_go_proto_validators.FieldError("TelNum", fmt.Errorf(`70002`))
}
return nil return nil
} }
func (this *TokenInfo) Validate() error { func (this *TokenInfo) Validate() error {

View File

@ -64,6 +64,9 @@ type AccountClient interface {
Register(ctx context.Context, in *RegistRequest, opts ...grpc_go.CallOption) (*RegisterResponse, common.ErrorWithAttachment) Register(ctx context.Context, in *RegistRequest, opts ...grpc_go.CallOption) (*RegisterResponse, common.ErrorWithAttachment)
UserList(ctx context.Context, in *UserListRequest, opts ...grpc_go.CallOption) (*UserListResponse, common.ErrorWithAttachment) UserList(ctx context.Context, in *UserListRequest, opts ...grpc_go.CallOption) (*UserListResponse, common.ErrorWithAttachment)
CheckRealName(ctx context.Context, in *CheckRealNameRequest, opts ...grpc_go.CallOption) (*CheckRealNameResponse, common.ErrorWithAttachment) CheckRealName(ctx context.Context, in *CheckRealNameRequest, opts ...grpc_go.CallOption) (*CheckRealNameResponse, common.ErrorWithAttachment)
GenerateSliderCaptcha(ctx context.Context, in *GenerateSliderCaptchaRequest, opts ...grpc_go.CallOption) (*GenerateSliderCaptchaResponse, common.ErrorWithAttachment)
VerifySliderCaptcha(ctx context.Context, in *VerifySliderCaptchaRequest, opts ...grpc_go.CallOption) (*VerifySliderCaptchaResponse, common.ErrorWithAttachment)
SendNationMsg(ctx context.Context, in *SendNationMsgRequest, opts ...grpc_go.CallOption) (*SendMsgStatusResponse, common.ErrorWithAttachment)
} }
type accountClient struct { type accountClient struct {
@ -106,6 +109,9 @@ type AccountClientImpl struct {
Register func(ctx context.Context, in *RegistRequest) (*RegisterResponse, error) Register func(ctx context.Context, in *RegistRequest) (*RegisterResponse, error)
UserList func(ctx context.Context, in *UserListRequest) (*UserListResponse, error) UserList func(ctx context.Context, in *UserListRequest) (*UserListResponse, error)
CheckRealName func(ctx context.Context, in *CheckRealNameRequest) (*CheckRealNameResponse, error) CheckRealName func(ctx context.Context, in *CheckRealNameRequest) (*CheckRealNameResponse, error)
GenerateSliderCaptcha func(ctx context.Context, in *GenerateSliderCaptchaRequest) (*GenerateSliderCaptchaResponse, error)
VerifySliderCaptcha func(ctx context.Context, in *VerifySliderCaptchaRequest) (*VerifySliderCaptchaResponse, error)
SendNationMsg func(ctx context.Context, in *SendNationMsgRequest) (*SendMsgStatusResponse, error)
} }
func (c *AccountClientImpl) GetDubboStub(cc *triple.TripleConn) AccountClient { func (c *AccountClientImpl) GetDubboStub(cc *triple.TripleConn) AccountClient {
@ -330,6 +336,24 @@ func (c *accountClient) CheckRealName(ctx context.Context, in *CheckRealNameRequ
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/CheckRealName", in, out) return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/CheckRealName", in, out)
} }
func (c *accountClient) GenerateSliderCaptcha(ctx context.Context, in *GenerateSliderCaptchaRequest, opts ...grpc_go.CallOption) (*GenerateSliderCaptchaResponse, common.ErrorWithAttachment) {
out := new(GenerateSliderCaptchaResponse)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GenerateSliderCaptcha", in, out)
}
func (c *accountClient) VerifySliderCaptcha(ctx context.Context, in *VerifySliderCaptchaRequest, opts ...grpc_go.CallOption) (*VerifySliderCaptchaResponse, common.ErrorWithAttachment) {
out := new(VerifySliderCaptchaResponse)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/VerifySliderCaptcha", in, out)
}
func (c *accountClient) SendNationMsg(ctx context.Context, in *SendNationMsgRequest, opts ...grpc_go.CallOption) (*SendMsgStatusResponse, common.ErrorWithAttachment) {
out := new(SendMsgStatusResponse)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/SendNationMsg", in, out)
}
// AccountServer is the server API for Account service. // AccountServer is the server API for Account service.
// All implementations must embed UnimplementedAccountServer // All implementations must embed UnimplementedAccountServer
// for forward compatibility // for forward compatibility
@ -370,6 +394,9 @@ type AccountServer interface {
Register(context.Context, *RegistRequest) (*RegisterResponse, error) Register(context.Context, *RegistRequest) (*RegisterResponse, error)
UserList(context.Context, *UserListRequest) (*UserListResponse, error) UserList(context.Context, *UserListRequest) (*UserListResponse, error)
CheckRealName(context.Context, *CheckRealNameRequest) (*CheckRealNameResponse, error) CheckRealName(context.Context, *CheckRealNameRequest) (*CheckRealNameResponse, error)
GenerateSliderCaptcha(context.Context, *GenerateSliderCaptchaRequest) (*GenerateSliderCaptchaResponse, error)
VerifySliderCaptcha(context.Context, *VerifySliderCaptchaRequest) (*VerifySliderCaptchaResponse, error)
SendNationMsg(context.Context, *SendNationMsgRequest) (*SendMsgStatusResponse, error)
mustEmbedUnimplementedAccountServer() mustEmbedUnimplementedAccountServer()
} }
@ -483,6 +510,15 @@ func (UnimplementedAccountServer) UserList(context.Context, *UserListRequest) (*
func (UnimplementedAccountServer) CheckRealName(context.Context, *CheckRealNameRequest) (*CheckRealNameResponse, error) { func (UnimplementedAccountServer) CheckRealName(context.Context, *CheckRealNameRequest) (*CheckRealNameResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method CheckRealName not implemented") return nil, status.Errorf(codes.Unimplemented, "method CheckRealName not implemented")
} }
func (UnimplementedAccountServer) GenerateSliderCaptcha(context.Context, *GenerateSliderCaptchaRequest) (*GenerateSliderCaptchaResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GenerateSliderCaptcha not implemented")
}
func (UnimplementedAccountServer) VerifySliderCaptcha(context.Context, *VerifySliderCaptchaRequest) (*VerifySliderCaptchaResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method VerifySliderCaptcha not implemented")
}
func (UnimplementedAccountServer) SendNationMsg(context.Context, *SendNationMsgRequest) (*SendMsgStatusResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SendNationMsg not implemented")
}
func (s *UnimplementedAccountServer) XXX_SetProxyImpl(impl protocol.Invoker) { func (s *UnimplementedAccountServer) XXX_SetProxyImpl(impl protocol.Invoker) {
s.proxyImpl = impl s.proxyImpl = impl
} }
@ -1526,6 +1562,93 @@ func _Account_CheckRealName_Handler(srv interface{}, ctx context.Context, dec fu
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _Account_GenerateSliderCaptcha_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(GenerateSliderCaptchaRequest)
if err := dec(in); err != nil {
return nil, err
}
base := srv.(dubbo3.Dubbo3GrpcService)
args := []interface{}{}
args = append(args, in)
md, _ := metadata.FromIncomingContext(ctx)
invAttachment := make(map[string]interface{}, len(md))
for k, v := range md {
invAttachment[k] = v
}
invo := invocation.NewRPCInvocation("GenerateSliderCaptcha", args, invAttachment)
if interceptor == nil {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
info := &grpc_go.UnaryServerInfo{
Server: srv,
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
return interceptor(ctx, in, info, handler)
}
func _Account_VerifySliderCaptcha_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(VerifySliderCaptchaRequest)
if err := dec(in); err != nil {
return nil, err
}
base := srv.(dubbo3.Dubbo3GrpcService)
args := []interface{}{}
args = append(args, in)
md, _ := metadata.FromIncomingContext(ctx)
invAttachment := make(map[string]interface{}, len(md))
for k, v := range md {
invAttachment[k] = v
}
invo := invocation.NewRPCInvocation("VerifySliderCaptcha", args, invAttachment)
if interceptor == nil {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
info := &grpc_go.UnaryServerInfo{
Server: srv,
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
return interceptor(ctx, in, info, handler)
}
func _Account_SendNationMsg_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(SendNationMsgRequest)
if err := dec(in); err != nil {
return nil, err
}
base := srv.(dubbo3.Dubbo3GrpcService)
args := []interface{}{}
args = append(args, in)
md, _ := metadata.FromIncomingContext(ctx)
invAttachment := make(map[string]interface{}, len(md))
for k, v := range md {
invAttachment[k] = v
}
invo := invocation.NewRPCInvocation("SendNationMsg", args, invAttachment)
if interceptor == nil {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
info := &grpc_go.UnaryServerInfo{
Server: srv,
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
return interceptor(ctx, in, info, handler)
}
// Account_ServiceDesc is the grpc_go.ServiceDesc for Account service. // Account_ServiceDesc is the grpc_go.ServiceDesc for Account service.
// It's only intended for direct use with grpc_go.RegisterService, // It's only intended for direct use with grpc_go.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@ -1673,6 +1796,18 @@ var Account_ServiceDesc = grpc_go.ServiceDesc{
MethodName: "CheckRealName", MethodName: "CheckRealName",
Handler: _Account_CheckRealName_Handler, Handler: _Account_CheckRealName_Handler,
}, },
{
MethodName: "GenerateSliderCaptcha",
Handler: _Account_GenerateSliderCaptcha_Handler,
},
{
MethodName: "VerifySliderCaptcha",
Handler: _Account_VerifySliderCaptcha_Handler,
},
{
MethodName: "SendNationMsg",
Handler: _Account_SendNationMsg_Handler,
},
}, },
Streams: []grpc_go.StreamDesc{}, Streams: []grpc_go.StreamDesc{},
Metadata: "api/account/account.proto", Metadata: "api/account/account.proto",

View File

@ -9,7 +9,7 @@ dubbo:
AccountClientImpl: AccountClientImpl:
protocol: tri protocol: tri
retries: 0 retries: 0
interface: com.fontree.microservices.common.account interface: com.fontree.microservices.common.micro.account
# filter: cshutdown,sign,fonDomainFilter,fonValidateFilter # filter: cshutdown,sign,fonDomainFilter,fonValidateFilter
# params: # params:
# .accessKeyId: "Accountksl" # .accessKeyId: "Accountksl"

View File

@ -30,7 +30,7 @@ const (
Status_Out_House //已出库 Status_Out_House //已出库
Status_Not_Pay //未付款 Status_Not_Pay //未付款
) )
const ZoneCn = "86"
const ( const (
DateNormalFormat = "2006-01-02 15:04:05" DateNormalFormat = "2006-01-02 15:04:05"
DateNormalYMDFormat = "2006-01-02" DateNormalYMDFormat = "2006-01-02"

View File

@ -46,6 +46,8 @@ func NewRouter() *gin.Engine {
r.POST("user/send", account.SendMsg) //发送验证码 r.POST("user/send", account.SendMsg) //发送验证码
r.POST("user/logout", account.UserLogout) //登出 r.POST("user/logout", account.UserLogout) //登出
r.POST("user/check/msg", account.CheckMsg) //校验验证码 r.POST("user/check/msg", account.CheckMsg) //校验验证码
r.POST("generate/captcha", account.GenerateCaptcha) //生成滑块验证码
r.POST("validate/captcha", account.ValidateCaptcha) //验证滑块验证码
acRoute := r.Group("/user") acRoute := r.Group("/user")
acRoute.Use(middleware.CheckLogin(service.AccountProvider)) acRoute.Use(middleware.CheckLogin(service.AccountProvider))
{ {
@ -54,7 +56,7 @@ func NewRouter() *gin.Engine {
} }
{ {
acRoute.POST("list", account.UserList) //用户列表 acRoute.POST("list", account.UserList) //用户列表
acRoute.POST("approval", account.UserApproval) //用户列表 acRoute.POST("approval", account.UserApproval) //实名审核
} }
} }
{ {

View File

@ -2,14 +2,18 @@ package account
import ( import (
"context" "context"
"errors"
"fmt"
"fonchain-fiee/api/account" "fonchain-fiee/api/account"
"fonchain-fiee/pkg/config" "fonchain-fiee/pkg/cache"
"fonchain-fiee/pkg/e" "fonchain-fiee/pkg/e"
"fonchain-fiee/pkg/model/login" "fonchain-fiee/pkg/model/login"
"fonchain-fiee/pkg/model/union" "fonchain-fiee/pkg/model/union"
"fonchain-fiee/pkg/service" "fonchain-fiee/pkg/service"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding" "github.com/gin-gonic/gin/binding"
"github.com/go-redis/redis"
"time"
) )
func UserApproval(c *gin.Context) { func UserApproval(c *gin.Context) {
@ -58,17 +62,75 @@ func UserInfo(c *gin.Context) {
return return
} }
// SendMsg 用户登录操作 // SendMsg 用户发送验证码
func SendMsg(c *gin.Context) { func SendMsg(c *gin.Context) {
var req account.SendMsgRequest var req account.SendMsgRequest
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil { if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
service.Error(c, err) service.Error(c, err)
return return
} }
//req.Domain = "app" req.Project = "fiee"
req.SignNo = uint32(config.DefaultSignNo) req.TelNum = req.Zone + req.TelNum
if req.Zone != e.ZoneCn && req.Zone != "" {
// ============================== redis检查ip开始
ip := c.ClientIP()
daykey := "day_sms_limit:" + ip
minutekey := "minute_sms_limit:" + ip
duration := time.Second
isBlacklisted, blackErr := cache.RedisClient.SIsMember("nation_sms_blacklist", ip).Result()
if blackErr != nil {
service.Error(c, errors.New("Redis error"))
return
}
if isBlacklisted {
fmt.Println("当前ip手机号在黑名单中", ip, ";手机号:", req.TelNum, ";domain", req.Domain)
service.Success(c, "succes!")
return
}
// 一分钟5次一天30次
if dayCount, redisErr := cache.RedisClient.Get(daykey).Int(); redisErr == redis.Nil {
cache.RedisClient.Set(daykey, 1, 24*time.Hour)
} else if redisErr != nil {
service.Error(c, errors.New("Redis error"))
return
} else if dayCount >= 30 {
cache.RedisClient.SAdd("nation_sms_blacklist", ip)
cache.RedisClient.Expire("nation_sms_blacklist", 24*time.Hour) // 黑名单记录有效期为24小时
fmt.Println("当前ip手机号在黑名单中", ip, ";手机号:", req.TelNum, ";domain", req.Domain)
service.Success(c, "succes!")
return
}
if minuteCount, redisErr := cache.RedisClient.Get(minutekey).Int(); redisErr == redis.Nil {
cache.RedisClient.Set(minutekey, 1, duration)
} else if redisErr != nil {
service.Error(c, errors.New("Redis error"))
return
} else if minuteCount >= 5 {
fmt.Println("当前ip触发每分钟5次限制", ip, ";手机号:", req.TelNum, ";domain", req.Domain)
service.Success(c, "succes!")
return
}
cache.RedisClient.Incr(daykey)
cache.RedisClient.Incr(minutekey)
// ============================== redis检查ip结束
tempReq := &account.SendNationMsgRequest{
Domain: req.Domain,
TelNum: req.TelNum,
Project: req.Project,
SignNo: req.SignNo,
MId: req.MId,
Scope: req.Scope,
}
res, err := service.AccountProvider.SendNationMsg(context.Background(), tempReq)
if err != nil {
service.Error(c, err)
return
}
service.Success(c, res)
return
} else {
res, err := service.AccountProvider.SendMsg(context.Background(), &req) res, err := service.AccountProvider.SendMsg(context.Background(), &req)
if err != nil { if err != nil {
service.Error(c, err) service.Error(c, err)
@ -78,6 +140,16 @@ func SendMsg(c *gin.Context) {
service.Success(c, res) service.Success(c, res)
return return
} }
//req.Domain = "app"
//req.SignNo = uint32(config.DefaultSignNo)
//res, err := service.AccountProvider.SendMsg(context.Background(), &req)
//if err != nil {
// service.Error(c, err)
// return
//}
}
func RealName(c *gin.Context) { func RealName(c *gin.Context) {
var req account.RealNameRequest var req account.RealNameRequest
@ -106,7 +178,7 @@ func CheckMsg(c *gin.Context) {
service.Error(c, err) service.Error(c, err)
return return
} }
req.TelNum = req.Zone + req.TelNum
res, err := service.AccountProvider.CheckMsg(context.Background(), &req) res, err := service.AccountProvider.CheckMsg(context.Background(), &req)
if err != nil { if err != nil {
service.Error(c, err) service.Error(c, err)
@ -116,7 +188,45 @@ func CheckMsg(c *gin.Context) {
service.Success(c, res) service.Success(c, res)
return return
} }
func GenerateCaptcha(c *gin.Context) {
req := account.GenerateSliderCaptchaRequest{}
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
service.Error(c, err)
return
}
res, err := service.AccountProvider.GenerateSliderCaptcha(context.Background(), &req)
if err != nil {
service.Error(c, err)
return
}
service.Success(c, res)
}
func ValidateCaptcha(c *gin.Context) {
req := account.VerifySliderCaptchaRequest{}
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
service.Error(c, err)
return
}
res, err := service.AccountProvider.VerifySliderCaptcha(context.Background(), &req)
if err != nil {
service.Error(c, err)
return
}
service.Success(c, res)
}
func UserLogout(c *gin.Context) { func UserLogout(c *gin.Context) {
req := account.DecryptJwtRequest{} req := account.DecryptJwtRequest{}
req.Token = c.GetHeader(e.Authorization) req.Token = c.GetHeader(e.Authorization)
@ -145,6 +255,7 @@ func UserRegister(c *gin.Context) {
Domain: req.Domain, Domain: req.Domain,
TelNum: req.TelNum, TelNum: req.TelNum,
Code: req.Code, Code: req.Code,
TelAreaCode: req.TelAreaCode,
}) })
if err != nil { if err != nil {
service.Error(c, err) service.Error(c, err)