util

package
v0.0.0-...-a0c205e Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SignTypeMD5        = `MD5`
	SignTypeHMACSHA256 = `HMAC-SHA256`
)

微信签名算法方式

View Source
const (
	ValidateSignatureError int = -40001
	ParseJsonError         int = -40002
	ComputeSignatureError  int = -40003
	IllegalAesKey          int = -40004
	ValidateCorpidError    int = -40005
	EncryptAESError        int = -40006
	DecryptAESError        int = -40007
	IllegalBuffer          int = -40008
	EncodeBase64Error      int = -40009
	DecodeBase64Error      int = -40010
	GenJsonError           int = -40011
	IllegalProtocolType    int = -40012
)

Variables

This section is empty.

Functions

func AESDecryptMsg

func AESDecryptMsg(ciphertext []byte, aesKey []byte) (random, rawXMLMsg, appID []byte, err error)

AESDecryptMsg ciphertext = AES_Encrypt[random(16B) + msg_len(4B) + rawXMLMsg + appId] 参考:github.com/chanxuehong/wechat.v2

func AESEncryptMsg

func AESEncryptMsg(random, rawXMLMsg []byte, appID string, aesKey []byte) (ciphertext []byte)

AESEncryptMsg ciphertext = AES_Encrypt[random(16B) + msg_len(4B) + rawXMLMsg + appId] 参考:github.com/chanxuehong/wechat.v2

func AesECBDecrypt

func AesECBDecrypt(ciphertext []byte, aesKey []byte) ([]byte, error)

AesECBDecrypt will decrypt data with PKCS5Padding

func CalculateSign

func CalculateSign(content, signType, key string) (string, error)

CalculateSign 计算签名

func DecodeWithCommonError

func DecodeWithCommonError(response []byte, apiName string) (err error)

DecodeWithCommonError 将返回值按照CommonError解析

func DecodeWithError

func DecodeWithError(response []byte, obj interface{}, apiName string) error

DecodeWithError 将返回值按照解析

func DecryptMsg

func DecryptMsg(appID, encryptedMsg, aesKey string) (random, rawMsgXMLBytes []byte, err error)

DecryptMsg 消息解密

func EncryptMsg

func EncryptMsg(random, rawXMLMsg []byte, appID, aesKey string) (encrtptMsg []byte, err error)

EncryptMsg 加密消息

func GetCurrTS

func GetCurrTS() int64

GetCurrTS return current timestamps

func HTTPGet

func HTTPGet(uri string) ([]byte, error)

HTTPGet get 请求

func HTTPPost

func HTTPPost(uri string, data string) ([]byte, error)

HTTPPost post 请求

func NewECBDecryptor

func NewECBDecryptor(b cipher.Block) cipher.BlockMode

NewECBDecryptor returns a BlockMode which decrypts in electronic code book mode, using the given Block.

func NewECBEncryptor

func NewECBEncryptor(b cipher.Block) cipher.BlockMode

NewECBEncryptor returns a BlockMode which encrypts in electronic code book mode, using the given Block.

func OrderParam

func OrderParam(p map[string]string, bizKey string) (returnStr string)

OrderParam order params

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

PKCS5Padding -

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

PKCS5UnPadding -

func ParamSign

func ParamSign(p map[string]string, key string) (string, error)

ParamSign 计算所传参数的签名

func PostFile

func PostFile(fieldname, filename, uri string) ([]byte, error)

PostFile 上传文件

func PostJSON

func PostJSON(uri string, obj interface{}) ([]byte, error)

PostJSON post json 数据请求

func PostJSONWithRespContentType

func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, error)

PostJSONWithRespContentType post json数据请求,且返回数据类型

func PostMultipartForm

func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte, err error)

PostMultipartForm 上传文件或其他多个字段

func PostXML

func PostXML(uri string, obj interface{}) ([]byte, error)

PostXML perform a HTTP/POST request with XML body

func PostXMLWithTLS

func PostXMLWithTLS(uri string, obj interface{}, ca, key string) ([]byte, error)

PostXMLWithTLS perform a HTTP/POST request with XML body and TLS

func RandomStr

func RandomStr(length int) string

RandomStr 随机生成字符串

func Signature

func Signature(params ...string) string

Signature sha1签名

func SliceChunk

func SliceChunk(src []string, chunkSize int) (chunks [][]string)

SliceChunk 用于将字符串切片分块

Types

type CommonError

type CommonError struct {
	ErrCode int64  `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

CommonError 微信返回的通用错误json

type CryptError

type CryptError struct {
	ErrCode int
	ErrMsg  string
}

func NewCryptError

func NewCryptError(err_code int, err_msg string) *CryptError

type ECBDecryptor

type ECBDecryptor ecb

ECBDecryptor -

func (*ECBDecryptor) BlockSize

func (x *ECBDecryptor) BlockSize() int

BlockSize implement BlockMode.BlockSize

func (*ECBDecryptor) CryptBlocks

func (x *ECBDecryptor) CryptBlocks(dst, src []byte)

CryptBlocks implement BlockMode.CryptBlocks

type ECBEncryptor

type ECBEncryptor ecb

ECBEncryptor -

func (*ECBEncryptor) BlockSize

func (x *ECBEncryptor) BlockSize() int

BlockSize implement BlockMode.BlockSize

func (*ECBEncryptor) CryptBlocks

func (x *ECBEncryptor) CryptBlocks(dst, src []byte)

CryptBlocks implement BlockMode.CryptBlocks

type JsonProcessor

type JsonProcessor struct {
}

type MultipartFormField

type MultipartFormField struct {
	IsFile    bool
	Fieldname string
	Value     []byte
	Filename  string
}

MultipartFormField 保存文件或其他字段信息

type ProtocolProcessor

type ProtocolProcessor interface {
	// contains filtered or unexported methods
}

type ProtocolType

type ProtocolType int
const (
	JsonType ProtocolType = 1
)

type WXBizJsonMsg4Recv

type WXBizJsonMsg4Recv struct {
	Tousername string `json:"tousername"`
	Encrypt    string `json:"encrypt"`
	Agentid    string `json:"agentid"`
}

type WXBizJsonMsg4Send

type WXBizJsonMsg4Send struct {
	Encrypt   string `json:"encrypt"`
	Signature string `json:"msgsignature"`
	Timestamp string `json:"timestamp"`
	Nonce     string `json:"nonce"`
}

func NewWXBizJsonMsg4Send

func NewWXBizJsonMsg4Send(encrypt, signature, timestamp, nonce string) *WXBizJsonMsg4Send

type WXBizMsgCrypt

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

func NewWXBizMsgCrypt

func NewWXBizMsgCrypt(token, encoding_aeskey, receiver_id string, protocol_type ProtocolType) *WXBizMsgCrypt

func (*WXBizMsgCrypt) DecryptMsg

func (self *WXBizMsgCrypt) DecryptMsg(msg_signature, timestamp, nonce string, post_data []byte) ([]byte, *CryptError)

func (*WXBizMsgCrypt) EncryptMsg

func (self *WXBizMsgCrypt) EncryptMsg(reply_msg, timestamp, nonce string) ([]byte, *CryptError)

func (*WXBizMsgCrypt) ParsePlainText

func (self *WXBizMsgCrypt) ParsePlainText(plaintext []byte) ([]byte, uint32, []byte, []byte, *CryptError)

func (*WXBizMsgCrypt) VerifyURL

func (self *WXBizMsgCrypt) VerifyURL(msg_signature, timestamp, nonce, echostr string) ([]byte, *CryptError)

Jump to

Keyboard shortcuts

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