From 70a105fffca4a9e885cd7813b6f522abd6c7beb3 Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Sat, 17 Jan 2026 16:46:27 +0800 Subject: [PATCH] f --- app/main/api/etc/main.dev.yaml | 1 + app/main/api/etc/main.yaml | 1 + app/main/api/internal/config/config.go | 1 + .../internal/service/yunyinSignPayService.go | 75 ++++++++++--------- 4 files changed, 42 insertions(+), 36 deletions(-) diff --git a/app/main/api/etc/main.dev.yaml b/app/main/api/etc/main.dev.yaml index 7db941f..f239ff5 100644 --- a/app/main/api/etc/main.dev.yaml +++ b/app/main/api/etc/main.dev.yaml @@ -101,5 +101,6 @@ YunYinSignPay: Mobile: "18566214578" Name: "陈立" CorpName: "海口开麦贸易有限公司" + TemplateID: "1461036991700317185" TemplateCode: "TP1461036991700317184" # 需要配置实际的模板ID TemplateName: "信息服务授权书" # 需要配置实际的模板名称 diff --git a/app/main/api/etc/main.yaml b/app/main/api/etc/main.yaml index 80689c0..b6f2764 100644 --- a/app/main/api/etc/main.yaml +++ b/app/main/api/etc/main.yaml @@ -100,5 +100,6 @@ YunYinSignPay: Mobile: "18566214578" Name: "陈立" CorpName: "海口开麦贸易有限公司" + TemplateID: "1461036991700317185" TemplateCode: "TP1461036991700317184" # 需要配置实际的模板ID TemplateName: "信息服务授权书" # 需要配置实际的模板名称 diff --git a/app/main/api/internal/config/config.go b/app/main/api/internal/config/config.go index 74ec3c3..883752e 100644 --- a/app/main/api/internal/config/config.go +++ b/app/main/api/internal/config/config.go @@ -146,6 +146,7 @@ type YunYinSignPayConfig struct { Mobile string // 我方手机号 Name string // 我方姓名 CorpName string // 我方公司名称 + TemplateID string // 模板ID TemplateCode string // 模板代码 TemplateName string // 模板名称 } diff --git a/app/main/api/internal/service/yunyinSignPayService.go b/app/main/api/internal/service/yunyinSignPayService.go index 8a95d5a..3b026b4 100644 --- a/app/main/api/internal/service/yunyinSignPayService.go +++ b/app/main/api/internal/service/yunyinSignPayService.go @@ -8,6 +8,7 @@ import ( "io" "jnc-server/app/main/api/internal/config" "net/http" + "strconv" "time" "github.com/zeromicro/go-zero/core/logx" @@ -308,7 +309,6 @@ type ParticipantInfo struct { PsnAccount string `json:"psnAccount"` PsnName string `json:"psnName"` ParticipantCorpName string `json:"participantCorpName,omitempty"` - ParticipantType int `json:"participantType"` PayeeContractFlag int `json:"payeeContractFlag,omitempty"` Payee *PayeeInfo `json:"payee,omitempty"` } @@ -327,13 +327,10 @@ type FillComponent struct { // StartSignFlowRequest 发起签署请求 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"` + TemplateID interface{} `json:"templateId,omitempty"` // 模板ID(int64或string,与templateCode二选一) + TemplateCode string `json:"templateCode,omitempty"` // 模板代码(与templateId二选一) + FlowType int `json:"flowType"` // 流程类型:0-正常签署流程,2-临时签署流程(买家信息后补) ParticipantList []ParticipantInfo `json:"participantList"` - FillComponents []FillComponent `json:"fillComponents"` } // StartSignFlowResponse 发起签署响应 @@ -428,12 +425,16 @@ func (r *StartSignFlowResponse) GetCodeInt() int { // StartSignFlow 发起签署流程 func (y *YunYinSignPayService) StartSignFlow(ctx context.Context, accessToken, userId string, req *StartSignFlowRequest) (*StartSignFlowResult, error) { - logx.Infof("[云印签API] StartSignFlow: 开始发起签署流程,订单号: %s, 模板代码: %s, 模板名称: %s, 用户ID: %s", - req.SourceOrderCode, req.TemplateCode, req.TemplateName, userId) + templateInfo := fmt.Sprintf("模板ID: %v", req.TemplateID) + if req.TemplateID == nil && req.TemplateCode != "" { + templateInfo = fmt.Sprintf("模板代码: %s", req.TemplateCode) + } + logx.Infof("[云印签API] StartSignFlow: 开始发起签署流程,%s, 流程类型: %d, 用户ID: %s", + templateInfo, req.FlowType, userId) logx.Infof("[云印签API] StartSignFlow: 参与者列表,数量: %d", len(req.ParticipantList)) for i, p := range req.ParticipantList { - logx.Infof("[云印签API] StartSignFlow: 参与者[%d],标志: %s, 账号: %s, 姓名: %s, 类型: %d, 企业名: %s", - i, p.ParticipantFlag, p.PsnAccount, p.PsnName, p.ParticipantType, p.ParticipantCorpName) + logx.Infof("[云印签API] StartSignFlow: 参与者[%d],标志: %s, 账号: %s, 姓名: %s, 企业名: %s", + i, p.ParticipantFlag, p.PsnAccount, p.PsnName, p.ParticipantCorpName) if p.Payee != nil { logx.Infof("[云印签API] StartSignFlow: 参与者[%d]收款信息,金额: %.2f, 优先级: %s", i, p.Payee.Amount, p.Payee.Priority) } @@ -519,8 +520,8 @@ func (y *YunYinSignPayService) StartSignFlow(ctx context.Context, accessToken, u return nil, fmt.Errorf("未找到签署方2的参与者ID") } - logx.Infof("[云印签API] StartSignFlow: 发起签署流程成功,订单号: %s, 流程ID: %s, 签署方2参与者ID: %s", - req.SourceOrderCode, flowIDStr, participantID2) + logx.Infof("[云印签API] StartSignFlow: 发起签署流程成功,流程ID: %s, 签署方2参与者ID: %s", + flowIDStr, participantID2) // 返回结果,包含签署方2的参与者ID和流程ID return &StartSignFlowResult{ @@ -692,8 +693,9 @@ func (y *YunYinSignPayService) CreateYunYinSignPayOrder(ctx context.Context, use // 2. 构建参与者列表 logx.Infof("[云印签API] CreateYunYinSignPayOrder: 步骤3-构建参与者列表,订单号: %s", outTradeNo) - // 使用固定的虚拟手机号作为签署方2的占位手机号(flowType=2时,后续会在小程序端通过授权更新) - virtualMobile := "18111111111" + // 签署方2使用固定的手机号和姓名 + fixedMobile := "18888888888" + fixedName := "李" participantList := []ParticipantInfo{ // 签署方1:我方 { @@ -701,39 +703,40 @@ func (y *YunYinSignPayService) CreateYunYinSignPayOrder(ctx context.Context, use PsnAccount: y.config.Mobile, PsnName: y.config.Name, ParticipantCorpName: y.config.CorpName, - ParticipantType: 1, // 1表示企业 }, - // 签署方2:用户(支付方) + // 签署方2:用户(支付方)- 使用固定的手机号和姓名 { ParticipantFlag: "签署方2", - PsnAccount: virtualMobile, // 使用固定的虚拟手机号(占位符) - PsnName: func() string { - if userName != "" { - return userName - } - return "用户" - }(), - ParticipantType: 0, // 0表示个人 + PsnAccount: fixedMobile, // 固定手机号 + PsnName: fixedName, // 固定姓名 PayeeContractFlag: 1, Payee: &PayeeInfo{ - Amount: amount, - Priority: "0", + Amount: amount, // 金额根据订单动态 + Priority: "0", // 固定优先级为0 }, }, } - logx.Infof("[云印签API] CreateYunYinSignPayOrder: 参与者列表构建完成,订单号: %s, 签署方1: %s(%s), 签署方2: %s(虚拟手机号:%s,实际手机号:%s), 金额: %.2f", - outTradeNo, y.config.Name, y.config.Mobile, userName, virtualMobile, userMobile, amount) + logx.Infof("[云印签API] CreateYunYinSignPayOrder: 参与者列表构建完成,订单号: %s, 签署方1: %s(%s), 签署方2: %s(%s), 金额: %.2f", + outTradeNo, y.config.Name, y.config.Mobile, fixedName, fixedMobile, amount) // 3. 发起签署流程 - logx.Infof("[云印签API] CreateYunYinSignPayOrder: 步骤4-发起签署流程,订单号: %s, 模板代码: %s", outTradeNo, y.config.TemplateCode) + logx.Infof("[云印签API] CreateYunYinSignPayOrder: 步骤4-发起签署流程,订单号: %s, 模板ID: %s", outTradeNo, y.config.TemplateID) + // 将 TemplateID 字符串转换为 int64(API要求是 integer (int64)) + var templateID interface{} + if y.config.TemplateID != "" { + if id, err := strconv.ParseInt(y.config.TemplateID, 10, 64); err == nil { + templateID = id + logx.Infof("[云印签API] CreateYunYinSignPayOrder: 模板ID转换成功,订单号: %s, 模板ID: %d", outTradeNo, id) + } else { + // 如果转换失败,使用字符串 + templateID = y.config.TemplateID + logx.Infof("[云印签API] CreateYunYinSignPayOrder: 模板ID使用字符串格式,订单号: %s, 模板ID: %s", outTradeNo, y.config.TemplateID) + } + } startSignFlowReq := &StartSignFlowRequest{ - TemplateCode: y.config.TemplateCode, - TemplateName: y.config.TemplateName, - FlowType: 2, // 0-正常签署流程(签署方信息需准确完整),2-临时签署流程(签署方二信息可为占位符) - AutoFill: 1, - SourceOrderCode: outTradeNo, + TemplateID: templateID, // 模板ID(int64类型) + FlowType: 2, // 2-临时签署流程(签署方二信息可为占位符) ParticipantList: participantList, - FillComponents: []FillComponent{}, // 可以根据需要填充 } signFlowData, err := y.StartSignFlow(ctx, accessToken, operationUserId, startSignFlowReq)