utils.go 855 B

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