作者 yangfu

1.增加推送日志

... ... @@ -48,7 +48,12 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ
requestOriginal.AppId = appInfo.AppId
requestOriginal.Secret = appInfo.AppMasterSecret
requestOriginal.ClientIdList = receivers
return NotificationOriginal(header, requestOriginal)
_, err = NotificationOriginal(header, requestOriginal)
repDevice.SaveLog(request, err)
if err != nil {
err = protocol.NewCustomMessage(1, err.Error())
}
return
}
func NotificationOriginal(header *protocol.RequestHeader, request *protocol.PushInfoOriginalRequest) (rsp *protocol.PushInfoResponse, err error) {
... ...
... ... @@ -70,7 +70,7 @@ func (notify *GetuiNotification) Send(option map[string]interface{}) (err error)
break
}
}
return nil
return err
}
//pushToSingle 单推
... ... @@ -246,7 +246,7 @@ func handleResult(url string, result *Result) (err error) {
setToken("")
break
}
err = fmt.Errorf("grequest fail,url:%v error:%v", url, result.Result)
err = fmt.Errorf("error:%v", result.Result)
return err
}
func sign(appkey, timestamp, mastersecret string) string {
... ...
... ... @@ -4,6 +4,7 @@ import (
"github.com/astaxie/beego/orm"
"openapi/pkg/domain"
"openapi/pkg/infrastructure/bgorm/model"
"openapi/pkg/infrastructure/utils"
"strings"
"time"
)
... ... @@ -62,6 +63,35 @@ func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, device
return nil
}
func (repository *PushDeviceRepository) SaveLog(request *domain.PushInfoRequest, err error) error {
var (
result int
errmsg string
)
if err != nil {
result = 1
errmsg = err.Error()
if v, ok := err.(*domain.ErrWithMessage); ok {
result = v.Errno
}
}
sql := `INSERT INTO push_log(msg_type,project,receivers,message,result,err_msg,create_at)VALUES(?,?,?,?,?,?,now())`
o := orm.NewOrm()
_, err = o.Raw(sql,
request.Type,
request.ProjectKey,
utils.JsonAssertString(request.Receivers),
utils.JsonAssertString(request),
result,
errmsg,
).Exec()
if err != nil {
return err
}
return nil
}
func (repository *PushDeviceRepository) transformBgormModelToDomainModel(model *models.PushDeviceInfo) (*domain.Device, error) {
return &domain.Device{
Uid: model.Uid,
... ...