getuipush

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 15 Imported by: 0

README

getui push sdk

* golang版本的个推API V2,限内部使用;
* 其他用户需要使用,请根据自己情况,修改 `getPushMessageAndChannel`和`getIntent`函数中的配置;

个推官方文档

https://docs.getui.com/getui/server/rest_v2/push/

更多方法请查看 getui.go
init pushClient

var (
	pushClient *push.PushClient
)

func InitClient() {
	conf := &push.PushConfig{
		AppId:        "xxxx",
		AppSecret:    "xxx",
		AppKey:       "xxxx",
		MasterSecret: "xxxx",
	}
	store := &push.PushStore{
		Host:     "127.0.0.1",
		Port:     6379,
		DB:       0,
		Password: "xxxx",
		Key:      "getui:token",
	}
	var err error

    // true 为是否打开调试模式
	pushClient, err = push.NewPushClient(conf, store, true)
	if err != nil {
		logy.Infof("init client error :%v", err)
	}
}

一些方法

// 获取token
func (g *PushClient) GetToken() (token string, err error) 


// 绑定别名
func (g *PushClient) BindAlias(param *models.Alias) (resp *models.Response, err error) 


// 绑定别名
func (g *PushClient) BindAlias(param *models.Alias) (resp *models.Response, err error) 


// 解绑别名
func (g *PushClient) UnBindAlias(param *models.Alias) (resp *models.Response, err error) 

// 根据cid绑定标签
func (g *PushClient) BindTags(cid string, param *models.CustomTagsParam) (resp *models.Response, err error) 


// 根据cid查询已经绑定的标签
func (g *PushClient) SearchTags(cid string) (resp *models.Response, err error) 


// 根据cid查询用户状态
func (g *PushClient) SearchStatus(cid string) (resp *models.Response, err error) 

// 根据cid查询个推的用户信息
func (g *PushClient) SearchUser(cid string) (resp *models.Response, err error) 

// 按cid查询绑定的别名
func (g *PushClient) SearchAliasByCid(cid string) (resp *models.Response, err error) 

// 按别名查询登录过的设备(cid)
func (g *PushClient) SearchCidByAlias(alias string) (resp *models.Response, err error) 

推送的方法

// 推给所有人
func (g *PushClient) PushAll(scheduleTime int, payload *models.CustomMessage) (resp *models.Response, err error) 

// 推给指定的客户端:android or iOS
func (g *PushClient) PushAllByClient(scheduleTime int, clientType ClientType, payload *models.CustomMessage) (resp *models.Response, err error) 


// 单推给某一个用户
//  根据cid
func (g *PushClient) PushSingleByCid(channelType int, cid string, payload *models.CustomMessage) (resp *models.Response, err error) 


// 单推给某一个用户
//  根据别名
func (g *PushClient) PushSingleByAlias(channelType int, alias string, payload *models.CustomMessage) (resp *models.Response, err error) 


// 按cid数组进行群推
func (g *PushClient) PushListByCid(cid []string, payload *models.CustomMessage) (data []*models.Response, err error) 

// 按自定义标签进行群推
func (g *PushClient) PushAllByCustomTag(scheduleTime int, customTag []string, payload *models.CustomMessage) (resp *models.Response, err error) 
第三方包
  • github.com/tidwall/gjson
  • github.com/zituocn/gow/lib/logy

Documentation

Index

Constants

View Source
const (
	//APIURL 服务器地址
	APIURL string = "https://restapi.getui.com/v2/"

	// NAME 日志中的前缀
	NAME = "[个推]"

	// PublicChannel 运营推送
	PublicChannel = 1 //公信通道

	// PrivateChannel 聊天推送
	PrivateChannel = 2
)

Variables

View Source
var (
	// TTL 消息存放时间
	TTL = 86400000 // 1天: 1 * 24 * 3600 * 1000

)
View Source
var (
	// ToDebug 全局的调试开关
	ToDebug = false
)

Functions

func HttpRequest

func HttpRequest(method, url, token string, bodyByte []byte) ([]byte, error)

HttpRequest 请求API,返回 []byte

func RequestAPI

func RequestAPI(method, url, token string, bodyByte []byte) (*models.Response, error)

RequestAPI 请求API,返回Response

Types

type ClientType

type ClientType int

ClientType APP客户端类型

const (
	Android   ClientType = iota + 1 //android
	IOS                             //ios
	WechatAPP                       //微信小程序
)

type MessageType added in v0.0.9

type MessageType int
const (
	ArticleMsg MessageType = iota + 1
	AlgorithmReCommendMsg
	AttendRecommendMsg
	PlatformActionMsg
	UserAccountMsg
	InstantMsg
)

