utils.go 725 B

123456789101112131415161718192021222324252627282930313233
  1. package util
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "ktogame/enums"
  6. "time"
  7. "github.com/astaxie/beego/logs"
  8. "github.com/ethereum/go-ethereum/crypto"
  9. )
  10. func NowTimeString() string {
  11. return time.Now().Format("2006-01-02 15:04:05")
  12. }
  13. func NowTimeDayString() string {
  14. return time.Now().Format("2006-01-02")
  15. }
  16. func Md5(str string) string {
  17. hash := md5.New()
  18. hash.Write([]byte(str))
  19. return hex.EncodeToString(hash.Sum(nil))
  20. }
  21. func Sign(amountStr, addr, timeStr string) string {
  22. logs.Info("Sign==========", amountStr, addr, timeStr)
  23. keccakA := crypto.Keccak256([]byte(amountStr), []byte(enums.DIGIT))
  24. keccakS := crypto.Keccak256(keccakA, []byte(timeStr), []byte(addr))
  25. return "0x" + hex.EncodeToString(keccakS)
  26. }