1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
package mns
import (
"crypto/hmac"
"crypto/md5"
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"fmt"
"io"
"time"
)
// 获取当前时间戳(毫秒)
func GetCurrentMillisecond() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
}
// 获取当前时间戳(秒)
func GetCurrentUnixMicro() int64 {
return time.Now().Unix() * 1000
}
// 对字符串进行sha1 计算
func Sha1(data string) string {
t := sha1.New()
io.WriteString(t, data)
return fmt.Sprintf("%x", t.Sum(nil))
}
// 对数据进行md5计算
func Md5(byteMessage []byte) string {
h := md5.New()
h.Write(byteMessage)
return hex.EncodeToString(h.Sum(nil))
}
func HamSha1(data string, key []byte) string {
hmac := hmac.New(sha1.New, key)
hmac.Write([]byte(data))
return base64.StdEncoding.EncodeToString(hmac.Sum(nil))
}
func dump(data interface{}) {
fmt.Println(data)
}
|