fet: message push support customize sound file
正在显示
10 个修改的文件
包含
80 行增加
和
15 行删除
@@ -18,9 +18,8 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ | @@ -18,9 +18,8 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ | ||
18 | repProject, _ = repository.NewProjectRepository() | 18 | repProject, _ = repository.NewProjectRepository() |
19 | appInfo *protocol.AppInfo | 19 | appInfo *protocol.AppInfo |
20 | project *protocol.Project | 20 | project *protocol.Project |
21 | - receivers []string | ||
22 | receiverIds []int64 | 21 | receiverIds []int64 |
23 | - deviceList []*protocol.Device | 22 | + |
24 | requestOriginal *protocol.PushInfoOriginalRequest = &protocol.PushInfoOriginalRequest{ | 23 | requestOriginal *protocol.PushInfoOriginalRequest = &protocol.PushInfoOriginalRequest{ |
25 | Type: request.Type, | 24 | Type: request.Type, |
26 | Title: request.Title, | 25 | Title: request.Title, |
@@ -33,6 +32,8 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ | @@ -33,6 +32,8 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ | ||
33 | projectKeys = request.ProjectKeys | 32 | projectKeys = request.ProjectKeys |
34 | } | 33 | } |
35 | for i := 0; i < len(projectKeys); i++ { | 34 | for i := 0; i < len(projectKeys); i++ { |
35 | + var receivers []string | ||
36 | + var deviceList []*protocol.Device | ||
36 | projectKey := projectKeys[i] | 37 | projectKey := projectKeys[i] |
37 | rsp = &protocol.PushInfoResponse{} | 38 | rsp = &protocol.PushInfoResponse{} |
38 | if project, err = repProject.FindOne(map[string]interface{}{"project_slave_key": projectKey}); err != nil { | 39 | if project, err = repProject.FindOne(map[string]interface{}{"project_slave_key": projectKey}); err != nil { |
@@ -58,7 +59,13 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ | @@ -58,7 +59,13 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ | ||
58 | requestOriginal.Ext["intent"] = extInfo.Intent | 59 | requestOriginal.Ext["intent"] = extInfo.Intent |
59 | } | 60 | } |
60 | if len(extInfo.Sound) > 0 { | 61 | if len(extInfo.Sound) > 0 { |
61 | - requestOriginal.Ext["sound"] = extInfo.Sound | 62 | + requestOriginal.SetExt(push.Sound, extInfo.Sound, false) |
63 | + } | ||
64 | + if len(extInfo.HWSound) > 0 { | ||
65 | + requestOriginal.SetExt(push.SoundHW, extInfo.HWSound, false) | ||
66 | + } | ||
67 | + if len(extInfo.XMSound) > 0 { | ||
68 | + requestOriginal.SetExt(push.SoundXM, extInfo.XMSound, false) | ||
62 | } | 69 | } |
63 | } | 70 | } |
64 | if len(deviceList) == 0 { | 71 | if len(deviceList) == 0 { |
@@ -143,15 +150,22 @@ func NotificationOriginal(header *protocol.RequestHeader, request *protocol.Push | @@ -143,15 +150,22 @@ func NotificationOriginal(header *protocol.RequestHeader, request *protocol.Push | ||
143 | func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) { | 150 | func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) { |
144 | var ( | 151 | var ( |
145 | //device *protocol.Device | 152 | //device *protocol.Device |
153 | + project *protocol.Project | ||
154 | + repProject, _ = repository.NewProjectRepository() | ||
155 | + rep, _ = repository.NewPushDeviceRepository(nil) | ||
146 | ) | 156 | ) |
147 | rsp = &protocol.UpdateDeviceResponse{} | 157 | rsp = &protocol.UpdateDeviceResponse{} |
148 | - rep, _ := repository.NewPushDeviceRepository(nil) | ||
149 | - | 158 | + if project, err = repProject.FindOne(map[string]interface{}{"project_master_key": request.ProjectMasterKey}); err != nil { |
159 | + log.Error(err) | ||
160 | + err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", request.ProjectMasterKey)) | ||
161 | + return | ||
162 | + } | ||
150 | if _, err = rep.FindOne(map[string]interface{}{ | 163 | if _, err = rep.FindOne(map[string]interface{}{ |
151 | "uid": request.Muid, | 164 | "uid": request.Muid, |
152 | - "project_master_key": request.ProjectKey, | 165 | + "project_master_key": request.ProjectMasterKey, |
153 | }); err != nil { | 166 | }); err != nil { |
154 | if err == protocol.ERR_DB_NOT_FOUND { | 167 | if err == protocol.ERR_DB_NOT_FOUND { |
168 | + request.Project = project.Project | ||
155 | err = rep.Save(request) | 169 | err = rep.Save(request) |
156 | if err != nil { | 170 | if err != nil { |
157 | log.Error(err) | 171 | log.Error(err) |
@@ -161,7 +175,7 @@ func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDevice | @@ -161,7 +175,7 @@ func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDevice | ||
161 | log.Error(err) | 175 | log.Error(err) |
162 | return | 176 | return |
163 | } | 177 | } |
164 | - if err = rep.UpdateDevice(request.Muid, request.ClientId, request.DeviceToken, request.ProjectKey, request.Phone); err != nil { | 178 | + if err = rep.UpdateDevice(request.Muid, request.ClientId, request.DeviceToken, request.ProjectMasterKey, request.Phone, request.Project); err != nil { |
165 | log.Error(err) | 179 | log.Error(err) |
166 | } | 180 | } |
167 | err = protocol.NewSuccessWithMessage("更新成功") | 181 | err = protocol.NewSuccessWithMessage("更新成功") |
@@ -5,6 +5,7 @@ type Project struct { | @@ -5,6 +5,7 @@ type Project struct { | ||
5 | ProjectName string | 5 | ProjectName string |
6 | ProjectMasterKey string | 6 | ProjectMasterKey string |
7 | ProjectSlaveKey string | 7 | ProjectSlaveKey string |
8 | + Project string | ||
8 | } | 9 | } |
9 | 10 | ||
10 | func (d *Project) Identify() interface{} { | 11 | func (d *Project) Identify() interface{} { |
@@ -17,6 +17,18 @@ type PushInfoOriginalRequest struct { | @@ -17,6 +17,18 @@ type PushInfoOriginalRequest struct { | ||
17 | Content string `json:"content" valid:"Required"` | 17 | Content string `json:"content" valid:"Required"` |
18 | Ext map[string]interface{} `json:"ext"` //key->transData:透传数据 | 18 | Ext map[string]interface{} `json:"ext"` //key->transData:透传数据 |
19 | } | 19 | } |
20 | + | ||
21 | +func (req *PushInfoOriginalRequest) SetExt(key string, value interface{}, force bool) { | ||
22 | + if force { | ||
23 | + req.Ext[key] = value | ||
24 | + return | ||
25 | + } | ||
26 | + if _, ok := req.Ext[key]; ok { | ||
27 | + return | ||
28 | + } | ||
29 | + req.Ext[key] = value | ||
30 | +} | ||
31 | + | ||
20 | type PushInfoResponse struct { | 32 | type PushInfoResponse struct { |
21 | ExtData map[string]interface{} `json:"-"` | 33 | ExtData map[string]interface{} `json:"-"` |
22 | } | 34 | } |
@@ -36,7 +48,8 @@ type PushInfoRequest struct { | @@ -36,7 +48,8 @@ type PushInfoRequest struct { | ||
36 | 48 | ||
37 | /*UpdateDevice 更新设备*/ | 49 | /*UpdateDevice 更新设备*/ |
38 | type UpdateDeviceRequest struct { | 50 | type UpdateDeviceRequest struct { |
39 | - ProjectKey string `json:"projectKey"` //项目主编号 | 51 | + ProjectMasterKey string `json:"projectKey"` //项目主编号 |
52 | + Project string `json:"-"` //项目主编号 | ||
40 | Muid int64 `json:"muid" valid:"Required;"` //企业平台中的用户 UID | 53 | Muid int64 `json:"muid" valid:"Required;"` //企业平台中的用户 UID |
41 | ClientId string `json:"clientId" valid:"Required"` | 54 | ClientId string `json:"clientId" valid:"Required"` |
42 | DeviceToken string `json:"deviceToken"` | 55 | DeviceToken string `json:"deviceToken"` |
@@ -66,6 +79,8 @@ type AppInfo struct { | @@ -66,6 +79,8 @@ type AppInfo struct { | ||
66 | type ExtInfo struct { | 79 | type ExtInfo struct { |
67 | Intent string `json:"intent"` | 80 | Intent string `json:"intent"` |
68 | Sound string `json:"sound,omitempty"` | 81 | Sound string `json:"sound,omitempty"` |
82 | + HWSound string `json:"sound_hw,omitempty"` | ||
83 | + XMSound string `json:"sound_xm,omitempty"` | ||
69 | } | 84 | } |
70 | 85 | ||
71 | func (t *AppInfo) GetExtInfo() (*ExtInfo, bool) { | 86 | func (t *AppInfo) GetExtInfo() (*ExtInfo, bool) { |
@@ -10,6 +10,7 @@ type Project struct { | @@ -10,6 +10,7 @@ type Project struct { | ||
10 | ProjectName string `orm:"column(project_name);size(255);null" description:"项目名称 能力展示"` | 10 | ProjectName string `orm:"column(project_name);size(255);null" description:"项目名称 能力展示"` |
11 | ProjectSlaveKey string `orm:"column(project_slave_key);size(255);null" description:"项目从键 ability"` | 11 | ProjectSlaveKey string `orm:"column(project_slave_key);size(255);null" description:"项目从键 ability"` |
12 | ProjectMasterKey string `orm:"column(project_master_key);size(50);null" description:"主项目主键编码 ability"` | 12 | ProjectMasterKey string `orm:"column(project_master_key);size(50);null" description:"主项目主键编码 ability"` |
13 | + Project string `orm:"column(project);size(50);null" description:"项目编码 ability"` | ||
13 | } | 14 | } |
14 | 15 | ||
15 | func (t *Project) TableName() string { | 16 | func (t *Project) TableName() string { |
@@ -16,6 +16,7 @@ type PushDeviceInfo struct { | @@ -16,6 +16,7 @@ type PushDeviceInfo struct { | ||
16 | UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` | 16 | UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` |
17 | IsActive int `orm:"column(is_active);null" description:"是否在活动 1:在线 0:离线(解绑,切换账号)"` | 17 | IsActive int `orm:"column(is_active);null" description:"是否在活动 1:在线 0:离线(解绑,切换账号)"` |
18 | ProjectMasterKey string `orm:"column(project_master_key);size(50);null" description:"主项目唯一标识 ability"` | 18 | ProjectMasterKey string `orm:"column(project_master_key);size(50);null" description:"主项目唯一标识 ability"` |
19 | + Project string `orm:"column(project);size(50);null" description:"项目唯一标识 ability"` | ||
19 | } | 20 | } |
20 | 21 | ||
21 | func (t *PushDeviceInfo) TableName() string { | 22 | func (t *PushDeviceInfo) TableName() string { |
@@ -116,6 +116,10 @@ func pushMessageNotification(m *MapData, option *push.Options) { | @@ -116,6 +116,10 @@ func pushMessageNotification(m *MapData, option *push.Options) { | ||
116 | m.SetFieldMap(notification, "click_type", "intent") | 116 | m.SetFieldMap(notification, "click_type", "intent") |
117 | m.SetFieldMap(notification, "intent", option.Intent) | 117 | m.SetFieldMap(notification, "intent", option.Intent) |
118 | } | 118 | } |
119 | + //if v, ok := option.GetExt("sound"); ok && len(v.(string)) > 0 { | ||
120 | + // filename:=filepath.Base(v.(string)) | ||
121 | + // m.SetFieldMap(notification, "ring_name",filename) | ||
122 | + //} | ||
119 | } | 123 | } |
120 | func pushMessageTransmission(m *MapData, option *push.Options) { | 124 | func pushMessageTransmission(m *MapData, option *push.Options) { |
121 | m.AddFiled("push_message.transmission", option.TransmissionContent) | 125 | m.AddFiled("push_message.transmission", option.TransmissionContent) |
@@ -150,6 +154,22 @@ func channelAndroid(m *MapData, option *push.Options) { | @@ -150,6 +154,22 @@ func channelAndroid(m *MapData, option *push.Options) { | ||
150 | optionsMap["VV"] = map[string]interface{}{ | 154 | optionsMap["VV"] = map[string]interface{}{ |
151 | "classification": 1, | 155 | "classification": 1, |
152 | } | 156 | } |
157 | + if v, ok := option.GetExt(push.SoundHW); ok && len(v.(string)) > 0 { | ||
158 | + channel, _ := option.GetExt(push.SoundChannelHW) | ||
159 | + optionsMap["HW"] = map[string]interface{}{ | ||
160 | + "/message/android/notification/default_sound": false, | ||
161 | + "/message/android/notification/channel_id": channel, //需要申请 | ||
162 | + "/message/android/notification/sound": v.(string), //自定义消息通知铃声 | ||
163 | + "/message/android/notification/importance": "NORMAL", | ||
164 | + } | ||
165 | + } | ||
166 | + if v, ok := option.GetExt(push.SoundXM); ok && len(v.(string)) > 0 { | ||
167 | + channel, _ := option.GetExt(push.SoundChannelXM) | ||
168 | + optionsMap["XM"] = map[string]interface{}{ | ||
169 | + "sound_uri": v.(string), //需要申请 自定义消息通知铃声 | ||
170 | + "channel": channel, //需要申请 | ||
171 | + } | ||
172 | + } | ||
153 | m.AddFiled("push_channel.android.ups.options", optionsMap) | 173 | m.AddFiled("push_channel.android.ups.options", optionsMap) |
154 | } | 174 | } |
155 | 175 | ||
@@ -177,7 +197,7 @@ func channelIOS(m *MapData, option *push.Options) { | @@ -177,7 +197,7 @@ func channelIOS(m *MapData, option *push.Options) { | ||
177 | //m.SetFieldMap(alert, "body", option.Content) | 197 | //m.SetFieldMap(alert, "body", option.Content) |
178 | m.AddFiled("push_channel.ios.aps.content-available", 0) | 198 | m.AddFiled("push_channel.ios.aps.content-available", 0) |
179 | 199 | ||
180 | - if v, ok := option.GetExt("sound"); ok && len(v.(string)) > 0 { | 200 | + if v, ok := option.GetExt(push.Sound); ok && len(v.(string)) > 0 { |
181 | m.AddFiled("push_channel.ios.aps.sound", v) | 201 | m.AddFiled("push_channel.ios.aps.sound", v) |
182 | } | 202 | } |
183 | m.AddFiled("push_channel.ios.auto_badge", "+1") | 203 | m.AddFiled("push_channel.ios.auto_badge", "+1") |
@@ -7,6 +7,14 @@ import ( | @@ -7,6 +7,14 @@ import ( | ||
7 | "strings" | 7 | "strings" |
8 | ) | 8 | ) |
9 | 9 | ||
10 | +const ( | ||
11 | + Sound = "sound" | ||
12 | + SoundXM = "sound_xm" | ||
13 | + SoundHW = "sound_hw" | ||
14 | + SoundChannelXM = "sound_channel_xm" | ||
15 | + SoundChannelHW = "sound_channel_hw" | ||
16 | +) | ||
17 | + | ||
10 | type Options struct { | 18 | type Options struct { |
11 | AppId string | 19 | AppId string |
12 | AppKey string | 20 | AppKey string |
@@ -50,6 +50,9 @@ func (repository *ProjectRepository) FindOne(queryOptions map[string]interface{} | @@ -50,6 +50,9 @@ func (repository *ProjectRepository) FindOne(queryOptions map[string]interface{} | ||
50 | if v, ok := queryOptions["project_slave_key"]; ok { | 50 | if v, ok := queryOptions["project_slave_key"]; ok { |
51 | qb.Where(fmt.Sprintf("project_slave_key = '%v'", v)) | 51 | qb.Where(fmt.Sprintf("project_slave_key = '%v'", v)) |
52 | } | 52 | } |
53 | + if v, ok := queryOptions["project_master_key"]; ok { | ||
54 | + qb.Where(fmt.Sprintf("project_master_key = '%v'", v)) | ||
55 | + } | ||
53 | sql := qb.String() | 56 | sql := qb.String() |
54 | o := orm.NewOrm() | 57 | o := orm.NewOrm() |
55 | if err := o.Raw(sql).QueryRow(m); err != nil { | 58 | if err := o.Raw(sql).QueryRow(m); err != nil { |
@@ -88,6 +91,7 @@ func (repository *ProjectRepository) transformPgModelToDomainModel(model *models | @@ -88,6 +91,7 @@ func (repository *ProjectRepository) transformPgModelToDomainModel(model *models | ||
88 | ProjectName: model.ProjectName, | 91 | ProjectName: model.ProjectName, |
89 | ProjectSlaveKey: model.ProjectSlaveKey, | 92 | ProjectSlaveKey: model.ProjectSlaveKey, |
90 | ProjectMasterKey: model.ProjectMasterKey, | 93 | ProjectMasterKey: model.ProjectMasterKey, |
94 | + Project: model.Project, | ||
91 | }, nil | 95 | }, nil |
92 | } | 96 | } |
93 | 97 |
@@ -22,7 +22,8 @@ func (repository *PushDeviceRepository) Save(device *domain.UpdateDeviceRequest) | @@ -22,7 +22,8 @@ func (repository *PushDeviceRepository) Save(device *domain.UpdateDeviceRequest) | ||
22 | DeviceToken: strings.TrimSpace(device.DeviceToken), | 22 | DeviceToken: strings.TrimSpace(device.DeviceToken), |
23 | CreateAt: time.Now(), | 23 | CreateAt: time.Now(), |
24 | UpdateAt: time.Now(), | 24 | UpdateAt: time.Now(), |
25 | - ProjectMasterKey: device.ProjectKey, | 25 | + ProjectMasterKey: device.ProjectMasterKey, |
26 | + Project: device.Project, | ||
26 | IsActive: 1, | 27 | IsActive: 1, |
27 | } | 28 | } |
28 | _, err := o.Insert(m) | 29 | _, err := o.Insert(m) |
@@ -61,17 +62,17 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} | @@ -61,17 +62,17 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{} | ||
61 | return | 62 | return |
62 | } | 63 | } |
63 | 64 | ||
64 | -func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string, projectKey string, phone string) error { | 65 | +func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string, projectKey string, phone string, project string) error { |
65 | o := orm.NewOrm() | 66 | o := orm.NewOrm() |
66 | o.Begin() | 67 | o.Begin() |
67 | //更新(这个项目)其他绑定这个client_id的设备 is_active=0 | 68 | //更新(这个项目)其他绑定这个client_id的设备 is_active=0 |
68 | - _, err := o.Raw("UPDATE push_device_info SET update_at=now(),is_active=0 where client_id=? and is_active=1 and project_master_key=?", clientId, projectKey).Exec() | 69 | + _, err := o.Raw("UPDATE push_device_info SET update_at=now(),is_active=0 where client_id=? and is_active=1 and project=?", clientId, project).Exec() |
69 | if err != nil { | 70 | if err != nil { |
70 | o.Rollback() | 71 | o.Rollback() |
71 | return err | 72 | return err |
72 | } | 73 | } |
73 | 74 | ||
74 | - _, err = o.Raw("UPDATE push_device_info SET client_id=?,device_token = ?,update_at=now(),is_active=1,phone=? where uid=? and project_master_key=?", clientId, deviceToken, phone, uid, projectKey).Exec() | 75 | + _, err = o.Raw("UPDATE push_device_info SET client_id=?,device_token = ?,update_at=now(),is_active=1,phone=?,project=? where uid=? and project_master_key=?", clientId, deviceToken, phone, project, uid, projectKey).Exec() |
75 | if err != nil { | 76 | if err != nil { |
76 | o.Rollback() | 77 | o.Rollback() |
77 | return err | 78 | return err |
@@ -78,8 +78,8 @@ func (this *PushController) UpdateDevice() { | @@ -78,8 +78,8 @@ func (this *PushController) UpdateDevice() { | ||
78 | msg = m | 78 | msg = m |
79 | return | 79 | return |
80 | } | 80 | } |
81 | - if request.ProjectKey == "" || request.ProjectKey == "mmm.boss.pad" || request.ProjectKey == "mmm.boss" { | ||
82 | - request.ProjectKey = "mmm.ability" //默认能力展示项目 | 81 | + if request.Project == "" { // || request.Project == "mmm.boss.pad" || request.Project == "mmm.boss" |
82 | + request.Project = "mmm.ability" //默认能力展示项目 | ||
83 | } | 83 | } |
84 | header := controllers.GetRequestHeader(this.Ctx) | 84 | header := controllers.GetRequestHeader(this.Ctx) |
85 | msg = protocol.NewReturnResponse(push.UpdateDevice(header, request)) | 85 | msg = protocol.NewReturnResponse(push.UpdateDevice(header, request)) |
-
请 注册 或 登录 后发表评论