storage

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthorizerAccessToken

type AuthorizerAccessToken struct {
	AuthorizerAppID        string    `json:"authorizer_appid"`
	AuthorizerAccessToken  string    `json:"authorizer_access_token"`
	ExpiresIn              int       `json:"expires_in"`
	ExpiresAt              time.Time `json:"expires_at"`
	AuthorizerRefreshToken string    `json:"authorizer_refresh_token"`
}

AuthorizerAccessToken 授权方access_token

type ComponentAccessToken

type ComponentAccessToken struct {
	AccessToken string    `json:"component_access_token"`
	ExpiresIn   int       `json:"expires_in"`
	ExpiresAt   time.Time `json:"expires_at"`
}

ComponentAccessToken 第三方平台access_token

type ComponentVerifyTicket

type ComponentVerifyTicket struct {
	Ticket    string    `json:"ticket"`     // 票据内容
	CreatedAt time.Time `json:"created_at"` // 创建时间
	ExpiresAt time.Time `json:"expires_at"` // 过期时间(创建时间+12小时)
}

ComponentVerifyTicket 验证票据结构

type DBAuthorizerToken

type DBAuthorizerToken struct {
	base.MysqlBaseModel

	ID                     uint      `gorm:"column:id;type:INT(11) UNSIGNED;primaryKey;autoIncrement" json:"id"`
	AuthorizerAppID        string    `gorm:"column:authorizer_app_id;type:varchar(64);not null;uniqueIndex" json:"authorizer_app_id"`
	AuthorizerAccessToken  string    `gorm:"column:authorizer_access_token;type:varchar(512);not null" json:"authorizer_access_token"`
	AuthorizerRefreshToken string    `gorm:"column:authorizer_refresh_token;type:varchar(512)" json:"authorizer_refresh_token"`
	ExpiresIn              int       `gorm:"column:expires_in;not null;comment:有效期限" json:"expires_in"`
	ExpiresAt              time.Time `gorm:"column:expires_at;not null;index;comment:过期时间" json:"expires_at"`
	CreatedAt              time.Time `gorm:"column:created_at;type:DATETIME;default:NULL;comment:创建时间" json:"created_at"`
	UpdatedAt              time.Time `gorm:"column:updated_at;type:DATETIME;default:NULL;comment:更新时间" json:"updated_at"`
}

DBAuthorizerToken 授权方令牌数据库模型

type DBAuthorizerTokenSqlite added in v0.0.3

type DBAuthorizerTokenSqlite struct {
	base.SqliteBaseModel
	ID                     uint      `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	AuthorizerAppID        string    `gorm:"column:authorizer_app_id;type:varchar(64);not null;uniqueIndex" json:"authorizer_app_id"`
	AuthorizerAccessToken  string    `gorm:"column:authorizer_access_token;type:varchar(512);not null" json:"authorizer_access_token"`
	AuthorizerRefreshToken string    `gorm:"column:authorizer_refresh_token;type:varchar(512)" json:"authorizer_refresh_token"`
	ExpiresIn              int       `gorm:"column:expires_in;not null" json:"expires_in"`
	ExpiresAt              time.Time `gorm:"column:expires_at;not null;index" json:"expires_at"`
	CreatedAt              time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt              time.Time `gorm:"column:updated_at" json:"updated_at"`
}

type DBComponentToken

type DBComponentToken struct {
	base.MysqlBaseModel

	ID          uint      `gorm:"column:id;type:INT(11) UNSIGNED;primaryKey;autoIncrement" json:"id"`
	AccessToken string    `gorm:"column:access_token;type:varchar(512);not null;comment:访问令牌" json:"access_token"`
	ExpiresIn   int       `gorm:"column:expires_in;not null;comment:有效期限" json:"expires_in"`
	ExpiresAt   time.Time `gorm:"column:expires_at;not null;index;comment:过期时间" json:"expires_at"`
	CreatedAt   time.Time `gorm:"column:created_at;type:DATETIME;default:NULL;comment:创建时间" json:"created_at"`
	UpdatedAt   time.Time `gorm:"column:updated_at;type:DATETIME;default:NULL;comment:更新时间" json:"updated_at"`
}

DBComponentToken 组件令牌数据库模型

type DBComponentTokenSqlite added in v0.0.3

type DBComponentTokenSqlite struct {
	base.SqliteBaseModel
	ID          uint      `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	AccessToken string    `gorm:"column:access_token;type:varchar(512);not null" json:"access_token"`
	ExpiresIn   int       `gorm:"column:expires_in;not null" json:"expires_in"`
	ExpiresAt   time.Time `gorm:"column:expires_at;not null;index" json:"expires_at"`
	CreatedAt   time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt   time.Time `gorm:"column:updated_at" json:"updated_at"`
}

type DBComponentVerifyTicket

