form_token.go 733 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * 表单令牌
  3. * @Company: 云南奇讯科技有限公司
  4. * @Author: yxf
  5. * @Description:
  6. * @Version: 1.0.0
  7. * @Date: 2021/9/15 17:47
  8. */
  9. package service
  10. import (
  11. "github.com/gogf/gf/util/guid"
  12. "time"
  13. )
  14. type formTokenService struct{}
  15. var FormToken = new(formTokenService)
  16. func (s *formTokenService) New(action string) (key string) {
  17. key = guid.S()
  18. cache := Cache.New()
  19. cache.Set(key, action, time.Hour)
  20. return key
  21. }
  22. func (s *formTokenService) Verify(key string, action string) bool {
  23. cache := Cache.New()
  24. value := cache.Get(key)
  25. if value != nil && value == action {
  26. return true
  27. }
  28. return false
  29. }
  30. func (s *formTokenService) Remove(key string) interface{} {
  31. cache := Cache.New()
  32. return cache.Remove(key)
  33. }