1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-08 22:52:27 +08:00

fix signature calculate

This commit is contained in:
Mongo
2017-10-31 19:22:43 +08:00
parent 0762d6c249
commit a9bfce3fbe
2 changed files with 20 additions and 9 deletions

View File

@@ -1,9 +1,13 @@
package util
import (
"bytes"
"bufio"
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"encoding/base64"
"encoding/hex"
"fmt"
)
@@ -181,3 +185,15 @@ func decodeNetworkByteOrder(orderBytes []byte) (n uint32) {
uint32(orderBytes[2])<<8 |
uint32(orderBytes[3])
}
// 计算 32 位长度的 MD5 sum
func Md5Sum(txt string) (sum string) {
h := md5.New()
buf := bufio.NewWriterSize(h, 128)
buf.WriteString(txt)
buf.Flush()
sign := make([]byte, hex.EncodedLen(h.Size()))
hex.Encode(sign, h.Sum(nil))
sum = string(bytes.ToUpper(sign))
return
}