getui_test.go 1.9 KB
package getui

import (
	"openapi/pkg/infrastructure/push"
	"openapi/pkg/infrastructure/utils"
	"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)
	}
}