util

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BeijingLocation = time.FixedZone("Asia/Shanghai", 8*60*60)
View Source
var DefaultHttpClient *http.Client
View Source
var DefaultMediaHttpClient *http.Client

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 Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func DecodeWithCommonError

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

DecodeWithCommonError 将返回值按照CommonError解析

func DecodeXMLToMap

func DecodeXMLToMap(r io.Reader) (m map[string]string, err error)

DecodeXMLToMap decodes xml reading from io.Reader and returns the first-level sub-node key-value set, if the first-level sub-node contains child nodes, skip it.

func DecryptMsg

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

DecryptMsg 消息解密

func EncodeXMLFromMap

func EncodeXMLFromMap(w io.Writer, m map[string]string, rootname string) (err error)

EncodeXMLFromMap encodes map[string]string to io.Writer with xml format.

NOTE: This function requires the rootname argument and the keys of m (type map[string]string) argument
are legitimate xml name string that does not contain the required escape character!

func EncryptMsg

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

EncryptMsg 加密消息

func Float32

func Float32(v float32) *float32

Float32 is a helper routine that allocates a new float32 value to store v and returns a pointer to it.

func Float64

func Float64(v float64) *float64

Float64 is a helper routine that allocates a new float64 value to store v and returns a pointer to it.

func GetCurrTs

func GetCurrTs() int64

GetCurrTs return current timestamps

func HTTPGet

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

HTTPGet get 请求

func HttpResponseWriter

func HttpResponseWriter(w io.Writer) http.ResponseWriter

将 io.Writer 从语义上实现 http.ResponseWriter.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func Int32

func Int32(v int32) *int32

Int32 is a helper routine that allocates a new int32 value to store v and returns a pointer to it.

func Int64

func Int64(v int64) *int64

Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

func MD5Sum

func MD5Sum(txt string) (sum string)

MD5Sum 计算 32 位长度的 MD5 sum

func NonceStr

func NonceStr() string

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 String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func Uint32

func Uint32(v uint32) *uint32

Uint32 is a helper routine that allocates a new uint32 value to store v and returns a pointer to it.

func Uint64

func Uint64(v uint64) *uint64

Uint64 is a helper routine that allocates a new uint64 value to store v and returns a pointer to it.

Types

type CommonError

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

CommonError 微信返回的通用错误json

type MultipartFormField

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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