esign

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

README

esign-go

golang GitHub release pkg.go.dev Apache 2.0 license

E签宝 Go SDK

go get -u github.com/shenghui0779/esign-go
签章准备

制作合同模板,切记:保存「模板ID」

  • 第一步:获取上传URL 👉 这里
  • 第二步:上传合同模板文件 👉 这里
  • 第三步:查询文件上传状态 👉 这里
  • 第四步:获取制作合同模板的页面 👉 这里
  • 第五步:查询合同模板控件详情 👉 这里
签章流程

基于合同模板创建签章流程,切记:保存「文件ID」和「流程ID」

  • 第一步:填写模板生成文件 👉 这里
  • 第二步:基于文件发起签署 👉 这里
  • 第三步:获取签署页面链接 👉 这里
  • 第四步:处理异步回调通知 👉 这里

Documentation

Index

Constants

View Source
const (
	HeaderAccept               = "Accept"
	HeaderContentType          = "Content-Type"
	HeaderContentMD5           = "Content-MD5"
	HeaderTSignOpenAppID       = "X-Tsign-Open-App-Id"
	HeaderTSignOpenAuthMode    = "X-Tsign-Open-Auth-Mode"
	HeaderTSignOpenCaTimestamp = "X-Tsign-Open-Ca-Timestamp"
	HeaderTSignOpenCaSignature = "X-Tsign-Open-Ca-Signature"
	HeaderTSignOpenTimestamp   = "X-Tsign-Open-TIMESTAMP"
	HeaderTSignOpenSignature   = "X-Tsign-Open-SIGNATURE"
)
View Source
const (
	AcceptAll     = "*/*"
	AuthModeSign  = "Signature"
	ContentJSON   = "application/json; charset=UTF-8"
	ContentStream = "application/octet-stream"
)

Variables

This section is empty.

Functions

func ContentMD5

func ContentMD5(b []byte) string

ContentMD5 计算内容MD5值

func FileMD5

func FileMD5(filename string) (string, int64)

FileMD5 计算文件MD5值

func HeaderEncode

func HeaderEncode(h http.Header) string

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client E签宝客户端

func NewClient

func NewClient(appid, secret string, options ...Option) *Client

NewClient 返回E签宝客户端

func NewSandbox

func NewSandbox(appid, secret string, options ...Option) *Client

NewSandbox 返回E签宝「沙箱环境」客户端

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, path string, query url.Values) (gjson.Result, error)

GetJSON GET请求JSON数据

func (*Client) PostJSON

func (c *Client) PostJSON(ctx context.Context, path string, params X) (gjson.Result, error)

PostJSON POST请求JSON数据

func (*Client) PutStream

func (c *Client) PutStream(ctx context.Context, uploadURL string, reader io.ReadSeeker) error

PutStream 上传文件流

func (*Client) PutStreamFromFile

func (c *Client) PutStreamFromFile(ctx context.Context, uploadURL, filename string) error

PutStreamFromFile 通过文件上传文件流

func (*Client) Verify

func (c *Client) Verify(header http.Header, body []byte) error

Verify 签名验证 (回调通知等)

type HTTPClient

type HTTPClient interface {
	// Do 发送HTTP请求
	// 注意:应该使用Context设置请求超时时间
	Do(ctx context.Context, method, reqURL string, body []byte, options ...HTTPOption) (*http.Response, error)
}

HTTPClient HTTP客户端

func NewDefaultHTTPClient

func NewDefaultHTTPClient() HTTPClient

NewDefaultHTTPClient 生成一个默认的HTTP客户端

func NewHTTPClient

func NewHTTPClient(cli *http.Client) HTTPClient

NewHTTPClient 通过官方 `http.Client` 生成一个HTTP客户端

type HTTPOption

type HTTPOption func(o *httpOptions)

HTTPOption HTTP请求选项

func HeaderToHttpOption

func HeaderToHttpOption(h http.Header) []HTTPOption

func WithHTTPClose

func WithHTTPClose() HTTPOption

WithHTTPClose 请求结束后关闭请求

func WithHTTPCookies

func WithHTTPCookies(cookies ...*http.Cookie) HTTPOption

WithHTTPCookies 设置HTTP请求Cookie

func WithHTTPHeader

func WithHTTPHeader(key string, vals ...string) HTTPOption