type DBComponentVerifyTicket struct {
	base.MysqlBaseModel

	ID        uint      `gorm:"column:id;type:INT(11) UNSIGNED;primaryKey;autoIncrement" json:"id"`
	Ticket    string    `gorm:"column:ticket;type:varchar(512);not null;comment:票据内容" json:"ticket"`                    // 票据内容
	ExpiresAt time.Time `gorm:"column:expires_at;type:DATETIME;default:NULL;comment:过期时间(创建时间+12小时)" json:"expires_at"` // 过期时间(创建时间+12小时)
	CreatedAt time.Time `gorm:"column:created_at;type:DATETIME;default:NULL;comment:创建时间" json:"created_at"`            // 创建时间
}

DBComponentVerifyTicket 验证票据数据库模型

type DBComponentVerifyTicketSqlite added in v0.0.3

type DBComponentVerifyTicketSqlite struct {
	base.SqliteBaseModel
	ID        uint      `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	Ticket    string    `gorm:"column:ticket;type:varchar(512);not null" json:"ticket"`
	ExpiresAt time.Time `gorm:"column:expires_at" json:"expires_at"`
	CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
}

type DBPreAuthCode

type DBPreAuthCode struct {
	base.MysqlBaseModel

	ID          uint      `gorm:"column:id;type:INT(11) UNSIGNED;primaryKey;autoIncrement" json:"id"`
	PreAuthCode string    `gorm:"column:pre_auth_code;type:varchar(256);not null;comment:预授权码" json:"pre_auth_code"`
	ExpiresIn   int       `gorm:"column:expires_in;not null;comment:有效期限" json:"expires_in"`
	ExpiresAt   time.Time `gorm:"column:expires_at;not null;index;comment:过期时间" json:"expires_at"`
	CreatedAt   time.Time `gorm:"column:created_at;type:DATETIME;default:NULL;comment:创建时间" json:"created_at"`
	UpdatedAt   time.Time `gorm:"column:updated_at;type:DATETIME;default:NULL;comment:更新时间" json:"updated_at"`
}

DBPreAuthCode 预授权码数据库模型

type DBPreAuthCodeSqlite added in v0.0.3

type DBPreAuthCodeSqlite struct {
	base.SqliteBaseModel
	ID          uint      `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	PreAuthCode string    `gorm:"column:pre_auth_code;type:varchar(256);not null" json:"pre_auth_code"`
	ExpiresIn   int       `gorm:"column:expires_in;not null" json:"expires_in"`
	ExpiresAt   time.Time `gorm:"column:expires_at;not null;index" json:"expires_at"`
	CreatedAt   time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt   time.Time `gorm:"column:updated_at" json:"updated_at"`
}

type DBPrevEncodingAESKey

type DBPrevEncodingAESKey struct {
	base.MysqlBaseModel

	ID              uint      `gorm:"column:id;type:INT(11) UNSIGNED;primaryKey;autoIncrement"`
	AppID           string    `gorm:"column:app_id;type:varchar(64);not null;uniqueIndex"`
	PrevEncodingKey string    `gorm:"column:prev_encoding_key;type:varchar(256);not null;comment:上一次EncodingAESKey" json:"prev_encoding_key"`
	CreatedAt       time.Time `gorm:"column:created_at;type:DATETIME;default:NULL;comment:创建时间" json:"created_at"`
	UpdatedAt       time.Time `gorm:"column:updated_at;type:DATETIME;default:NULL;comment:更新时间" json:"updated_at"`
}

DBPrevEncodingAESKey 上一次EncodingAESKey数据库模型

type DBPrevEncodingAESKeySqlite added in v0.0.3

type DBPrevEncodingAESKeySqlite struct {
	base.SqliteBaseModel
	ID              uint      `gorm:"column:id;primaryKey;autoIncrement"`
	AppID           string    `gorm:"column:app_id;type:varchar(64);not null;uniqueIndex"`
	PrevEncodingKey string    `gorm:"column:prev_encoding_key;type:varchar(256);not null" json:"prev_encoding_key"`
	CreatedAt       time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt       time.Time `gorm:"column:updated_at" json:"updated_at"`
}

type DBStorage

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

DBStorage 数据库存储实现 将令牌数据持久化到关系型数据库

func NewDBStorage

func NewDBStorage(dbConfig jcbaseGo.DbStruct, opts ...string) (*DBStorage, error)

NewDBStorage 创建数据库存储实例 @param dbConfig jcbaseGo.DbStruct 数据库配置结构 @param opts ...string 可选参数 @return *DBStorage 数据库存储实例 @return error 错误信息

func (*DBStorage) ClearAuthorizerTokens

func (s *DBStorage) ClearAuthorizerTokens(ctx context.Context) error

ClearAuthorizerTokens 清除所有授权方令牌

func (*DBStorage) DeleteAuthorizerToken

func (s *DBStorage) DeleteAuthorizerToken(ctx context.Context, authorizerAppID string) error

DeleteAuthorizerToken 删除授权方令牌

func (*DBStorage) DeleteComponentToken

func (s *DBStorage) DeleteComponentToken(ctx context.Context) error

DeleteComponentToken 删除组件令牌

func (*DBStorage) DeleteComponentVerifyTicket

func (s *DBStorage) DeleteComponentVerifyTicket(ctx context.Context) error

