From 3dc6ffe0d7d307a1fe752f07ed743bee14a76a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 20 Mar 2023 16:13:35 +0800 Subject: [PATCH] 1 --- .../tiktok_shop/ascription_place/dd_test.go | 2 +- platformapi/uinapp/uin_app_test.go | 89 ++++++++----------- platformapi/uinapp/uinapp_model.go | 22 ++--- platformapi/uinapp/uinapp_send_msg.go | 14 ++- 4 files changed, 62 insertions(+), 65 deletions(-) diff --git a/platformapi/tiktok_shop/ascription_place/dd_test.go b/platformapi/tiktok_shop/ascription_place/dd_test.go index ede9d539..6cb2baf0 100644 --- a/platformapi/tiktok_shop/ascription_place/dd_test.go +++ b/platformapi/tiktok_shop/ascription_place/dd_test.go @@ -6,7 +6,7 @@ import ( ) func TestAscriptionPlace(t *testing.T) { - p, err := Find("13146872779") + p, err := Find("17146563473") fmt.Println(p) fmt.Println(err) } diff --git a/platformapi/uinapp/uin_app_test.go b/platformapi/uinapp/uin_app_test.go index 4b43e9c8..100755e3 100644 --- a/platformapi/uinapp/uin_app_test.go +++ b/platformapi/uinapp/uin_app_test.go @@ -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) } diff --git a/platformapi/uinapp/uinapp_model.go b/platformapi/uinapp/uinapp_model.go index 491492e2..0ddd7e0c 100644 --- a/platformapi/uinapp/uinapp_model.go +++ b/platformapi/uinapp/uinapp_model.go @@ -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 { diff --git a/platformapi/uinapp/uinapp_send_msg.go b/platformapi/uinapp/uinapp_send_msg.go index 30b9c97f..b7a87ea0 100644 --- a/platformapi/uinapp/uinapp_send_msg.go +++ b/platformapi/uinapp/uinapp_send_msg.go @@ -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