From 851348ed5ce7e3d75ffd43f1cf63d6f75463065f Mon Sep 17 00:00:00 2001 From: zzw <1464003642@qq.com> Date: Mon, 5 Oct 2026 15:29:19 +0800 Subject: [PATCH] feat: payment --- rpc/payment/payment.proto | 2 +- rpc/user/pb/user.pb.go | 247 ++++++++++++++++-- rpc/user/pb/user_grpc.pb.go | 39 +++ rpc/user/user.pb | Bin 16845 -> 17317 bytes rpc/user/user.proto | 19 ++ services/payment/internal/dao/const.go | 11 - services/payment/internal/logic/payLogic.go | 19 +- services/payment/internal/logic/userRpc.go | 35 +++ .../logic/internalGetUserInfoLogic.go | 86 ++++++ services/user/internal/server/userServer.go | 5 + services/user/userClient/user.go | 8 + services/user/validator/user.go | 15 ++ 12 files changed, 427 insertions(+), 59 deletions(-) create mode 100644 services/payment/internal/logic/userRpc.go create mode 100644 services/user/internal/logic/internalGetUserInfoLogic.go diff --git a/rpc/payment/payment.proto b/rpc/payment/payment.proto index 339cc56..81ee847 100644 --- a/rpc/payment/payment.proto +++ b/rpc/payment/payment.proto @@ -35,7 +35,7 @@ service Payment { rpc Notify(NotifyReq) returns (Response) { option (google.api.http) = { - post: "/api/v3/payment/notify/{channel}" + post: "/api/v3/payment/notify" body: "*" }; } diff --git a/rpc/user/pb/user.pb.go b/rpc/user/pb/user.pb.go index 0174d7f..52d6a9b 100644 --- a/rpc/user/pb/user.pb.go +++ b/rpc/user/pb/user.pb.go @@ -1218,6 +1218,174 @@ func (x *InternalUpdateData) GetName() string { return "" } +type InternalGetUserInfoReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + CredentialType string `protobuf:"bytes,2,opt,name=credential_type,json=credentialType,proto3" json:"credential_type,omitempty"` + SubjectType string `protobuf:"bytes,3,opt,name=subject_type,json=subjectType,proto3" json:"subject_type,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *InternalGetUserInfoReq) Reset() { + *x = InternalGetUserInfoReq{} + mi := &file_user_user_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *InternalGetUserInfoReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InternalGetUserInfoReq) ProtoMessage() {} + +func (x *InternalGetUserInfoReq) ProtoReflect() protoreflect.Message { + mi := &file_user_user_proto_msgTypes[19] + 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 InternalGetUserInfoReq.ProtoReflect.Descriptor instead. +func (*InternalGetUserInfoReq) Descriptor() ([]byte, []int) { + return file_user_user_proto_rawDescGZIP(), []int{19} +} + +func (x *InternalGetUserInfoReq) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *InternalGetUserInfoReq) GetCredentialType() string { + if x != nil { + return x.CredentialType + } + return "" +} + +func (x *InternalGetUserInfoReq) GetSubjectType() string { + if x != nil { + return x.SubjectType + } + return "" +} + +type InternalGetUserInfoData struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Mobile string `protobuf:"bytes,2,opt,name=mobile,proto3" json:"mobile,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` + Avatar string `protobuf:"bytes,4,opt,name=avatar,proto3" json:"avatar,omitempty"` + Gender uint32 `protobuf:"varint,5,opt,name=gender,proto3" json:"gender,omitempty"` + Birthday string `protobuf:"bytes,6,opt,name=birthday,proto3" json:"birthday,omitempty"` + Status uint32 `protobuf:"varint,7,opt,name=status,proto3" json:"status,omitempty"` + Identifier string `protobuf:"bytes,8,opt,name=identifier,proto3" json:"identifier,omitempty"` + CredentialType string `protobuf:"bytes,9,opt,name=credential_type,json=credentialType,proto3" json:"credential_type,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *InternalGetUserInfoData) Reset() { + *x = InternalGetUserInfoData{} + mi := &file_user_user_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *InternalGetUserInfoData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InternalGetUserInfoData) ProtoMessage() {} + +func (x *InternalGetUserInfoData) ProtoReflect() protoreflect.Message { + mi := &file_user_user_proto_msgTypes[20] + 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 InternalGetUserInfoData.ProtoReflect.Descriptor instead. +func (*InternalGetUserInfoData) Descriptor() ([]byte, []int) { + return file_user_user_proto_rawDescGZIP(), []int{20} +} + +func (x *InternalGetUserInfoData) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *InternalGetUserInfoData) GetMobile() string { + if x != nil { + return x.Mobile + } + return "" +} + +func (x *InternalGetUserInfoData) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *InternalGetUserInfoData) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +func (x *InternalGetUserInfoData) GetGender() uint32 { + if x != nil { + return x.Gender + } + return 0 +} + +func (x *InternalGetUserInfoData) GetBirthday() string { + if x != nil { + return x.Birthday + } + return "" +} + +func (x *InternalGetUserInfoData) GetStatus() uint32 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *InternalGetUserInfoData) GetIdentifier() string { + if x != nil { + return x.Identifier + } + return "" +} + +func (x *InternalGetUserInfoData) GetCredentialType() string { + if x != nil { + return x.CredentialType + } + return "" +} + type InfoReq struct { state protoimpl.MessageState `protogen:"open.v1"` unknownFields protoimpl.UnknownFields @@ -1226,7 +1394,7 @@ type InfoReq struct { func (x *InfoReq) Reset() { *x = InfoReq{} - mi := &file_user_user_proto_msgTypes[19] + mi := &file_user_user_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1238,7 +1406,7 @@ func (x *InfoReq) String() string { func (*InfoReq) ProtoMessage() {} func (x *InfoReq) ProtoReflect() protoreflect.Message { - mi := &file_user_user_proto_msgTypes[19] + mi := &file_user_user_proto_msgTypes[21] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1251,7 +1419,7 @@ func (x *InfoReq) ProtoReflect() protoreflect.Message { // Deprecated: Use InfoReq.ProtoReflect.Descriptor instead. func (*InfoReq) Descriptor() ([]byte, []int) { - return file_user_user_proto_rawDescGZIP(), []int{19} + return file_user_user_proto_rawDescGZIP(), []int{21} } type ClientReq struct { @@ -1265,7 +1433,7 @@ type ClientReq struct { func (x *ClientReq) Reset() { *x = ClientReq{} - mi := &file_user_user_proto_msgTypes[20] + mi := &file_user_user_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1277,7 +1445,7 @@ func (x *ClientReq) String() string { func (*ClientReq) ProtoMessage() {} func (x *ClientReq) ProtoReflect() protoreflect.Message { - mi := &file_user_user_proto_msgTypes[20] + mi := &file_user_user_proto_msgTypes[22] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1290,7 +1458,7 @@ func (x *ClientReq) ProtoReflect() protoreflect.Message { // Deprecated: Use ClientReq.ProtoReflect.Descriptor instead. func (*ClientReq) Descriptor() ([]byte, []int) { - return file_user_user_proto_rawDescGZIP(), []int{20} + return file_user_user_proto_rawDescGZIP(), []int{22} } func (x *ClientReq) GetName() string { @@ -1412,12 +1580,28 @@ const file_user_user_proto_rawDesc = "" + "\x12InternalUpdateData\x12\x17\n" + "\auser_id\x18\x01 \x01(\x03R\x06userId\x12\x16\n" + "\x06mobile\x18\x02 \x01(\tR\x06mobile\x12\x12\n" + - "\x04name\x18\x03 \x01(\tR\x04name\"\t\n" + + "\x04name\x18\x03 \x01(\tR\x04name\"}\n" + + "\x16InternalGetUserInfoReq\x12\x17\n" + + "\auser_id\x18\x01 \x01(\x03R\x06userId\x12'\n" + + "\x0fcredential_type\x18\x02 \x01(\tR\x0ecredentialType\x12!\n" + + "\fsubject_type\x18\x03 \x01(\tR\vsubjectType\"\x82\x02\n" + + "\x17InternalGetUserInfoData\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + + "\x06mobile\x18\x02 \x01(\tR\x06mobile\x12\x12\n" + + "\x04name\x18\x03 \x01(\tR\x04name\x12\x16\n" + + "\x06avatar\x18\x04 \x01(\tR\x06avatar\x12\x16\n" + + "\x06gender\x18\x05 \x01(\rR\x06gender\x12\x1a\n" + + "\bbirthday\x18\x06 \x01(\tR\bbirthday\x12\x16\n" + + "\x06status\x18\a \x01(\rR\x06status\x12\x1e\n" + + "\n" + + "identifier\x18\b \x01(\tR\n" + + "identifier\x12'\n" + + "\x0fcredential_type\x18\t \x01(\tR\x0ecredentialType\"\t\n" + "\aInfoReq\"V\n" + "\tClientReq\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12\x12\n" + "\x04type\x18\x02 \x01(\tR\x04type\x12!\n" + - "\fsubject_type\x18\x03 \x01(\rR\vsubjectType2\xbc\a\n" + + "\fsubject_type\x18\x03 \x01(\rR\vsubjectType2\x90\b\n" + "\x04User\x12A\n" + "\x05Login\x12\x0e.user.LoginReq\x1a\x0e.user.Response\"\x18\x82\xd3\xe4\x93\x02\x12:\x01*\"\r/api/v3/login\x12C\n" + "\x04Info\x12\r.user.InfoReq\x1a\x0e.user.Response\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\x12\x11/api/v3/user/info\x12K\n" + @@ -1431,7 +1615,8 @@ const file_user_user_proto_rawDesc = "" + "\x0eInternalUpdate\x12\x17.user.InternalUpdateReq\x1a\x18.user.InternalUpdateData\x12O\n" + "\x12InternalUsersByIds\x12\x1b.user.InternalUsersByIdsReq\x1a\x1c.user.InternalUsersByIdsData\x12U\n" + "\x14InternalUpdateMobile\x12\x1d.user.InternalUpdateMobileReq\x1a\x1e.user.InternalUpdateMobileData\x12^\n" + - "\x17InternalRevokeBizClient\x12 .user.InternalRevokeBizClientReq\x1a!.user.InternalRevokeBizClientDataB\x18Z\x16lone-services/rpc/userb\x06proto3" + "\x17InternalRevokeBizClient\x12 .user.InternalRevokeBizClientReq\x1a!.user.InternalRevokeBizClientData\x12R\n" + + "\x13InternalGetUserInfo\x12\x1c.user.InternalGetUserInfoReq\x1a\x1d.user.InternalGetUserInfoDataB\x18Z\x16lone-services/rpc/userb\x06proto3" var ( file_user_user_proto_rawDescOnce sync.Once @@ -1445,7 +1630,7 @@ func file_user_user_proto_rawDescGZIP() []byte { return file_user_user_proto_rawDescData } -var file_user_user_proto_msgTypes = make([]protoimpl.MessageInfo, 21) +var file_user_user_proto_msgTypes = make([]protoimpl.MessageInfo, 23) var file_user_user_proto_goTypes = []any{ (*Response)(nil), // 0: user.Response (*LoginReq)(nil), // 1: user.LoginReq @@ -1466,14 +1651,16 @@ var file_user_user_proto_goTypes = []any{ (*InternalCheckUpdateData)(nil), // 16: user.InternalCheckUpdateData (*InternalUpdateReq)(nil), // 17: user.InternalUpdateReq (*InternalUpdateData)(nil), // 18: user.InternalUpdateData - (*InfoReq)(nil), // 19: user.InfoReq - (*ClientReq)(nil), // 20: user.ClientReq + (*InternalGetUserInfoReq)(nil), // 19: user.InternalGetUserInfoReq + (*InternalGetUserInfoData)(nil), // 20: user.InternalGetUserInfoData + (*InfoReq)(nil), // 21: user.InfoReq + (*ClientReq)(nil), // 22: user.ClientReq } var file_user_user_proto_depIdxs = []int32{ 7, // 0: user.InternalUsersByIdsData.items:type_name -> user.UserBriefItem 1, // 1: user.User.Login:input_type -> user.LoginReq - 19, // 2: user.User.Info:input_type -> user.InfoReq - 20, // 3: user.User.Client:input_type -> user.ClientReq + 21, // 2: user.User.Info:input_type -> user.InfoReq + 22, // 3: user.User.Client:input_type -> user.ClientReq 2, // 4: user.User.UserItems:input_type -> user.UserItemsReq 3, // 5: user.User.UserStatus:input_type -> user.UserStatusReq 4, // 6: user.User.InternalCreate:input_type -> user.InternalCreateReq @@ -1483,20 +1670,22 @@ var file_user_user_proto_depIdxs = []int32{ 6, // 10: user.User.InternalUsersByIds:input_type -> user.InternalUsersByIdsReq 9, // 11: user.User.InternalUpdateMobile:input_type -> user.InternalUpdateMobileReq 11, // 12: user.User.InternalRevokeBizClient:input_type -> user.InternalRevokeBizClientReq - 0, // 13: user.User.Login:output_type -> user.Response - 0, // 14: user.User.Info:output_type -> user.Response - 0, // 15: user.User.Client:output_type -> user.Response - 0, // 16: user.User.UserItems:output_type -> user.Response - 0, // 17: user.User.UserStatus:output_type -> user.Response - 5, // 18: user.User.InternalCreate:output_type -> user.InternalCreateData - 14, // 19: user.User.InternalCheckCreate:output_type -> user.InternalCheckCreateData - 16, // 20: user.User.InternalCheckUpdate:output_type -> user.InternalCheckUpdateData - 18, // 21: user.User.InternalUpdate:output_type -> user.InternalUpdateData - 8, // 22: user.User.InternalUsersByIds:output_type -> user.InternalUsersByIdsData - 10, // 23: user.User.InternalUpdateMobile:output_type -> user.InternalUpdateMobileData - 12, // 24: user.User.InternalRevokeBizClient:output_type -> user.InternalRevokeBizClientData - 13, // [13:25] is the sub-list for method output_type - 1, // [1:13] is the sub-list for method input_type + 19, // 13: user.User.InternalGetUserInfo:input_type -> user.InternalGetUserInfoReq + 0, // 14: user.User.Login:output_type -> user.Response + 0, // 15: user.User.Info:output_type -> user.Response + 0, // 16: user.User.Client:output_type -> user.Response + 0, // 17: user.User.UserItems:output_type -> user.Response + 0, // 18: user.User.UserStatus:output_type -> user.Response + 5, // 19: user.User.InternalCreate:output_type -> user.InternalCreateData + 14, // 20: user.User.InternalCheckCreate:output_type -> user.InternalCheckCreateData + 16, // 21: user.User.InternalCheckUpdate:output_type -> user.InternalCheckUpdateData + 18, // 22: user.User.InternalUpdate:output_type -> user.InternalUpdateData + 8, // 23: user.User.InternalUsersByIds:output_type -> user.InternalUsersByIdsData + 10, // 24: user.User.InternalUpdateMobile:output_type -> user.InternalUpdateMobileData + 12, // 25: user.User.InternalRevokeBizClient:output_type -> user.InternalRevokeBizClientData + 20, // 26: user.User.InternalGetUserInfo:output_type -> user.InternalGetUserInfoData + 14, // [14:27] is the sub-list for method output_type + 1, // [1:14] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name 1, // [1:1] is the sub-list for extension extendee 0, // [0:1] is the sub-list for field type_name @@ -1513,7 +1702,7 @@ func file_user_user_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_user_proto_rawDesc), len(file_user_user_proto_rawDesc)), NumEnums: 0, - NumMessages: 21, + NumMessages: 23, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/user/pb/user_grpc.pb.go b/rpc/user/pb/user_grpc.pb.go index 88e2424..a667bd7 100644 --- a/rpc/user/pb/user_grpc.pb.go +++ b/rpc/user/pb/user_grpc.pb.go @@ -8,6 +8,7 @@ package user import ( context "context" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -31,6 +32,7 @@ const ( User_InternalUsersByIds_FullMethodName = "/user.User/InternalUsersByIds" User_InternalUpdateMobile_FullMethodName = "/user.User/InternalUpdateMobile" User_InternalRevokeBizClient_FullMethodName = "/user.User/InternalRevokeBizClient" + User_InternalGetUserInfo_FullMethodName = "/user.User/InternalGetUserInfo" ) // UserClient is the client API for User service. @@ -49,6 +51,7 @@ type UserClient interface { InternalUsersByIds(ctx context.Context, in *InternalUsersByIdsReq, opts ...grpc.CallOption) (*InternalUsersByIdsData, error) InternalUpdateMobile(ctx context.Context, in *InternalUpdateMobileReq, opts ...grpc.CallOption) (*InternalUpdateMobileData, error) InternalRevokeBizClient(ctx context.Context, in *InternalRevokeBizClientReq, opts ...grpc.CallOption) (*InternalRevokeBizClientData, error) + InternalGetUserInfo(ctx context.Context, in *InternalGetUserInfoReq, opts ...grpc.CallOption) (*InternalGetUserInfoData, error) } type userClient struct { @@ -179,6 +182,16 @@ func (c *userClient) InternalRevokeBizClient(ctx context.Context, in *InternalRe return out, nil } +func (c *userClient) InternalGetUserInfo(ctx context.Context, in *InternalGetUserInfoReq, opts ...grpc.CallOption) (*InternalGetUserInfoData, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(InternalGetUserInfoData) + err := c.cc.Invoke(ctx, User_InternalGetUserInfo_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // UserServer is the server API for User service. // All implementations must embed UnimplementedUserServer // for forward compatibility. @@ -195,6 +208,7 @@ type UserServer interface { InternalUsersByIds(context.Context, *InternalUsersByIdsReq) (*InternalUsersByIdsData, error) InternalUpdateMobile(context.Context, *InternalUpdateMobileReq) (*InternalUpdateMobileData, error) InternalRevokeBizClient(context.Context, *InternalRevokeBizClientReq) (*InternalRevokeBizClientData, error) + InternalGetUserInfo(context.Context, *InternalGetUserInfoReq) (*InternalGetUserInfoData, error) mustEmbedUnimplementedUserServer() } @@ -241,6 +255,9 @@ func (UnimplementedUserServer) InternalUpdateMobile(context.Context, *InternalUp func (UnimplementedUserServer) InternalRevokeBizClient(context.Context, *InternalRevokeBizClientReq) (*InternalRevokeBizClientData, error) { return nil, status.Error(codes.Unimplemented, "method InternalRevokeBizClient not implemented") } +func (UnimplementedUserServer) InternalGetUserInfo(context.Context, *InternalGetUserInfoReq) (*InternalGetUserInfoData, error) { + return nil, status.Error(codes.Unimplemented, "method InternalGetUserInfo not implemented") +} func (UnimplementedUserServer) mustEmbedUnimplementedUserServer() {} func (UnimplementedUserServer) testEmbeddedByValue() {} @@ -478,6 +495,24 @@ func _User_InternalRevokeBizClient_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } +func _User_InternalGetUserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InternalGetUserInfoReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserServer).InternalGetUserInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: User_InternalGetUserInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserServer).InternalGetUserInfo(ctx, req.(*InternalGetUserInfoReq)) + } + return interceptor(ctx, in, info, handler) +} + // User_ServiceDesc is the grpc.ServiceDesc for User service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -533,6 +568,10 @@ var User_ServiceDesc = grpc.ServiceDesc{ MethodName: "InternalRevokeBizClient", Handler: _User_InternalRevokeBizClient_Handler, }, + { + MethodName: "InternalGetUserInfo", + Handler: _User_InternalGetUserInfo_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "user/user.proto", diff --git a/rpc/user/user.pb b/rpc/user/user.pb index bbcaa4b57f60ec2fe86a57ed50cd8826f95c1120..bfc75fbcc560dd5d5bbff2c5b22231e72f2afe7e 100644 GIT binary patch delta 261 zcmX@x%(%3jaf6d7(?glfE~aiAVzpdio_QsyMR|!i?x`iA#i>P}d1?8R&soZ1iu_STwMT-TKFPJN0 xGmjISc^$T?OcOXZzqj4P93T|LC5**fAsM|=pi}j*NCl-9O3C7soxI#p4FII@T%iB} delta 33 pcmZ45&Um(&af6d7Q>Wx+7gINm$$a+7OncZj7u)Y)p4{xL1OUfV3u^!X diff --git a/rpc/user/user.proto b/rpc/user/user.proto index 5e18e15..26e95cd 100644 --- a/rpc/user/user.proto +++ b/rpc/user/user.proto @@ -126,6 +126,24 @@ message InternalUpdateData { string name = 3; } +message InternalGetUserInfoReq { + int64 user_id = 1; + string credential_type = 2; + string subject_type = 3; +} + +message InternalGetUserInfoData { + int64 id = 1; + string mobile = 2; + string name = 3; + string avatar = 4; + uint32 gender = 5; + string birthday = 6; + uint32 status = 7; + string identifier = 8; + string credential_type = 9; +} + message InfoReq {} message ClientReq { @@ -173,4 +191,5 @@ service User { rpc InternalUsersByIds(InternalUsersByIdsReq) returns (InternalUsersByIdsData); rpc InternalUpdateMobile(InternalUpdateMobileReq) returns (InternalUpdateMobileData); rpc InternalRevokeBizClient(InternalRevokeBizClientReq) returns (InternalRevokeBizClientData); + rpc InternalGetUserInfo(InternalGetUserInfoReq) returns (InternalGetUserInfoData); } diff --git a/services/payment/internal/dao/const.go b/services/payment/internal/dao/const.go index 8b5e871..c693317 100644 --- a/services/payment/internal/dao/const.go +++ b/services/payment/internal/dao/const.go @@ -10,9 +10,6 @@ const ( PayTypeWechat uint8 = 1 PayTypeAlipay uint8 = 2 PayTypeBank uint8 = 4 - - CredentialTypeOpenid = "openid" - CredentialEnabled = 1 ) type OrderPayRow struct { @@ -25,14 +22,6 @@ type OrderPayRow struct { OutTradeNo string `gorm:"column:out_trade_no" json:"out_trade_no"` } -type UserCredential struct { - Id int64 `gorm:"column:id" json:"id"` - UserId int64 `gorm:"column:user_id" json:"user_id"` - CredentialType string `gorm:"column:credential_type" json:"credential_type"` - Identifier string `gorm:"column:identifier" json:"identifier"` - Status uint8 `gorm:"column:status" json:"status"` -} - func ChannelToPayType(channel string) uint8 { switch channel { case "wechat": diff --git a/services/payment/internal/logic/payLogic.go b/services/payment/internal/logic/payLogic.go index 16bb119..99b4456 100644 --- a/services/payment/internal/logic/payLogic.go +++ b/services/payment/internal/logic/payLogic.go @@ -2,10 +2,8 @@ package logic import ( "context" - "fmt" "math" - "lone-services/pkg/modelbase" pkgpay "lone-services/pkg/payment" "lone-services/pkg/utils" payment "lone-services/rpc/payment/pb" @@ -80,7 +78,7 @@ func (l *PayLogic) Pay(in *payment.PayReq) (*payment.Response, error) { switch channelCode { case pkgpay.ChannelWechat: - openid, oErr := loadOpenID(loginUser.ID) + openid, oErr := loadOpenID(l.ctx, l.svcCtx.UserSvcName, loginUser.ID) if oErr != nil || openid == utils.StringEmpty { l.Errorf("pay openid: %v", oErr) return outResponse(utils.Fail, "未绑定微信openid"), nil @@ -101,21 +99,6 @@ func (l *PayLogic) Pay(in *payment.PayReq) (*payment.Response, error) { return okResponse(result), nil } -func loadOpenID(userID int64) (string, error) { - var cred dao.UserCredential - err := modelbase.DB().Table(modelbase.Prefix()+"user_credential"). - Where("user_id = ? AND credential_type = ? AND status = ?", - userID, dao.CredentialTypeOpenid, dao.CredentialEnabled). - Take(&cred).Error - if err != nil { - return "", err - } - if cred.Id < utils.NumberOne { - return "", fmt.Errorf("openid credential not found") - } - return cred.Identifier, nil -} - func yuanToFen(yuan float64) int64 { return int64(math.Round(yuan * 100)) } diff --git a/services/payment/internal/logic/userRpc.go b/services/payment/internal/logic/userRpc.go new file mode 100644 index 0000000..3d0f6e9 --- /dev/null +++ b/services/payment/internal/logic/userRpc.go @@ -0,0 +1,35 @@ +package logic + +import ( + "context" + "fmt" + + "lone-services/pkg/utils" + userpb "lone-services/rpc/user/pb" + "lone-services/services/payment/internal/svc" +) + +func loadOpenID(ctx context.Context, userSvcName string, userID int64) (string, error) { + if userSvcName == utils.StringEmpty { + return utils.StringEmpty, fmt.Errorf("user service not configured") + } + if userID < utils.NumberOne { + return utils.StringEmpty, fmt.Errorf("invalid user id") + } + + cli, err := svc.GetRpcClient(userSvcName) + if err != nil { + return utils.StringEmpty, err + } + info, err := userpb.NewUserClient(cli.Conn()).InternalGetUserInfo(ctx, &userpb.InternalGetUserInfoReq{ + UserId: userID, + CredentialType: "openid", + }) + if err != nil { + return utils.StringEmpty, err + } + if info == nil || info.Identifier == utils.StringEmpty { + return utils.StringEmpty, fmt.Errorf("openid credential not found") + } + return info.Identifier, nil +} diff --git a/services/user/internal/logic/internalGetUserInfoLogic.go b/services/user/internal/logic/internalGetUserInfoLogic.go new file mode 100644 index 0000000..342fb2c --- /dev/null +++ b/services/user/internal/logic/internalGetUserInfoLogic.go @@ -0,0 +1,86 @@ +package logic + +import ( + "context" + "strconv" + + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + user "lone-services/rpc/user/pb" + "lone-services/services/user/internal/dao" + "lone-services/services/user/internal/model" + "lone-services/services/user/internal/svc" + "lone-services/services/user/validator" + + "github.com/zeromicro/go-zero/core/logx" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type InternalGetUserInfoLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewInternalGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InternalGetUserInfoLogic { + return &InternalGetUserInfoLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *InternalGetUserInfoLogic) InternalGetUserInfo(in *user.InternalGetUserInfoReq) (*user.InternalGetUserInfoData, error) { + var req validator.InternalGetUserInfoValidator + if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty { + return nil, status.Error(codes.InvalidArgument, msg) + } + + userModel := model.UserModel{}.Init() + var row dao.UserRow + if err := userModel.GetOne(modelbase.Params{ + Eq: map[string]string{"id": strconv.FormatInt(req.UserId, utils.NumberTen)}, + }, &row); err != nil { + l.Errorf("internal get user info: %v", err) + return nil, status.Error(codes.Internal, utils.Fail.Msg) + } + if row.Id < utils.NumberOne { + return nil, status.Error(codes.NotFound, utils.ErrorNotFund.Msg) + } + + out := &user.InternalGetUserInfoData{ + Id: row.Id, + Mobile: row.Mobile, + Name: row.Name, + Avatar: row.Avatar, + Gender: uint32(row.Gender), + Birthday: row.Birthday.DateString(), + Status: uint32(row.Status), + CredentialType: req.CredentialType, + } + if req.CredentialType == utils.StringEmpty { + return out, nil + } + + eq := map[string]string{ + "user_id": strconv.FormatInt(req.UserId, utils.NumberTen), + "credential_type": req.CredentialType, + "status": strconv.Itoa(int(dao.StatusEnabled)), + } + if req.SubjectType != utils.StringEmpty { + eq["subject_type"] = req.SubjectType + } + + var cred dao.UserCredential + credModel := model.UserCredentialModel{}.Init() + if err := credModel.GetOne(modelbase.Params{Eq: eq}, &cred); err != nil { + l.Errorf("internal get user credential: %v", err) + return nil, status.Error(codes.Internal, utils.Fail.Msg) + } + if cred.Id > utils.NumberZero { + out.Identifier = cred.Identifier + } + return out, nil +} diff --git a/services/user/internal/server/userServer.go b/services/user/internal/server/userServer.go index e41578c..f4dafcb 100644 --- a/services/user/internal/server/userServer.go +++ b/services/user/internal/server/userServer.go @@ -82,3 +82,8 @@ func (s *UserServer) InternalRevokeBizClient(ctx context.Context, in *user.Inter l := logic.NewInternalRevokeBizClientLogic(ctx, s.svcCtx) return l.InternalRevokeBizClient(in) } + +func (s *UserServer) InternalGetUserInfo(ctx context.Context, in *user.InternalGetUserInfoReq) (*user.InternalGetUserInfoData, error) { + l := logic.NewInternalGetUserInfoLogic(ctx, s.svcCtx) + return l.InternalGetUserInfo(in) +} diff --git a/services/user/userClient/user.go b/services/user/userClient/user.go index be13d6d..18e2569 100644 --- a/services/user/userClient/user.go +++ b/services/user/userClient/user.go @@ -22,6 +22,8 @@ type ( InternalCheckUpdateReq = user.InternalCheckUpdateReq InternalCreateData = user.InternalCreateData InternalCreateReq = user.InternalCreateReq + InternalGetUserInfoData = user.InternalGetUserInfoData + InternalGetUserInfoReq = user.InternalGetUserInfoReq InternalRevokeBizClientData = user.InternalRevokeBizClientData InternalRevokeBizClientReq = user.InternalRevokeBizClientReq InternalUpdateData = user.InternalUpdateData @@ -49,6 +51,7 @@ type ( InternalUsersByIds(ctx context.Context, in *InternalUsersByIdsReq, opts ...grpc.CallOption) (*InternalUsersByIdsData, error) InternalUpdateMobile(ctx context.Context, in *InternalUpdateMobileReq, opts ...grpc.CallOption) (*InternalUpdateMobileData, error) InternalRevokeBizClient(ctx context.Context, in *InternalRevokeBizClientReq, opts ...grpc.CallOption) (*InternalRevokeBizClientData, error) + InternalGetUserInfo(ctx context.Context, in *InternalGetUserInfoReq, opts ...grpc.CallOption) (*InternalGetUserInfoData, error) } defaultUser struct { @@ -121,3 +124,8 @@ func (m *defaultUser) InternalRevokeBizClient(ctx context.Context, in *InternalR client := user.NewUserClient(m.cli.Conn()) return client.InternalRevokeBizClient(ctx, in, opts...) } + +func (m *defaultUser) InternalGetUserInfo(ctx context.Context, in *InternalGetUserInfoReq, opts ...grpc.CallOption) (*InternalGetUserInfoData, error) { + client := user.NewUserClient(m.cli.Conn()) + return client.InternalGetUserInfo(ctx, in, opts...) +} diff --git a/services/user/validator/user.go b/services/user/validator/user.go index 55868e4..5784670 100644 --- a/services/user/validator/user.go +++ b/services/user/validator/user.go @@ -75,6 +75,21 @@ func (p InternalCreateValidator) GetMessage() validate.ValidatorMessages { } } +type InternalGetUserInfoValidator struct { + UserId int64 `validate:"required,gt=0"` + CredentialType string `validate:"omitempty,oneof=password sms wecom openid unionid"` + SubjectType string `validate:"omitempty,oneof=sale store user"` +} + +func (p InternalGetUserInfoValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "UserId.required": "用户ID不能为空", + "UserId.gt": "用户ID必须大于0", + "CredentialType.oneof": "凭证类型不正确", + "SubjectType.oneof": "主体类型不正确", + } +} + type InternalUsersByIdsValidator struct { Ids []int64 `validate:"required,min=1,dive,gt=0"` }