utils.go 804 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package utils
  2. import (
  3. "crypto/md5"
  4. "gd_gateway/common.in/jsonrpc2"
  5. "encoding/hex"
  6. "encoding/json"
  7. "fmt"
  8. "strings"
  9. "time"
  10. )
  11. func GetUniqueLogID(cmd string) string {
  12. return fmt.Sprintf("%d_%s", time.Now().Unix(), cmd)
  13. }
  14. // 获取args对应的json字符串
  15. func MarshalJsonString(args ...interface{}) (result string) {
  16. if len(args) > 0 {
  17. if r, err := json.Marshal(args); err == nil {
  18. result = string(r)
  19. }
  20. }
  21. return
  22. }
  23. func MD5(text string) string {
  24. h := md5.New()
  25. h.Write([]byte(text))
  26. return hex.EncodeToString(h.Sum(nil))
  27. }
  28. func CheckPlateCity(plateNo, filter string) error {
  29. citys := strings.Split(filter, ",")
  30. for _, city := range citys {
  31. if strings.HasPrefix(plateNo, city) {
  32. return nil
  33. }
  34. }
  35. return jsonrpc2.NewJsonError(20004, "参数错误,不支持该省份")
  36. }