You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

95 lines
2.1 KiB

  1. package service
  2. import (
  3. "context"
  4. md3 "egg-im/internal/logic/domain/message/md"
  5. "egg-im/pkg/pb"
  6. "egg-im/pkg/util"
  7. "fmt"
  8. "google.golang.org/grpc/metadata"
  9. "google.golang.org/protobuf/proto"
  10. "strconv"
  11. "testing"
  12. "time"
  13. jsoniter "github.com/json-iterator/go"
  14. )
  15. func TestMessageService_Add(t *testing.T) {
  16. }
  17. func TestMessageService_ListByUserIdAndSequence(t *testing.T) {
  18. }
  19. func TestJson(t *testing.T) {
  20. var st = struct {
  21. Nickname string `json:"nickname"`
  22. }{}
  23. json := `{
  24. "user_id":3,
  25. "nickname":"h",
  26. "sex":2,
  27. "avatar_url":"no",
  28. "extra":{"nickname":"hjkladsjfkl"}
  29. }`
  30. jsoniter.Get([]byte(json), "extra").ToVal(&st)
  31. fmt.Println(st)
  32. }
  33. func Test_messageService_Sync(t *testing.T) {
  34. resp, err := MessageService.Sync(context.TODO(), 6, 0)
  35. fmt.Println(err)
  36. fmt.Println(resp.HasMore)
  37. fmt.Println(len(resp.Messages))
  38. }
  39. func Test_CommAddPush(t *testing.T) {
  40. CommAddPush(md3.PushParams{
  41. Uid: "123",
  42. PushAlia: "22255132_21702",
  43. Title: "测试",
  44. Content: "您收到一条新消息,来自会员[消息发送者-会员昵称],发送时间[时间],消息类型[消息类型],备注[备注]",
  45. PushType: "egg-im",
  46. MessageType: "text",
  47. SendUserNickname: "fsahfjs",
  48. SendUserAvatarUrl: "fafsd",
  49. Memo: "fasf",
  50. Times: "sadff",
  51. })
  52. }
  53. func Test_SendToUser(t *testing.T) {
  54. buf, _ := proto.Marshal(&pb.Text{
  55. Text: "hello world!",
  56. })
  57. MessageService.SendToUser(getCtx(),
  58. &pb.Sender{
  59. SenderType: pb.SenderType_ST_USER,
  60. SenderId: 2,
  61. },
  62. 21,
  63. &pb.SendMessageReq{
  64. ReceiverType: pb.ReceiverType_RT_USER,
  65. ReceiverId: 21,
  66. ToUserIds: nil,
  67. MessageType: pb.MessageType_MT_TEXT,
  68. MessageContent: buf,
  69. SendTime: util.UnixMilliTime(time.Now()),
  70. IsPersist: true,
  71. },
  72. )
  73. }
  74. func getCtx() context.Context {
  75. token := "ICXKTELAGMMJYXITSIOUNXFHYMTCWJHMJCIRZLPX"
  76. return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs(
  77. "user_id", "2",
  78. "device_id", "5",
  79. "token", token,
  80. "master_id", "123456",
  81. "request_id", strconv.FormatInt(time.Now().UnixNano(), 10)))
  82. }