Compare commits

...

4 Commits

Author SHA1 Message Date
Wbbbbjikjgo 1820438dc8 init_jwt
9 months ago
Wbbbbjikjgo b7afa35d9d init_login
9 months ago
Wbbbbjikjgo 7aa55ac46e init_table
9 months ago
Wbbbbjikjgo 806647c5ea init_mysql
9 months ago

@ -21,6 +21,224 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
) )
// 推出
type LogoutReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *LogoutReq) Reset() {
*x = LogoutReq{}
mi := &file_api_customer_customer_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *LogoutReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LogoutReq) ProtoMessage() {}
func (x *LogoutReq) ProtoReflect() protoreflect.Message {
mi := &file_api_customer_customer_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LogoutReq.ProtoReflect.Descriptor instead.
func (*LogoutReq) Descriptor() ([]byte, []int) {
return file_api_customer_customer_proto_rawDescGZIP(), []int{0}
}
type LogoutResp struct {
state protoimpl.MessageState `protogen:"open.v1"`
Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *LogoutResp) Reset() {
*x = LogoutResp{}
mi := &file_api_customer_customer_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *LogoutResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LogoutResp) ProtoMessage() {}
func (x *LogoutResp) ProtoReflect() protoreflect.Message {
mi := &file_api_customer_customer_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LogoutResp.ProtoReflect.Descriptor instead.
func (*LogoutResp) Descriptor() ([]byte, []int) {
return file_api_customer_customer_proto_rawDescGZIP(), []int{1}
}
func (x *LogoutResp) GetCode() int64 {
if x != nil {
return x.Code
}
return 0
}
func (x *LogoutResp) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
// 登录的消息
type LoginReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Telephone string `protobuf:"bytes,1,opt,name=telephone,proto3" json:"telephone,omitempty"`
VerifyCode string `protobuf:"bytes,2,opt,name=verify_code,json=verifyCode,proto3" json:"verify_code,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *LoginReq) Reset() {
*x = LoginReq{}
mi := &file_api_customer_customer_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *LoginReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LoginReq) ProtoMessage() {}
func (x *LoginReq) ProtoReflect() protoreflect.Message {
mi := &file_api_customer_customer_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LoginReq.ProtoReflect.Descriptor instead.
func (*LoginReq) Descriptor() ([]byte, []int) {
return file_api_customer_customer_proto_rawDescGZIP(), []int{2}
}
func (x *LoginReq) GetTelephone() string {
if x != nil {
return x.Telephone
}
return ""
}
func (x *LoginReq) GetVerifyCode() string {
if x != nil {
return x.VerifyCode
}
return ""
}
type LoginResp struct {
state protoimpl.MessageState `protogen:"open.v1"`
Code int64 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
Token string `protobuf:"bytes,3,opt,name=token,proto3" json:"token,omitempty"`
TokenCreateAt int64 `protobuf:"varint,4,opt,name=token_create_at,json=tokenCreateAt,proto3" json:"token_create_at,omitempty"`
TokenLife int64 `protobuf:"varint,5,opt,name=token_life,json=tokenLife,proto3" json:"token_life,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *LoginResp) Reset() {
*x = LoginResp{}
mi := &file_api_customer_customer_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *LoginResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LoginResp) ProtoMessage() {}
func (x *LoginResp) ProtoReflect() protoreflect.Message {
mi := &file_api_customer_customer_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LoginResp.ProtoReflect.Descriptor instead.
func (*LoginResp) Descriptor() ([]byte, []int) {
return file_api_customer_customer_proto_rawDescGZIP(), []int{3}
}
func (x *LoginResp) GetCode() int64 {
if x != nil {
return x.Code
}
return 0
}
func (x *LoginResp) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
func (x *LoginResp) GetToken() string {
if x != nil {
return x.Token
}
return ""
}
func (x *LoginResp) GetTokenCreateAt() int64 {
if x != nil {
return x.TokenCreateAt
}
return 0
}
func (x *LoginResp) GetTokenLife() int64 {
if x != nil {
return x.TokenLife
}
return 0
}
type GetVerifyCodeReq struct { type GetVerifyCodeReq struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
Telephone string `protobuf:"bytes,1,opt,name=telephone,proto3" json:"telephone,omitempty"` Telephone string `protobuf:"bytes,1,opt,name=telephone,proto3" json:"telephone,omitempty"`
@ -30,7 +248,7 @@ type GetVerifyCodeReq struct {
func (x *GetVerifyCodeReq) Reset() { func (x *GetVerifyCodeReq) Reset() {
*x = GetVerifyCodeReq{} *x = GetVerifyCodeReq{}
mi := &file_api_customer_customer_proto_msgTypes[0] mi := &file_api_customer_customer_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -42,7 +260,7 @@ func (x *GetVerifyCodeReq) String() string {
func (*GetVerifyCodeReq) ProtoMessage() {} func (*GetVerifyCodeReq) ProtoMessage() {}
func (x *GetVerifyCodeReq) ProtoReflect() protoreflect.Message { func (x *GetVerifyCodeReq) ProtoReflect() protoreflect.Message {
mi := &file_api_customer_customer_proto_msgTypes[0] mi := &file_api_customer_customer_proto_msgTypes[4]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -55,7 +273,7 @@ func (x *GetVerifyCodeReq) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetVerifyCodeReq.ProtoReflect.Descriptor instead. // Deprecated: Use GetVerifyCodeReq.ProtoReflect.Descriptor instead.
func (*GetVerifyCodeReq) Descriptor() ([]byte, []int) { func (*GetVerifyCodeReq) Descriptor() ([]byte, []int) {
return file_api_customer_customer_proto_rawDescGZIP(), []int{0} return file_api_customer_customer_proto_rawDescGZIP(), []int{4}
} }
func (x *GetVerifyCodeReq) GetTelephone() string { func (x *GetVerifyCodeReq) GetTelephone() string {
@ -78,7 +296,7 @@ type GetVerifyCodeResp struct {
func (x *GetVerifyCodeResp) Reset() { func (x *GetVerifyCodeResp) Reset() {
*x = GetVerifyCodeResp{} *x = GetVerifyCodeResp{}
mi := &file_api_customer_customer_proto_msgTypes[1] mi := &file_api_customer_customer_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -90,7 +308,7 @@ func (x *GetVerifyCodeResp) String() string {
func (*GetVerifyCodeResp) ProtoMessage() {} func (*GetVerifyCodeResp) ProtoMessage() {}
func (x *GetVerifyCodeResp) ProtoReflect() protoreflect.Message { func (x *GetVerifyCodeResp) ProtoReflect() protoreflect.Message {
mi := &file_api_customer_customer_proto_msgTypes[1] mi := &file_api_customer_customer_proto_msgTypes[5]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -103,7 +321,7 @@ func (x *GetVerifyCodeResp) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetVerifyCodeResp.ProtoReflect.Descriptor instead. // Deprecated: Use GetVerifyCodeResp.ProtoReflect.Descriptor instead.
func (*GetVerifyCodeResp) Descriptor() ([]byte, []int) { func (*GetVerifyCodeResp) Descriptor() ([]byte, []int) {
return file_api_customer_customer_proto_rawDescGZIP(), []int{1} return file_api_customer_customer_proto_rawDescGZIP(), []int{5}
} }
func (x *GetVerifyCodeResp) GetCode() int64 { func (x *GetVerifyCodeResp) GetCode() int64 {
@ -148,34 +366,63 @@ var file_api_customer_customer_proto_rawDesc = []byte{
0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x61, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x61,
0x70, 0x69, 0x2e, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x70, 0x69, 0x2e, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x1a, 0x1c, 0x67, 0x6f, 0x6f,
0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x30, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x0b, 0x0a, 0x09, 0x4c, 0x6f, 0x67,
0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1c, 0x0a, 0x6f, 0x75, 0x74, 0x52, 0x65, 0x71, 0x22, 0x3a, 0x0a, 0x0a, 0x4c, 0x6f, 0x67, 0x6f, 0x75, 0x74,
0x09, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01,
0x52, 0x09, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x22, 0xbe, 0x01, 0x0a, 0x11, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73,
0x47, 0x65, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61,
0x70, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x67, 0x65, 0x22, 0x49, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x1c,
0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x0a, 0x09, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x09, 0x52, 0x09, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x12, 0x1f, 0x0a, 0x0b,
0x1f, 0x0a, 0x0b, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x09, 0x52, 0x0a, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x96, 0x01,
0x12, 0x30, 0x0a, 0x14, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x0a, 0x09, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x63,
0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x12, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12,
0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x54, 0x69, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x6d, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x5f, 0x63, 0x6f, 0x64, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b,
0x65, 0x5f, 0x6c, 0x69, 0x66, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x76, 0x65, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12,
0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x4c, 0x69, 0x66, 0x65, 0x32, 0x8b, 0x01, 0x0a, 0x26, 0x0a, 0x0f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f,
0x08, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x12, 0x7f, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x43,
0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1e, 0x2e, 0x61, 0x70, 0x69, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x74, 0x6f, 0x6b, 0x65, 0x6e,
0x2e, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72, 0x5f, 0x6c, 0x69, 0x66, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x6f, 0x6b,
0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x1f, 0x2e, 0x61, 0x70, 0x69, 0x65, 0x6e, 0x4c, 0x69, 0x66, 0x65, 0x22, 0x30, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72,
0x2e, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x65,
0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74,
0x93, 0x02, 0x27, 0x12, 0x25, 0x2f, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2f, 0x67, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x22, 0xbe, 0x01, 0x0a, 0x11, 0x47, 0x65, 0x74,
0x65, 0x74, 0x2d, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x2d, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x7b, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12,
0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x7d, 0x42, 0x20, 0x5a, 0x1e, 0x63, 0x75, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f,
0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20,
0x6d, 0x65, 0x72, 0x3b, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x0b,
0x6f, 0x74, 0x6f, 0x33, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28,
0x09, 0x52, 0x0a, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x30, 0x0a,
0x14, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65,
0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x12, 0x76, 0x65, 0x72,
0x69, 0x66, 0x79, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12,
0x28, 0x0a, 0x10, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x5f, 0x6c,
0x69, 0x66, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x76, 0x65, 0x72, 0x69, 0x66,
0x79, 0x43, 0x6f, 0x64, 0x65, 0x4c, 0x69, 0x66, 0x65, 0x32, 0xba, 0x02, 0x0a, 0x08, 0x43, 0x75,
0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x12, 0x7f, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72,
0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x75,
0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79,
0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x1f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x75,
0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79,
0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x2d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x27,
0x12, 0x25, 0x2f, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2f, 0x67, 0x65, 0x74, 0x2d,
0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x2d, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x7b, 0x74, 0x65, 0x6c,
0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x7d, 0x12, 0x54, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e,
0x12, 0x16, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2e,
0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63,
0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73,
0x70, 0x22, 0x1a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x3a, 0x01, 0x2a, 0x22, 0x0f, 0x2f, 0x63,
0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2f, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x57, 0x0a,
0x08, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x6f, 0x75, 0x74, 0x12, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e,
0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2e, 0x4c, 0x6f, 0x67, 0x6f, 0x75, 0x74, 0x52,
0x65, 0x71, 0x1a, 0x18, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65,
0x72, 0x2e, 0x4c, 0x6f, 0x67, 0x6f, 0x75, 0x74, 0x52, 0x65, 0x73, 0x70, 0x22, 0x18, 0x82, 0xd3,
0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2f,
0x6c, 0x6f, 0x67, 0x6f, 0x75, 0x74, 0x42, 0x20, 0x5a, 0x1e, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d,
0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x3b,
0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -190,16 +437,24 @@ func file_api_customer_customer_proto_rawDescGZIP() []byte {
return file_api_customer_customer_proto_rawDescData return file_api_customer_customer_proto_rawDescData
} }
var file_api_customer_customer_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_api_customer_customer_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_api_customer_customer_proto_goTypes = []any{ var file_api_customer_customer_proto_goTypes = []any{
(*GetVerifyCodeReq)(nil), // 0: api.customer.GetVerifyCodeReq (*LogoutReq)(nil), // 0: api.customer.LogoutReq
(*GetVerifyCodeResp)(nil), // 1: api.customer.GetVerifyCodeResp (*LogoutResp)(nil), // 1: api.customer.LogoutResp
(*LoginReq)(nil), // 2: api.customer.LoginReq
(*LoginResp)(nil), // 3: api.customer.LoginResp
(*GetVerifyCodeReq)(nil), // 4: api.customer.GetVerifyCodeReq
(*GetVerifyCodeResp)(nil), // 5: api.customer.GetVerifyCodeResp
} }
var file_api_customer_customer_proto_depIdxs = []int32{ var file_api_customer_customer_proto_depIdxs = []int32{
0, // 0: api.customer.Customer.GetVerifyCode:input_type -> api.customer.GetVerifyCodeReq 4, // 0: api.customer.Customer.GetVerifyCode:input_type -> api.customer.GetVerifyCodeReq
1, // 1: api.customer.Customer.GetVerifyCode:output_type -> api.customer.GetVerifyCodeResp 2, // 1: api.customer.Customer.Login:input_type -> api.customer.LoginReq
1, // [1:2] is the sub-list for method output_type 0, // 2: api.customer.Customer.Loginout:input_type -> api.customer.LogoutReq
0, // [0:1] is the sub-list for method input_type 5, // 3: api.customer.Customer.GetVerifyCode:output_type -> api.customer.GetVerifyCodeResp
3, // 4: api.customer.Customer.Login:output_type -> api.customer.LoginResp
1, // 5: api.customer.Customer.Loginout:output_type -> api.customer.LogoutResp
3, // [3:6] is the sub-list for method output_type
0, // [0:3] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name 0, // [0:0] is the sub-list for field type_name
@ -216,7 +471,7 @@ func file_api_customer_customer_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_api_customer_customer_proto_rawDesc, RawDescriptor: file_api_customer_customer_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 2, NumMessages: 6,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

@ -4,13 +4,49 @@ package api.customer;
import "google/api/annotations.proto"; import "google/api/annotations.proto";
option go_package = "customer/api/customer;customer"; option go_package = "customer/api/customer;customer";
//
service Customer { service Customer {
//
rpc GetVerifyCode(GetVerifyCodeReq) returns (GetVerifyCodeResp){ rpc GetVerifyCode(GetVerifyCodeReq) returns (GetVerifyCodeResp){
option (google.api.http)={//{telephone} option (google.api.http)={//{telephone}
get:"/customer/get-verify-code/{telephone}" get:"/customer/get-verify-code/{telephone}"
}; };
} }
//
rpc Login (LoginReq) returns (LoginResp){
option (google.api.http)={
post:"/customer/login",
body:"*",
};
}
//退
rpc Loginout (LogoutReq) returns (LogoutResp){
option (google.api.http)={
get:"/customer/logout",
};
}
}
//
message LogoutReq{
}
message LogoutResp{
int64 code =1;
string message =2;
}
//
message LoginReq{
string telephone =1;
string verify_code =2;
};
message LoginResp{
int64 code =1;
string message =2;
string token = 3;
int64 token_create_at=4;
int64 token_life=5;
} }
message GetVerifyCodeReq{ message GetVerifyCodeReq{
@ -22,4 +58,5 @@ message GetVerifyCodeResp {
string verify_code =3; string verify_code =3;
int64 verify_generate_time=4; int64 verify_generate_time=4;
int64 verify_code_life=5; int64 verify_code_life=5;
} }
//退

@ -20,13 +20,22 @@ const _ = grpc.SupportPackageIsVersion9
const ( const (
Customer_GetVerifyCode_FullMethodName = "/api.customer.Customer/GetVerifyCode" Customer_GetVerifyCode_FullMethodName = "/api.customer.Customer/GetVerifyCode"
Customer_Login_FullMethodName = "/api.customer.Customer/Login"
Customer_Loginout_FullMethodName = "/api.customer.Customer/Loginout"
) )
// CustomerClient is the client API for Customer service. // CustomerClient is the client API for Customer service.
// //
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
//
// 验证码
type CustomerClient interface { type CustomerClient interface {
// 验证码
GetVerifyCode(ctx context.Context, in *GetVerifyCodeReq, opts ...grpc.CallOption) (*GetVerifyCodeResp, error) GetVerifyCode(ctx context.Context, in *GetVerifyCodeReq, opts ...grpc.CallOption) (*GetVerifyCodeResp, error)
// 登录
Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*LoginResp, error)
// 退出
Loginout(ctx context.Context, in *LogoutReq, opts ...grpc.CallOption) (*LogoutResp, error)
} }
type customerClient struct { type customerClient struct {
@ -47,11 +56,38 @@ func (c *customerClient) GetVerifyCode(ctx context.Context, in *GetVerifyCodeReq
return out, nil return out, nil
} }
func (c *customerClient) Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*LoginResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(LoginResp)
err := c.cc.Invoke(ctx, Customer_Login_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *customerClient) Loginout(ctx context.Context, in *LogoutReq, opts ...grpc.CallOption) (*LogoutResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(LogoutResp)
err := c.cc.Invoke(ctx, Customer_Loginout_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// CustomerServer is the server API for Customer service. // CustomerServer is the server API for Customer service.
// All implementations must embed UnimplementedCustomerServer // All implementations must embed UnimplementedCustomerServer
// for forward compatibility. // for forward compatibility.
//
// 验证码
type CustomerServer interface { type CustomerServer interface {
// 验证码
GetVerifyCode(context.Context, *GetVerifyCodeReq) (*GetVerifyCodeResp, error) GetVerifyCode(context.Context, *GetVerifyCodeReq) (*GetVerifyCodeResp, error)
// 登录
Login(context.Context, *LoginReq) (*LoginResp, error)
// 退出
Loginout(context.Context, *LogoutReq) (*LogoutResp, error)
mustEmbedUnimplementedCustomerServer() mustEmbedUnimplementedCustomerServer()
} }
@ -65,6 +101,12 @@ type UnimplementedCustomerServer struct{}
func (UnimplementedCustomerServer) GetVerifyCode(context.Context, *GetVerifyCodeReq) (*GetVerifyCodeResp, error) { func (UnimplementedCustomerServer) GetVerifyCode(context.Context, *GetVerifyCodeReq) (*GetVerifyCodeResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetVerifyCode not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetVerifyCode not implemented")
} }
func (UnimplementedCustomerServer) Login(context.Context, *LoginReq) (*LoginResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Login not implemented")
}
func (UnimplementedCustomerServer) Loginout(context.Context, *LogoutReq) (*LogoutResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Loginout not implemented")
}
func (UnimplementedCustomerServer) mustEmbedUnimplementedCustomerServer() {} func (UnimplementedCustomerServer) mustEmbedUnimplementedCustomerServer() {}
func (UnimplementedCustomerServer) testEmbeddedByValue() {} func (UnimplementedCustomerServer) testEmbeddedByValue() {}
@ -104,6 +146,42 @@ func _Customer_GetVerifyCode_Handler(srv interface{}, ctx context.Context, dec f
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _Customer_Login_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LoginReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CustomerServer).Login(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Customer_Login_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CustomerServer).Login(ctx, req.(*LoginReq))
}
return interceptor(ctx, in, info, handler)
}
func _Customer_Loginout_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LogoutReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CustomerServer).Loginout(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Customer_Loginout_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CustomerServer).Loginout(ctx, req.(*LogoutReq))
}
return interceptor(ctx, in, info, handler)
}
// Customer_ServiceDesc is the grpc.ServiceDesc for Customer service. // Customer_ServiceDesc is the grpc.ServiceDesc for Customer service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@ -115,6 +193,14 @@ var Customer_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetVerifyCode", MethodName: "GetVerifyCode",
Handler: _Customer_GetVerifyCode_Handler, Handler: _Customer_GetVerifyCode_Handler,
}, },
{
MethodName: "Login",
Handler: _Customer_Login_Handler,
},
{
MethodName: "Loginout",
Handler: _Customer_Loginout_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "api/customer/customer.proto", Metadata: "api/customer/customer.proto",

@ -20,14 +20,23 @@ var _ = binding.EncodeURL
const _ = http.SupportPackageIsVersion1 const _ = http.SupportPackageIsVersion1
const OperationCustomerGetVerifyCode = "/api.customer.Customer/GetVerifyCode" const OperationCustomerGetVerifyCode = "/api.customer.Customer/GetVerifyCode"
const OperationCustomerLogin = "/api.customer.Customer/Login"
const OperationCustomerLoginout = "/api.customer.Customer/Loginout"
type CustomerHTTPServer interface { type CustomerHTTPServer interface {
// GetVerifyCode验证码
GetVerifyCode(context.Context, *GetVerifyCodeReq) (*GetVerifyCodeResp, error) GetVerifyCode(context.Context, *GetVerifyCodeReq) (*GetVerifyCodeResp, error)
// Login登录
Login(context.Context, *LoginReq) (*LoginResp, error)
// Loginout退出
Loginout(context.Context, *LogoutReq) (*LogoutResp, error)
} }
func RegisterCustomerHTTPServer(s *http.Server, srv CustomerHTTPServer) { func RegisterCustomerHTTPServer(s *http.Server, srv CustomerHTTPServer) {
r := s.Route("/") r := s.Route("/")
r.GET("/customer/get-verify-code/{telephone}", _Customer_GetVerifyCode0_HTTP_Handler(srv)) r.GET("/customer/get-verify-code/{telephone}", _Customer_GetVerifyCode0_HTTP_Handler(srv))
r.POST("/customer/login", _Customer_Login0_HTTP_Handler(srv))
r.GET("/customer/logout", _Customer_Loginout0_HTTP_Handler(srv))
} }
func _Customer_GetVerifyCode0_HTTP_Handler(srv CustomerHTTPServer) func(ctx http.Context) error { func _Customer_GetVerifyCode0_HTTP_Handler(srv CustomerHTTPServer) func(ctx http.Context) error {
@ -52,8 +61,51 @@ func _Customer_GetVerifyCode0_HTTP_Handler(srv CustomerHTTPServer) func(ctx http
} }
} }
func _Customer_Login0_HTTP_Handler(srv CustomerHTTPServer) func(ctx http.Context) error {
return func(ctx http.Context) error {
var in LoginReq
if err := ctx.Bind(&in); err != nil {
return err
}
if err := ctx.BindQuery(&in); err != nil {
return err
}
http.SetOperation(ctx, OperationCustomerLogin)
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.Login(ctx, req.(*LoginReq))
})
out, err := h(ctx, &in)
if err != nil {
return err
}
reply := out.(*LoginResp)
return ctx.Result(200, reply)
}
}
func _Customer_Loginout0_HTTP_Handler(srv CustomerHTTPServer) func(ctx http.Context) error {
return func(ctx http.Context) error {
var in LogoutReq
if err := ctx.BindQuery(&in); err != nil {
return err
}
http.SetOperation(ctx, OperationCustomerLoginout)
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.Loginout(ctx, req.(*LogoutReq))
})
out, err := h(ctx, &in)
if err != nil {
return err
}
reply := out.(*LogoutResp)
return ctx.Result(200, reply)
}
}
type CustomerHTTPClient interface { type CustomerHTTPClient interface {
GetVerifyCode(ctx context.Context, req *GetVerifyCodeReq, opts ...http.CallOption) (rsp *GetVerifyCodeResp, err error) GetVerifyCode(ctx context.Context, req *GetVerifyCodeReq, opts ...http.CallOption) (rsp *GetVerifyCodeResp, err error)
Login(ctx context.Context, req *LoginReq, opts ...http.CallOption) (rsp *LoginResp, err error)
Loginout(ctx context.Context, req *LogoutReq, opts ...http.CallOption) (rsp *LogoutResp, err error)
} }
type CustomerHTTPClientImpl struct { type CustomerHTTPClientImpl struct {
@ -76,3 +128,29 @@ func (c *CustomerHTTPClientImpl) GetVerifyCode(ctx context.Context, in *GetVerif
} }
return &out, nil return &out, nil
} }
func (c *CustomerHTTPClientImpl) Login(ctx context.Context, in *LoginReq, opts ...http.CallOption) (*LoginResp, error) {
var out LoginResp
pattern := "/customer/login"
path := binding.EncodeURL(pattern, in, false)
opts = append(opts, http.Operation(OperationCustomerLogin))
opts = append(opts, http.PathTemplate(pattern))
err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...)
if err != nil {
return nil, err
}
return &out, nil
}
func (c *CustomerHTTPClientImpl) Loginout(ctx context.Context, in *LogoutReq, opts ...http.CallOption) (*LogoutResp, error) {
var out LogoutResp
pattern := "/customer/logout"
path := binding.EncodeURL(pattern, in, true)
opts = append(opts, http.Operation(OperationCustomerLoginout))
opts = append(opts, http.PathTemplate(pattern))
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
if err != nil {
return nil, err
}
return &out, nil
}

@ -8,7 +8,7 @@ server:
data: data:
database: database:
driver: mysql driver: mysql
source: "root:123456@tcp(localhost:3306)/laomadj_customer?charset=utf8mb4&parseTime=True&loc=Local&maxConnLifetime=60s&maxIdleConns=10&maxOpenConns=100" source: root:123456@tcp(localhost:3306)/laomadj_customer?charset=utf8mb4&parseTime=True&loc=Local
redis: redis:
addr: 127.0.0.1:6379 addr: 127.0.0.1:6379
read_timeout: 0.2s read_timeout: 0.2s

@ -1,15 +0,0 @@
server:
http:
addr: 0.0.0.0:8100
timeout: 1s
grpc:
addr: 0.0.0.0:9100
timeout: 1s
data:
database:
driver: mysql
source: dsn := "root:123456@tcp(localhost:3306)/mydatabase?charset=utf8mb4&parseTime=True&loc=Local&maxConnLifetime=60s&maxIdleConns=10&maxOpenConns=100"
redis:
addr: 127.0.0.1:6379
read_timeout: 0.2s
write_timeout: 0.2s

@ -21,6 +21,7 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/form/v4 v4.2.1 // indirect github.com/go-playground/form/v4 v4.2.1 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/mux v1.8.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect

@ -34,6 +34,8 @@ github.com/go-playground/form/v4 v4.2.1 h1:HjdRDKO0fftVMU5epjPW2SOREcZ6/wLUzEobq
github.com/go-playground/form/v4 v4.2.1/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U= github.com/go-playground/form/v4 v4.2.1/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=

@ -5,6 +5,9 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
const Secrret = "yourSecretKey"
const Duration = 2 * 30 * 24 * 3600
// 模型 // 模型
type Customer struct { type Customer struct {
//业务逻辑 //业务逻辑
@ -17,10 +20,11 @@ type Customer struct {
//业务逻辑部分 //业务逻辑部分
type CustomerWork struct { type CustomerWork struct {
Telephone string `gorm:"type:varchar(15);uniqueIndex;" json:"telephone"` Telephone string `gorm:"type:varchar(15);uniqueIndex;" json:"telephone"`
Name string `gorm:"type:varchar(255);uniqueIndex;" json:"name"` Name sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"name"`
Email string `gorm:"type:varchar(255);uniqueIndex;" json:"email"` Email sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"email"`
Wechat string `gorm:"type:varchar(255);uniqueIndex;" json:"wechat"` Wechat sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"wechat"`
CityId uint `gorm:"index;" json:"city_id"`
} }
// token简介 // token简介

@ -2,6 +2,12 @@ package data
import ( import (
"context" "context"
"customer/internal/biz"
"database/sql"
"fmt"
"github.com/go-kratos/kratos/v2/errors"
"github.com/golang-jwt/jwt/v5"
"gorm.io/gorm"
"time" "time"
) )
@ -24,3 +30,105 @@ func (cd CustomerData) SetVerifyCode(telephone, code string, ex int64) error {
} }
return nil return nil
} }
// 获取redis中的验证码
func (cd CustomerData) GetVerifyCode(telephone string) string {
status := cd.data.Rdb.Get(context.Background(), "CVC"+telephone)
return status.Val()
}
// 根据电话 获取客户信息
func (cd CustomerData) GetCustomerByTelephone(telephone string) (*biz.Customer, error) {
//查询基于电话
customer := &biz.Customer{}
result := cd.data.Mdb.Where("telephone=?", telephone).First(customer)
//query 执行成功 同时查询到记录
if result.Error == nil && customer.ID > 0 {
return customer, nil
}
if result.Error != nil && errors.Is(result.Error, gorm.ErrRecordNotFound) {
//有错误但是错误是 不错在这个数据 那么我就创建
customer.Telephone = telephone
customer.Name = sql.NullString{Valid: false}
customer.Email = sql.NullString{Valid: false}
customer.Wechat = sql.NullString{Valid: false}
resultCreate := cd.data.Mdb.Create(customer)
if resultCreate.Error == nil {
return customer, nil
} else {
return nil, result.Error
}
}
//有错误 但是不是插叙不到的粗欧文
return nil, result.Error
}
// 生成token
func (cd CustomerData) GenerateTokenAndSave(c *biz.Customer, duration time.Duration, secret string) (string, error) {
cliams := jwt.RegisteredClaims{
//签发方
Issuer: "LaoMaDJ",
Subject: "customer-authentication",
//前发给谁使用
Audience: []string{"customer", "other"},
//有效日期至
ExpiresAt: jwt.NewNumericDate(time.Now().Add(duration)),
//何时启用
NotBefore: nil,
//签发时间
IssuedAt: jwt.NewNumericDate(time.Now()),
//ID用户的ID
ID: fmt.Sprintf("%d", c.ID),
}
//生成token
token := jwt.NewWithClaims(jwt.SigningMethodHS256, cliams)
//签发token
signedToken, err := token.SignedString([]byte(secret))
if err != nil {
return "", nil
}
//二 存储
c.Token = signedToken
now := time.Now()
formattedTime := now.Format("2006-01-02 15:04:05") // 这里使用的是 Go 的时间格式化布局
const layout = "2006-01-02 15:04:05" // 时间格式布局,与 formattedTime 的格式相匹配
// 解析字符串为 time.Time 类型
parsedTime, err := time.Parse(layout, formattedTime)
c.TokenCreatAt = sql.NullTime{
Time: parsedTime,
Valid: true,
}
if result := cd.data.Mdb.Save(c); result.Error != nil {
return "", result.Error
}
//操作成功
return signedToken, nil
}
// 根据用户ID获取对应的token
func (cd CustomerData) GetToken(id interface{}) (string, error) {
c := &biz.Customer{}
if result := cd.data.Mdb.First(c, id); result.Error != nil {
return "", result.Error
}
return c.Token, nil
}
// 根据用户ID获取删除的token
func (cd CustomerData) DelToken(id interface{}) error {
c := &biz.Customer{}
if result := cd.data.Mdb.First(c, id); result.Error != nil {
return result.Error
}
//删除customer的token
c.Token = ""
c.TokenCreatAt = sql.NullTime{Valid: false}
cd.data.Mdb.Save(c)
return nil
}

@ -41,6 +41,7 @@ func NewData(c *conf.Data, logger log.Logger) (*Data, func(), error) {
} }
//连接mysql //连接mysql
//用户名:密码啊@tcp(ip:端口)/数据库的名字 //用户名:密码啊@tcp(ip:端口)/数据库的名字
dsn := c.Database.Source dsn := c.Database.Source
//连接数据集 //连接数据集
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) //open不会检验用户名和密码 db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) //open不会检验用户名和密码

@ -0,0 +1,47 @@
package server
import (
"context"
"customer/internal/service"
"github.com/go-kratos/kratos/v2/errors"
"github.com/go-kratos/kratos/v2/middleware"
"github.com/go-kratos/kratos/v2/middleware/auth/jwt"
"github.com/go-kratos/kratos/v2/transport"
jwtv5 "github.com/golang-jwt/jwt/v5"
"strings"
)
func CustomerJWT(customerService *service.CustomerService) middleware.Middleware {
return func(handler middleware.Handler) middleware.Handler {
return func(ctx context.Context, req interface{}) (interface{}, error) {
//获取存储在jwt中的顾客的id
claims, ok := jwt.FromContext(ctx)
if !ok {
return nil, errors.Unauthorized("UNAUTHORIZED",
"claims not found")
}
//断言使用
claimsMap := claims.(jwtv5.MapClaims)
id := claimsMap["jti"]
//获取id对应的顾客的token
token, err := customerService.CustomerService.GetToken(id)
if err != nil {
return nil, errors.Unauthorized("UNAUTHORIZED",
"customer not found")
}
//对比数据表中的token与请求的token是否一致
//获取请求头
header, _ := transport.FromServerContext(ctx)
//从header中获取token
auths := strings.SplitN(header.RequestHeader().Get("Authorization"), " ", 2)
jwtToken := auths[1]
//比较请求中的token是否和表中的token是否一致
if jwtToken != token {
return nil, errors.Unauthorized("UNAUTHORIZED",
"token was updated")
}
//校验通过 执行下面的中间件
return handler(ctx, req)
}
}
}

@ -1,14 +1,18 @@
package server package server
import ( import (
"context"
"customer/api/customer" "customer/api/customer"
v1 "customer/api/helloworld/v1" v1 "customer/api/helloworld/v1"
"customer/internal/biz"
"customer/internal/conf" "customer/internal/conf"
"customer/internal/service" "customer/internal/service"
"github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/middleware/auth/jwt"
"github.com/go-kratos/kratos/v2/middleware/recovery" "github.com/go-kratos/kratos/v2/middleware/recovery"
"github.com/go-kratos/kratos/v2/middleware/selector"
"github.com/go-kratos/kratos/v2/transport/http" "github.com/go-kratos/kratos/v2/transport/http"
jwtv5 "github.com/golang-jwt/jwt/v5"
) )
// NewHTTPServer new an HTTP server. // NewHTTPServer new an HTTP server.
@ -16,6 +20,21 @@ func NewHTTPServer(c *conf.Server, greeter *service.GreeterService, customerServ
var opts = []http.ServerOption{ var opts = []http.ServerOption{
http.Middleware( http.Middleware(
recovery.Recovery(), recovery.Recovery(),
//自己设置的中间件
selector.Server(jwt.Server(func(token *jwtv5.Token) (interface{}, error) {
return []byte(biz.Secrret), nil
}), CustomerJWT(customerService)).Match(
func(ctx context.Context, operation string) bool {
//根据自己的需求 完成是否启用中间件的校验
noJWT := map[string]struct{}{
"/api.customer.Customer/Login": {},
"/api.customer.Customer/GetVerifyCode": {},
}
if _, exists := noJWT[operation]; exists {
return false
}
return true
}).Build(),
), ),
} }
if c.Http.Network != "" { if c.Http.Network != "" {

@ -2,13 +2,15 @@ package service
import ( import (
"context" "context"
pb "customer/api/customer"
"customer/api/verifyCode" "customer/api/verifyCode"
"customer/internal/biz"
"customer/internal/data" "customer/internal/data"
"github.com/go-kratos/kratos/v2/middleware/auth/jwt"
"github.com/go-kratos/kratos/v2/transport/grpc" "github.com/go-kratos/kratos/v2/transport/grpc"
jwtv5 "github.com/golang-jwt/jwt/v5"
"regexp" "regexp"
"time" "time"
pb "customer/api/customer"
) )
type CustomerService struct { type CustomerService struct {
@ -80,3 +82,56 @@ func (s *CustomerService) GetVerifyCode(ctx context.Context, req *pb.GetVerifyCo
}, nil }, nil
} }
// 登录
func (s *CustomerService) Login(ctx context.Context, req *pb.LoginReq) (*pb.LoginResp, error) {
//1 校验电话和验证码
code := s.CustomerService.GetVerifyCode(req.Telephone)
if code == "" || code != req.VerifyCode {
return &pb.LoginResp{
Code: 1,
Message: "验证码不匹配",
}, nil
}
//2 判定电话号码是否注册 来获取顾客信息
customer, err := s.CustomerService.GetCustomerByTelephone(req.Telephone)
if err != nil {
return &pb.LoginResp{
Code: 1,
Message: "顾客信息获取错误",
}, nil
}
//3.获取token jwt-token
token, err := s.CustomerService.GenerateTokenAndSave(customer, biz.Duration*time.Second, biz.Secrret)
if err != nil {
return &pb.LoginResp{
Code: 1,
Message: "Token生成失败",
}, nil
}
return &pb.LoginResp{
Code: 0,
Message: "login success",
Token: token,
TokenCreateAt: time.Now().Unix(),
TokenLife: biz.Duration,
}, nil
}
// 推出
func (s *CustomerService) Loginout(ctx context.Context, req *pb.LogoutReq) (*pb.LogoutResp, error) {
claim, _ := jwt.FromContext(ctx)
claimsMap := claim.(jwtv5.MapClaims)
//删除用户的token
if err := s.CustomerService.DelToken(claimsMap["jti"]); err != nil {
return &pb.LogoutResp{
Code: 1,
Message: "TOKEN删除失败",
}, nil
}
return &pb.LogoutResp{
Code: 0,
Message: "logout success",
}, nil
}

@ -4,12 +4,14 @@
openapi: 3.0.3 openapi: 3.0.3
info: info:
title: Customer API title: Customer API
description: 验证码
version: 0.0.1 version: 0.0.1
paths: paths:
/customer/get-verify-code/{telephone}: /customer/get-verify-code/{telephone}:
get: get:
tags: tags:
- Customer - Customer
description: 验证码
operationId: Customer_GetVerifyCode operationId: Customer_GetVerifyCode
parameters: parameters:
- name: telephone - name: telephone
@ -30,6 +32,50 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/Status' $ref: '#/components/schemas/Status'
/customer/login:
post:
tags:
- Customer
description: 登录
operationId: Customer_Login
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/LoginReq'
required: true
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/LoginResp'
default:
description: Default error response
content:
application/json:
schema:
$ref: '#/components/schemas/Status'
/customer/logout:
get:
tags:
- Customer
description: 退出
operationId: Customer_Loginout
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/LogoutResp'
default:
description: Default error response
content:
application/json:
schema:
$ref: '#/components/schemas/Status'
components: components:
schemas: schemas:
GetVerifyCodeResp: GetVerifyCodeResp:
@ -53,6 +99,34 @@ components:
description: The type of the serialized message. description: The type of the serialized message.
additionalProperties: true additionalProperties: true
description: Contains an arbitrary serialized message along with a @type that describes the type of the serialized message. description: Contains an arbitrary serialized message along with a @type that describes the type of the serialized message.
LoginReq:
type: object
properties:
telephone:
type: string
verifyCode:
type: string
description: 登录的消息
LoginResp:
type: object
properties:
code:
type: string
message:
type: string
token:
type: string
tokenCreateAt:
type: string
tokenLife:
type: string
LogoutResp:
type: object
properties:
code:
type: string
message:
type: string
Status: Status:
type: object type: object
properties: properties:

@ -5,4 +5,14 @@ services:
ports: ports:
- "6379:6379" - "6379:6379"
volumes: volumes:
- ./data/redis:/data - ./data/redis:/data
mysql:
container_name : laomaDJMySQL
image: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: laomadj_customer
volumes:
- ./data/mysql:/var/lib/mysql
Loading…
Cancel
Save