|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- package api
-
- import (
- "context"
- "egg-im/config"
- "egg-im/internal/logic/domain/message/model"
- "egg-im/pkg/db"
- "egg-im/pkg/pb"
- "egg-im/pkg/util"
- "fmt"
- "github.com/jinzhu/gorm"
- "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_protoUnmarshal(t *testing.T) {
- db.InitMysql(config.MySQL)
- var msg model.Message
- if err := db.DB.Table("message_000").Where("`id` = 194581").First(&msg).Error; err != nil {
- if err == gorm.ErrRecordNotFound {
- fmt.Println(err)
- return
- }
- }
-
- var temp pb.RED_PACKAGE
- //var temp1 pb.RED_PACKAGE
- err := proto.Unmarshal(msg.Content, &temp)
- if err != nil {
- fmt.Println(err)
- return
- }
-
- //err = proto.Unmarshal(temp.Data, &temp1)
- //if err != nil {
- // fmt.Println(err)
- // return
- //}
-
- fmt.Println(temp)
- fmt.Printf("!!!!")
- }
-
- 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)
- }
|