WithHTTPHeader 设置HTTP请求头

type Option

type Option func(c *Client)

Option 自定义设置项

func WithHttpCli

func WithHttpCli(cli *http.Client) Option

WithHttpCli 设置自定义 HTTP Client

func WithLogger

func WithLogger(f func(ctx context.Context, data map[string]string)) Option

WithLogger 设置日志记录

type ReqLog

type ReqLog struct {
	// contains filtered or unexported fields
}

ReqLog 请求日志

func NewReqLog

func NewReqLog(method, reqURL string) *ReqLog

NewReqLog 生成请求日志

func (*ReqLog) Do

func (l *ReqLog) Do(ctx context.Context, log func(ctx context.Context, data map[string]string))

Do 日志记录

func (*ReqLog) Set

func (l *ReqLog) Set(k, v string)

Set 设置日志K-V

func (*ReqLog) SetReqBody

func (l *ReqLog) SetReqBody(v string)

SetBody 设置请求Body

func (*ReqLog) SetReqHeader

func (l *ReqLog) SetReqHeader(h http.Header)

SetReqHeader 设置请求头

func (*ReqLog) SetRespBody

func (l *ReqLog) SetRespBody(v string)

SetResp 设置返回报文

func (*ReqLog) SetRespHeader

func (l *ReqLog) SetRespHeader(h http.Header)

SetRespHeader 设置返回头

func (*ReqLog) SetStatusCode

func (l *ReqLog) SetStatusCode(code int)

SetStatusCode 设置HTTP状态码

type SignOption

type SignOption func(sf *signfields)

SignOption 签名选项

func WithSignAccept

func WithSignAccept(v string) SignOption

WithSignAccept 设置Accept

func WithSignContMD5

func WithSignContMD5(v string) SignOption

WithSignContMD5 设置ContentMD5

func WithSignContType

func WithSignContType(v string) SignOption

WithSignContType 设置ContentType

func WithSignDate

func WithSignDate(v string) SignOption

WithSignDate 设置Date

func WithSignHeader

func WithSignHeader(k, v string) SignOption

WithSignHeader 设置Header

func WithSignParam

func WithSignParam(k, v string) SignOption

WithSignParam 以 K-V 设置参数

func WithSignValues

func WithSignValues(v url.Values) SignOption

WithSignValues 以 url.Values 设置参数

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

Signer 签名器

func NewSigner

func NewSigner(method, path string, options ...SignOption) *Signer

NewSigner 返回新的签名器

func (*Signer) Do

func (s *Signer) Do(secret string) string

Do 生成签名

func (*Signer) String

func (s *Signer) String() string

String 返回签名字符串

type V

type V map[string]string

V 用于处理 k-v 需要格式化的场景,如:签名

func (V) Del

func (v V) Del(key string)

Del 删除Key

func (V) Encode

func (v V) Encode(sym, sep string, options ...VEncOption) string

Encode 通过自定义的符号和分隔符按照key的ASCII码升序格式化为字符串。 例如:("=", "&") ---> bar=baz&foo=quux; 例如:(":", "#") ---> bar:baz#foo:quux;

func (V) Get

func (v V) Get(key string) string

Get 获取值

func (V) Has

func (v V) Has(key string) bool

Has 判断Key是否存在

func (V) Set

func (v V) Set(key, value string)

Set 设置 k-v

type VEmptyMode added in v1.0.4

type VEmptyMode int

VEmptyMode 值为空时的Encode模式

const (
	EmptyDefault VEmptyMode = iota // 默认:bar=baz&foo=
	EmptyIgnore                    // 忽略:bar=baz
	EmptyOnlyKey                   // 仅保留Key:bar=baz&foo
)

type VEncOption

type VEncOption func(o *vEncOptions)

VEncOption V Encode 选项

func WithEmptyMode added in v1.0.4

func WithEmptyMode(mode VEmptyMode) VEncOption

WithEmptyMode 设置值为空时的Encode模式

func WithIgnoreKeys

func WithIgnoreKeys(keys ...string) VEncOption

WithIgnoreKeys 设置Encode时忽略的key

func WithKVEscape

func WithKVEscape() VEncOption

WithKVEscape 设置K-V是否需要QueryEscape

type X

type X map[string]any

X `map[string]any` 别名

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL