utils

package
v0.0.0-...-49a96a4 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

weixin.go

Index

Constants

This section is empty.

Variables

View Source
var NONCE_LETTERS_TOTAL = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

用于生成随机字符串 代码摘自: http://blog.csdn.net/luciswe/article/details/45900373

Functions

func GetNonceStr

func GetNonceStr(n int) string

func InvalidateForWeiXin

func InvalidateForWeiXin(token string, r *http.Request, w http.ResponseWriter)

func JSONMarshal

func JSONMarshal(v interface{}, safeEncoding bool) ([]byte, error)

注意当把AuthCodeURL生成的url用作菜单的url时,微信服务器端会把”非法字法的错误信息,如:& 被json.marshal转化为\u0026; 可微信不认这个,报\u0026为非法字符!” 现在写一个方法将微信认为非法的转义后字符再转化回原字符

func MakeSignature

func MakeSignature(token, timestamp, nonce string) string

func Map2XMLBytes

func Map2XMLBytes(m map[string]string) ([]byte, error)

对于value值没有转义,只是加了CDATA保护,即然xml不再解释它,我就先不加转义了.

func NewTLSHttpClient

func NewTLSHttpClient(certFile, keyFile string) (*http.Client, error)

创建应用证书之httpClient. NewTLSHttpClient 创建支持双向证书认证的 http.Client 引自:https://github.com/chanxuehong/wechat/blob/master/mch/http_client.go 参考:https://github.com/bigwhite/experiments/blob/master/gohttps/6-dual-verify-certs/client.go http://stackoverflow.com/questions/18187136/net-http-ignoring-system-proxy-settings http://blog.csdn.net/luciswe/article/details/45890713 现在没有对服务端身体进行验证即InsecureSkipVerify=true,以后有必要再加。

func SignForWXPay

func SignForWXPay(parameters map[string]string, apiKey string, fn func() hash.Hash) string

引自:https://github.com/chanxuehong/wechat/blob/master/mch/sign.go 写的非常清晰,我就不再造车轮了,感恩前辈。 微信支付签名.

parameters: 待签名的参数集合
apiKey:     API密钥
fn:         func() hash.Hash, 如果 fn == nil 则默认用 md5.New

func XML2Map

func XML2Map(stream io.Reader) (map[string]string, error)

此接口只用于处理微信支付接口xml,其它复杂情况没有考虑. 没有处理深度,如果有嵌套,只取最内层的key:value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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