From 625207e013b5e37c8f6a4d1b35c9a3bf0683d13b Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Fri, 16 Jan 2026 18:50:16 +0800 Subject: [PATCH] f --- .../internal/service/yunyinSignPayService.go | 80 +++++++++++++++---- 1 file changed, 63 insertions(+), 17 deletions(-) diff --git a/app/main/api/internal/service/yunyinSignPayService.go b/app/main/api/internal/service/yunyinSignPayService.go index 88762f3..d0fd08c 100644 --- a/app/main/api/internal/service/yunyinSignPayService.go +++ b/app/main/api/internal/service/yunyinSignPayService.go @@ -173,9 +173,9 @@ type GetUserIdRequest struct { // GetUserIdResponse 获取操作ID响应 type GetUserIdResponse struct { - Code interface{} `json:"code"` // 可能是字符串"200"或数字200 - Msg string `json:"msg"` - Data *UserIdData `json:"data,omitempty"` + Code interface{} `json:"code"` // 可能是字符串"200"或数字200 + Msg string `json:"msg"` + Data []UserIdData `json:"data,omitempty"` // data 是数组 } // GetCodeInt 获取 code 的 int 值 @@ -197,7 +197,12 @@ func (r *GetUserIdResponse) GetCodeInt() int { // UserIdData 操作ID数据 type UserIdData struct { - UserId string `json:"userId"` + UserId string `json:"userId"` + UserName string `json:"userName,omitempty"` + Mobile string `json:"mobile,omitempty"` + UserStatus int `json:"userStatus,omitempty"` + RealName string `json:"realName,omitempty"` + RealNameStatus int `json:"realNameStatus,omitempty"` } // GetUserId 获取操作ID(带缓存) @@ -270,14 +275,19 @@ func (y *YunYinSignPayService) GetUserId(ctx context.Context, accessToken string return "", fmt.Errorf("获取操作ID失败: %s", userIdResp.Msg) } - if userIdResp.Data == nil || userIdResp.Data.UserId == "" { + if len(userIdResp.Data) == 0 { logx.Errorf("[云印签API] GetUserId: 操作ID数据为空,响应: %+v", userIdResp) return "", fmt.Errorf("操作ID数据为空") } - // 获取操作ID - operationUserId := userIdResp.Data.UserId - logx.Infof("[云印签API] GetUserId: 获取操作ID成功,UserID: %s", operationUserId) + // 获取操作ID(从数组中取第一个元素) + operationUserId := userIdResp.Data[0].UserId + if operationUserId == "" { + logx.Errorf("[云印签API] GetUserId: 操作ID为空,响应数据: %+v", userIdResp.Data[0]) + return "", fmt.Errorf("操作ID为空") + } + logx.Infof("[云印签API] GetUserId: 获取操作ID成功,UserID: %s, 用户名: %s, 手机号: %s", + operationUserId, userIdResp.Data[0].UserName, userIdResp.Data[0].Mobile) // 存储到Redis,2小时过期 err = y.redis.SetexCtx(ctx, YunYinSignPayUserIdKey, operationUserId, int(UserIdCacheExpire.Seconds())) @@ -319,6 +329,7 @@ type FillComponent struct { type StartSignFlowRequest struct { TemplateCode string `json:"templateCode"` TemplateName string `json:"templateName"` + FlowType int `json:"flowType"` // 流程类型:0-正常签署流程,2-临时签署流程(买家信息后补) AutoFill int `json:"autoFill"` SourceOrderCode string `json:"sourceOrderCode"` ParticipantList []ParticipantInfo `json:"participantList"` @@ -334,7 +345,7 @@ type StartSignFlowResponse struct { // StartSignFlowData 发起签署数据(API响应) type StartSignFlowData struct { - FlowID string `json:"flowId,omitempty"` + FlowID interface{} `json:"flowId,omitempty"` // 可能是 int64 或 string FlowStatus int `json:"flowStatus,omitempty"` FlowDesc string `json:"flowDesc,omitempty"` FlowTitle string `json:"flowTitle,omitempty"` @@ -345,6 +356,22 @@ type StartSignFlowData struct { ParticipantList []ParticipantItem `json:"participantList,omitempty"` } +// GetFlowIDString 获取 flowId 的字符串值 +func (d *StartSignFlowData) GetFlowIDString() string { + switch v := d.FlowID.(type) { + case string: + return v + case int: + return fmt.Sprintf("%d", v) + case int64: + return fmt.Sprintf("%d", v) + case float64: + return fmt.Sprintf("%.0f", v) + default: + return fmt.Sprintf("%v", v) + } +} + // StartSignFlowResult 发起签署流程返回结果 type StartSignFlowResult struct { ParticipantID string // 签署方2的参与者ID @@ -353,19 +380,35 @@ type StartSignFlowResult struct { // ParticipantItem 参与者项(响应中的) type ParticipantItem struct { - ParticipantID string `json:"participantId"` + ParticipantID interface{} `json:"participantId"` // 可能是 int64 或 string ParticipantFlag string `json:"participantFlag"` SignStatus interface{} `json:"signStatus,omitempty"` - ParticipantCorpID string `json:"participantCorpId,omitempty"` + ParticipantCorpID interface{} `json:"participantCorpId,omitempty"` // 可能是 int64 或 string ParticipantCorpName string `json:"participantCorpName,omitempty"` ParticipantType int `json:"participantType"` ParticipateBizType []string `json:"participateBizType,omitempty"` - PsnID string `json:"psnId,omitempty"` + PsnID interface{} `json:"psnId,omitempty"` // 可能是 int64 或 string PsnName string `json:"psnName,omitempty"` PayeeContractFlag interface{} `json:"payeeContractFlag,omitempty"` Payee interface{} `json:"payee,omitempty"` } +// GetParticipantIDString 获取 participantId 的字符串值 +func (p *ParticipantItem) GetParticipantIDString() string { + switch v := p.ParticipantID.(type) { + case string: + return v + case int: + return fmt.Sprintf("%d", v) + case int64: + return fmt.Sprintf("%d", v) + case float64: + return fmt.Sprintf("%.0f", v) + default: + return fmt.Sprintf("%v", v) + } +} + // GetCodeInt 获取 code 的 int 值 func (r *StartSignFlowResponse) GetCodeInt() int { switch v := r.Code.(type) { @@ -454,16 +497,18 @@ func (y *YunYinSignPayService) StartSignFlow(ctx context.Context, accessToken, u return nil, fmt.Errorf("签署数据为空") } + flowIDStr := signFlowResp.Data.GetFlowIDString() logx.Infof("[云印签API] StartSignFlow: 签署数据,流程ID: %s, 流程状态: %d, 流程描述: %s, 参与者数量: %d", - signFlowResp.Data.FlowID, signFlowResp.Data.FlowStatus, signFlowResp.Data.FlowDesc, len(signFlowResp.Data.ParticipantList)) + flowIDStr, signFlowResp.Data.FlowStatus, signFlowResp.Data.FlowDesc, len(signFlowResp.Data.ParticipantList)) // 从 participantList 中找到签署方2的 participantId var participantID2 string for i, participant := range signFlowResp.Data.ParticipantList { + participantIDStr := participant.GetParticipantIDString() logx.Infof("[云印签API] StartSignFlow: 响应参与者[%d],标志: %s, 参与者ID: %s, 类型: %d", - i, participant.ParticipantFlag, participant.ParticipantID, participant.ParticipantType) + i, participant.ParticipantFlag, participantIDStr, participant.ParticipantType) if participant.ParticipantFlag == "签署方2" { - participantID2 = participant.ParticipantID + participantID2 = participantIDStr logx.Infof("[云印签API] StartSignFlow: 找到签署方2,参与者ID: %s", participantID2) break } @@ -475,12 +520,12 @@ func (y *YunYinSignPayService) StartSignFlow(ctx context.Context, accessToken, u } logx.Infof("[云印签API] StartSignFlow: 发起签署流程成功,订单号: %s, 流程ID: %s, 签署方2参与者ID: %s", - req.SourceOrderCode, signFlowResp.Data.FlowID, participantID2) + req.SourceOrderCode, flowIDStr, participantID2) // 返回结果,包含签署方2的参与者ID和流程ID return &StartSignFlowResult{ ParticipantID: participantID2, - TaskID: signFlowResp.Data.FlowID, // 使用 flowId 作为 taskId + TaskID: flowIDStr, // 使用 flowId 作为 taskId }, nil } @@ -670,6 +715,7 @@ func (y *YunYinSignPayService) CreateYunYinSignPayOrder(ctx context.Context, use startSignFlowReq := &StartSignFlowRequest{ TemplateCode: y.config.TemplateCode, TemplateName: y.config.TemplateName, + FlowType: 0, // 0-正常签署流程(签署方信息需准确完整),2-临时签署流程(签署方二信息可为占位符) AutoFill: 1, SourceOrderCode: outTradeNo, ParticipantList: participantList,