正在显示
3 个修改的文件
包含
38 行增加
和
3 行删除
| @@ -48,7 +48,12 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ | @@ -48,7 +48,12 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ | ||
| 48 | requestOriginal.AppId = appInfo.AppId | 48 | requestOriginal.AppId = appInfo.AppId |
| 49 | requestOriginal.Secret = appInfo.AppMasterSecret | 49 | requestOriginal.Secret = appInfo.AppMasterSecret |
| 50 | requestOriginal.ClientIdList = receivers | 50 | requestOriginal.ClientIdList = receivers |
| 51 | - return NotificationOriginal(header, requestOriginal) | 51 | + _, err = NotificationOriginal(header, requestOriginal) |
| 52 | + repDevice.SaveLog(request, err) | ||
| 53 | + if err != nil { | ||
| 54 | + err = protocol.NewCustomMessage(1, err.Error()) | ||
| 55 | + } | ||
| 56 | + return | ||
| 52 | } | 57 | } |
| 53 | 58 | ||
| 54 | func NotificationOriginal(header *protocol.RequestHeader, request *protocol.PushInfoOriginalRequest) (rsp *protocol.PushInfoResponse, err error) { | 59 | 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) | @@ -70,7 +70,7 @@ func (notify *GetuiNotification) Send(option map[string]interface{}) (err error) | ||
| 70 | break | 70 | break |
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | - return nil | 73 | + return err |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | //pushToSingle 单推 | 76 | //pushToSingle 单推 |
| @@ -246,7 +246,7 @@ func handleResult(url string, result *Result) (err error) { | @@ -246,7 +246,7 @@ func handleResult(url string, result *Result) (err error) { | ||
| 246 | setToken("") | 246 | setToken("") |
| 247 | break | 247 | break |
| 248 | } | 248 | } |
| 249 | - err = fmt.Errorf("grequest fail,url:%v error:%v", url, result.Result) | 249 | + err = fmt.Errorf("error:%v", result.Result) |
| 250 | return err | 250 | return err |
| 251 | } | 251 | } |
| 252 | func sign(appkey, timestamp, mastersecret string) string { | 252 | func sign(appkey, timestamp, mastersecret string) string { |
| @@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
| 4 | "github.com/astaxie/beego/orm" | 4 | "github.com/astaxie/beego/orm" |
| 5 | "openapi/pkg/domain" | 5 | "openapi/pkg/domain" |
| 6 | "openapi/pkg/infrastructure/bgorm/model" | 6 | "openapi/pkg/infrastructure/bgorm/model" |
| 7 | + "openapi/pkg/infrastructure/utils" | ||
| 7 | "strings" | 8 | "strings" |
| 8 | "time" | 9 | "time" |
| 9 | ) | 10 | ) |
| @@ -62,6 +63,35 @@ func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, device | @@ -62,6 +63,35 @@ func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, device | ||
| 62 | return nil | 63 | return nil |
| 63 | } | 64 | } |
| 64 | 65 | ||
| 66 | +func (repository *PushDeviceRepository) SaveLog(request *domain.PushInfoRequest, err error) error { | ||
| 67 | + var ( | ||
| 68 | + result int | ||
| 69 | + errmsg string | ||
| 70 | + ) | ||
| 71 | + if err != nil { | ||
| 72 | + result = 1 | ||
| 73 | + errmsg = err.Error() | ||
| 74 | + if v, ok := err.(*domain.ErrWithMessage); ok { | ||
| 75 | + result = v.Errno | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + sql := `INSERT INTO push_log(msg_type,project,receivers,message,result,err_msg,create_at)VALUES(?,?,?,?,?,?,now())` | ||
| 80 | + o := orm.NewOrm() | ||
| 81 | + _, err = o.Raw(sql, | ||
| 82 | + request.Type, | ||
| 83 | + request.ProjectKey, | ||
| 84 | + utils.JsonAssertString(request.Receivers), | ||
| 85 | + utils.JsonAssertString(request), | ||
| 86 | + result, | ||
| 87 | + errmsg, | ||
| 88 | + ).Exec() | ||
| 89 | + if err != nil { | ||
| 90 | + return err | ||
| 91 | + } | ||
| 92 | + return nil | ||
| 93 | +} | ||
| 94 | + | ||
| 65 | func (repository *PushDeviceRepository) transformBgormModelToDomainModel(model *models.PushDeviceInfo) (*domain.Device, error) { | 95 | func (repository *PushDeviceRepository) transformBgormModelToDomainModel(model *models.PushDeviceInfo) (*domain.Device, error) { |
| 66 | return &domain.Device{ | 96 | return &domain.Device{ |
| 67 | Uid: model.Uid, | 97 | Uid: model.Uid, |
-
请 注册 或 登录 后发表评论