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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user