http_sign

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

by Iori 2022/2/14

Index

Constants

View Source
const (
	Const_SignVer_Name   string = "sign_ver"   //签名规范版本名称
	Const_SignType_Name  string = "sign_type"  //签名加密方式名称
	Const_TimeStamp_Name string = "timestamp"  //默认时间戳字段名
	Const_RequestId_Name string = "request_id" //默认时间戳字段名
	Const_SignName       string = "sign"       //默认签名字段名
	Const_ExpiredTime    int64  = 60           //默认签名有效时长
)

---------------------- const --------------------

Variables

This section is empty.

Functions

func Map2uri

func Map2uri(params *map[string]string, filter_field string, need_sort, url_encode bool) string

* * @Description: map转为URL字符串参数 ,内部使用 * @param: params * @param: filter_field * @param: need_sort * @param: url_encode * @return: string * @Author: Iori * @Date: 2022-02-17 10:12:58 *

func MapParam2Uri

func MapParam2Uri(params *map[string]string, url_encode bool) string

* * @Description: 把参数列表map转为URL字符串参数,,外部使用 * @param: params * @param: url_encode * @return: string * @Author: Iori * @Date: 2022-02-17 10:01:06 *

func UriParam2Map

func UriParam2Map(params string) *map[string]string

*

  • @Description: 把URL字符串参数转为参数列表map
  • @Author Iori
  • @Date 2022-01-22 18:33:33
  • @param params
  • @return map[string]string *

Types

type Config

type Config struct {
	IndexName     string `json:"IndexName" yaml:"IndexName"`
	PrivateKey    string `json:"PrivateKey" yaml:"PrivateKey"`
	SignName      string `json:"SignName" yaml:"SignName"`
	ExpiredTime   int    `json:"ExpiredTime" yaml:"ExpiredTime"`
	TimestampName string `json:"TimestampName" yaml:"TimestampName"`
	SignType      string `json:"SignType" yaml:"SignType"`
	RequestIDName string `json:"RequestIDName" yaml:"RequestIDName"`
	VersionType   string `json:"VersionType" yaml:"VersionType"`
}

type ESignType

type ESignType string

签名类型

const (
	Sign_Md5  ESignType = "md5"  //md5 加密方式
	Sign_Sha1 ESignType = "sha1" //sha1 加密方式
)

type EVersionType

type EVersionType string

--------------------- enum ---------------------- 版本类型

const (
	Version_Overseas_NewV1 EVersionType = "1"     //海外新签名规范版本1  20220104
	Version_Overseas_NewV2 EVersionType = "2"     //海外新签名规范版本2  20230111
	Version_Cloud          EVersionType = "cloud" // 云服签名规范
)

type ErrorCode

type ErrorCode int32

-- err code

const (
	SIGH_OK           ErrorCode = 0  //签名成功
	TIMESTAMP_INVALID ErrorCode = -1 //时间戳无效
	PARSE_FAIL        ErrorCode = -2 //解析失败
	TIME_OUT          ErrorCode = -3 //时间超时
	SIGN_NOT_FOUND    ErrorCode = -4 //签名未找到
	ARGUMENTS_INVALID ErrorCode = -5 //参数无效
	VERIFY_FAILURE    ErrorCode = -6 //签名验证失败
	SIGNTYPE_INVALID  ErrorCode = -7 //签名加密类型无效
)

func (ErrorCode) String

func (x ErrorCode) String() string

type HttpSign

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

* HttpSign * @Description: 签名信息结构 * @Author: Iori

func BuildHttpSign

func BuildHttpSign(signName, secret string, expiredTime int64, timestampName, requestIdName, version string) *HttpSign

* * @Description: 创建httpSign对象 * @param: signName * @param: secret * @param: expiredTime * @param: timestampName * @param: requestIdName 请求唯一标识 * @return: *HttpSign * @Author: Iori * @Date: 2022-01-27 16:46:05 *

func (*HttpSign) CheckSign

func (this *HttpSign) CheckSign(head map[string][]string, params *map[string]string, body []byte, sign string) (bool, error, int)

*

  • @Description: 签名认证
  • @receiver this
  • @Date 2022-01-22 18:41:24
  • @param sign 待认证的签名
  • @return bool 认证成功返回tue 否则返回false
  • @return error 认证成功返回nil 否则返回异常值 *

func (*HttpSign) PushSign

func (this *HttpSign) PushSign(head map[string][]string, params *map[string]string, body []byte,
	signType ESignType) *map[string]string

*

  • @Description: 添加签名
  • @receiver this
  • @Date 2022-01-22 18:41:24
  • @param sign 待认证的签名
  • @return bool 认证成功返回tue 否则返回false
  • @return error 认证成功返回nil 否则返回异常值 *

type SignMgr

type SignMgr struct {
	Instances map[string]*HttpSign
	// contains filtered or unexported fields
}

* SignMgr * @Description:

func NewSignMgr

func NewSignMgr() *SignMgr

* * @Description: 创建签名管理器 * @return: *SignMgr * @Author: Iori * @Date: 2022-02-14 11:28:59 *

func (*SignMgr) GetSignIns

func (self *SignMgr) GetSignIns(keys ...string) *HttpSign

* * @Description: 获取签名类型 * @receiver: self * @param: key * @param: o * @Author: Iori * @Date: 2022-02-14 11:29:20 *

func (*SignMgr) InitAndRun

func (self *SignMgr) InitAndRun(cfgs []Config)

* * @Description: 初始化签名管理器 * @receiver: self * @param: cfgs * @return: error * @Author: Iori * @Date: 2022-02-14 11:29:45 *

func (*SignMgr) SetSignIns

func (self *SignMgr) SetSignIns(key string, impl *HttpSign)

* * @Description: 设置签名类型实例 * @param: key * @param: impl * @Author: Iori * @Date: 2022-02-14 16:13:53 *

func (*SignMgr) Tick

func (self *SignMgr) Tick(nowMs int64)

* * @Description: tick * @receiver: self * @param: nowMs * @Author: Iori * @Date: 2022-02-14 11:39:54 *

Jump to

Keyboard shortcuts

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