DeleteComponentVerifyTicket 删除验证票据 @param ctx context.Context 上下文 @return error 错误信息

func (*DBStorage) DeletePreAuthCode

func (s *DBStorage) DeletePreAuthCode(ctx context.Context) error

DeletePreAuthCode 删除预授权码

func (*DBStorage) DeletePrevEncodingAESKey

func (s *DBStorage) DeletePrevEncodingAESKey(ctx context.Context, appID string) error

DeletePrevEncodingAESKey 删除上一次EncodingAESKey

func (*DBStorage) DeleteWechatPayCert added in v0.1.0

func (s *DBStorage) DeleteWechatPayCert(ctx context.Context, mchID, serialNo string) error

DeleteWechatPayCert 从数据库删除指定微信支付平台证书

参数:

  • ctx: 上下文
  • mchID: 商户号
  • serialNo: 证书序列号

返回:

  • error: 删除失败时返回错误

func (*DBStorage) GetAuthorizerToken

func (s *DBStorage) GetAuthorizerToken(ctx context.Context, authorizerAppID string) (*AuthorizerAccessToken, error)

GetAuthorizerToken 从数据库读取授权方令牌

func (*DBStorage) GetComponentToken

func (s *DBStorage) GetComponentToken(ctx context.Context) (*ComponentAccessToken, error)

GetComponentToken 从数据库读取组件令牌

func (*DBStorage) GetComponentVerifyTicket

func (s *DBStorage) GetComponentVerifyTicket(ctx context.Context) (*ComponentVerifyTicket, error)

GetComponentVerifyTicket 从数据库读取验证票据 @param ctx context.Context 上下文 @return *ComponentVerifyTicket 票据结构,包含创建时间 @return error 错误信息

func (*DBStorage) GetLatestWechatPayCert added in v0.1.0

func (s *DBStorage) GetLatestWechatPayCert(ctx context.Context, mchID string) (*WechatPayCertificate, error)

GetLatestWechatPayCert 从数据库读取最新的微信支付平台证书

参数:

  • ctx: 上下文
  • mchID: 商户号

返回:

  • *WechatPayCertificate: 最新的证书信息,不存在返回 nil
  • error: 查询失败时返回错误

func (*DBStorage) GetPreAuthCode

func (s *DBStorage) GetPreAuthCode(ctx context.Context) (*PreAuthCode, error)

GetPreAuthCode 从数据库读取预授权码

func (*DBStorage) GetPrevEncodingAESKey

func (s *DBStorage) GetPrevEncodingAESKey(ctx context.Context, appID string) (*PrevEncodingAESKey, error)

GetPrevEncodingAESKey 从数据库读取上一次EncodingAESKey

func (*DBStorage) GetWechatPayCert added in v0.1.0

func (s *DBStorage) GetWechatPayCert(ctx context.Context, mchID, serialNo string) (*WechatPayCertificate, error)

GetWechatPayCert 从数据库读取指定序列号的微信支付平台证书

参数:

  • ctx: 上下文
  • mchID: 商户号
  • serialNo: 证书序列号

返回:

  • *WechatPayCertificate: 证书信息,不存在返回 nil
  • error: 查询失败时返回错误

func (*DBStorage) ListAuthorizerTokens

func (s *DBStorage) ListAuthorizerTokens(ctx context.Context) ([]string, error)

ListAuthorizerTokens 列出所有已存储的授权方appid

func (*DBStorage) ListWechatPayCertSerialNos added in v0.1.0

func (s *DBStorage) ListWechatPayCertSerialNos(ctx context.Context, mchID string) ([]string, error)

ListWechatPayCertSerialNos 列出数据库中指定商户的所有微信支付平台证书序列号

参数:

  • ctx: 上下文
  • mchID: 商户号

返回:

  • []string: 证书序列号列表
  • error: 查询失败时返回错误

func (*DBStorage) Ping

func (s *DBStorage) Ping(ctx context.Context) error

Ping 存储健康检查

func (*DBStorage) SaveAuthorizerToken

func (s *DBStorage) SaveAuthorizerToken(ctx context.Context, authorizerAppID string, token *AuthorizerAccessToken) error

SaveAuthorizerToken 保存授权方令牌到数据库

func (*DBStorage) SaveComponentToken

func (s *DBStorage) SaveComponentToken(ctx context.Context, token *ComponentAccessToken) error

SaveComponentToken 保存组件令牌到数据库

func (*DBStorage) SaveComponentVerifyTicket

func (s *DBStorage) SaveComponentVerifyTicket(ctx context.Context, ticket string) error

SaveComponentVerifyTicket 保存验证票据到数据库 @param ctx context.Context 上下文 @param ticket string 票据内容 @return error 错误信息

func (*DBStorage) SavePreAuthCode

func (s *DBStorage) SavePreAuthCode(ctx context.Context, code *PreAuthCode) error

SavePreAuthCode 保存预授权码到数据库

func (*DBStorage) SavePrevEncodingAESKey

func (s *DBStorage) SavePrevEncodingAESKey(ctx context.Context, appID string, prevKey string) error

