@@ -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" `
TemplateNam e 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二选一)
TemplateCod e 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时, 后续会在小程序端通过授权更新)
virtual Mobile := "18111111111 "
// 签署方2 使用固定的手机号和姓名
fixed Mobile := "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 : virtual Mobile, // 使用固定的虚拟手机号(占位符)
PsnName : func ( ) string {
if userName != "" {
return userName
}
return "用户"
} ( ) ,
ParticipantType : 0 , // 0表示个人
PsnAccount : fixed Mobile, // 固定手机号
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 , user Name, virtualMobile , user Mobile, amount )
logx . Infof ( "[云印签API] CreateYunYinSignPayOrder: 参与者列表构建完成,订单号: %s, 签署方1: %s(%s), 签署方2: %s(%s), 金额: %.2f" ,
outTradeNo , y . config . Name , y . config . Mobile , fixed Name, fixed Mobile, 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 )