qr.go 835 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package model
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "io"
  6. "strconv"
  7. "time"
  8. xtime "go-common/library/time"
  9. )
  10. // QR represents pay qr info.
  11. type QR struct {
  12. ExpireAt xtime.Time
  13. URL string
  14. Token string
  15. }
  16. // PayParam represents pay params.
  17. type PayParam struct {
  18. Mid int64
  19. Pid int32
  20. BuyNum int32
  21. Guid string
  22. AppChannel string
  23. Status int8
  24. OrderNo string
  25. ExpireAt xtime.Time
  26. }
  27. // MD5 calculates md5 of pay params.
  28. func (p *PayParam) MD5() string {
  29. m := md5.New()
  30. io.WriteString(m, strconv.Itoa(int(p.Mid)))
  31. io.WriteString(m, strconv.Itoa(int(p.Pid)))
  32. io.WriteString(m, strconv.Itoa(int(p.ExpireAt)))
  33. return fmt.Sprintf("%x", string(m.Sum(nil)))
  34. }
  35. // IsExpired return true if pay param is expired.
  36. func (p *PayParam) IsExpired() bool {
  37. return int64(p.ExpireAt) < time.Now().Unix()
  38. }