Skip to content

Commit ff87af2

Browse files
李海燕李海燕
authored andcommitted
update xiaomi msg type
1 parent 52be97f commit ff87af2

2 files changed

Lines changed: 70 additions & 27 deletions

File tree

constname.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ const (
1717
limit = 1000
1818
)
1919

20+
type XiaoMiMsgType int
21+
22+
const (
23+
ArticleMsg XiaoMiMsgType = iota + 1
24+
AlgorithmReCommendMsg
25+
AttendRecommendMsg
26+
PlatformActionMsg
27+
UserAccountMsg
28+
InstantMsg
29+
)
30+
31+
var xiaomiMagTypeChannelId = map[XiaoMiMsgType]string{
32+
ArticleMsg: "103533",
33+
AlgorithmReCommendMsg: "103779",
34+
AttendRecommendMsg: "103777",
35+
PlatformActionMsg: "103781",
36+
UserAccountMsg: "103776",
37+
InstantMsg: "103782",
38+
}
39+
40+
func (m XiaoMiMsgType) GetMsgChannelId() string {
41+
return xiaomiMagTypeChannelId[m]
42+
}
43+
2044
// ClientType APP客户端类型
2145
type ClientType int
2246

getui.go

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,12 @@ func (g *PushClient) ReportPushTask(taskId string) (resp *models.Response, err e
394394
// PushAll 推送给所有人
395395
//
396396
// scheduleTime 定时推送时间戳,为0时,不定时
397-
func (g *PushClient) PushAll(scheduleTime int, payload *models.CustomMessage) (resp *models.Response, err error) {
397+
func (g *PushClient) PushAll(msgType, scheduleTime int, payload *models.CustomMessage) (resp *models.Response, err error) {
398398
token, err := g.GetToken()
399399
if err != nil {
400400
return
401401
}
402-
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(PublicChannel, scheduleTime, payload)
402+
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(msgType, PublicChannel, scheduleTime, payload)
403403
if err != nil {
404404
return
405405
}
@@ -429,12 +429,12 @@ func (g *PushClient) PushAll(scheduleTime int, payload *models.CustomMessage) (r
429429
//
430430
// clientType 客户端类型,只能选1种
431431
// scheduleTime 定时推送时间戳,为0时,不定时
432-
func (g *PushClient) PushAllByClient(scheduleTime int, clientType ClientType, payload *models.CustomMessage) (resp *models.Response, err error) {
432+
func (g *PushClient) PushAllByClient(msgType, scheduleTime int, clientType ClientType, payload *models.CustomMessage) (resp *models.Response, err error) {
433433
token, err := g.GetToken()
434434
if err != nil {
435435
return
436436
}
437-
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(PublicChannel, scheduleTime, payload)
437+
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(msgType, PublicChannel, scheduleTime, payload)
438438
if err != nil {
439439
return
440440
}
@@ -486,12 +486,12 @@ func (g *PushClient) PushAllByClient(scheduleTime int, clientType ClientType, pa
486486
//
487487
// cid = 用户的cid信息
488488
// channelType = 通道类型
489-
func (g *PushClient) PushSingleByCid(channelType int, cid string, payload *models.CustomMessage) (resp *models.Response, err error) {
489+
func (g *PushClient) PushSingleByCid(msgType, channelType int, cid string, payload *models.CustomMessage) (resp *models.Response, err error) {
490490
token, err := g.GetToken()
491491
if err != nil {
492492
return
493493
}
494-
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(channelType, 0, payload)
494+
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(msgType, channelType, 0, payload)
495495
if err != nil {
496496
return
497497
}
@@ -524,12 +524,12 @@ func (g *PushClient) PushSingleByCid(channelType int, cid string, payload *model
524524
//
525525
// alias = 用户的alias
526526
// channelType = 通道类型
527-
func (g *PushClient) PushSingleByAlias(channelType int, alias string, payload *models.CustomMessage) (resp *models.Response, err error) {
527+
func (g *PushClient) PushSingleByAlias(msgType, channelType int, alias string, payload *models.CustomMessage) (resp *models.Response, err error) {
528528
token, err := g.GetToken()
529529
if err != nil {
530530
return
531531
}
532-
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(channelType, 0, payload)
532+
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(msgType, channelType, 0, payload)
533533
if err != nil {
534534
return
535535
}
@@ -562,7 +562,7 @@ func (g *PushClient) PushSingleByAlias(channelType int, alias string, payload *m
562562
// PushListByCid 按cid群推消息
563563
//
564564
// 当cid长度大于1000时,会分页循环进行推送
565-
func (g *PushClient) PushListByCid(cid []string, payload *models.CustomMessage) (data []*models.Response, err error) {
565+
func (g *PushClient) PushListByCid(msgType int, cid []string, payload *models.CustomMessage) (data []*models.Response, err error) {
566566
if len(cid) == 0 {
567567
err = errors.New("cid长度为0")
568568
return
@@ -571,7 +571,7 @@ func (g *PushClient) PushListByCid(cid []string, payload *models.CustomMessage)
571571
if err != nil {
572572
return
573573
}
574-
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(PublicChannel, 0, payload)
574+
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(msgType, PublicChannel, 0, payload)
575575
if err != nil {
576576
return
577577
}
@@ -606,8 +606,9 @@ func (g *PushClient) PushListByCid(cid []string, payload *models.CustomMessage)
606606
pushListParam.IsAsync = false //不异步
607607

608608
respList, err := pushListByCid(g.AppId, token, pushListParam)
609+
609610
if err != nil {
610-
logy.Errorf("%s 按cid群推失败: %s %s", NAME, respList.Msg, err.Error())
611+
logy.Errorf("%s 按cid群推失败: %s", NAME, err.Error())
611612
}
612613
data = append(data, respList)
613614
time.Sleep(time.Microsecond * 500) //休眠500ms
@@ -627,7 +628,7 @@ func (g *PushClient) PushListByCid(cid []string, payload *models.CustomMessage)
627628
// 此接口频次限制100次/天,每分钟不能超过5次(推送限制和接口执行群推共享限制),定时推送功能需要申请开通才可以使用
628629
// scheduleTime 定时推送时间戳,为0时,不定时
629630
// customTag 内的标签是交集的关系
630-
func (g *PushClient) PushAllByCustomTag(scheduleTime int, customTag []string, payload *models.CustomMessage) (resp *models.Response, err error) {
631+
func (g *PushClient) PushAllByCustomTag(msgType, scheduleTime int, customTag []string, payload *models.CustomMessage) (resp *models.Response, err error) {
631632
if len(customTag) == 0 {
632633
err = errors.New("自定义标签长度为0")
633634
return
@@ -636,7 +637,7 @@ func (g *PushClient) PushAllByCustomTag(scheduleTime int, customTag []string, pa
636637
if err != nil {
637638
return
638639
}
639-
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(PublicChannel, scheduleTime, payload)
640+
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(msgType, PublicChannel, scheduleTime, payload)
640641
if err != nil {
641642
return
642643
}
@@ -675,7 +676,7 @@ func (g *PushClient) PushAllByCustomTag(scheduleTime int, customTag []string, pa
675676
// scheduleTime 定时推送时间戳,为0时,不定时
676677
// tags为[]*models.Tag,需要自己构建tag表达式
677678
// see @https://docs.getui.com/getui/server/rest_v2/push/
678-
func (g *PushClient) PushAllByLogicTags(scheduleTime int, tags []*models.Tag, payload *models.CustomMessage) (resp *models.Response, err error) {
679+
func (g *PushClient) PushAllByLogicTags(msgType, scheduleTime int, tags []*models.Tag, payload *models.CustomMessage) (resp *models.Response, err error) {
679680
if len(tags) == 0 {
680681
err = errors.New("标签表达式长度为0")
681682
return
@@ -684,7 +685,7 @@ func (g *PushClient) PushAllByLogicTags(scheduleTime int, tags []*models.Tag, pa
684685
if err != nil {
685686
return
686687
}
687-
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(PublicChannel, scheduleTime, payload)
688+
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(msgType, PublicChannel, scheduleTime, payload)
688689
if err != nil {
689690
return
690691
}
@@ -720,7 +721,7 @@ func (g *PushClient) PushAllByLogicTags(scheduleTime int, tags []*models.Tag, pa
720721
// tag 为某一个标签名
721722
// scheduleTime 为定时任务的时间戳
722723
// 此接口需要SVIP才有使用权限
723-
func (g *PushClient) PushAppByFastCustomTag(scheduleTime int, tag string, payload *models.CustomMessage) (resp *models.Response, err error) {
724+
func (g *PushClient) PushAppByFastCustomTag(msgType, scheduleTime int, tag string, payload *models.CustomMessage) (resp *models.Response, err error) {
724725
if tag == "" {
725726
err = errors.New("自定义标签长度为0")
726727
return
@@ -729,7 +730,7 @@ func (g *PushClient) PushAppByFastCustomTag(scheduleTime int, tag string, payloa
729730
if err != nil {
730731
return
731732
}
732-
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(PublicChannel, scheduleTime, payload)
733+
pushMessage, pushChannel, setting, err := getPushMessageAndChannel(msgType, PublicChannel, scheduleTime, payload)
733734
if err != nil {
734735
return
735736
}
@@ -782,9 +783,10 @@ private
782783
// getPushMessageAndChannel 构造消息
783784
//
784785
// channelType 通道
786+
// xmMsgType 小米专用-指定的消息类型
785787
// scheduleTime 定时任务的时间戳
786788
// payload 消息结构体
787-
func getPushMessageAndChannel(channelType int, scheduleTime int, payload *models.CustomMessage) (pushMessage *models.PushMessage, pushChannel *models.PushChannel, setting *models.Setting, err error) {
789+
func getPushMessageAndChannel(xmMsgType, channelType int, scheduleTime int, payload *models.CustomMessage) (pushMessage *models.PushMessage, pushChannel *models.PushChannel, setting *models.Setting, err error) {
788790
payload.Title = strings.TrimSpace(payload.Title)
789791
pushInfo, err := json.Marshal(payload)
790792
if err != nil {
@@ -875,16 +877,19 @@ func getPushMessageAndChannel(channelType int, scheduleTime int, payload *models
875877
"/channel_id": "yuanmeng_push",
876878
}
877879

878-
// 小米公共
879-
android.Ups.Options.Xm = map[string]interface{}{
880-
"/extra.channel_id": "pre213",
881-
"notifyType": -1,
882-
}
880+
//// 小米公共
881+
//android.Ups.Options.Xm = map[string]interface{}{
882+
// "/extra.channel_id": "pre213",
883+
// "notifyType": -1,
884+
//}
885+
886+
logy.Errorf("小米新的channel")
883887

884888
//vivo
885889
android.Ups.Options.Vv.Classification = 0
886890
android.Ups.Options.Vv.NotifyType = 4
887891
}
892+
888893
//聊天、即时类消息
889894
if channelType == PrivateChannel {
890895
android.Ups.Options.All.Channel = "yuanmeng_push_im"
@@ -908,16 +913,30 @@ func getPushMessageAndChannel(channelType int, scheduleTime int, payload *models
908913
}
909914

910915
// 小米聊天
911-
android.Ups.Options.Xm = map[string]interface{}{
912-
"/extra.channel_id": "high_system",
913-
"notifyType": -1,
914-
}
916+
//android.Ups.Options.Xm = map[string]interface{}{
917+
// "/extra.channel_id": "high_system",
918+
// "notifyType": -1,
919+
//}
915920

916921
//vivo
917922
android.Ups.Options.Vv.Classification = 1
918923
android.Ups.Options.Vv.NotifyType = 4
919924
}
920925

926+
//根据小米最新的消息推送规定,需要按照指定的消息类型推送,不再仅分为 公用消息 和 聊天消息
927+
if xmMsgType > 0 {
928+
var xmChannelId string = "103533" //内容资讯的channelId,给一个默认的channelId
929+
channelId := XiaoMiMsgType(xmMsgType).GetMsgChannelId()
930+
if channelId != "" {
931+
xmChannelId = channelId
932+
}
933+
logy.Errorf("小米推送channelID:%v", xmChannelId)
934+
android.Ups.Options.Xm = map[string]interface{}{
935+
"/extra.channel_id": xmChannelId,
936+
"notifyType": -1,
937+
}
938+
}
939+
921940
pushChannel = &models.PushChannel{
922941
Android: android,
923942
IOS: ios,

0 commit comments

Comments
 (0)