|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- package api
-
- import (
- "context"
- "fmt"
- "gim/pkg/pb"
- "gim/pkg/util"
- "strconv"
- "testing"
- "time"
-
- "google.golang.org/grpc"
- "google.golang.org/grpc/metadata"
- "google.golang.org/protobuf/proto"
- )
-
- func getLogicExtClient() pb.LogicExtClient {
- conn, err := grpc.Dial("im-rpc-logic.izhyin.com:8003", grpc.WithInsecure())
- if err != nil {
- fmt.Println(err)
- return nil
- }
- return pb.NewLogicExtClient(conn)
- }
-
- // deprecated:
-
- 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)))
- }
-
- func TestLogicExtServer_RegisterDevice(t *testing.T) {
- resp, err := getLogicExtClient().RegisterDevice(context.TODO(),
- &pb.RegisterDeviceReq{
- Type: 1,
- Brand: "huawei",
- Model: "huawei P30",
- SystemVersion: "1.0.0",
- SdkVersion: "1.0.0",
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_SendMessage(t *testing.T) {
- buf, err := proto.Marshal(&pb.Text{
- Text: "hello world!",
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- var one = string(buf)
- fmt.Printf(one)
- resp, err := getLogicExtClient().SendMessage(getCtx(),
- &pb.SendMessageReq{
- ReceiverType: pb.ReceiverType_RT_USER,
- ReceiverId: 21,
- ToUserIds: nil,
- MessageType: pb.MessageType_MT_TEXT,
- MessageContent: buf,
- IsPersist: true,
- SendTime: util.UnixMilliTime(time.Now()),
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_SendImageMessage(t *testing.T) {
- buf, err := proto.Marshal(&pb.Image{
- Id: "",
- Width: 0,
- Height: 0,
- Url: "https://img.iplaysoft.com/wp-content/uploads/2019/free-images/free_stock_photo.jpg",
- ThumbnailUrl: "",
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- resp, err := getLogicExtClient().SendMessage(getCtx(),
- &pb.SendMessageReq{
- ReceiverType: pb.ReceiverType_RT_USER,
- ReceiverId: 1,
- ToUserIds: nil,
- MessageType: pb.MessageType_MT_IMAGE,
- MessageContent: buf,
- IsPersist: true,
- SendTime: util.UnixMilliTime(time.Now()),
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_CreateGroup(t *testing.T) {
- resp, err := getLogicExtClient().CreateGroup(getCtx(),
- &pb.CreateGroupReq{
- Name: "10",
- Introduction: "10",
- Extra: "10",
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_UpdateGroup(t *testing.T) {
- resp, err := getLogicExtClient().UpdateGroup(getCtx(),
- &pb.UpdateGroupReq{
- GroupId: 2,
- Name: "11",
- Introduction: "11",
- Extra: "11",
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_GetGroup(t *testing.T) {
- resp, err := getLogicExtClient().GetGroup(getCtx(),
- &pb.GetGroupReq{
- GroupId: 2,
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_GetUserGroups(t *testing.T) {
- resp, err := getLogicExtClient().GetGroups(getCtx(), &pb.Empty{})
- if err != nil {
- fmt.Println(err)
- return
- }
- // todo 不能获取用户所在的超大群组
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_AddGroupMember(t *testing.T) {
- resp, err := getLogicExtClient().AddGroupMembers(getCtx(),
- &pb.AddGroupMembersReq{
- GroupId: 2,
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_UpdateGroupMember(t *testing.T) {
- resp, err := getLogicExtClient().UpdateGroupMember(getCtx(),
- &pb.UpdateGroupMemberReq{
- GroupId: 2,
- UserId: 3,
- Remarks: "2",
- Extra: "2",
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_DeleteGroupMember(t *testing.T) {
- resp, err := getLogicExtClient().DeleteGroupMember(getCtx(),
- &pb.DeleteGroupMemberReq{
- GroupId: 10,
- UserId: 1,
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_GetGroupMembers(t *testing.T) {
- resp, err := getLogicExtClient().GetGroupMembers(getCtx(),
- &pb.GetGroupMembersReq{
- GroupId: 2,
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
-
- func TestLogicExtServer_AddFriend(t *testing.T) {
- resp, err := getLogicExtClient().AddFriend(getCtx(),
- &pb.AddFriendReq{
- FriendId: 2,
- Remarks: "weihan",
- Description: "hello",
- })
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Printf("%+v\n", resp)
- }
|