utils.go 680 B

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