...
|
...
|
@@ -46,23 +46,23 @@ func (notify *GetuiNotification) Init(options ...push.Option) error { |
|
|
notify.retry = 3
|
|
|
return nil
|
|
|
}
|
|
|
func (notify *GetuiNotification) Send(option map[string]interface{}) (err error) {
|
|
|
func (notify *GetuiNotification) Send(option map[string]interface{}) (rsp map[string]interface{}, err error) {
|
|
|
retry := 1
|
|
|
for {
|
|
|
switch notify.Options.PushType {
|
|
|
case push.PushToSingle:
|
|
|
err = notify.pushToSingle(option)
|
|
|
rsp, err = notify.pushToSingle(option)
|
|
|
case push.PushToList:
|
|
|
err = notify.pushToList(option)
|
|
|
rsp, err = notify.pushToList(option)
|
|
|
default:
|
|
|
err = notify.pushToSingle(option)
|
|
|
rsp, err = notify.pushToSingle(option)
|
|
|
}
|
|
|
if err == nil {
|
|
|
break
|
|
|
}
|
|
|
//重试
|
|
|
if err != nil && retry > notify.retry {
|
|
|
return err
|
|
|
return
|
|
|
}
|
|
|
log.Error(fmt.Sprintf("【个推】 重试:%v 失败:%v", retry, err))
|
|
|
retry++
|
...
|
...
|
@@ -70,14 +70,15 @@ func (notify *GetuiNotification) Send(option map[string]interface{}) (err error) |
|
|
break
|
|
|
}
|
|
|
}
|
|
|
return err
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//pushToSingle 单推
|
|
|
func (notify *GetuiNotification) pushToSingle(option map[string]interface{}) (err error) {
|
|
|
func (notify *GetuiNotification) pushToSingle(option map[string]interface{}) (rsp map[string]interface{}, err error) {
|
|
|
var token string
|
|
|
rsp = make(map[string]interface{})
|
|
|
if token, err = notify.GetAuthToken(); err != nil {
|
|
|
return err
|
|
|
return
|
|
|
}
|
|
|
|
|
|
var (
|
...
|
...
|
@@ -89,29 +90,31 @@ func (notify *GetuiNotification) pushToSingle(option map[string]interface{}) (er |
|
|
notify.Request.Header("authtoken", token)
|
|
|
notify.Request.JSONBody(m)
|
|
|
if err = notify.Request.ToJSON(&result); err != nil {
|
|
|
return err
|
|
|
return
|
|
|
}
|
|
|
rsp[push.TaskID] = result.TaskId
|
|
|
notify.print(url, m, result, result)
|
|
|
if err = handleResult(url, result); err != nil {
|
|
|
return err
|
|
|
return
|
|
|
}
|
|
|
return nil
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//pushToList 群推
|
|
|
//步骤1.获取token
|
|
|
//步骤2.save_list_body保存消息共同体
|
|
|
//步骤3.push_list
|
|
|
func (notify *GetuiNotification) pushToList(option map[string]interface{}) (err error) {
|
|
|
func (notify *GetuiNotification) pushToList(option map[string]interface{}) (rsp map[string]interface{}, err error) {
|
|
|
var (
|
|
|
token string
|
|
|
taskId string
|
|
|
)
|
|
|
rsp = make(map[string]interface{})
|
|
|
if token, err = notify.GetAuthToken(); err != nil {
|
|
|
return err
|
|
|
return
|
|
|
}
|
|
|
if taskId, err = notify.saveListBody(token, option); err != nil {
|
|
|
return err
|
|
|
return
|
|
|
}
|
|
|
var (
|
|
|
result *Result
|
...
|
...
|
@@ -130,13 +133,14 @@ func (notify *GetuiNotification) pushToList(option map[string]interface{}) (err |
|
|
notify.Request.Header("authtoken", token)
|
|
|
notify.Request.JSONBody(m)
|
|
|
if err = notify.Request.ToJSON(&result); err != nil {
|
|
|
return err
|
|
|
return
|
|
|
}
|
|
|
rsp[push.TaskID] = result.TaskId
|
|
|
notify.print(url, m, result, result)
|
|
|
if err = handleResult(url, result); err != nil {
|
|
|
return err
|
|
|
return
|
|
|
}
|
|
|
return nil
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//saveListBody 保存消息共同体
|
...
|
...
|
|