私のバックエンドアプリケーションからAndroid携帯電話に通知を送信しようとしています。私は、デバイスをインストールしてそれらを削除することができました。メッセージのペイロードに問題があります。私は警報を発する必要があり、メッセージにアプリケーションデータを送る必要があります。これは私が今ペイロードを構築する方法ですが、私はそれは良くないことだと思う。Azure Notification Hubを使用してアプリケーションデータを含むGoogle Cloud Messagingペイロード
string notificationText = NotificationText(story, profile);
JProperty messageJProperty = new JProperty("message", notificationText);
JObject messageJObject = new JObject(messageJProperty);
JProperty objectJProperty = new JProperty("data", messageJObject);
JObject message = new JObject(objectJProperty);
var payload = message.ToString();
return payload;
のthnx
アップデート(2017年11月-3): 私は、このペイロード形式は、Azureので受け入れられることがわかりました。
private string Payload(string notificationText, StoryEntity story, ProfileEntity profile, string deviceToken)
{
var payload = new JObject
(
new JProperty("registration_ids", new JArray(deviceToken)),
new JProperty("data", new JObject(
new JProperty("title", "Mapporia has new stroy>"),
new JProperty("message", notificationText)
)),
new JProperty("notId", $"{new Random().Next(int.MaxValue)}"),
new JProperty("content-available", 1),
new JProperty("soundname", "default"),
new JProperty("image", @"www/assets/img/logo.png"),
new JProperty("image-type", "circle"),
new JProperty("style", "inbox"),
new JProperty("notData", new JObject(
new JProperty("storyId", story.Id),
new JProperty("profileId", profile.Id)
))
).ToString(Newtonsoft.Json.Formatting.None);
return payload;
}
これは私のJSONがどのように見えるかです:
しかし、今Azureでは、例外がスローされます。
1 2017-11-01 Create Story : The remote server returned an error: (400) Bad Request. The supplied notification payload is invalid.TrackingId:666febf6-85fe-4ebd-867d-00ce5a668809_G3,TimeStamp:11/1/2017 9:53:07 PM
は、私が何かを見逃していましたか? このpageによれば、私はそれを間違って作りました!
ペイロード形式が問題ではなく、どのように構築しますそれは物理的に。 – Wasyster
私は答えを更新しました。詳細情報は、**更新**セクションを参照してください。 –
Thnx、私はこの部分をどのように得たのですか。通知内でアプリデータを送信する方法、音を有効にする方法を知りたい – Wasyster