112 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package esign
 | |
| 
 | |
| import "fmt"
 | |
| 
 | |
| 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"`
 | |
| }
 | |
| 
 | |
| // Config e签宝服务配置结构体
 | |
| // 包含应用ID、密钥、服务器URL和模板ID等基础配置信息
 | |
| // 新增Contract、Auth、Sign配置
 | |
| type Config struct {
 | |
| 	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"`
 | |
| }
 | |
| 
 | |
| // NewConfig 创建新的配置实例
 | |
| // 提供配置验证和默认值设置
 | |
| func NewConfig(appID, appSecret, serverURL, templateID string, contract *EsignContractConfig, auth *EsignAuthConfig, sign *EsignSignConfig) (*Config, error) {
 | |
| 	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不能为空")
 | |
| 	}
 | |
| 
 | |
| 	return &Config{
 | |
| 		AppID:      appID,
 | |
| 		AppSecret:  appSecret,
 | |
| 		ServerURL:  serverURL,
 | |
| 		TemplateID: templateID,
 | |
| 		Contract:   contract,
 | |
| 		Auth:       auth,
 | |
| 		Sign:       sign,
 | |
| 	}, 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"    // 银行卡认证
 | |
| 
 | |
| 	// 意愿认证模式
 | |
| 	WillingnessAuthSMS   = "CODE_SMS"   // 短信验证码
 | |
| 	WillingnessAuthEmail = "CODE_EMAIL" // 邮箱验证码
 | |
| 
 | |
| 	// 证件类型常量
 | |
| 	IDCardTypeChina = "CRED_PSN_CH_IDCARD" // 中国大陆居民身份证
 | |
| 	OrgCardTypeUSCC = "CRED_ORG_USCC"      // 统一社会信用代码
 | |
| 
 | |
| 	// 签署区样式常量
 | |
| 	SignFieldStyleNormal = 1 // 普通签章
 | |
| 	SignFieldStyleSeam   = 2 // 骑缝签章
 | |
| 
 | |
| 	// 签署人类型常量
 | |
| 	SignerTypePerson = 0 // 个人
 | |
| 	SignerTypeOrg    = 1 // 机构
 | |
| 
 | |
| 	// URL类型常量
 | |
| 	UrlTypeSign = 2 // 签署链接
 | |
| 
 | |
| 	// 客户端类型常量
 | |
| 	ClientTypeAll = "ALL" // 所有客户端
 | |
| )
 |