You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
package service
|
|
|
|
import (
|
|
"context"
|
|
"github.com/go-kratos/kratos/v2/errors"
|
|
"net/http"
|
|
"regexp"
|
|
|
|
pb "customer/api/customer"
|
|
)
|
|
|
|
type CustomerService struct {
|
|
pb.UnimplementedCustomerServer
|
|
}
|
|
|
|
func NewCustomerService() *CustomerService {
|
|
return &CustomerService{}
|
|
}
|
|
|
|
func (s *CustomerService) GetVerifyCode(ctx context.Context, req *pb.GetVerifyCodeReq) (*pb.GetVerifyCodeReply, error) {
|
|
// # 验证电话号码
|
|
pattern := regexp.MustCompile(`^(13\d|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18\d|19[0-35-9])\d{8}$`)
|
|
if !pattern.MatchString(req.PhoneNumber) {
|
|
// 如果正则匹配失败,则返回错误
|
|
return nil,
|
|
errors.New(http.StatusBadRequest, "PHONENUMBER_ERROR", "电话号码格式错误")
|
|
}
|
|
// # gRPC 调用验证码生成服务获取验证码
|
|
|
|
// # 临时存储
|
|
// # gRPC 调用短信服务发送短信
|
|
// # 成功响应,告知请求端,验证码已发送
|
|
return &pb.GetVerifyCodeReply{
|
|
Error: false,
|
|
Message: "验证码已发送",
|
|
Duration: 60,
|
|
}, nil
|
|
}
|
|
func (s *CustomerService) Login(ctx context.Context, req *pb.LoginReq) (*pb.LoginReply, error) {
|
|
return &pb.LoginReply{}, nil
|
|
}
|
|
func (s *CustomerService) Logout(ctx context.Context, req *pb.LogoutReq) (*pb.LogoutReply, error) {
|
|
return &pb.LogoutReply{}, nil
|
|
}
|