123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package mi
- import (
- "encoding/json"
- "fmt"
- "net/url"
- "strconv"
- "time"
- )
- type XMMessage struct {
- Payload string
- RestrictedPackageName string
- PassThrough int
- NotifyType int
- Title string
- Description string
- TaskID string
- xmuv url.Values
- }
- func (xm *XMMessage) buildXMPostParam() {
- xmuv := url.Values{}
- xmuv.Set("payload", xm.Payload)
- xmuv.Set("restricted_package_name", xm.RestrictedPackageName)
- xmuv.Set("pass_through", strconv.Itoa(xm.PassThrough))
- xmuv.Set("title", xm.Title)
- xmuv.Set("description", xm.Description)
- xmuv.Set("notify_type", strconv.Itoa(xm.NotifyType))
- xmuv.Set("extra.task_id", xm.TaskID)
- xmuv.Set("extra.jobkey", xm.TaskID)
- xmuv.Set("extra.callback", CallbackURL)
- xmuv.Set("extra.callback.type", "1")
- xm.xmuv = xmuv
- }
- func (xm *XMMessage) SetNotifyID(notifyID string) {
- if xm.xmuv == nil {
- xm.buildXMPostParam()
- }
- xm.xmuv.Set("notify_id", notifyID)
- }
- func (xm *XMMessage) SetNotifyType(typ int) {
- if xm.xmuv == nil {
- xm.buildXMPostParam()
- }
- xm.xmuv.Set("notify_type", strconv.Itoa(typ))
- }
- func (xm *XMMessage) SetTimeToLive(expire int64) {
- if xm.xmuv == nil {
- xm.buildXMPostParam()
- }
- timeToLive := (expire - time.Now().Unix()) * 1000
- xm.xmuv.Set("time_to_live", fmt.Sprintf("%d", timeToLive))
- }
- func (xm *XMMessage) SetTimeToSend(timeToSend int64) {
- if xm.xmuv == nil {
- xm.buildXMPostParam()
- }
- xm.xmuv.Set("time_to_send", fmt.Sprintf("%d", timeToSend))
- }
- func (xm *XMMessage) SetUserAccount(UserAccount string) {
- if xm.xmuv == nil {
- xm.buildXMPostParam()
- }
- xm.xmuv.Set("user_account", UserAccount)
- }
- func (xm *XMMessage) SetUserAccounts(UserAccount string) {
- if xm.xmuv == nil {
- xm.buildXMPostParam()
- }
- xm.xmuv.Set("user_accounts", UserAccount)
- }
- func (xm *XMMessage) SetRegID(deviceToken string) {
- if xm.xmuv == nil {
- xm.buildXMPostParam()
- }
- xm.xmuv.Set("registration_id", deviceToken)
- }
- func (xm *XMMessage) SetTopic(UserAccount string) {
- if xm.xmuv == nil {
- xm.buildXMPostParam()
- }
- xm.xmuv.Set("topic", UserAccount)
- }
- func (xm *XMMessage) SetCallbackParam(p string) {
- if xm.xmuv == nil {
- xm.buildXMPostParam()
- }
- xm.xmuv.Set("extra.callback.param", p)
- }
- type Response struct {
- Result string `json:"result,omitempty"`
- Reason string `json:"reason,omitempty"`
- Code int `json:"code,omitempty"`
- Data Data `json:"data,omitempty"`
- Description string `json:"description,omitempty"`
- Info string `json:"info,omitempty"`
- TraceID string `json:"trace_id,omitempty"`
- }
- type Data struct {
- ID string `json:"id,omitempty"`
- List []string `json:"list,omitempty"`
- Data json.RawMessage `json:"data,omitempty"`
- }
- type UninstalledResponse struct {
- Code int `json:"errorCode,omitempty"`
- Reason string `json:"reason,omitempty"`
- Result []string `json:"result,omitempty"`
- Data []string
- }
- type UninstalledData struct {
- Token string `json:"regId"`
- Ts int64 `json:"ts"`
-
- }
- type RegidCallback struct {
- AppID string `json:"app_id"`
- AppVer string `json:"app_version"`
- AppPkg string `json:"app_pkg"`
- AppSecret string `json:"app_secret"`
- Regid string `json:"regid"`
- }
- type Callback struct {
- Param string `json:"param"`
- BarStatus string `json:"barStatus"`
- Type int `json:"type"`
- Targets string `json:"targets"`
- Jobkey string `json:"jobkey"`
- }
|