gomeng

package module
v0.0.0-...-cf938fe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2021 License: MIT Imports: 9 Imported by: 0

README

gomeng

友盟消息推送 Golang SDK 友盟开发者中心 U-Push API 集成文档:传送门

使用示例

需要先在友盟官网创建应用获得 App Key 和 App Secret!

  • Push() 单播
  • Listcast() 多播
  • Broadcast()广播(默认每天可推送10次)
import (
    umeng "github.com/crazytaxii/gomeng"
)

func main() {
    client := umeng.NewClient(false, "app_key", "app_master_secret", 10 * time.Second)
    payload := map[string]interface{}{
        "display_type": "notification",
        "body": map[string]interface{}{
            "ticker":   "test_ticker",
            "title":    "test_title",
            "text":     "test_text",
            "builder:": 1,
            "custom": map[string]interface{}{
                "key1": "value1",
                "key2": "value2",
                "key3": "value3",
            },
            "after_open": "go_app",
            "play_sound": "true",
        },
    }

    if err := client.Push(payload, "device_token"); err != nil {
        log.Fatalf("err: %v", err)
    }

    if err := client.Listcast(payload, "device_token1", "device_token2", "device_token3"); err != nil {
        log.Fatalf("err: %v", err)
    }

    if err := client.Broadcast(payload); err != nil {
        fmt.Fatalf("err: %v", err)
    }
}

Documentation

Index

Constants

View Source
const (
	BaseURL = "https://msgapi.umeng.com/api/"

	APIPush      = "send"
	APIBroadcast = "send"
)
View Source
const DefaultTimeout = 10 * time.Second

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(productMode bool, key, secret string, timeout time.Duration) *Client

func (*Client) Broadcast

func (c *Client) Broadcast(payload map[string]interface{}) error

*

  • 推送给所有用户(广播)
  • 默认每天可推送10次

func (*Client) ListCast

func (c *Client) ListCast(payload map[string]interface{}, deviceTokens ...string) error

*

  • 推送给多用户(列播)

func (*Client) Push

func (c *Client) Push(payload map[string]interface{}, deviceToken string) error

*

  • 推送给单用户(单播)

type ResponseMessage

type ResponseMessage struct {
	Ret  string `json:"ret"`
	Data struct {
		MsgID   string `json:"msg_id"`
		TaskID  string `json:"task_id"`
		ErrMsg  string `json:"error_msg"`
		ErrCode string `json:"error_code"`
	} `json:"data"`
}

func (*ResponseMessage) Error

func (rm *ResponseMessage) Error() error

func (*ResponseMessage) Unmarshal

func (rm *ResponseMessage) Unmarshal(data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL