golang-im聊天
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.

message_service_test.go 2.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. md3 "gim/internal/logic/domain/message/md"
  6. "gim/pkg/pb"
  7. "gim/pkg/util"
  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. MasterId: "123456",
  42. Uid: "123",
  43. PushAlia: "22255132_21702",
  44. Title: "测试",
  45. Content: "您收到一条新消息,来自会员[消息发送者-会员昵称],发送时间[时间],消息类型[消息类型],备注[备注]",
  46. PushType: "gim",
  47. MessageType: "text",
  48. SendUserNickname: "fsahfjs",
  49. SendUserAvatarUrl: "fafsd",
  50. Memo: "fasf",
  51. Times: "sadff",
  52. })
  53. }
  54. func Test_SendToUser(t *testing.T) {
  55. buf, _ := proto.Marshal(&pb.Text{
  56. Text: "hello world!",
  57. })
  58. MessageService.SendToUser(getCtx(),
  59. &pb.Sender{
  60. SenderType: pb.SenderType_ST_USER,
  61. SenderId: 2,
  62. },
  63. 21,
  64. &pb.SendMessageReq{
  65. ReceiverType: pb.ReceiverType_RT_USER,
  66. ReceiverId: 21,
  67. ToUserIds: nil,
  68. MessageType: pb.MessageType_MT_TEXT,
  69. MessageContent: buf,
  70. SendTime: util.UnixMilliTime(time.Now()),
  71. IsPersist: true,
  72. },
  73. )
  74. }
  75. func getCtx() context.Context {
  76. token := "ICXKTELAGMMJYXITSIOUNXFHYMTCWJHMJCIRZLPX"
  77. return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs(
  78. "user_id", "2",
  79. "device_id", "5",
  80. "token", token,
  81. "master_id", "123456",
  82. "request_id", strconv.FormatInt(time.Now().UnixNano(), 10)))
  83. }