diff --git a/backend/customer/api/customer/customer.pb.go b/backend/customer/api/customer/customer.pb.go index 66df1f6..d55d548 100644 --- a/backend/customer/api/customer/customer.pb.go +++ b/backend/customer/api/customer/customer.pb.go @@ -21,6 +21,95 @@ const ( _ = 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"` @@ -32,7 +121,7 @@ type LoginReq struct { func (x *LoginReq) Reset() { *x = LoginReq{} - mi := &file_api_customer_customer_proto_msgTypes[0] + mi := &file_api_customer_customer_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -44,7 +133,7 @@ func (x *LoginReq) String() string { func (*LoginReq) ProtoMessage() {} func (x *LoginReq) ProtoReflect() protoreflect.Message { - mi := &file_api_customer_customer_proto_msgTypes[0] + mi := &file_api_customer_customer_proto_msgTypes[2] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -57,7 +146,7 @@ func (x *LoginReq) ProtoReflect() protoreflect.Message { // Deprecated: Use LoginReq.ProtoReflect.Descriptor instead. func (*LoginReq) Descriptor() ([]byte, []int) { - return file_api_customer_customer_proto_rawDescGZIP(), []int{0} + return file_api_customer_customer_proto_rawDescGZIP(), []int{2} } func (x *LoginReq) GetTelephone() string { @@ -87,7 +176,7 @@ type LoginResp struct { func (x *LoginResp) Reset() { *x = LoginResp{} - mi := &file_api_customer_customer_proto_msgTypes[1] + mi := &file_api_customer_customer_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -99,7 +188,7 @@ func (x *LoginResp) String() string { func (*LoginResp) ProtoMessage() {} func (x *LoginResp) ProtoReflect() protoreflect.Message { - mi := &file_api_customer_customer_proto_msgTypes[1] + mi := &file_api_customer_customer_proto_msgTypes[3] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -112,7 +201,7 @@ func (x *LoginResp) ProtoReflect() protoreflect.Message { // Deprecated: Use LoginResp.ProtoReflect.Descriptor instead. func (*LoginResp) Descriptor() ([]byte, []int) { - return file_api_customer_customer_proto_rawDescGZIP(), []int{1} + return file_api_customer_customer_proto_rawDescGZIP(), []int{3} } func (x *LoginResp) GetCode() int64 { @@ -159,7 +248,7 @@ type GetVerifyCodeReq struct { func (x *GetVerifyCodeReq) Reset() { *x = GetVerifyCodeReq{} - mi := &file_api_customer_customer_proto_msgTypes[2] + mi := &file_api_customer_customer_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -171,7 +260,7 @@ func (x *GetVerifyCodeReq) String() string { func (*GetVerifyCodeReq) ProtoMessage() {} func (x *GetVerifyCodeReq) ProtoReflect() protoreflect.Message { - mi := &file_api_customer_customer_proto_msgTypes[2] + mi := &file_api_customer_customer_proto_msgTypes[4] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -184,7 +273,7 @@ func (x *GetVerifyCodeReq) ProtoReflect() protoreflect.Message { // Deprecated: Use GetVerifyCodeReq.ProtoReflect.Descriptor instead. func (*GetVerifyCodeReq) Descriptor() ([]byte, []int) { - return file_api_customer_customer_proto_rawDescGZIP(), []int{2} + return file_api_customer_customer_proto_rawDescGZIP(), []int{4} } func (x *GetVerifyCodeReq) GetTelephone() string { @@ -207,7 +296,7 @@ type GetVerifyCodeResp struct { func (x *GetVerifyCodeResp) Reset() { *x = GetVerifyCodeResp{} - mi := &file_api_customer_customer_proto_msgTypes[3] + mi := &file_api_customer_customer_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -219,7 +308,7 @@ func (x *GetVerifyCodeResp) String() string { func (*GetVerifyCodeResp) ProtoMessage() {} func (x *GetVerifyCodeResp) ProtoReflect() protoreflect.Message { - mi := &file_api_customer_customer_proto_msgTypes[3] + mi := &file_api_customer_customer_proto_msgTypes[5] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -232,7 +321,7 @@ func (x *GetVerifyCodeResp) ProtoReflect() protoreflect.Message { // Deprecated: Use GetVerifyCodeResp.ProtoReflect.Descriptor instead. func (*GetVerifyCodeResp) Descriptor() ([]byte, []int) { - return file_api_customer_customer_proto_rawDescGZIP(), []int{3} + return file_api_customer_customer_proto_rawDescGZIP(), []int{5} } func (x *GetVerifyCodeResp) GetCode() int64 { @@ -277,53 +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, 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, - 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x49, 0x0a, 0x08, 0x4c, 0x6f, 0x67, - 0x69, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, - 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, - 0x6f, 0x6e, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x5f, 0x63, 0x6f, - 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, - 0x43, 0x6f, 0x64, 0x65, 0x22, 0x96, 0x01, 0x0a, 0x09, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, - 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x26, 0x0a, 0x0f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, - 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x0d, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x74, 0x12, 0x1d, - 0x0a, 0x0a, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x6c, 0x69, 0x66, 0x65, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x09, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x4c, 0x69, 0x66, 0x65, 0x22, 0x30, 0x0a, - 0x10, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, - 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x22, - 0xbe, 0x01, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, - 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 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, 0xe1, 0x01, 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, 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, + 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x0b, 0x0a, 0x09, 0x4c, 0x6f, 0x67, + 0x6f, 0x75, 0x74, 0x52, 0x65, 0x71, 0x22, 0x3a, 0x0a, 0x0a, 0x4c, 0x6f, 0x67, 0x6f, 0x75, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x22, 0x49, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x1c, + 0x0a, 0x09, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x12, 0x1f, 0x0a, 0x0b, + 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x22, 0x96, 0x01, + 0x0a, 0x09, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x63, + 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, + 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, + 0x26, 0x0a, 0x0f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, + 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x5f, 0x6c, 0x69, 0x66, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x4c, 0x69, 0x66, 0x65, 0x22, 0x30, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72, + 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x65, + 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, + 0x65, 0x6c, 0x65, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x22, 0xbe, 0x01, 0x0a, 0x11, 0x47, 0x65, 0x74, + 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, + 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, + 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x0b, + 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 ( @@ -338,20 +437,24 @@ func file_api_customer_customer_proto_rawDescGZIP() []byte { return file_api_customer_customer_proto_rawDescData } -var file_api_customer_customer_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_api_customer_customer_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_api_customer_customer_proto_goTypes = []any{ - (*LoginReq)(nil), // 0: api.customer.LoginReq - (*LoginResp)(nil), // 1: api.customer.LoginResp - (*GetVerifyCodeReq)(nil), // 2: api.customer.GetVerifyCodeReq - (*GetVerifyCodeResp)(nil), // 3: api.customer.GetVerifyCodeResp + (*LogoutReq)(nil), // 0: api.customer.LogoutReq + (*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{ - 2, // 0: api.customer.Customer.GetVerifyCode:input_type -> api.customer.GetVerifyCodeReq - 0, // 1: api.customer.Customer.Login:input_type -> api.customer.LoginReq - 3, // 2: api.customer.Customer.GetVerifyCode:output_type -> api.customer.GetVerifyCodeResp - 1, // 3: api.customer.Customer.Login:output_type -> api.customer.LoginResp - 2, // [2:4] is the sub-list for method output_type - 0, // [0:2] is the sub-list for method input_type + 4, // 0: api.customer.Customer.GetVerifyCode:input_type -> api.customer.GetVerifyCodeReq + 2, // 1: api.customer.Customer.Login:input_type -> api.customer.LoginReq + 0, // 2: api.customer.Customer.Loginout:input_type -> api.customer.LogoutReq + 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 extendee 0, // [0:0] is the sub-list for field type_name @@ -368,7 +471,7 @@ func file_api_customer_customer_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_api_customer_customer_proto_rawDesc, NumEnums: 0, - NumMessages: 4, + NumMessages: 6, NumExtensions: 0, NumServices: 1, }, diff --git a/backend/customer/api/customer/customer.proto b/backend/customer/api/customer/customer.proto index c2a03c7..4e75265 100644 --- a/backend/customer/api/customer/customer.proto +++ b/backend/customer/api/customer/customer.proto @@ -19,6 +19,21 @@ service Customer { 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{ @@ -43,4 +58,5 @@ message GetVerifyCodeResp { string verify_code =3; int64 verify_generate_time=4; int64 verify_code_life=5; -} \ No newline at end of file +} +//退出方法 diff --git a/backend/customer/api/customer/customer_grpc.pb.go b/backend/customer/api/customer/customer_grpc.pb.go index eeca2a9..4339c5f 100644 --- a/backend/customer/api/customer/customer_grpc.pb.go +++ b/backend/customer/api/customer/customer_grpc.pb.go @@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion9 const ( 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. @@ -33,6 +34,8 @@ type CustomerClient interface { 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 { @@ -63,6 +66,16 @@ func (c *customerClient) Login(ctx context.Context, in *LoginReq, opts ...grpc.C 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. // All implementations must embed UnimplementedCustomerServer // for forward compatibility. @@ -73,6 +86,8 @@ type CustomerServer interface { GetVerifyCode(context.Context, *GetVerifyCodeReq) (*GetVerifyCodeResp, error) // 登录 Login(context.Context, *LoginReq) (*LoginResp, error) + // 退出 + Loginout(context.Context, *LogoutReq) (*LogoutResp, error) mustEmbedUnimplementedCustomerServer() } @@ -89,6 +104,9 @@ func (UnimplementedCustomerServer) GetVerifyCode(context.Context, *GetVerifyCode 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) testEmbeddedByValue() {} @@ -146,6 +164,24 @@ func _Customer_Login_Handler(srv interface{}, ctx context.Context, dec func(inte 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. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -161,6 +197,10 @@ var Customer_ServiceDesc = grpc.ServiceDesc{ MethodName: "Login", Handler: _Customer_Login_Handler, }, + { + MethodName: "Loginout", + Handler: _Customer_Loginout_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "api/customer/customer.proto", diff --git a/backend/customer/api/customer/customer_http.pb.go b/backend/customer/api/customer/customer_http.pb.go index ca9ee0f..dc6080a 100644 --- a/backend/customer/api/customer/customer_http.pb.go +++ b/backend/customer/api/customer/customer_http.pb.go @@ -21,18 +21,22 @@ const _ = http.SupportPackageIsVersion1 const OperationCustomerGetVerifyCode = "/api.customer.Customer/GetVerifyCode" const OperationCustomerLogin = "/api.customer.Customer/Login" +const OperationCustomerLoginout = "/api.customer.Customer/Loginout" type CustomerHTTPServer interface { // GetVerifyCode验证码 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) { r := s.Route("/") 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 { @@ -79,9 +83,29 @@ func _Customer_Login0_HTTP_Handler(srv CustomerHTTPServer) func(ctx http.Context } } +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 { 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 { @@ -117,3 +141,16 @@ func (c *CustomerHTTPClientImpl) Login(ctx context.Context, in *LoginReq, opts . } 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 +} diff --git a/backend/customer/configs/config.yaml~ b/backend/customer/configs/config.yaml~ deleted file mode 100644 index 94bdedf..0000000 --- a/backend/customer/configs/config.yaml~ +++ /dev/null @@ -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 diff --git a/backend/customer/go.mod b/backend/customer/go.mod index e17b390..26bda8d 100644 --- a/backend/customer/go.mod +++ b/backend/customer/go.mod @@ -21,6 +21,7 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-playground/form/v4 v4.2.1 // 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/gorilla/mux v1.8.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect diff --git a/backend/customer/go.sum b/backend/customer/go.sum index f770ad3..4acbab9 100644 --- a/backend/customer/go.sum +++ b/backend/customer/go.sum @@ -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-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/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/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= diff --git a/backend/customer/internal/biz/customer.go b/backend/customer/internal/biz/customer.go index 91ef47a..b9c0333 100644 --- a/backend/customer/internal/biz/customer.go +++ b/backend/customer/internal/biz/customer.go @@ -5,6 +5,9 @@ import ( "gorm.io/gorm" ) +const Secrret = "yourSecretKey" +const Duration = 2 * 30 * 24 * 3600 + // 模型 type Customer struct { //业务逻辑 @@ -17,11 +20,11 @@ type Customer struct { //业务逻辑部分 type CustomerWork struct { - Telephone string `gorm:"type:varchar(15);uniqueIndex;" json:"telephone"` - Name string `gorm:"type:varchar(255);uniqueIndex;" json:"name"` - Email string `gorm:"type:varchar(255);uniqueIndex;" json:"email"` - Wechat string `gorm:"type:varchar(255);uniqueIndex;" json:"wechat"` - CityId uint `gorm:"index;" json:"city_id"` + Telephone string `gorm:"type:varchar(15);uniqueIndex;" json:"telephone"` + Name sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"name"` + Email sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"email"` + Wechat sql.NullString `gorm:"type:varchar(255);uniqueIndex;" json:"wechat"` + CityId uint `gorm:"index;" json:"city_id"` } // token简介 diff --git a/backend/customer/internal/data/customer.go b/backend/customer/internal/data/customer.go index 43375f9..9926110 100644 --- a/backend/customer/internal/data/customer.go +++ b/backend/customer/internal/data/customer.go @@ -2,6 +2,12 @@ package data import ( "context" + "customer/internal/biz" + "database/sql" + "fmt" + "github.com/go-kratos/kratos/v2/errors" + "github.com/golang-jwt/jwt/v5" + "gorm.io/gorm" "time" ) @@ -24,3 +30,105 @@ func (cd CustomerData) SetVerifyCode(telephone, code string, ex int64) error { } 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 +} diff --git a/backend/customer/internal/server/customer.go b/backend/customer/internal/server/customer.go new file mode 100644 index 0000000..13552e8 --- /dev/null +++ b/backend/customer/internal/server/customer.go @@ -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) + } + } +} diff --git a/backend/customer/internal/server/http.go b/backend/customer/internal/server/http.go index 9cbc536..ff0ab51 100644 --- a/backend/customer/internal/server/http.go +++ b/backend/customer/internal/server/http.go @@ -1,14 +1,18 @@ package server import ( + "context" "customer/api/customer" v1 "customer/api/helloworld/v1" + "customer/internal/biz" "customer/internal/conf" "customer/internal/service" - "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/selector" "github.com/go-kratos/kratos/v2/transport/http" + jwtv5 "github.com/golang-jwt/jwt/v5" ) // NewHTTPServer new an HTTP server. @@ -16,6 +20,21 @@ func NewHTTPServer(c *conf.Server, greeter *service.GreeterService, customerServ var opts = []http.ServerOption{ http.Middleware( 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 != "" { diff --git a/backend/customer/internal/service/customer.go b/backend/customer/internal/service/customer.go index 0efd6bf..41d82e7 100644 --- a/backend/customer/internal/service/customer.go +++ b/backend/customer/internal/service/customer.go @@ -2,13 +2,15 @@ package service import ( "context" + pb "customer/api/customer" "customer/api/verifyCode" + "customer/internal/biz" "customer/internal/data" + "github.com/go-kratos/kratos/v2/middleware/auth/jwt" "github.com/go-kratos/kratos/v2/transport/grpc" + jwtv5 "github.com/golang-jwt/jwt/v5" "regexp" "time" - - pb "customer/api/customer" ) type CustomerService struct { @@ -83,5 +85,53 @@ func (s *CustomerService) GetVerifyCode(ctx context.Context, req *pb.GetVerifyCo // 登录 func (s *CustomerService) Login(ctx context.Context, req *pb.LoginReq) (*pb.LoginResp, error) { - return &pb.LoginResp{}, nil + //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 } diff --git a/backend/customer/openapi.yaml b/backend/customer/openapi.yaml index 023023c..55dc216 100644 --- a/backend/customer/openapi.yaml +++ b/backend/customer/openapi.yaml @@ -57,6 +57,25 @@ paths: 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: schemas: GetVerifyCodeResp: @@ -101,6 +120,13 @@ components: type: string tokenLife: type: string + LogoutResp: + type: object + properties: + code: + type: string + message: + type: string Status: type: object properties: