callback

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package callback 封装 SessionToken 回调派发、签名与重试逻辑。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSignature

func BuildSignature(secret string, timestamp int64, nonce string, body []byte) (string, error)

BuildSignature 是 Signer.Sign 的便捷封装。

Types

type Cookie struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Domain string `json:"domain,omitempty"`
}

Cookie 是回传时的 cookie 结构。

type CredentialPayload

type CredentialPayload struct {
	SessionToken string            `json:"session_token"`
	Cookies      []Cookie          `json:"cookies_json,omitempty"`
	Headers      map[string]string `json:"headers_json,omitempty"`
	ExpiresAt    string            `json:"expires_at,omitempty"`
	CapturedAt   string            `json:"captured_at,omitempty"`
	Note         string            `json:"note,omitempty"`
}

CredentialPayload 表示需要回传给业务的凭证。

type Dispatcher

type Dispatcher interface {
	Dispatch(ctx context.Context, req *Request) (int, error)
}

Dispatcher 抽象回调投递行为。

type HTTPDispatcher

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

HTTPDispatcher 使用 HTTP POST 投递回调请求。

func NewHTTPDispatcher

func NewHTTPDispatcher(secret string, log *logger.Logger, opts ...HTTPDispatcherOption) *HTTPDispatcher

NewHTTPDispatcher 创建默认的 HTTP dispatcher。

func (*HTTPDispatcher) Dispatch

func (d *HTTPDispatcher) Dispatch(ctx context.Context, req *Request) (int, error)

Dispatch 将回调请求发送到业务侧,失败时按照 2s→4s→8s 重试。

type HTTPDispatcherOption

type HTTPDispatcherOption func(*HTTPDispatcher)

HTTPDispatcherOption 配置 dispatcher。

func WithHTTPClient

func WithHTTPClient(client *http.Client) HTTPDispatcherOption

WithHTTPClient 设置自定义 HTTP 客户端。

func WithRetrySchedule

func WithRetrySchedule(delays []time.Duration) HTTPDispatcherOption

WithRetrySchedule 自定义重试间隔。

type Payload

type Payload struct {
	FlowID          string             `json:"flow_id"`
	State           string             `json:"state"`
	Status          string             `json:"status"`
	ProviderCode    string             `json:"provider_code,omitempty"`
	ProviderAppCode string             `json:"provider_app_code,omitempty"`
	TenantUUID      string             `json:"tenant_uuid,omitempty"`
	Code            string             `json:"code,omitempty"`
	Message         string             `json:"message,omitempty"`
	LastFailedAPI   string             `json:"last_failed_api,omitempty"`
	Credentials     *CredentialPayload `json:"credentials,omitempty"`
	Metadata        map[string]string  `json:"metadata,omitempty"`
	Timestamp       int64              `json:"timestamp"`
	Nonce           string             `json:"nonce"`
}

Payload 是发送到业务侧的回调信息。

func (*Payload) Body

func (p *Payload) Body() ([]byte, error)

Body 返回 JSON 编码后的 payload。

type Request

type Request struct {
	URL     string            `json:"-"`
	Payload *Payload          `json:"payload"`
	Headers map[string]string `json:"headers"`
}

Request 定义了回调请求。

type Signer

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

Signer 负责根据 secret 生成 HMAC-SHA256 签名。

func NewSigner

func NewSigner(secret string) *Signer

NewSigner 创建新的 HMAC 签名器。

func (*Signer) Sign

func (s *Signer) Sign(timestamp int64, nonce string, body []byte) (string, error)

Sign 根据约定的格式生成签名:HMAC(secret, "timestamp:nonce:" + body)。

Jump to

Keyboard shortcuts

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