Parcourir la source

修复oss登录bug

kobe6258 il y a 4 mois
Parent
commit
cb5c968edc

+ 9 - 0
config/rsa_public_key.pem

@@ -0,0 +1,9 @@
+-----BEGIN PUBLIC KEY-----
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Gh3c2fki27yLKMUPUqZ
+hDa0vGRp01ca5Rbpd6RoZURIA4Ti1k/zf2jW0tJ1OUnkBiBtcfZ4d+6gPr1kdsdp
+xSjlV1PQfzaMtZg0ZKiHTw4xhJ+P/XCzIPJaUKAwKqb8U0gsXfZVcF0OEwWAgNxL
+zMhPlTiSAWaRUOumOHNexSRzG9URy+v/UIVkuDXFwzb1aly93S0Elp7cDPQA0FCL
+qiwofnNdPTJ1BiXa1OO8UFXuV16Hw0JeYdl+GWUf8Q4uTKUesclnBkLgOUaXSJQq
+fNwqSBj39H4vRTBKX1eiqhCwt3/lwBEpWW8YHkfEssclh0x2xf0714e/H3BuwLwd
+WwIDAQAB
+-----END PUBLIC KEY-----

+ 3 - 2
controller/haitong/auth_controller.go

@@ -5,6 +5,7 @@ import (
 	"eta/eta_bridge/controller/resp"
 	"eta/eta_bridge/global"
 	"eta/eta_bridge/logic/htfutures"
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/go-playground/validator/v10"
 )
@@ -38,13 +39,13 @@ func (xc *SSOLoginController) SSOLogin(c *gin.Context) {
 		return
 	}
 	result, err, errMsg := htfutures.LoginEta(req.Code)
-	global.FILE_LOG.Info("oss 请求结束", err.Error())
+	global.FILE_LOG.Info("oss 请求结束")
 	if err != nil {
 		resp.FailData(errMsg, err.Error(), c)
 		return
 	}
 	str, err := json.Marshal(result)
-	global.FILE_LOG.Info("请求成功,返回响应体:%s", str)
+	global.FILE_LOG.Info(fmt.Sprintf("请求成功,返回响应体:%s", str))
 	resp.OkData("获取成功", result, c)
 	return
 }

+ 2 - 4
logic/htfutures/http_client.go

