|
- package service
-
- import (
- "context"
- "fmt"
- md3 "gim/internal/logic/domain/message/md"
- "gim/pkg/pb"
- "gim/pkg/util"
- "google.golang.org/grpc/metadata"
- "google.golang.org/protobuf/proto"
- "strconv"
- "testing"
- "time"
-
- jsoniter "github.com/json-iterator/go"
- )
-
- func TestMessageService_Add(t *testing.T) {
-
- }
-
- func TestMessageService_ListByUserIdAndSequence(t *testing.T) {
-
- }
-
- func TestJson(t *testing.T) {
- var st = struct {
- Nickname string `json:"nickname"`
- }{}
-
- json := `{
- "user_id":3,
- "nickname":"h",
- "sex":2,
- "avatar_url":"no",
- "extra":{"nickname":"hjkladsjfkl"}
- }`
- jsoniter.Get([]byte(json), "extra").ToVal(&st)
- fmt.Println(st)
- }
-
- func Test_messageService_Sync(t *testing.T) {
- resp, err := MessageService.Sync(context.TODO(), 6, 0)
- fmt.Println(err)
- fmt.Println(resp.HasMore)
- fmt.Println(len(resp.Messages))
- }
-
- func Test_CommAddPush(t *testing.T) {
- CommAddPush(md3.PushParams{
- MasterId: "123456",
- Uid: "123",
- PushAlia: "22255132_21702",
- Title: "测试",
- Content: "您收到一条新消息,来自会员[消息发送者-会员昵称],发送时间[时间],消息类型[消息类型],备注[备注]",
- PushType: "gim",
- MessageType: "text",
- SendUserNickname: "fsahfjs",
- SendUserAvatarUrl: "fafsd",
- Memo: "fasf",
- Times: "sadff",
- })
- }
-
- func Test_SendToUser(t *testing.T) {
- buf, _ := proto.Marshal(&pb.Text{
- Text: "hello world!",
- })
- MessageService.SendToUser(getCtx(),
- &pb.Sender{
- SenderType: pb.SenderType_ST_USER,
- SenderId: 2,
- },
- 21,
- &pb.SendMessageReq{
- ReceiverType: pb.ReceiverType_RT_USER,
- ReceiverId: 21,
- ToUserIds: nil,
- MessageType: pb.MessageType_MT_TEXT,
- MessageContent: buf,
- SendTime: util.UnixMilliTime(time.Now()),
- IsPersist: true,
- },
- )
- }
-
- func getCtx() context.Context {
- token := "ICXKTELAGMMJYXITSIOUNXFHYMTCWJHMJCIRZLPX"
- return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs(
- "user_id", "2",
- "device_id", "5",
- "token", token,
- "master_id", "123456",
- "request_id", strconv.FormatInt(time.Now().UnixNano(), 10)))
- }
|