getui

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

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

Go to latest
Published: Jun 24, 2020 License: MIT Imports: 8 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

getui

个推push

Software License GoDoc

由于官方没有推出Go版本的推送SDK,故自己实现了。支持:

  • 按cid单推
  • 按cid群推
  • 全推
  • 根据taskId查询推送结果

使用起来简单,推送模板支持自由组合。各接口独立,便于扩展。

使用

安装:

go get https://github.com/geek-go/getui

SDK 测试(使用前先打开getui_test.go配置appid等参数):

# 测试单推
go test -v  -run="^TestGeTui_SendByCid$" 

# 测试群推
go test -v  -run="^TestGeTui_SendByCids$"

# 测试全推
go test -v  -run="^TestGeTui_SendAll$"  

其它例子参照 getui_test.go 的调用。

测试用例里针对SDK进行了一些封装,大家可以参考快速实现。例如IGtTransmissionTemplate()是透传模板的实现。其它模板可以参考实现,比较简单。

文档参考

https://pkg.go.dev/github.com/geek-go/getui

如何参与该项目

如果需要增加个推其它接口的实现,请参考api_开头的文件实现。规范:

  • 每个接口对应一个文件
  • 每个文件均包含接口请求结构体、接口响应结构体、接口调用的实现
  • 增加测试用例
  • 注意避免过度封装,以免使用者困惑

Documentation

Index

Constants

View Source
const (
	API_URL = "https://restapi.getui.com/v1/"
)
View Source
const PHONE_TYPE = "phonetype"

手机类型

View Source
const REGION = "region"

地区

View Source
const TAG = "tag"

自定义tag

Variables

View Source
var MsgType = &messageType{
	"notification",
	"link",
	"notypopload",
	"transmission",
}

消息类型

Functions

func GetGeTuiToken

func GetGeTuiToken(appID string, appKey string, masterSecret string) (string, error)

获取Auth签名 http://docs.getui.com/getui/server/rest/other_if/

func MakeReqBody

func MakeReqBody(param interface{}) ([]byte, error)

生成请求参数对应的JSON

func SendPost

func SendPost(url string, authToken string, bodyByte []byte) (string, error)

post请求

func Signature

func Signature(appKey string, masterSecret string) (string, string)

Types

type Alert

type Alert struct {
	Title string `json:"title"` //通知标题
	Body  string `json:"body"`  //通知内容
}

push_info.Alert

type Apns

type Apns struct {
	Alert            *Alert `json:"alert"`               //
	AutoBadge        string `json:"autoBadge,omitempty"` //用于计算icon上显示的数字,还可以实现显示数字的自动增减,如“+1”、 “-1”、 “1” 等,计算结果将覆盖badge
	Sound            string `json:"sound,omitempty"`     //通知铃声文件名,无声设置为“com.gexin.ios.silence”
	ContentAvailable int    `json:"content-available"`   //推送直接带有透传数据
	Category         string `json:"category,omitempty"`  //在客户端通知栏触发特定的action和button显示
}

push_info.Apns

type AppCondition

type AppCondition struct {
	Key     string   `json:"key"`      //筛选条件类型名称(省市region,手机类型phonetype,用户标签tag)
	Values  []string `json:"values"`   //筛选参数
	OptType int      `json:"opt_type"` //筛选参数的组合,0:取参数并集or,1:交集and,2:相当与not in {参数1,参数2,....}
}

type Condition

type Condition []AppCondition

type GtFeedBack

type GtFeedBack struct {
	Feedback  int    `json:"feedback"`
	Displayed int    `json:"displayed"`
	Result    string `json:"result"`
	Sent      int    `json:"sent"`
	Clicked   int    `json:"clicked"`
}
type Link struct {
	Url           string      `json:"url,omitempty"`            //	打开网址 可选
	DurationBegin string      `json:"duration_begin,omitempty"` //	设定展示开始时间,格式为yyyy-MM-dd HH:mm:ss  可选
	DurationEnd   string      `json:"duration_end,omitempty"`   //设定展示结束时间,格式为yyyy-MM-dd HH:mm:ss  可选
	Style         interface{} `json:"style,omitempty"`          //	通知栏消息布局样式(0 系统样式 1 个推样式) 默认为0  可选
}

开通知打开网页模板

type Message

type Message struct {
	AppKey            string `json:"appkey"`                        //	注册应用时生成的appkey
	IsOffline         bool   `json:"is_offline,omitempty"`          //	是否离线推送 可选 默认true
	OfflineExpireTime int    `json:"offline_expire_time,omitempty"` //	消息离线存储有效期,单位:ms 默认24小时
	PushNetWorkType   int    `json:"push_network_type,omitempty"`   //	选择推送消息使用网络类型,0:不限制,1:wifi 默认0
	MsgType           string `json:"msgtype"`                       //	消息应用类型,可选项:notification、link、notypopload、transmission。选了MsgType,那么必须有对应的模板,否则失败
}