func (MessageType) GetHonorImportance added in v0.0.9

func (m MessageType) GetHonorImportance() (importance string)

func (MessageType) GetHuaweiCategory added in v0.0.9

func (m MessageType) GetHuaweiCategory() string

GetHuaweiCategory 华为: 不同消息类型对应的category

func (MessageType) GetHuaweiChannelId added in v0.0.9

func (m MessageType) GetHuaweiChannelId() string

GetHuaweiChannelId 华为 channelId

func (MessageType) GetHuaweiImportance added in v0.0.9

func (m MessageType) GetHuaweiImportance() string

func (MessageType) GetHuaweiInfo added in v0.0.9

func (m MessageType) GetHuaweiInfo() (channelId, category, importance string)

GetHuaweiInfo 华为 channelId category

func (MessageType) GetOPPOChannelId added in v0.0.9

func (m MessageType) GetOPPOChannelId() string

func (MessageType) GetViVoCategory added in v0.0.9

func (m MessageType) GetViVoCategory() string

GetViVoCategory vivo: 不同消息类型对应的category

func (MessageType) GetViVoClassification added in v0.0.9

func (m MessageType) GetViVoClassification() int64

GetViVoClassification vivo: 不同消息类型对应的分类

func (MessageType) GetXiaoMiChannelId added in v0.0.9

func (m MessageType) GetXiaoMiChannelId() string

GetXiaoMiChannelId 小米: 不同消息类型对应的channelId

type PushClient

type PushClient struct {
	*PushConfig
	*PushStore
}

PushClient 个推 push client

func NewPushClient

func NewPushClient(conf *PushConfig, store *PushStore, toDebug bool) (client *PushClient, err error)

NewPushClient 返回个推实例并初始化redis信息

func (*PushClient) BindAlias

func (g *PushClient) BindAlias(param *models.Alias) (resp *models.Response, err error)

BindAlias 绑定别名

func (*PushClient) BindTags

func (g *PushClient) BindTags(cid string, param *models.CustomTagsParam) (resp *models.Response, err error)

BindTags 一个用户绑定一批标签

cid表示用户

func (*PushClient) GetToken

func (g *PushClient) GetToken() (token string, err error)

GetToken 获取token

从redis中或api中获取

func (*PushClient) GetUserCount added in v0.0.2

func (g *PushClient) GetUserCount(tags []*models.Tag) (resp *models.Response, err error)

GetUserCount 查询用户总量

func (*PushClient) PushAll

func (g *PushClient) PushAll(msgType, scheduleTime int, payload *models.CustomMessage) (resp *models.Response, err error)

PushAll 推送给所有人

scheduleTime 定时推送时间戳,为0时,不定时

func (*PushClient) PushAllByClient

func (g *PushClient) PushAllByClient(msgType, scheduleTime int, clientType ClientType, payload *models.CustomMessage) (resp *models.Response, err error)

PushAllByClient 推送给不同的客户端

clientType 客户端类型,只能选1种
scheduleTime 定时推送时间戳,为0时,不定时

func (*PushClient) PushAllByCustomTag

func (g *PushClient) PushAllByCustomTag(msgType, scheduleTime int, customTag []string, payload *models.CustomMessage) (resp *models.Response, err error)

PushAllByCustomTag 对指定应用的符合筛选条件的用户群发推送消息。支持定时、定速功能

此接口频次限制100次/天,每分钟不能超过5次(推送限制和接口执行群推共享限制),定时推送功能需要申请开通才可以使用
scheduleTime 定时推送时间戳,为0时,不定时
customTag 内的标签是交集的关系

func (*PushClient) PushAllByLogicTags added in v0.0.2

func (g *PushClient) PushAllByLogicTags(msgType, scheduleTime int, tags []*models.Tag, payload *models.CustomMessage) (resp *models.Response, err error)

PushAllByLogicTags 对指定应用的符合筛选条件的用户群发推送消息。支持定时、定速功能

此接口频次限制100次/天,每分钟不能超过5次(推送限制和接口执行群推共享限制),定时推送功能需要申请开通才可以使用
scheduleTime 定时推送时间戳,为0时,不定时
tags为[]*models.Tag,需要自己构建tag表达式
see @https://docs.getui.com/getui/server/rest_v2/push/

func (*PushClient) PushAppByFastCustomTag

func (g *PushClient) PushAppByFastCustomTag(msgType, scheduleTime int, tag string, payload *models.CustomMessage) (resp *models.Response, err error)

PushAppByFastCustomTag 使用标签快速推送