@@ -111,7 +111,7 @@ func (c *DefaultHttpClient[T]) retryRequest(requestFunc func() (*http.Response,
 }
 
 func (c *DefaultHttpClient[T]) doPostForm(urlStr string, values url.Values) (response Response[T], err error) {
-	global.FILE_LOG.Info("发送请求:")
+	global.FILE_LOG.Info("发送请求:" + urlStr)
 	//ctx 用Background
 	resp, err := c.retryRequest(func() (*http.Response, error) {
 		return c.client.PostForm(urlStr, values)
@@ -126,12 +126,10 @@ func (c *DefaultHttpClient[T]) doPostForm(urlStr string, values url.Values) (res
 		global.FILE_LOG.Error("http请求失败,读取body失败:" + err.Error())
 		return
 	}
-	global.FILE_LOG.Info("应答为:" + string(repBody))
 	if resp.StatusCode != http.StatusOK {
 		global.FILE_LOG.Error("http请求异常,请求状态为:" + resp.Status)
-		return
 	}
-	global.FILE_LOG.Info("htt请求成功,body:" + string(repBody))
+	global.FILE_LOG.Info("http应答为:" + string(repBody))
 	err = json.Unmarshal(repBody, &response)
 	if err != nil {
 		global.FILE_LOG.Error("解析应答失败,反序列化失败:" + err.Error())

+ 22 - 2
logic/htfutures/sso_auth.go

@@ -72,11 +72,21 @@ func ssoLogin(code string, systemType string) (token string, userInfo UserInfoRe
 func LoginCRM(code string) (resp response.LoginResp, err error, errMsg string) {
 	// 获取用户信息
 	token, userInfo, err := ssoLogin(code, etaCrm)
+	if err != nil {
+		global.FILE_LOG.Error("获取sso用户信息失败:" + err.Error())
+		errMsg = "获取sso用户信息失败:" + err.Error()
+		return
+	}
+	if userInfo.Username == "" {
+		global.FILE_LOG.Error("sso用户信息不存在")
+		errMsg = "sso用户信息不存在"
+		return
+	}
 	//获取eta用户信息
 	adminInfo, err := eta.GetSysUserByAdminName(userInfo.Username)
 	if err != nil {
 		global.FILE_LOG.Error("获取eta用户信息失败:" + err.Error())
-		errMsg = "获取eta用户信息失败"
+		errMsg = "获取eta用户信息失败:" + err.Error()
 		return
 	}
 	adminInfo.LastLoginTime, err = time.Parse(time.RFC3339, userInfo.LastLogin)
@@ -136,6 +146,16 @@ func LoginCRM(code string) (resp response.LoginResp, err error, errMsg string) {
 func LoginEta(code string) (resp response.LoginResp, err error, errMsg string) {
 	// 获取用户信息
 	token, userInfo, err := ssoLogin(code, etaAdmin)
+	if err != nil {
+		global.FILE_LOG.Error("获取sso用户信息失败:" + err.Error())
+		errMsg = "获取sso用户信息失败::" + err.Error()
+		return
+	}
+	if userInfo.Username == "" {
+		global.FILE_LOG.Error("sso用户信息不存在")
+		errMsg = "sso用户信息不存在,获取的用户名为空"
+		return
+	}
 	//获取eta用户信息
 	adminInfo, err := eta.GetSysUserByAdminName(userInfo.Username)
 	if err != nil {
@@ -144,7 +164,7 @@ func LoginEta(code string) (resp response.LoginResp, err error, errMsg string) {
 			errMsg = "eta用户信息不存在"
 		} else {
 			global.FILE_LOG.Error("获取eta用户信息失败:" + err.Error())
-			errMsg = "获取eta用户信息失败"
+			errMsg = "获取eta用户信息失败" + err.Error()
 		}
 		return
 	}

+ 26 - 10
main.go

@@ -1,18 +1,34 @@
 package main
 
 import (
-	"eta/eta_bridge/core"
+	"encoding/base64"
+	"eta/eta_bridge/utils"
+	"fmt"
 )
 
 // @BasePath /
 func main() {
-	//	resp := `{"data":{"userId":"66bdb5fbf6c885e788a745e4","createdAt":"2024-08-15T08:02:03.829Z","updatedAt":"2024-09-19T01:24:30.315Z","status":"ACTIVATED","workStatus":"CLOSED","externalId":null,"email":null,"phone":null,"phoneCountryCode":null,"username":"iirphz","name":"洪泽账号","nickname":null,"photo":"//auth-files.htfutures.com/authing-console/default-user-avatar.png","loginsCount":6,"lastLogin":"2024-09-19T01:24:30.000Z","lastIp":"10.219.161.70","gender":"U","emailVerified":false,"phoneVerified":false,"passwordLastSetAt":null,"birthdate":null,"country":null,"province":null,"city":null,"address":null,"streetAddress":null,"postalCode":null,"company":null,"browser":null,"device":null,"givenName":null,"familyName":null,"middleName":null,"profile":null,"preferredUsername":null,"website":null,"zoneinfo":null,"locale":null,"formatted":null,"region":null,"userSourceType":"ADMIN_CREATED","userSourceId":null,"lastLoginApp":"6658225e2f0010df5906d4ec","mainDepartmentId":null,"lastMfaTime":null,"passwordSecurityLevel":1,"resetPasswordOnNextLogin":false,"registerSource":["import:manual"],"departmentIds":[],"identities":[],"identityNumber":null,"customData":null,"metadataSource":null,"postIdList":null,"statusChangedAt":"2024-08-26T08:28:17.679Z","tenantId":null},"code":0,"message":"success","traceId":"44bef1abdb90463e89ec8dfe77c990f2"}
-	//`
-	//	var userInfo htfutures.Response[htfutures.UserInfoResp]
-	//	err := json.Unmarshal([]byte(resp), &userInfo)
-	//	if err != nil {
-	//		fmt.Sprintln(err)
-	//		return
-	//	}
-	core.RunServe()
+	resp := `{
+    "data": {
+        "riskInfo": {
+            "corp_begin_date": "开始时间",
+            "corp_end_date": "结束时间",
+            "user_invest_term": "投资期限",
+            "user_invest_kind": "投资品种",
+            "corp_risk_level": "风险等级"
+        },
+        "custInfo": {
+            "mobile_tel": "手机号",
+            "client_name": "客户姓名",
+            "id_kind": "证件类型",
+            "id_no": "证件号"
+        }
+    }
+}`
+	publicKey, _ := utils.ParsePublicKeyFromPEM()
+	rsa, _ := utils.EncryptWithRSA(publicKey, []byte(resp))
+	fmt.Printf(base64.StdEncoding.EncodeToString(rsa))
+	_, _ = utils.ParsePrivateKeyFromPEM("./config/")
+
+	//core.RunServe()
 }

+ 9 - 1
rpc/protos/sso.proto

@@ -12,6 +12,14 @@ message LoginRequest {
   string  source = 2;
 }
 
+message UserInfo {
+  string userId = 1;
+  string username = 2;
+  string name = 3;
+}
 message LoginResponse {
-  string result = 1;
+  int32 errCode = 1;
+  string errMsg = 2;
+  string msg = 3;
+  UserInfo data = 4;
 }

+ 136 - 25
rpc/sso/sso.pb.go

@@ -77,18 +77,84 @@ func (x *LoginRequest) GetSource() string {
 	return ""
 }
 
+type UserInfo struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	UserId   string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty"`
+	Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
+	Name     string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
+}
+
+func (x *UserInfo) Reset() {
+	*x = UserInfo{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_rpc_protos_sso_proto_msgTypes[1]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *UserInfo) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*UserInfo) ProtoMessage() {}
+
+func (x *UserInfo) ProtoReflect() protoreflect.Message {
+	mi := &file_rpc_protos_sso_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use UserInfo.ProtoReflect.Descriptor instead.
+func (*UserInfo) Descriptor() ([]byte, []int) {
+	return file_rpc_protos_sso_proto_rawDescGZIP(), []int{1}
+}
+
+func (x *UserInfo) GetUserId() string {
+	if x != nil {
+		return x.UserId
+	}
+	return ""
+}
+
+func (x *UserInfo) GetUsername() string {
+	if x != nil {
+		return x.Username
+	}
+	return ""
+}
+
+func (x *UserInfo) GetName() string {
+	if x != nil {
+		return x.Name
+	}
+	return ""
+}
+
 type LoginResponse struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Result string `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"`
+	ErrCode int32     `protobuf:"varint,1,opt,name=errCode,proto3" json:"errCode,omitempty"`
+	ErrMsg  string    `protobuf:"bytes,2,opt,name=errMsg,proto3" json:"errMsg,omitempty"`
+	Msg     string    `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"`
+	Data    *UserInfo `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
 }
 
 func (x *LoginResponse) Reset() {
 	*x = LoginResponse{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_rpc_protos_sso_proto_msgTypes[1]
+		mi := &file_rpc_protos_sso_proto_msgTypes[2]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -101,7 +167,7 @@ func (x *LoginResponse) String() string {
 func (*LoginResponse) ProtoMessage() {}
 
 func (x *LoginResponse) ProtoReflect() protoreflect.Message {
-	mi := &file_rpc_protos_sso_proto_msgTypes[1]
+	mi := &file_rpc_protos_sso_proto_msgTypes[2]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -114,16 +180,37 @@ func (x *LoginResponse) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use LoginResponse.ProtoReflect.Descriptor instead.
 func (*LoginResponse) Descriptor() ([]byte, []int) {
-	return file_rpc_protos_sso_proto_rawDescGZIP(), []int{1}
+	return file_rpc_protos_sso_proto_rawDescGZIP(), []int{2}
+}
+
+func (x *LoginResponse) GetErrCode() int32 {
+	if x != nil {
+		return x.ErrCode
+	}
+	return 0
+}
+
+func (x *LoginResponse) GetErrMsg() string {
+	if x != nil {
+		return x.ErrMsg
+	}
+	return ""
 }
 
-func (x *LoginResponse) GetResult() string {
+func (x *LoginResponse) GetMsg() string {
 	if x != nil {
-		return x.Result
+		return x.Msg
 	}
 	return ""
 }
 
+func (x *LoginResponse) GetData() *UserInfo {
+	if x != nil {
+		return x.Data
+	}
+	return nil
+}
+
 var File_rpc_protos_sso_proto protoreflect.FileDescriptor
 
 var file_rpc_protos_sso_proto_rawDesc = []byte{
@@ -132,15 +219,25 @@ var file_rpc_protos_sso_proto_rawDesc = []byte{
 	0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63,
 	0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12,
 	0x16, 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
-	0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x27, 0x0a, 0x0d, 0x4c, 0x6f, 0x67, 0x69, 0x6e,
-	0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75,
-	0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74,
-	0x32, 0x3c, 0x0a, 0x08, 0x53, 0x53, 0x4f, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x30, 0x0a, 0x05,
-	0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x11, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x6f, 0x67, 0x69,
-	0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c,
-	0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x10,
-	0x5a, 0x0e, 0x2e, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x73, 0x73, 0x6f, 0x2f, 0x3b, 0x73, 0x73, 0x6f,
-	0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x52, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x49,
+	0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20,
+	0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75,
+	0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75,
+	0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
+	0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x76, 0x0a, 0x0d, 0x4c,
+	0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07,
+	0x65, 0x72, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x65,
+	0x72, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67,
+	0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x12, 0x10,
+	0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67,
+	0x12, 0x21, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d,
+	0x2e, 0x72, 0x70, 0x63, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x64,
+	0x61, 0x74, 0x61, 0x32, 0x3c, 0x0a, 0x08, 0x53, 0x53, 0x4f, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12,
+	0x30, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x11, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c,
+	0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x72, 0x70,
+	0x63, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
+	0x00, 0x42, 0x10, 0x5a, 0x0e, 0x2e, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x73, 0x73, 0x6f, 0x2f, 0x3b,
+	0x73, 0x73, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -155,19 +252,21 @@ func file_rpc_protos_sso_proto_rawDescGZIP() []byte {
 	return file_rpc_protos_sso_proto_rawDescData
 }
 
-var file_rpc_protos_sso_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
+var file_rpc_protos_sso_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
 var file_rpc_protos_sso_proto_goTypes = []any{
 	(*LoginRequest)(nil),  // 0: rpc.LoginRequest
-	(*LoginResponse)(nil), // 1: rpc.LoginResponse
+	(*UserInfo)(nil),      // 1: rpc.UserInfo
+	(*LoginResponse)(nil), // 2: rpc.LoginResponse
 }
 var file_rpc_protos_sso_proto_depIdxs = []int32{
-	0, // 0: rpc.SSOLogin.Login:input_type -> rpc.LoginRequest
-	1, // 1: rpc.SSOLogin.Login:output_type -> rpc.LoginResponse
-	1, // [1:2] is the sub-list for method output_type
-	0, // [0:1] 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
+	1, // 0: rpc.LoginResponse.data:type_name -> rpc.UserInfo
+	0, // 1: rpc.SSOLogin.Login:input_type -> rpc.LoginRequest
+	2, // 2: rpc.SSOLogin.Login:output_type -> rpc.LoginResponse
+	2, // [2:3] is the sub-list for method output_type
+	1, // [1:2] 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
 }
 
 func init() { file_rpc_protos_sso_proto_init() }
@@ -189,6 +288,18 @@ func file_rpc_protos_sso_proto_init() {
 			}
 		}
 		file_rpc_protos_sso_proto_msgTypes[1].Exporter = func(v any, i int) any {
+			switch v := v.(*UserInfo); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_rpc_protos_sso_proto_msgTypes[2].Exporter = func(v any, i int) any {
 			switch v := v.(*LoginResponse); i {
 			case 0:
 				return &v.state
@@ -207,7 +318,7 @@ func file_rpc_protos_sso_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_rpc_protos_sso_proto_rawDesc,
 			NumEnums:      0,
-			NumMessages:   2,
+			NumMessages:   3,
 			NumExtensions: 0,
 			NumServices:   1,
 		},

+ 24 - 9
rpc/sso/sso_service.go

@@ -6,7 +6,6 @@ import (
 	"eta/eta_bridge/global"
 	"eta/eta_bridge/logic/htfutures"
 	"eta/eta_bridge/utils"
-	"fmt"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/metadata"
 	"google.golang.org/grpc/status"
@@ -43,45 +42,61 @@ func (s *SSOService) Login(ctx context.Context, req *LoginRequest) (*LoginRespon
 	}
 	if len(encryptedCode) == 0 {
 		return &LoginResponse{
-			Result: "登录失败,code不能为空",
+			ErrCode: 10001,
+			ErrMsg:  "登录失败,code不能为空",
+			Msg:     "登录失败",
 		}, nil
 	}
 	privateKey, err := utils.ParsePrivateKeyFromPEM(global.CONFIG.HTFutures.PrivateKeyPemPath)
 	if err != nil {
 		return &LoginResponse{
-			Result: "登录失败,解析私钥失败",
+			ErrCode: 10002,
+			ErrMsg:  "登录失败,解析私钥失败",
+			Msg:     "登录失败",
 		}, nil
 	}
 	aesKey, err := utils.DecryptWithRSA(privateKey, decryptedAESKey)
 	if err != nil {
 		return &LoginResponse{
-			Result: "登录失败,解密失败",
+			ErrCode: 10003,
+			ErrMsg:  "登录失败,解密失败",
+			Msg:     "登录失败",
 		}, nil
 	}
 	code, err := utils.DecryptWithAES(aesKey, encryptedCode)
 	if err != nil {
 		return &LoginResponse{
-			Result: "登录失败,解析code失败",
+			ErrCode: 10004,
+			ErrMsg:  "登录失败,解析code失败",
+			Msg:     "登录失败",
 		}, nil
 	}
 	global.FILE_LOG.Info("传入参数code:%v", code)
-	fmt.Printf("入参code:%s", code)
 	token, err := htfutures.GetToken(string(code), req.Source)
 	if err != nil {
 		return &LoginResponse{
-			Result: "登录失败,获取token失败",
+			ErrCode: 10005,
+			ErrMsg:  "登录失败,获取token失败",
+			Msg:     "登录失败",
 		}, nil
 	}
 	global.FILE_LOG.Info("返回的token结果集%v", token)
 	user, err := htfutures.GetUserInfo(token, req.Source)
 	if err != nil {
 		return &LoginResponse{
-			Result: "登录失败,获取token失败",
+			ErrCode: 10006,
+			ErrMsg:  "登录失败,获取token失败",
+			Msg:     "登录失败",
 		}, nil
 	}
 	global.FILE_LOG.Info("返回的userInfo结果集%v", user)
 	return &LoginResponse{
-		Result: "登录成功",
+		Msg: "登录成功",
+		Data: &UserInfo{
+			Name:     user.Name,
+			UserId:   user.UserId,
+			Username: user.Username,
+		},
 	}, nil
 }
 

+ 19 - 0
utils/rsa.go

@@ -5,8 +5,10 @@ import (
 	"crypto/rsa"
 	"crypto/sha256"
 	"crypto/x509"
+	"encoding/base64"
 	"encoding/pem"
 	"errors"
+	"fmt"
 	"os"
 )
 
@@ -33,6 +35,8 @@ func DecryptWithRSA(privateKey *rsa.PrivateKey, encrypted []byte) ([]byte, error
 func ParsePrivateKeyFromPEM(path string) (privateKey *rsa.PrivateKey, err error) {
 	pemBlock, err := os.ReadFile(path + "rsa_private_key.pem")
 	block, _ := pem.Decode(pemBlock)
+	str := base64.StdEncoding.EncodeToString(pemBlock)
+	fmt.Printf(str)
 	if block == nil {
 		return nil, errors.New("私钥解析失败")
 	}
@@ -42,3 +46,18 @@ func ParsePrivateKeyFromPEM(path string) (privateKey *rsa.PrivateKey, err error)
 	}
 	return
 }
+
+// ParsePublicKeyFromPEM 解析RSA公钥
+func ParsePublicKeyFromPEM() (publicKey *rsa.PublicKey, err error) {
+	pemBlock, err := os.ReadFile("./config/rsa_public_key.pem")
+	block, _ := pem.Decode(pemBlock)
+	if block == nil {
+		return nil, errors.New("公钥解析失败")
+	}
+	key, err := x509.ParsePKIXPublicKey(block.Bytes)
+	if err != nil {
+		return nil, err
+	}
+	publicKey = key.(*rsa.PublicKey)
+	return
+}