@see http://docs.getui.com/getui/server/rest/explain/

func GetMessage

func GetMessage() *Message

获取Message实例

type Notification

type Notification struct {
	TransmissionType    bool        `json:"transmission_type,omitempty"`    //收到消息是否立即启动应用,true为立即启动,false则广播等待启动,默认是否  可选
	TransmissionContent string      `json:"transmission_content,omitempty"` //透传内容  可选
	DurationBegin       string      `json:"duration_begin,omitempty"`       //设定展示开始时间,格式为yyyy-MM-dd HH:mm:ss  可选
	DurationEnd         string      `json:"duration_end,omitempty"`         //设定展示结束时间,格式为yyyy-MM-dd HH:mm:ss  可选
	Style               interface{} `json:"style"`                          //通知栏消息布局样式(0 系统样式 1 个推样式) 默认为0  可选
}

点开通知打开应用模板 在通知栏显示一条含图标、标题等的通知,用户点击后,会激活您的应用 http://docs.getui.com/getui/server/rest/template/?id=doc-title-0

type Notify

type Notify struct {
	Title   string `json:"title"`
	Content string `json:"content"`
	Intent  string `json:"intent"`
	Type    string `json:"type"`
}

多厂商推送透传消息带通知

type NotyPopload

type NotyPopload struct {
	NotyIcon    string `json:"notyicon"`    //通知栏图标
	NotyTitle   string `json:"notytitle"`   //	通知标题
	NotyContent string `json:"notycontent"` //	通知内容
	//	LogoUrl       string `json:"logourl,omitempty"`        //	通知的网络图标地址 可选
	PopTitle      string      `json:"poptitle"`                 //	弹出框标题
	PopContent    string      `json:"popcontent"`               //弹出框内容
	PopImage      string      `json:"popimage"`                 //弹出框图标
	PopButton1    string      `json:"PopButton1"`               //弹出框左边按钮名称
	PopButton2    string      `json:"PopButton2"`               //弹出框左边按钮名称
	LoadUrl       string      `json:"loadurl"`                  //	下载文件地址
	LoadIcon      string      `json:"loadicon,omitempty"`       // 下载图标  可选
	LoadTitle     string      `json:"loadtitle,omitempty"`      //	下载标题  可选
	IsAutoinstall bool        `json:"is_autoinstall,omitempty"` //	是否自动安装,默认值false 可选
	IsActived     bool        `json:"is_actived,omitempty"`     //安装完成后是否自动启动应用程序,默认值false 可选
	AndroidMark   string      `json:"androidmark,omitempty"`    //安卓标识 可选
	SymbianMark   string      `json:"symbianmark,omitempty"`    //塞班标识 可选
	IphoneMark    string      `json:"iphonemark,omitempty"`     //苹果标志 可选
	DurationBegin string      `json:"duration_begin,omitempty"` //	设定展示开始时间,格式为yyyy-MM-dd HH:mm:ss 可选
	DurationEnd   string      `json:"duration_end,omitempty"`   //设定展示结束时间,格式为yyyy-MM-dd HH:mm:ss  可选
	NotifyStyle   int         `json:"notify_style,omitempty"`   //	通知栏消息布局样式(0 系统样式 1 个推样式) 默认为0  可选
	Style         interface{} `json:"style,omitempty"`          //通知栏消息布局样式(0 系统样式 1 个推样式) 默认为0  可选
}

点击通知弹窗下载模板

type PushAppParam

type PushAppParam struct {
	Message       *Message      `json:"message"`
	Notification  *Notification `json:"notification"`
	Link          *Link         `json:"link,omitempty"`
	Notypopload   *NotyPopload  `json:"notypopload,omitempty"`
	Transmission  *Transmission `json:"transmission,omitempty"`
	PushInfo      *PushInfo     `json:"push_info,omitempty"`
	Condition     *Condition    `json:"condition,omitempty"`
	RequestId     string        `json:"requestid"`                //请求唯一标识
	Speed         int64         `json:"speed,omitempty"`          //推送速度控制。设置群推接口的推送速度,单位为条/秒,例如填写100,则为100条/秒。仅对指定应用群推接口有效。
	TaskName      string        `json:"task_name,omitempty"`      //任务别名
	DurationBegin string        `json:"duration_begin,omitempty"` //设定展示开始时间,格式为yyyy-MM-dd HH:mm:ss
	DurationEnd   string        `json:"duration_end,omitempty"`   //设定展示结束时间,格式为yyyy-MM-dd HH:mm:ss
}

type PushAppResult

type PushAppResult struct {
	Result string `json:"result"`
	Taskid string `json:"taskid"`
	Desc   string `json:"desc"`
}

type PushInfo

type PushInfo map[string]interface{}

json串,当手机为ios,并且为离线的时候

type PushListParam

