我正在開發一款應用程序,一款允許用戶使用FCM主題訂閱訂閱其最喜愛的團隊的實時分數應用程序,我需要幫助才能將通知傳遞給該用戶。使用fcm的Firebase Live分數推送通知
現在我可以定期發送通知到設備,我可以通過控制檯,管理員node.js中,REST API手動發送通知,即使對於用戶訂閱訂閱話題,我還可以列出一個具體登記訂閱ID。
所以...我的用戶訂閱的主題是團隊id(橄欖球隊),我想要做的是通知用戶訂閱某個特定主題,當一些遊戲事件發生像目標,遊戲狀態(遊戲開始,半場時間,下半場比賽開始,比賽結束),這是推送通知系統的一個非常常見的用例。
我存儲在火力數據庫我的遊戲數據,我從外部供應商把它和「實時」更新,看起來像:
{
"AwayTeamShort": "ANZ",
"League": "Russian Premier League",
"comp_id": "1457",
"events": [
{
"assist": "G. Gabulov",
"assist_id": "29779",
"extra_min": "",
"id": "23177131",
"minute": "46",
"player": "M. Kazankov",
"player_id": "113277",
"result": "",
"team": "localteam",
"type": "subst"
},
{
"assist": "",
"assist_id": "",
"extra_min": "",
"id": "23177132",
"minute": "57",
"player": "I. Yediev",
"player_id": "",
"result": "",
"team": "localteam",
"type": "yellowcard"
},
{
"assist": "K. Bazelyuk",
"assist_id": "269373",
"extra_min": "",
"id": "23177133",
"minute": "57",
"player": "A. Katsaev",
"player_id": "92363",
"result": "",
"team": "visitorteam",
"type": "subst"
},
{
"assist": "J. Lipartia",
"assist_id": "41506",
"extra_min": "",
"id": "23177134",
"minute": "58",
"player": "K. Mamtov",
"player_id": "29851",
"result": "",
"team": "visitorteam",
"type": "subst"
},
{
"assist": "E. Balyajkin",
"assist_id": "6770",
"extra_min": "",
"id": "23177135",
"minute": "67",
"player": "N. Kalinski",
"player_id": "",
"result": "",
"team": "localteam",
"type": "subst"
},
{
"assist": "R. Koryan",
"assist_id": "123728",
"extra_min": "",
"id": "23177136",
"minute": "68",
"player": "M. Markovic",
"player_id": "139251",
"result": "[1-0]",
"team": "localteam",
"type": "goal"
},
{
"assist": "P. Yakovlev",
"assist_id": "82061",
"extra_min": "",
"id": "23177137",
"minute": "71",
"player": "P. Dolgov",
"player_id": "309265",
"result": "",
"team": "visitorteam",
"type": "subst"
},
{
"assist": "R. Koryan",
"assist_id": "123728",
"extra_min": "",
"id": "23177138",
"minute": "72",
"player": "V. Nikiforov",
"player_id": "26213",
"result": "",
"team": "localteam",
"type": "subst"
},
{
"assist": "",
"assist_id": "",
"extra_min": "",
"id": "23177139",
"minute": "89",
"player": "A. Dovbnya",
"player_id": "123582",
"result": "",
"team": "localteam",
"type": "yellowcard"
},
{
"assist": "",
"assist_id": "",
"extra_min": "2",
"id": "231771310",
"minute": "90",
"player": "T. Phibel",
"player_id": "58795",
"result": "",
"team": "visitorteam",
"type": "yellowcard"
},
{
"assist": "",
"assist_id": "",
"extra_min": "2",
"id": "231771311",
"minute": "90",
"player": "S. Bryzgalov",
"player_id": "122214",
"result": "",
"team": "visitorteam",
"type": "yellowcard"
},
{
"assist": "V. Nikiforov",
"assist_id": "26213",
"extra_min": "5",
"id": "231771312",
"minute": "90",
"player": "N. Kalinski",
"player_id": "",
"result": "[2-0]",
"team": "localteam",
"type": "goal"
}
],
"formatted_date": "08.08.2017",
"ft_score": "[2-0]",
"ht_score": "[0-0]",
"id": "2211727",
"localteam_id": "14810",
"localteam_name": "SKA Khabarovsk",
"localteam_score": "2",
"region": "Russia",
"season": "2017/2018",
"status": "FT",
"time": "08:00」,
"venue": "Stadion imeni V.I. Lenina (Khabarovsk)",
"venue_city": "Khabarovsk",
"venue_id": "88600",
"visitorteam_id": "14786",
"visitorteam_name": "FK Anzi Makhackala",
"visitorteam_score": "0",
"week": "5"
}
的用戶訂閱球隊ID在JSON在團隊id上面是visitorteam_id,localteam_id,這些ID總是相同的,如果是訪問者或本地團隊,則該團隊無關緊要。在實例
我的訂閱ID API的樣子(我然後將其存儲在數據庫中,但不要緊,這個問題):
{
"application":"com.iid.example",
"authorizedEntity":"123456782354",
"platform":"Android",
"attestStatus":"ROOTED",
"appSigner":"1a2bc3d4e5",
"connectionType":"WIFI",
"connectDate":"2017-08-07
"rel":{
"topics":{
"42332":{"addDate":"2017-08-07"},
"14810":{"addDate":"2017-08-07"},
"14786":{"addDate":"2017-08-07"}
}
}
}
所以...我怎麼能通知訂閱設備一個特定的話題(團隊id)關於他們認購的團隊在玩遊戲的目標?
PS:我知道大概的解決方案是複雜的,但每一個幫助,實例會受到歡迎
嗨Javi,就像我提到的,我可以訂閱主題並獲取數據庫中的更改通知我的問題更多地是關於使用我的json和「連接」到特定主題的方法,例如: –