notice.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package member
  2. import (
  3. "context"
  4. "net"
  5. "go-common/app/interface/main/account/model"
  6. secmodel "go-common/app/service/main/secure/model"
  7. "go-common/library/log"
  8. )
  9. // NoticeV2 notice v2.
  10. func (s *Service) NoticeV2(c context.Context, mid int64, uuid string, pf string, b int64) (res *model.Notice2, err error) {
  11. var msg *secmodel.Msg
  12. if msg, err = s.secureRPC.Status(c, &secmodel.ArgSecure{Mid: mid, UUID: uuid}); err != nil {
  13. log.Error("service.secureRPC.Status(%d) uuid(%s) error(%v)", mid, uuid, err)
  14. return
  15. }
  16. if msg == nil || !msg.Notify {
  17. log.Info("s.NoticeV2(%d) msg(%v) continue", mid, msg)
  18. res = &model.Notice2{Status: model.NoticeStatusNotNotify}
  19. return
  20. }
  21. res = &model.Notice2{
  22. Status: model.NoticeStatusNotify,
  23. Type: model.NoticeTypeSecurity,
  24. Security: &model.Security{
  25. Location: msg.Log.Location,
  26. Time: msg.Log.Time,
  27. IP: inetNtoA(msg.Log.IP),
  28. Mid: msg.Log.Mid,
  29. }}
  30. return
  31. }
  32. func inetNtoA(sum uint32) string {
  33. ip := make(net.IP, net.IPv4len)
  34. ip[0] = byte((sum >> 24) & 0xFF)
  35. ip[1] = byte((sum >> 16) & 0xFF)
  36. ip[2] = byte((sum >> 8) & 0xFF)
  37. ip[3] = byte(sum & 0xFF)
  38. return ip.String()
  39. }
  40. // CloseNoticeV2 close notice v2.
  41. func (s *Service) CloseNoticeV2(c context.Context, mid int64, uuid string) (err error) {
  42. arg := &secmodel.ArgSecure{Mid: mid, UUID: uuid}
  43. if err = s.secureRPC.CloseNotify(c, arg); err != nil {
  44. log.Error("service.secureRPC.CloseNotify(%v) error(%v)", arg, err)
  45. return
  46. }
  47. return
  48. }