SavePrevEncodingAESKey 保存上一次EncodingAESKey到数据库

func (*DBStorage) SaveWechatPayCert added in v0.1.0

func (s *DBStorage) SaveWechatPayCert(ctx context.Context, mchID string, cert *WechatPayCertificate) error

SaveWechatPayCert 保存微信支付平台证书到数据库

参数:

  • ctx: 上下文
  • mchID: 商户号
  • cert: 微信支付平台证书信息

返回:

  • error: 保存失败时返回错误

type DBWechatPayCertificate added in v0.1.0

type DBWechatPayCertificate struct {
	base.MysqlBaseModel

	ID          uint      `gorm:"column:id;type:INT(11) UNSIGNED;primaryKey;autoIncrement" json:"id"`
	MchID       string    `gorm:"column:mch_id;type:varchar(64);not null;uniqueIndex:idx_mch_serial;comment:商户号" json:"mch_id"`
	SerialNo    string    `gorm:"column:serial_no;type:varchar(64);not null;uniqueIndex:idx_mch_serial;comment:证书序列号" json:"serial_no"`
	Certificate string    `gorm:"column:certificate;type:LONGTEXT;not null;comment:证书PEM内容" json:"certificate"`
	ExpiresAt   time.Time `gorm:"column:expires_at;not null;index;comment:证书过期时间" json:"expires_at"`
	CreatedAt   time.Time `gorm:"column:created_at;type:DATETIME;default:NULL;comment:创建时间" json:"created_at"`
	UpdatedAt   time.Time `gorm:"column:updated_at;type:DATETIME;default:NULL;comment:更新时间" json:"updated_at"`
}

DBWechatPayCertificate 微信支付平台证书数据库模型

type DBWechatPayCertificateSqlite added in v0.1.0

