getui_test.go 2.5 KB
package getuiV2

import (
	"openapi/pkg/infrastructure/push"
	"openapi/pkg/infrastructure/utils"
	"sync"
	"testing"
)

func TestGetui(t *testing.T) {
	var param = make(map[string]interface{})
	param["A"] = "A1"
	param["B"] = 2
	param["transData"] = struct{ Id int }{Id: 10}
	notification := &GetuiNotification{}
	err := notification.Init(
		push.DebugModule(true),

		push.AppId("TkpBI4awmg9fBUx3NWKXS6"),
		push.AppKey("5AjJeDOSOZ5ojQpXJFjhg9"),
		push.AppMasterSecret("9VnM8MaA6n84Y5VnOIaSvA"),
		//单推
		push.PushType(push.PushToSingle),
		push.ClientId("b5fff5f6b0af551da5f381fa47991828"),
		//群推
		//push.PushType(push.PushToList),
		//push.ClientIds([]string{"b5fff5f6b0af551da5f381fa47991828"}),

		push.MsgType(push.SystemTransmission), //push.SystemNotification
		push.Title("测试 hello"),
		push.Content("hello content"),

		push.TransmissionContent(utils.JsonAssertString(param["transData"])),
		push.Extra(param),
	)
	if err != nil {
		t.Fatal(err)
	}
	_, err = notification.Send(param)
	if err != nil {
		t.Fatal(err)
	}
}

func TestGetuiPrd(t *testing.T) {
	var param = make(map[string]interface{})
	param["A"] = "A1"
	param["B"] = 2
	param["transData"] = struct {
		Id int `json:"id"`
	}{Id: 1}
	notification := &GetuiNotification{}
	err := notification.Init(
		push.DebugModule(true),

		push.AppId("WgrbaaStTk7JElrXOCgUg6"),
		push.AppKey("FG5lbqVrHa5rS9NVfxNP7"),
		push.AppMasterSecret("FW3jMNLJrRARYKv2iqA5H5"),
		//单推
		//push.PushType(push.PushToSingle),
		//push.ClientId("502f4fd7ba5df15ac6b3d5c561efd9ca"),
		//群推
		push.PushType(push.PushToList),
		push.ClientIds([]string{"502f4fd7ba5df15ac6b3d5c561efd9ca"}),

		push.MsgType(push.SystemTransmission),
		push.Title("hello"),
		push.Content("hello content"),

		push.TransmissionContent(utils.JsonAssertString(param["transData"])),
		push.Extra(param),
	)
	if err != nil {
		t.Fatal(err)
	}
	_, err = notification.Send(param)
	if err != nil {
		t.Fatal(err)
	}
}

func TestGetAuthToken(t *testing.T) {
	var wg sync.WaitGroup
	round := 100
	notification := &GetuiNotification{}
	var tokenMap = make(map[string]string)
	notification.Init(
		push.DebugModule(true),

		push.AppId("WgrbaaStTk7JElrXOCgUg6"),
		push.AppKey("FG5lbqVrHa5rS9NVfxNP7"),
		push.AppMasterSecret("FW3jMNLJrRARYKv2iqA5H5"),
	)
	for i := 0; i < round; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			token, _ := notification.GetAuthToken()
			tokenMap[token] = token
		}()
	}
	wg.Wait()
	if len(tokenMap) > 1 {
		t.Fatalf("token want 1 get %v", len(tokenMap))
	}
}