1
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
package uinapp
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -18,55 +17,45 @@ func TestGetToken(t *testing.T) {
|
||||
globals.SugarLogger.Debug("result := %v", err)
|
||||
}
|
||||
|
||||
func TestSendMsgAndroid(t *testing.T) {
|
||||
api.SendMsgByUinApp(SendMsgReq{
|
||||
RequestId: utils.Int64ToStr(time.Now().UnixNano()),
|
||||
GroupName: "",
|
||||
Audience: AudienceCid{CId: []string{android}},
|
||||
Settings: SendMsgSetting{},
|
||||
PushMessage: PushMessageDetail{
|
||||
Notification: PushMessageDetailNotification{
|
||||
Title: "测试消息推送[个推推送消息参数]",
|
||||
Body: "吃早饭了没得[个推推送消息参数]",
|
||||
BigText: "这是个什么东西[个推推送消息参数]",
|
||||
BigImage: "",
|
||||
Logo: "",
|
||||
LogoUrl: "",
|
||||
ChannelId: "",
|
||||
ChannelName: "",
|
||||
ChannelLevel: 0,
|
||||
ClickType: "startapp",
|
||||
Intent: "",
|
||||
Url: "",
|
||||
Payload: "",
|
||||
NotifyId: 0,
|
||||
RingName: "",
|
||||
BadgeAddNum: 0,
|
||||
ThreadId: "",
|
||||
func TestCidSend(t *testing.T) {
|
||||
err := api.SendMsgByUinApp(map[string]interface{}{
|
||||
"request_id": "12345237568ydfd2",
|
||||
"settings": map[string]interface{}{
|
||||
"ttl": 7200000,
|
||||
},
|
||||
"audience": map[string]interface{}{
|
||||
"cid": []string{"808ba3cebba05782f82063d590b738a3"},
|
||||
},
|
||||
"push_message": map[string]interface{}{
|
||||
"transmission": "{'type':'new','title':'火车南站店','content':'老板,您来新订单了,请尽快接单!'}",
|
||||
},
|
||||
"push_channel": map[string]interface{}{
|
||||
"android": map[string]interface{}{
|
||||
"ups": map[string]interface{}{
|
||||
"transmission": "厂商透传消息",
|
||||
},
|
||||
},
|
||||
"ios": map[string]interface{}{
|
||||
"type": "notify",
|
||||
"payload": "{'type':'new','title':'火车南站店','content':'老板,您来新订单了,请尽快接单!'}",
|
||||
"aps": map[string]interface{}{
|
||||
"alert": map[string]interface{}{
|
||||
"title": "火车南站店",
|
||||
"body": "新订单",
|
||||
},
|
||||
"content-available": 0,
|
||||
"sound": "自定义铃声,设置为包含后缀名的完整文件名,示例值:ring.mp3",
|
||||
"category": "在客户端通知栏触发特定的action和button显示",
|
||||
},
|
||||
"auto_badge": "+1",
|
||||
"multimedia": []map[string]interface{}{
|
||||
{
|
||||
"url": "https://xxx",
|
||||
"type": 1,
|
||||
"only_wifi": false},
|
||||
},
|
||||
},
|
||||
},
|
||||
PushChannel: PushChannelDetail{
|
||||
//Ios: IosApsDetail{},
|
||||
Android: AndroidPushChannelDetail{Ups: AndroidPushChannelUps{
|
||||
Notification: AndroidPushChannelNotification{
|
||||
Title: "测试消息推送[厂商推送消息参数]",
|
||||
Body: "吃早饭了没得[厂商推送消息参数]",
|
||||
ClickType: "startapp",
|
||||
Intent: "",
|
||||
Url: "",
|
||||
NotifyId: 0,
|
||||
},
|
||||
Transmission: "",
|
||||
Revoke: struct {
|
||||
OldTaskId string `json:"old_task_id"`
|
||||
}{},
|
||||
Options: struct {
|
||||
Constraint string `json:"constraint"`
|
||||
Key string `json:"key"`
|
||||
Value interface{} `json:"value"`
|
||||
}{},
|
||||
}},
|
||||
Mp: MpPushChannelDetail{},
|
||||
},
|
||||
})
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
@@ -109,17 +109,19 @@ type IosPushChannelAps struct {
|
||||
ContentState struct{} `json:"content-state"` // type为liveactivity时必填
|
||||
}
|
||||
|
||||
type MultimediaIos struct {
|
||||
Url string `json:"url"` // 多媒体资源地址
|
||||
TypeMultimedia int64 `json:"type"` // 资源类型(1.图片,2.音频,3.视频)
|
||||
OnlyWifi bool `json:"only_wifi"` // 是否只在wifi环境下加载,如果设置成true,但未使用wifi时,会展示成普通通知
|
||||
}
|
||||
|
||||
type IosApsDetail struct {
|
||||
NotifyType string `json:"type"` // notify默认通知消息 voip:voip语音推送,notify:apns通知消息,liveactivity:灵动岛推送(不支持p12证书)
|
||||
Aps IosPushChannelAps `json:"aps"` // 推送通知消息内容
|
||||
AutoBadge string `json:""` // 用于计算icon上显示的数字,还可以实现显示数字的自动增减,如“+1”、 “-1”、 “1” 等,计算结果将覆盖badge
|
||||
Payload string `json:"payload"` // 增加自定义的数据
|
||||
Multimedia []struct { // 多媒体设置
|
||||
Url string `json:"url"` // 多媒体资源地址
|
||||
TypeMultimedia int64 `json:"type"` // 资源类型(1.图片,2.音频,3.视频)
|
||||
OnlyWifi bool `json:"only_wifi"` // 是否只在wifi环境下加载,如果设置成true,但未使用wifi时,会展示成普通通知
|
||||
} `json:"multimedia"` // 多媒体设置
|
||||
ApnsCollapseId string `json:"apns-collapse-id"` // 使用相同的apns-collapse-id可以覆盖之前的消息
|
||||
NotifyType string `json:"type"` // notify默认通知消息 voip:voip语音推送,notify:apns通知消息,liveactivity:灵动岛推送(不支持p12证书)
|
||||
Aps IosPushChannelAps `json:"aps"` // 推送通知消息内容
|
||||
AutoBadge string `json:""` // 用于计算icon上显示的数字,还可以实现显示数字的自动增减,如“+1”、 “-1”、 “1” 等,计算结果将覆盖badge
|
||||
Payload string `json:"payload"` // 增加自定义的数据
|
||||
Multimedia []MultimediaIos `json:"multimedia"` // 多媒体设置
|
||||
ApnsCollapseId string `json:"apns-collapse-id"` // 使用相同的apns-collapse-id可以覆盖之前的消息
|
||||
}
|
||||
|
||||
type AndroidPushChannelUps struct {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package uinapp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SendMsgRes struct {
|
||||
@@ -16,13 +19,16 @@ type SendMsgRes struct {
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
func (a *API) SendMsgByUinApp(parma SendMsgReq) error {
|
||||
func (a *API) SendMsgByUinApp(parma map[string]interface{}) error {
|
||||
if err := a.CheckTokenIsExpire(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := a.AccessAPI(BaseUrl+a.appId, PushMsgByCid, http.MethodPost, utils.Struct2MapByJson(parma))
|
||||
if err != nil {
|
||||
data, _ := json.Marshal(parma)
|
||||
fmt.Println(string(data))
|
||||
result, err := a.AccessAPI(BaseUrl+a.appId, PushMsgByCid, http.MethodPost, parma)
|
||||
fmt.Println(err.Error())
|
||||
if err != nil && !strings.Contains(err.Error(), "success") {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -30,7 +36,7 @@ func (a *API) SendMsgByUinApp(parma SendMsgReq) error {
|
||||
if err := utils.Map2StructByJson(result, &sendMsgRes, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if sendMsgRes.Code != 200 {
|
||||
if sendMsgRes.Code != 0 {
|
||||
return errors.New(sendMsgRes.Msg)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user