| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | package esign | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import "fmt" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | type EsignContractConfig struct { | 
					
						
							|  |  |  | 	Name       string `json:"name" yaml:"name"` | 
					
						
							|  |  |  | 	ExpireDays int    `json:"expireDays" yaml:"expire_days"` | 
					
						
							|  |  |  | 	RetryCount int    `json:"retryCount" yaml:"retry_count"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type EsignAuthConfig struct { | 
					
						
							|  |  |  | 	OrgAuthModes         []string `json:"orgAuthModes" yaml:"org_auth_modes"` | 
					
						
							|  |  |  | 	DefaultAuthMode      string   `json:"defaultAuthMode" yaml:"default_auth_mode"` | 
					
						
							|  |  |  | 	PsnAuthModes         []string `json:"psnAuthModes" yaml:"psn_auth_modes"` | 
					
						
							|  |  |  | 	WillingnessAuthModes []string `json:"willingnessAuthModes" yaml:"willingness_auth_modes"` | 
					
						
							|  |  |  | 	RedirectUrl          string   `json:"redirectUrl" yaml:"redirect_url"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type EsignSignConfig struct { | 
					
						
							|  |  |  | 	AutoFinish     bool   `json:"autoFinish" yaml:"auto_finish"` | 
					
						
							|  |  |  | 	SignFieldStyle int    `json:"signFieldStyle" yaml:"sign_field_style"` | 
					
						
							|  |  |  | 	ClientType     string `json:"clientType" yaml:"client_type"` | 
					
						
							|  |  |  | 	RedirectUrl    string `json:"redirectUrl" yaml:"redirect_url"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | // Config e签宝服务配置结构体 | 
					
						
							|  |  |  | // 包含应用ID、密钥、服务器URL和模板ID等基础配置信息 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | // 新增Contract、Auth、Sign配置 | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | type Config struct { | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	AppID         string              `json:"appId" yaml:"app_id"` | 
					
						
							|  |  |  | 	AppSecret     string              `json:"appSecret" yaml:"app_secret"` | 
					
						
							|  |  |  | 	ServerURL     string              `json:"serverUrl" yaml:"server_url"` | 
					
						
							|  |  |  | 	TemplateID    string              `json:"templateId" yaml:"template_id"` | 
					
						
							|  |  |  | 	Contract      *EsignContractConfig `json:"contract" yaml:"contract"` | 
					
						
							|  |  |  | 	Auth          *EsignAuthConfig     `json:"auth" yaml:"auth"` | 
					
						
							|  |  |  | 	Sign          *EsignSignConfig     `json:"sign" yaml:"sign"` | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NewConfig 创建新的配置实例 | 
					
						
							|  |  |  | // 提供配置验证和默认值设置 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | func NewConfig(appID, appSecret, serverURL, templateID string, contract *EsignContractConfig, auth *EsignAuthConfig, sign *EsignSignConfig) (*Config, error) { | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | 	if appID == "" { | 
					
						
							|  |  |  | 		return nil, fmt.Errorf("应用ID不能为空") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if appSecret == "" { | 
					
						
							|  |  |  | 		return nil, fmt.Errorf("应用密钥不能为空") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if serverURL == "" { | 
					
						
							|  |  |  | 		return nil, fmt.Errorf("服务器URL不能为空") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if templateID == "" { | 
					
						
							|  |  |  | 		return nil, fmt.Errorf("模板ID不能为空") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | 	return &Config{ | 
					
						
							|  |  |  | 		AppID:      appID, | 
					
						
							|  |  |  | 		AppSecret:  appSecret, | 
					
						
							|  |  |  | 		ServerURL:  serverURL, | 
					
						
							|  |  |  | 		TemplateID: templateID, | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 		Contract:   contract, | 
					
						
							|  |  |  | 		Auth:       auth, | 
					
						
							|  |  |  | 		Sign:       sign, | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | 	}, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Validate 验证配置的完整性 | 
					
						
							|  |  |  | func (c *Config) Validate() error { | 
					
						
							|  |  |  | 	if c.AppID == "" { | 
					
						
							|  |  |  | 		return fmt.Errorf("应用ID不能为空") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if c.AppSecret == "" { | 
					
						
							|  |  |  | 		return fmt.Errorf("应用密钥不能为空") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if c.ServerURL == "" { | 
					
						
							|  |  |  | 		return fmt.Errorf("服务器URL不能为空") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if c.TemplateID == "" { | 
					
						
							|  |  |  | 		return fmt.Errorf("模板ID不能为空") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // 认证模式常量 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	// 个人认证模式 | 
					
						
							|  |  |  | 	AuthModeMobile3 = "PSN_MOBILE3" // 手机号三要素认证 | 
					
						
							|  |  |  | 	AuthModeIDCard  = "PSN_IDCARD"  // 身份证认证 | 
					
						
							|  |  |  | 	AuthModeBank    = "PSN_BANK"    // 银行卡认证 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 意愿认证模式 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	WillingnessAuthSMS   = "CODE_SMS"   // 短信验证码 | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | 	WillingnessAuthEmail = "CODE_EMAIL" // 邮箱验证码 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 证件类型常量 | 
					
						
							|  |  |  | 	IDCardTypeChina = "CRED_PSN_CH_IDCARD" // 中国大陆居民身份证 | 
					
						
							|  |  |  | 	OrgCardTypeUSCC = "CRED_ORG_USCC"      // 统一社会信用代码 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 签署区样式常量 | 
					
						
							|  |  |  | 	SignFieldStyleNormal = 1 // 普通签章 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | 	SignFieldStyleSeam   = 2 // 骑缝签章 | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// 签署人类型常量 | 
					
						
							|  |  |  | 	SignerTypePerson = 0 // 个人 | 
					
						
							|  |  |  | 	SignerTypeOrg    = 1 // 机构 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// URL类型常量 | 
					
						
							|  |  |  | 	UrlTypeSign = 2 // 签署链接 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 客户端类型常量 | 
					
						
							|  |  |  | 	ClientTypeAll = "ALL" // 所有客户端 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  | ) |