tag 为某一个标签名
scheduleTime 为定时任务的时间戳
此接口需要SVIP才有使用权限

func (*PushClient) PushListByCid

func (g *PushClient) PushListByCid(msgType int, cid []string, payload *models.CustomMessage) (data []*models.Response, err error)

PushListByCid 按cid群推消息

当cid长度大于1000时,会分页循环进行推送

func (*PushClient) PushSingleByAlias

func (g *PushClient) PushSingleByAlias(msgType int, alias string, payload *models.CustomMessage) (resp *models.Response, err error)

PushSingleByAlias 单推给某一个用户

alias = 用户的alias
channelType = 通道类型

func (*PushClient) PushSingleByCid

func (g *PushClient) PushSingleByCid(msgType int, cid string, payload *models.CustomMessage) (resp *models.Response, err error)

PushSingleByCid 单推给某一个用户

cid = 用户的cid信息
channelType = 通道类型

func (*PushClient) ReportPushTask added in v0.0.5

func (g *PushClient) ReportPushTask(taskId string) (resp *models.Response, err error)

ReportPushTask 获取推送结果(含自定义事件)可查询消息可下发数、下发数,接收数、展示数、点击数等结果

用于跟踪某个用户的消息到达情况

func (*PushClient) SearchAliasByCid

func (g *PushClient) SearchAliasByCid(cid string) (resp *models.Response, err error)

SearchAliasByCid 按cid查别名

即这台设备上登录过哪些帐号

{"alias":"255617"}

func (*PushClient) SearchCidByAlias

func (g *PushClient) SearchCidByAlias(alias string) (resp *models.Response, err error)

SearchCidByAlias 按alias查cid

即这个alias绑定过哪些设备
{
  "cid": [
    "1fb427ab8f93a6de4655f4a15add51d2",
    "699214926b118e9512a9330423fbaf5f"
  ]
}

func (*PushClient) SearchStatus

func (g *PushClient) SearchStatus(cid string) (resp *models.Response, err error)

SearchStatus 查询某个用户的状态,是否在线,上次在线时间等

根据cid查询
{
  "294d4da8b52d909ed30d261baf91d2d2": {
    "last_login_time": "1663897775596",
    "status": "offline"
  }
}

func (*PushClient) SearchTags

func (g *PushClient) SearchTags(cid string) (resp *models.Response, err error)

SearchTags 查询某个用户已经绑定的标签

{
  "7399c780f73ac4046d930dd2b4edf3b4": [
    "VIP用户 文科 手机登录 本科二批 iOS guangdong"
  ]
}

func (*PushClient) SearchTaskDetailByCid

func (g *PushClient) SearchTaskDetailByCid(cid, taskId string) (resp *models.TaskDetailResp, err error)

SearchTaskDetailByCid 可以查询某任务下某cid的具体实时推送路径情况

用于跟踪某个用户的消息到达情况
此接口需要SVIP权限,暂时不可用

func (*PushClient) SearchUser

func (g *PushClient) SearchUser(cid string) (resp *models.Response, err error)

SearchUser 查询用户信息

根据cid查询
{
  "validCids": {
    "294d4da8b52d909ed30d261baf91d2d2": {
      "client_app_id": "7a4W8IrA3rAHxlJunzfTe",
      "package_name": "ymzy-dream-iOS",
      "device_token": "c2a73ad014d19111fef4454ebe19c811fd9c994f1e9f767318667adf9d0bbb69,,",
      "phone_type": 2,
      "phone_model": "iPhone14,2",
      "notification_switch": true,
      "create_time": "2022-03-03 14:10:46",
      "login_freq": 21,
      "brand": "iphone"
    }
  }
}

func (*PushClient) StopTask

func (g *PushClient) StopTask(taskId string) (resp *models.Response, err error)

StopTask 停止推送任务

对正处于推送状态,或者未接收的消息停止下发(只支持批量推和群推任务)

func (*PushClient) UnBindAlias

func (g *PushClient) UnBindAlias(param *models.Alias) (resp *models.Response, err error)

UnBindAlias 解绑别名

cid与alias成对出现

func (*PushClient) UnBindAllAlias

func (g *PushClient) UnBindAllAlias(alias string) (resp *models.Response, err error)

UnBindAllAlias 解绑所有与该别名绑定的cid

type PushConfig

type PushConfig struct {
	AppId        string
	AppKey       string
	AppSecret    string
	MasterSecret string
}

PushConfig 配置

从个推获取

type PushStore

type PushStore struct {
	Host     string //redis host
	Port     int    // redis port
	DB       int    // redis db
	Password string //redis password
	Key      string //存储key名称
}

PushStore token存储配置

redis配置信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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