type DBWechatPayCertificateSqlite struct {
	base.SqliteBaseModel
	ID          uint      `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	MchID       string    `gorm:"column:mch_id;type:varchar(64);not null;uniqueIndex:idx_mch_serial" json:"mch_id"`
	SerialNo    string    `gorm:"column:serial_no;type:varchar(64);not null;uniqueIndex:idx_mch_serial" json:"serial_no"`
	Certificate string    `gorm:"column:certificate;type:TEXT;not null" json:"certificate"`
	ExpiresAt   time.Time `gorm:"column:expires_at;not null;index" json:"expires_at"`
	CreatedAt   time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt   time.Time `gorm:"column:updated_at" json:"updated_at"`
}

type FileStorage

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

FileStorage 文件存储实现 将令牌数据持久化到本地文件系统

func NewFileStorage

func NewFileStorage(baseDir string) (*FileStorage, error)

NewFileStorage 创建文件存储实例

func (*FileStorage) ClearAuthorizerTokens

func (s *FileStorage) ClearAuthorizerTokens(ctx context.Context) error

ClearAuthorizerTokens 清除所有授权方令牌

func (*FileStorage) DeleteAuthorizerToken

func (s *FileStorage) DeleteAuthorizerToken(ctx context.Context, authorizerAppID string) error

DeleteAuthorizerToken 删除授权方令牌文件

func (*FileStorage) DeleteComponentToken

func (s *FileStorage) DeleteComponentToken(ctx context.Context) error

DeleteComponentToken 删除组件令牌文件

func (*FileStorage) DeleteComponentVerifyTicket

func (s *FileStorage) DeleteComponentVerifyTicket(ctx context.Context) error

DeleteVerifyTicket 删除验证票据文件

func (*FileStorage) DeletePreAuthCode

func (s *FileStorage) DeletePreAuthCode(ctx context.Context) error

DeletePreAuthCode 删除预授权码文件

func (*FileStorage) DeletePrevEncodingAESKey

func (s *FileStorage) DeletePrevEncodingAESKey(ctx context.Context, appID string) error

DeletePrevEncodingAESKey 删除上一次的EncodingAESKey文件

func (*FileStorage) DeleteWechatPayCert added in v0.1.0

func (s *FileStorage) DeleteWechatPayCert(ctx context.Context, mchID, serialNo string) error

DeleteWechatPayCert 从文件删除指定微信支付平台证书

func (*FileStorage) GetAuthorizerToken

func (s *FileStorage) GetAuthorizerToken(ctx context.Context, authorizerAppID string) (*AuthorizerAccessToken, error)

GetAuthorizerToken 从文件读取授权方令牌

func (*FileStorage) GetComponentToken

func (s *FileStorage) GetComponentToken(ctx context.Context) (*ComponentAccessToken, error)

GetComponentToken 从文件读取组件令牌

func (*FileStorage) GetComponentVerifyTicket

func (s *FileStorage) GetComponentVerifyTicket(ctx context.Context) (*ComponentVerifyTicket, error)

GetVerifyTicket 从文件读取验证票据

func (*FileStorage) GetLatestWechatPayCert added in v0.1.0

func (s *FileStorage) GetLatestWechatPayCert(ctx context.Context, mchID string) (*WechatPayCertificate, error)

GetLatestWechatPayCert 从文件读取最新的微信支付平台证书

func (*FileStorage) GetPreAuthCode

func (s *FileStorage) GetPreAuthCode(ctx context.Context) (*PreAuthCode, error)

GetPreAuthCode 从文件读取预授权码

func (*FileStorage) GetPrevEncodingAESKey

func (s *FileStorage) GetPrevEncodingAESKey(ctx context.Context, appID string) (*PrevEncodingAESKey, error)

GetPrevEncodingAESKey 从文件读取上一次的EncodingAESKey

func (*FileStorage) GetWechatPayCert added in v0.1.0

func (s *FileStorage) GetWechatPayCert(ctx context.Context, mchID, serialNo string) (*WechatPayCertificate, error)

GetWechatPayCert 从文件读取指定序列号的微信支付平台证书

func (*FileStorage) ListAuthorizerTokens

func (s *FileStorage) ListAuthorizerTokens(ctx context.Context) ([]string, error)

ListAuthorizerTokens 列出所有已存储的授权方appid

func (*FileStorage) ListWechatPayCertSerialNos added in v0.1.0

func (s *FileStorage) ListWechatPayCertSerialNos(ctx context.Context, mchID string) ([]string, error)

ListWechatPayCertSerialNos 列出文件中指定商户的所有微信支付平台证书序列号

func (*FileStorage) Ping

func (s *FileStorage) Ping(ctx context.Context) error

Ping 存储健康检查

func (*FileStorage) SaveAuthorizerToken

func (s *FileStorage) SaveAuthorizerToken(ctx context.Context, authorizerAppID string, token *AuthorizerAccessToken) error

SaveAuthorizerToken 保存授权方令牌到文件

func (*FileStorage) SaveComponentToken

func (s *FileStorage) SaveComponentToken(ctx context.Context, token *ComponentAccessToken) error

SaveComponentToken 保存组件令牌到文件

func (*FileStorage) SaveComponentVerifyTicket

func (s *FileStorage) SaveComponentVerifyTicket(ctx context.Context, ticket string) error

SaveVerifyTicket 保存验证票据到文件

func (*FileStorage) SavePreAuthCode

func (s *FileStorage) SavePreAuthCode(ctx context.Context, code *PreAuthCode) error

SavePreAuthCode 保存预授权码到文件

func (*FileStorage) SavePrevEncodingAESKey

func (s *FileStorage) SavePrevEncodingAESKey(ctx context.Context, appID string, prevKey string) error

SavePrevEncodingAESKey 保存上一次的EncodingAESKey到文件

func (*FileStorage) SaveWechatPayCert added in v0.1.0

func (s *FileStorage) SaveWechatPayCert(ctx context.Context, mchID string, cert *WechatPayCertificate) error

SaveWechatPayCert 保存微信支付平台证书到文件

type PreAuthCode

type PreAuthCode struct {
	PreAuthCode string    `json:"pre_auth_code"`
	ExpiresIn   int       `json:"expires_in"`
	ExpiresAt   time.Time `json:"expires_at"`
}

PreAuthCode 预授权码

type PrevEncodingAESKey

type PrevEncodingAESKey struct {
	AppID              string    `json:"appid"`                 // 应用ID
	PrevEncodingAESKey string    `json:"prev_encoding_aes_key"` // 上一次的EncodingAESKey
	UpdatedAt          time.Time `json:"updated_at"`            // 更新时间
}

PrevEncodingAESKey 上一次的EncodingAESKey结构体

type RedisConfig

type RedisConfig struct {
	RedisInstance *redis.Instance // jcbaseGo Redis实例
	KeyPrefix     string          // 键前缀,用于区分不同应用实例,默认"wego:"
}

RedisConfig Redis存储配置选项

type RedisStorage

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

func NewRedisStorage

func NewRedisStorage(config *RedisConfig) (*RedisStorage, error)

NewRedisStorage 创建Redis存储实例

参数:

config: Redis配置选项

返回:

*RedisStorage: Redis存储实例
error: 配置验证失败时返回错误

示例:

redisInstance := redis.New(redis.Config{Addr: "localhost:6379"})
storage, err := NewRedisStorage(&RedisConfig{
    RedisInstance: redisInstance,
    KeyPrefix: "myapp:",
})

func (*RedisStorage) ClearAuthorizerTokens

func (s *RedisStorage) ClearAuthorizerTokens(ctx context.Context) error

ClearAuthorizerTokens 清除所有授权方令牌

参数:

ctx: 上下文

返回:

error: 清除失败时返回错误

func (*RedisStorage) DeleteAuthorizerToken

func (s *RedisStorage) DeleteAuthorizerToken(ctx context.Context, authorizerAppID string) error

DeleteAuthorizerToken 从Redis删除授权方令牌

参数:

ctx: 上下文
authorizerAppID: 授权方应用ID

返回:

error: 删除失败时返回错误

func (*RedisStorage) DeleteComponentToken

func (s *RedisStorage) DeleteComponentToken(ctx context.Context) error

DeleteComponentToken 从Redis删除组件令牌

参数:

ctx: 上下文

返回:

error: 删除失败时返回错误

func (*RedisStorage) DeleteComponentVerifyTicket

func (s *RedisStorage) DeleteComponentVerifyTicket(ctx context.Context) error

DeleteComponentVerifyTicket 从Redis删除验证票据

参数:

ctx: 上下文

返回:

error: 删除失败时返回错误

func (*RedisStorage) DeletePreAuthCode

func (s *RedisStorage) DeletePreAuthCode(ctx context.Context) error

DeletePreAuthCode 从Redis删除预授权码

参数:

ctx: 上下文

返回:

error: 删除失败时返回错误

func (*RedisStorage) DeletePrevEncodingAESKey

func (s *RedisStorage) DeletePrevEncodingAESKey(ctx context.Context, appID string) error

DeletePrevEncodingAESKey 从Redis删除上一次的EncodingAESKey

参数:

ctx: 上下文
appID: 应用ID

返回:

error: 删除失败时返回错误

func (*RedisStorage) DeleteWechatPayCert added in v0.1.0

func (s *RedisStorage) DeleteWechatPayCert(ctx context.Context, mchID, serialNo string) error

DeleteWechatPayCert 从Redis删除指定微信支付平台证书

func (*RedisStorage) GetAuthorizerToken

func (s *RedisStorage) GetAuthorizerToken(ctx context.Context, authorizerAppID string) (*AuthorizerAccessToken, error)

GetAuthorizerToken 从Redis获取授权方令牌

参数:

ctx: 上下文
authorizerAppID: 授权方应用ID

返回:

*AuthorizerAccessToken: 授权方令牌信息,不存在或过期返回nil
error: 获取失败时返回错误

func (*RedisStorage) GetComponentToken

func (s *RedisStorage) GetComponentToken(ctx context.Context) (*ComponentAccessToken, error)

GetComponentToken 从Redis获取组件令牌

参数:

ctx: 上下文

返回:

*ComponentAccessToken: 组件令牌信息,不存在或过期返回nil
error: 获取失败时返回错误

func (*RedisStorage) GetComponentVerifyTicket

func (s *RedisStorage) GetComponentVerifyTicket(ctx context.Context) (*ComponentVerifyTicket, error)

GetComponentVerifyTicket 从Redis获取验证票据

参数:

ctx: 上下文

返回:

*ComponentVerifyTicket: 验证票据信息,包含创建时间
error: 获取失败时返回错误

func (*RedisStorage) GetLatestWechatPayCert added in v0.1.0

func (s *RedisStorage) GetLatestWechatPayCert(ctx context.Context, mchID string) (*WechatPayCertificate, error)

GetLatestWechatPayCert 从Redis读取最新的微信支付平台证书

func (*RedisStorage) GetPreAuthCode

func (s *RedisStorage) GetPreAuthCode(ctx context.Context) (*PreAuthCode, error)

GetPreAuthCode 从Redis获取预授权码

参数:

ctx: 上下文

返回:

*PreAuthCode: 预授权码信息,不存在或过期返回nil
error: 获取失败时返回错误

func (*RedisStorage) GetPrevEncodingAESKey

func (s *RedisStorage) GetPrevEncodingAESKey(ctx context.Context, appID string) (*PrevEncodingAESKey, error)

GetPrevEncodingAESKey 从Redis获取上一次的EncodingAESKey

参数:

ctx: 上下文
appID: 应用ID

返回:

*PrevEncodingAESKey: 上一次的EncodingAESKey信息
error: 获取失败时返回错误

func (*RedisStorage) GetWechatPayCert added in v0.1.0

func (s *RedisStorage) GetWechatPayCert(ctx context.Context, mchID, serialNo string) (*WechatPayCertificate, error)

GetWechatPayCert 从Redis读取指定序列号的微信支付平台证书

func (*RedisStorage) ListAuthorizerTokens

func (s *RedisStorage) ListAuthorizerTokens(ctx context.Context) ([]string, error)

ListAuthorizerTokens 返回所有已存储的授权方appid

参数:

ctx: 上下文

返回:

[]string: 授权方appid列表
error: 获取失败时返回错误

func (*RedisStorage) ListWechatPayCertSerialNos added in v0.1.0

func (s *RedisStorage) ListWechatPayCertSerialNos(ctx context.Context, mchID string) ([]string, error)

ListWechatPayCertSerialNos 列出Redis中指定商户的所有微信支付平台证书序列号

func (*RedisStorage) Ping

func (s *RedisStorage) Ping(ctx context.Context) error

Ping 检查Redis连接状态

参数:

ctx: 上下文

返回:

error: 连接正常返回nil,否则返回错误

func (*RedisStorage) SaveAuthorizerToken

func (s *RedisStorage) SaveAuthorizerToken(ctx context.Context, authorizerAppID string, token *AuthorizerAccessToken) error

SaveAuthorizerToken 保存授权方令牌到Redis

参数:

ctx: 上下文
authorizerAppID: 授权方应用ID
token: 授权方令牌信息

返回:

error: 保存失败时返回错误

func (*RedisStorage) SaveComponentToken

func (s *RedisStorage) SaveComponentToken(ctx context.Context, token *ComponentAccessToken) error

SaveComponentToken 保存组件令牌到Redis

参数:

ctx: 上下文
token: 组件令牌信息

返回:

error: 保存失败时返回错误

func (*RedisStorage) SaveComponentVerifyTicket

func (s *RedisStorage) SaveComponentVerifyTicket(ctx context.Context, ticket string) error

SaveComponentVerifyTicket 保存验证票据到Redis

参数:

ctx: 上下文
ticket: 票据内容

返回:

error: 保存失败时返回错误

func (*RedisStorage) SavePreAuthCode

func (s *RedisStorage) SavePreAuthCode(ctx context.Context, code *PreAuthCode) error

SavePreAuthCode 保存预授权码到Redis

参数:

ctx: 上下文
code: 预授权码信息

返回:

error: 保存失败时返回错误

func (*RedisStorage) SavePrevEncodingAESKey

func (s *RedisStorage) SavePrevEncodingAESKey(ctx context.Context, appID string, prevKey string) error

SavePrevEncodingAESKey 保存上一次的EncodingAESKey到Redis

参数:

ctx: 上下文
appID: 应用ID
prevKey: 上一次的EncodingAESKey

返回:

error: 保存失败时返回错误

func (*RedisStorage) SaveWechatPayCert added in v0.1.0

func (s *RedisStorage) SaveWechatPayCert(ctx context.Context, mchID string, cert *WechatPayCertificate) error

SaveWechatPayCert 保存微信支付平台证书到Redis

type SqliteStorage added in v0.0.3

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

func NewSqliteStorage added in v0.0.3

func NewSqliteStorage(conf jcbaseGo.SqlLiteStruct, opts ...string) (*SqliteStorage, error)

func (*SqliteStorage) ClearAuthorizerTokens added in v0.0.3

func (s *SqliteStorage) ClearAuthorizerTokens(ctx context.Context) error

func (*SqliteStorage) DeleteAuthorizerToken added in v0.0.3

func (s *SqliteStorage) DeleteAuthorizerToken(ctx context.Context, authorizerAppID string) error

func (*SqliteStorage) DeleteComponentToken added in v0.0.3

func (s *SqliteStorage) DeleteComponentToken(ctx context.Context) error

func (*SqliteStorage) DeleteComponentVerifyTicket added in v0.0.3

func (s *SqliteStorage) DeleteComponentVerifyTicket(ctx context.Context) error

func (*SqliteStorage) DeletePreAuthCode added in v0.0.3

func (s *SqliteStorage) DeletePreAuthCode(ctx context.Context) error

func (*SqliteStorage) DeletePrevEncodingAESKey added in v0.0.3

func (s *SqliteStorage) DeletePrevEncodingAESKey(ctx context.Context, appID string) error

func (*SqliteStorage) DeleteWechatPayCert added in v0.1.0

func (s *SqliteStorage) DeleteWechatPayCert(ctx context.Context, mchID, serialNo string) error

func (*SqliteStorage) GetAuthorizerToken added in v0.0.3

func (s *SqliteStorage) GetAuthorizerToken(ctx context.Context, authorizerAppID string) (*AuthorizerAccessToken, error)

func (*SqliteStorage) GetComponentToken added in v0.0.3

func (s *SqliteStorage) GetComponentToken(ctx context.Context) (*ComponentAccessToken, error)

func (*SqliteStorage) GetComponentVerifyTicket added in v0.0.3

func (s *SqliteStorage) GetComponentVerifyTicket(ctx context.Context) (*ComponentVerifyTicket, error)

func (*SqliteStorage) GetLatestWechatPayCert added in v0.1.0

func (s *SqliteStorage) GetLatestWechatPayCert(ctx context.Context, mchID string) (*WechatPayCertificate, error)

func (*SqliteStorage) GetPreAuthCode added in v0.0.3

func (s *SqliteStorage) GetPreAuthCode(ctx context.Context) (*PreAuthCode, error)

func (*SqliteStorage) GetPrevEncodingAESKey added in v0.0.3

func (s *SqliteStorage) GetPrevEncodingAESKey(ctx context.Context, appID string) (*PrevEncodingAESKey, error)

func (*SqliteStorage) GetWechatPayCert added in v0.1.0

func (s *SqliteStorage) GetWechatPayCert(ctx context.Context, mchID, serialNo string) (*WechatPayCertificate, error)

func (*SqliteStorage) ListAuthorizerTokens added in v0.0.3

func (s *SqliteStorage) ListAuthorizerTokens(ctx context.Context) ([]string, error)

func (*SqliteStorage) ListWechatPayCertSerialNos added in v0.1.0

func (s *SqliteStorage) ListWechatPayCertSerialNos(ctx context.Context, mchID string) ([]string, error)

func (*SqliteStorage) Ping added in v0.0.3

func (s *SqliteStorage) Ping(ctx context.Context) error

func (*SqliteStorage) SaveAuthorizerToken added in v0.0.3

func (s *SqliteStorage) SaveAuthorizerToken(ctx context.Context, authorizerAppID string, token *AuthorizerAccessToken) error

func (*SqliteStorage) SaveComponentToken added in v0.0.3

func (s *SqliteStorage) SaveComponentToken(ctx context.Context, token *ComponentAccessToken) error

func (*SqliteStorage) SaveComponentVerifyTicket added in v0.0.3

func (s *SqliteStorage) SaveComponentVerifyTicket(ctx context.Context, ticket string) error

func (*SqliteStorage) SavePreAuthCode added in v0.0.3

func (s *SqliteStorage) SavePreAuthCode(ctx context.Context, code *PreAuthCode) error

func (*SqliteStorage) SavePrevEncodingAESKey added in v0.0.3

func (s *SqliteStorage) SavePrevEncodingAESKey(ctx context.Context, appID string, prevKey string) error

func (*SqliteStorage) SaveWechatPayCert added in v0.1.0

func (s *SqliteStorage) SaveWechatPayCert(ctx context.Context, mchID string, cert *WechatPayCertificate) error

type StorageClient

type StorageClient struct{}

StorageClient 存储客户端

func NewStorageClient

func NewStorageClient() *StorageClient

NewStorageClient 创建新的存储客户端

func (*StorageClient) NewDBStorage

func (c *StorageClient) NewDBStorage(dbConfig jcbaseGo.DbStruct, opts ...string) (*DBStorage, error)

NewDBStorage 创建新的数据库存储实例

func (*StorageClient) NewFileStorage

func (c *StorageClient) NewFileStorage(baseDir string) (*FileStorage, error)

NewFileStorage 创建新的文件存储实例

func (*StorageClient) NewRedisStorage added in v0.0.2

func (c *StorageClient) NewRedisStorage(config *RedisConfig) (*RedisStorage, error)

NewRedisStorage 创建新的Redis存储实例 @param config *RedisConfig Redis存储配置 @return *RedisStorage Redis存储实例 @return error 错误信息

func (*StorageClient) NewSqliteStorage added in v0.0.3

func (c *StorageClient) NewSqliteStorage(conf jcbaseGo.SqlLiteStruct, opts ...string) (*SqliteStorage, error)

NewSqliteStorage 创建新的SQLite存储实例

type TokenStorage

type TokenStorage interface {
	// 组件令牌相关方法
	SaveComponentToken(ctx context.Context, token *ComponentAccessToken) error
	GetComponentToken(ctx context.Context) (*ComponentAccessToken, error)
	DeleteComponentToken(ctx context.Context) error

	// 预授权码相关方法
	SavePreAuthCode(ctx context.Context, code *PreAuthCode) error
	GetPreAuthCode(ctx context.Context) (*PreAuthCode, error)
	DeletePreAuthCode(ctx context.Context) error

	// 验证票据相关方法
	SaveComponentVerifyTicket(ctx context.Context, ticket string) error
	GetComponentVerifyTicket(ctx context.Context) (*ComponentVerifyTicket, error) // 返回票据结构,包含创建时间
	DeleteComponentVerifyTicket(ctx context.Context) error

	// 授权方令牌相关方法
	SaveAuthorizerToken(ctx context.Context, authorizerAppID string, token *AuthorizerAccessToken) error
	GetAuthorizerToken(ctx context.Context, authorizerAppID string) (*AuthorizerAccessToken, error)
	DeleteAuthorizerToken(ctx context.Context, authorizerAppID string) error
	ClearAuthorizerTokens(ctx context.Context) error            // 清除所有授权方令牌
	ListAuthorizerTokens(ctx context.Context) ([]string, error) // 返回所有已存储的授权方appid

	// 上一次EncodingAESKey相关方法
	SavePrevEncodingAESKey(ctx context.Context, appID string, prevKey string) error
	GetPrevEncodingAESKey(ctx context.Context, appID string) (*PrevEncodingAESKey, error)
	DeletePrevEncodingAESKey(ctx context.Context, appID string) error

	// 微信支付平台证书相关方法
	SaveWechatPayCert(ctx context.Context, mchID string, cert *WechatPayCertificate) error
	GetWechatPayCert(ctx context.Context, mchID, serialNo string) (*WechatPayCertificate, error)
	GetLatestWechatPayCert(ctx context.Context, mchID string) (*WechatPayCertificate, error)
	DeleteWechatPayCert(ctx context.Context, mchID, serialNo string) error
	ListWechatPayCertSerialNos(ctx context.Context, mchID string) ([]string, error)

	// 存储健康检查
	Ping(ctx context.Context) error
}

TokenStorage 令牌存储接口

type WechatPayCertificate added in v0.1.0

type WechatPayCertificate struct {
	MchID       string    `json:"mch_id"`      // 商户号
	SerialNo    string    `json:"serial_no"`   // 证书序列号
	Certificate string    `json:"certificate"` // 证书内容(PEM 格式)
	ExpiresAt   time.Time `json:"expires_at"`  // 证书过期时间
}

WechatPayCertificate 微信支付平台证书存储结构

Jump to

Keyboard shortcuts

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