type PushListParam struct {
	Cid        []string `json:"cid"` //cid为cid list,与alias list二选一
	Alias      []string `json:"alias"`
	Taskid     string   `json:"taskid"`
	NeedDetail bool     `json:"need_detail"`
}

http://docs.getui.com/getui/server/rest/push/#doc-title-1

type PushListResult

type PushListResult struct {
	Result       string            `json:"result"`
	Taskid       string            `json:"taskid"`
	Desc         string            `json:"desc"`
	CidDetails   map[string]string `json:"cid_details"`
	AliasDetails map[string]string `json:"alias_details"`
}

func PushList

func PushList(appId string, authToken string, param *PushListParam) (*PushListResult, error)

群推

type PushResult

type PushResult struct {
	Result string `json:"result"`
	Data   []struct {
		Taskid     string `json:"taskId"`
		MsgTotal   int    `json:"msgTotal"`
		MsgProcess int    `json:"msgProcess"`
		ClickNum   int    `json:"clickNum"`
		PushNum    int    `json:"pushNum"`
		APN        string `json:"APN,omitempty"`
		GT         string `json:"GT"`
	} `json:"data"`
}

func GetPushResult

func GetPushResult(appId string, authToken string, param *PushResultParam) (*PushResult, error)

获取推送结果接口

type PushResultParam

type PushResultParam struct {
	Taskidlist []string `json:"taskIdList"` //查询的任务结果列表
}

type PushSingleParam

type PushSingleParam struct {
	Message      *Message      `json:"message"`
	Notification *Notification `json:"notification,omitempty"`
	Link         *Link         `json:"link,omitempty"`
	Notypopload  *NotyPopload  `json:"notypopload,omitempty"`
	Transmission *Transmission `json:"transmission,omitempty"`
	PushInfo     *PushInfo     `json:"push_info,omitempty"`
	Cid          string        `json:"cid,omitempty"`
	Alias        string        `json:"alias,omitempty"`
	RequestId    string        `json:"requestid"`
}

type PushSingleResult

type PushSingleResult struct {
	Result string `json:"result"` //ok 鉴权成功
	TaskId string `json:"taskid"` //任务标识号
	Desc   string `json:"desc"`   //错误信息描述
	Status string `json:"status"` //推送结果successed_offline 离线下发successed_online 在线下发successed_ignore 非活跃用户不下发
}

func PushSingle

func PushSingle(appId string, authToken string, param *PushSingleParam) (*PushSingleResult, error)

单推

type SaveListBodyParam

type SaveListBodyParam struct {
	Message      *Message      `json:"message"`                //消息内容
	Notification *Notification `json:"notification,omitempty"` //通知模板
	Link         *Link         `json:"link,omitempty"`
	Notypopload  *NotyPopload  `json:"notypopload,omitempty"`
	Transmission *Transmission `json:"transmission,omitempty"` //透传模板
	PushInfo     *PushInfo     `json:"push_info,omitempty"`    //json串,当手机为ios,并且为离线的时候;或者简化推送的时候,使用该参数
	TaskName     string        `json:"task_name,omitempty"`    //	任务名称 可以给多个任务指定相同的task_name,后面用task_name查询推送结果能得到多个任务的结果  可选
}

消息应用模板 notification、link、notypopload、transmission 四种类型选其一该属性与message下面的msgtype一致

type SaveListBodyResult

type SaveListBodyResult struct {
	Result string `json:"result"`
	TaskId string `json:"taskid"` //	任务标识号
	Desc   string `json:"desc"`   //	错误信息描述
}

func SaveListBody

func SaveListBody(appId string, authToken string, param *SaveListBodyParam) (*SaveListBodyResult, error)

保存消息共同体,获取推送taskid

type SignParam

type SignParam struct {
	Sign      string `json:"sign"`
	Timestamp string `json:"timestamp"`
	AppKey    string `json:"appkey"`
}

type SignResult

type SignResult struct {
	Result    string `json:"result"`
	AuthToken string `json:"auth_token"`
}

token

type Transmission

type Transmission struct {
	TransmissionType    bool    `json:"transmission_type"`        //	收到消息是否立即启动应用,true为立即启动,false则广播等待启动,默认是否  可选
	TransmissionContent string  `json:"transmission_content"`     //透传内容
	DurationBegin       string  `json:"duration_begin,omitempty"` //	设定展示开始时间,格式为yyyy-MM-dd HH:mm:ss  可选
	DurationEnd         string  `json:"duration_end,omitempty"`   //设定展示结束时间,格式为yyyy-MM-dd HH:mm:ss  可选
	Notify              *Notify `json:"notify,omitempty"`         //多厂商推送透传消息带通知
}

透传消息模板 透传消息是指消息传递到客户端只有消息内容,展现的形式由客户端自行定义。客户端可自定义通知的展现形式,可以自定义通知到达后的动作,或者不做任何展现。IOS推送也使用该模板 http://docs.getui.com/getui/server/rest/template/?id=doc-title-3

Jump to

Keyboard shortcuts

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