作者 yangfu

fet: message push support customize sound file

... ... @@ -18,9 +18,8 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ
repProject, _ = repository.NewProjectRepository()
appInfo *protocol.AppInfo
project *protocol.Project
receivers []string
receiverIds []int64
deviceList []*protocol.Device
requestOriginal *protocol.PushInfoOriginalRequest = &protocol.PushInfoOriginalRequest{
Type: request.Type,
Title: request.Title,
... ... @@ -33,6 +32,8 @@ func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequ
projectKeys = request.ProjectKeys
}
for i := 0; i < len(projectKeys); i++ {
var receivers []string
var deviceList []*protocol.Device
projectKey := projectKeys[i]
rsp = &protocol.PushInfoResponse{}
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
requestOriginal.Ext["intent"] = extInfo.Intent
}
if len(extInfo.Sound) > 0 {
requestOriginal.Ext["sound"] = extInfo.Sound
requestOriginal.SetExt(push.Sound, extInfo.Sound, false)
}
if len(extInfo.HWSound) > 0 {
requestOriginal.SetExt(push.SoundHW, extInfo.HWSound, false)
}
if len(extInfo.XMSound) > 0 {
requestOriginal.SetExt(push.SoundXM, extInfo.XMSound, false)
}
}
if len(deviceList) == 0 {
... ... @@ -143,15 +150,22 @@ func NotificationOriginal(header *protocol.RequestHeader, request *protocol.Push
func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDeviceRequest) (rsp *protocol.UpdateDeviceResponse, err error) {
var (
//device *protocol.Device
project *protocol.Project
repProject, _ = repository.NewProjectRepository()
rep, _ = repository.NewPushDeviceRepository(nil)
)
rsp = &protocol.UpdateDeviceResponse{}
rep, _ := repository.NewPushDeviceRepository(nil)
if project, err = repProject.FindOne(map[string]interface{}{"project_master_key": request.ProjectMasterKey}); err != nil {
log.Error(err)
err = protocol.NewCustomMessage(1, fmt.Sprintf("project_key:%v not found", request.ProjectMasterKey))
return
}
if _, err = rep.FindOne(map[string]interface{}{
"uid": request.Muid,
"project_master_key": request.ProjectKey,
"project_master_key": request.ProjectMasterKey,
}); err != nil {
if err == protocol.ERR_DB_NOT_FOUND {
request.Project = project.Project
err = rep.Save(request)
if err != nil {
log.Error(err)
... ... @@ -161,7 +175,7 @@ func UpdateDevice(header *protocol.RequestHeader, request *protocol.UpdateDevice
log.Error(err)
return
}
if err = rep.UpdateDevice(request.Muid, request.ClientId, request.DeviceToken, request.ProjectKey, request.Phone); err != nil {
if err = rep.UpdateDevice(request.Muid, request.ClientId, request.DeviceToken, request.ProjectMasterKey, request.Phone, request.Project); err != nil {
log.Error(err)
}
err = protocol.NewSuccessWithMessage("更新成功")
... ...
... ... @@ -5,6 +5,7 @@ type Project struct {
ProjectName string
ProjectMasterKey string
ProjectSlaveKey string
Project string
}
func (d *Project) Identify() interface{} {
... ...
... ... @@ -17,6 +17,18 @@ type PushInfoOriginalRequest struct {
Content string `json:"content" valid:"Required"`
Ext map[string]interface{} `json:"ext"` //key->transData:透传数据
}
func (req *PushInfoOriginalRequest) SetExt(key string, value interface{}, force bool) {
if force {
req.Ext[key] = value
return
}
if _, ok := req.Ext[key]; ok {
return
}
req.Ext[key] = value
}
type PushInfoResponse struct {
ExtData map[string]interface{} `json:"-"`
}
... ... @@ -36,7 +48,8 @@ type PushInfoRequest struct {
/*UpdateDevice 更新设备*/
type UpdateDeviceRequest struct {
ProjectKey string `json:"projectKey"` //项目主编号
ProjectMasterKey string `json:"projectKey"` //项目主编号
Project string `json:"-"` //项目主编号
Muid int64 `json:"muid" valid:"Required;"` //企业平台中的用户 UID
ClientId string `json:"clientId" valid:"Required"`
DeviceToken string `json:"deviceToken"`
... ... @@ -66,6 +79,8 @@ type AppInfo struct {
type ExtInfo struct {
Intent string `json:"intent"`
Sound string `json:"sound,omitempty"`
HWSound string `json:"sound_hw,omitempty"`
XMSound string `json:"sound_xm,omitempty"`
}
func (t *AppInfo) GetExtInfo() (*ExtInfo, bool) {
... ...
... ... @@ -10,6 +10,7 @@ type Project struct {
ProjectName string `orm:"column(project_name);size(255);null" description:"项目名称 能力展示"`
ProjectSlaveKey string `orm:"column(project_slave_key);size(255);null" description:"项目从键 ability"`
ProjectMasterKey string `orm:"column(project_master_key);size(50);null" description:"主项目主键编码 ability"`
Project string `orm:"column(project);size(50);null" description:"项目编码 ability"`
}
func (t *Project) TableName() string {
... ...
... ... @@ -16,6 +16,7 @@ type PushDeviceInfo struct {
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
IsActive int `orm:"column(is_active);null" description:"是否在活动 1:在线 0:离线(解绑,切换账号)"`
ProjectMasterKey string `orm:"column(project_master_key);size(50);null" description:"主项目唯一标识 ability"`
Project string `orm:"column(project);size(50);null" description:"项目唯一标识 ability"`
}
func (t *PushDeviceInfo) TableName() string {
... ...
... ... @@ -116,6 +116,10 @@ func pushMessageNotification(m *MapData, option *push.Options) {
m.SetFieldMap(notification, "click_type", "intent")
m.SetFieldMap(notification, "intent", option.Intent)
}
//if v, ok := option.GetExt("sound"); ok && len(v.(string)) > 0 {
// filename:=filepath.Base(v.(string))
// m.SetFieldMap(notification, "ring_name",filename)
//}
}
func pushMessageTransmission(m *MapData, option *push.Options) {
m.AddFiled("push_message.transmission", option.TransmissionContent)
... ... @@ -150,6 +154,22 @@ func channelAndroid(m *MapData, option *push.Options) {
optionsMap["VV"] = map[string]interface{}{
"classification": 1,
}
if v, ok := option.GetExt(push.SoundHW); ok && len(v.(string)) > 0 {
channel, _ := option.GetExt(push.SoundChannelHW)
optionsMap["HW"] = map[string]interface{}{
"/message/android/notification/default_sound": false,
"/message/android/notification/channel_id": channel, //需要申请
"/message/android/notification/sound": v.(string), //自定义消息通知铃声
"/message/android/notification/importance": "NORMAL",
}
}
if v, ok := option.GetExt(push.SoundXM); ok && len(v.(string)) > 0 {
channel, _ := option.GetExt(push.SoundChannelXM)
optionsMap["XM"] = map[string]interface{}{
"sound_uri": v.(string), //需要申请 自定义消息通知铃声
"channel": channel, //需要申请
}
}
m.AddFiled("push_channel.android.ups.options", optionsMap)
}
... ... @@ -177,7 +197,7 @@ func channelIOS(m *MapData, option *push.Options) {
//m.SetFieldMap(alert, "body", option.Content)
m.AddFiled("push_channel.ios.aps.content-available", 0)
if v, ok := option.GetExt("sound"); ok && len(v.(string)) > 0 {
if v, ok := option.GetExt(push.Sound); ok && len(v.(string)) > 0 {
m.AddFiled("push_channel.ios.aps.sound", v)
}
m.AddFiled("push_channel.ios.auto_badge", "+1")
... ...
... ... @@ -7,6 +7,14 @@ import (
"strings"
)
const (
Sound = "sound"
SoundXM = "sound_xm"
SoundHW = "sound_hw"
SoundChannelXM = "sound_channel_xm"
SoundChannelHW = "sound_channel_hw"
)
type Options struct {
AppId string
AppKey string
... ...
... ... @@ -50,6 +50,9 @@ func (repository *ProjectRepository) FindOne(queryOptions map[string]interface{}
if v, ok := queryOptions["project_slave_key"]; ok {
qb.Where(fmt.Sprintf("project_slave_key = '%v'", v))
}
if v, ok := queryOptions["project_master_key"]; ok {
qb.Where(fmt.Sprintf("project_master_key = '%v'", v))
}
sql := qb.String()
o := orm.NewOrm()
if err := o.Raw(sql).QueryRow(m); err != nil {
... ... @@ -88,6 +91,7 @@ func (repository *ProjectRepository) transformPgModelToDomainModel(model *models
ProjectName: model.ProjectName,
ProjectSlaveKey: model.ProjectSlaveKey,
ProjectMasterKey: model.ProjectMasterKey,
Project: model.Project,
}, nil
}
... ...
... ... @@ -22,7 +22,8 @@ func (repository *PushDeviceRepository) Save(device *domain.UpdateDeviceRequest)
DeviceToken: strings.TrimSpace(device.DeviceToken),
CreateAt: time.Now(),
UpdateAt: time.Now(),
ProjectMasterKey: device.ProjectKey,
ProjectMasterKey: device.ProjectMasterKey,
Project: device.Project,
IsActive: 1,
}
_, err := o.Insert(m)
... ... @@ -61,17 +62,17 @@ func (repository *PushDeviceRepository) Find(queryOptions map[string]interface{}
return
}
func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string, projectKey string, phone string) error {
func (repository *PushDeviceRepository) UpdateDevice(uid int64, clientId, deviceToken string, projectKey string, phone string, project string) error {
o := orm.NewOrm()
o.Begin()
//更新(这个项目)其他绑定这个client_id的设备 is_active=0
_, 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()
_, 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()
if err != nil {
o.Rollback()
return err
}
_, 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()
_, 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()
if err != nil {
o.Rollback()
return err
... ...
... ... @@ -78,8 +78,8 @@ func (this *PushController) UpdateDevice() {
msg = m
return
}
if request.ProjectKey == "" || request.ProjectKey == "mmm.boss.pad" || request.ProjectKey == "mmm.boss" {
request.ProjectKey = "mmm.ability" //默认能力展示项目
if request.Project == "" { // || request.Project == "mmm.boss.pad" || request.Project == "mmm.boss"
request.Project = "mmm.ability" //默认能力展示项目
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(push.UpdateDevice(header, request))
... ...