作者 yangfu

推送修改 兼容 单个/数组的cid

... ... @@ -30,5 +30,5 @@ func (this *PushController) PushInfo() {
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(push.PushInfo(header, request))
msg = protocol.NewReturnResponse(push.Notification(header, request))
}
... ...
package protocol
import "encoding/json"
/*PushInfo 推送信息*/
type PushInfoRequest struct {
Type int `json:"mmmType" valid:"Required"`
DeviceToken string `json:"deviceToken" `
ClientId string `json:"clientId"`
AppKey string `json:"appKey" valid:"Required"`
Secret string `json:"secret" valid:"Required"`
AppId string `json:"appId" valid:"Required"`
Type int `json:"mmmType" valid:"Required"`
DeviceToken json.RawMessage `json:"deviceToken" `
ClientId json.RawMessage `json:"clientId"`
AppKey string `json:"appKey" valid:"Required"`
Secret string `json:"secret" valid:"Required"`
AppId string `json:"appId" valid:"Required"`
Title string `json:"title" valid:"Required"`
Content string `json:"content" valid:"Required"`
... ...
package push
import (
"encoding/json"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"openapi/internal/push"
"openapi/internal/push/getui"
... ... @@ -9,24 +10,64 @@ import (
)
//推送信息
func PushInfo(header *protocol.RequestHeader, request *protocol.PushInfoRequest) (rsp *protocol.PushInfoResponse, err error) {
func Notification(header *protocol.RequestHeader, request *protocol.PushInfoRequest) (rsp *protocol.PushInfoResponse, err error) {
var (
sendData = make(map[string]interface{})
options []push.Option = []push.Option{
sendData = make(map[string]interface{})
clientIds []string
fc = func(m json.RawMessage) {
if len(m) == 0 {
return
}
var (
id string
ids []string
)
if e := json.Unmarshal(m, &ids); e == nil {
clientIds = append(clientIds, ids...)
return
}
if e := json.Unmarshal(m, &id); e == nil {
if len(id) == 0 {
return
}
clientIds = append(clientIds, id)
return
}
return
}
options []push.Option = []push.Option{
push.DebugModule(true),
push.AppId(request.AppId),
push.AppKey(request.AppKey),
push.AppMasterSecret(request.Secret),
push.ClientId(request.ClientId),
push.MsgType(request.Type),
push.PushType(push.PushToSingle),
push.Title(request.Title),
push.Content(request.Content),
push.TransmissionContent(utils.JsonAssertString(request.Ext)),
}
)
fc(request.ClientId)
fc(request.DeviceToken)
switch len(clientIds) {
case 0:
err = protocol.NewCustomMessage(2, "clientId/deviceToken 不能同时为空.")
return
case 1:
options = append(options,
push.PushType(push.PushToSingle),
push.ClientId(clientIds[0]),
)
break
default:
options = append(options,
push.PushType(push.PushToList),
push.ClientIds(clientIds),
)
break
}
var pushService push.INotification = &getui.GetuiNotification{}
err = pushService.Init(options...)
if err != nil {
... ...