//身体就像这样
{
"to":
"/topics/NEWS"
,
"data":{
"extra_information": "This is some extra information"
},
Run Code Online (Sandbox Code Playgroud)
//我需要提供的通知
"notification":{
"title": "ChitChat Group",
"text": "You may have new messages",
"click_action":"ChatActivity"
}
}
Run Code Online (Sandbox Code Playgroud) 我执行此代码以使用FCM库将通知推送到移动设备
public string PushFCMNotification(string deviceId, string message)
{
string SERVER_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxx";
var SENDER_ID = "xxxxxxxxx";
var value = message;
WebRequest tRequest;
tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/json";
tRequest.Headers.Add(string.Format("Authorization: key={0}", SERVER_API_KEY));
tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
var data = new
{
to = deviceId,
notification = new
{
body = "This is the message",
title = "This is the title",
icon = "myicon"
}
};
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(data);
Byte[] byteArray = Encoding.UTF8.GetBytes(json);
tRequest.ContentLength …Run Code Online (Sandbox Code Playgroud) 我可以从Firebase控制台向单个设备,主题和用户细分发送通知.
我想将推送通知发送到用户段.我搜索了很多,但我只是通过脚本向单个用户或主题发送通知而不是用户段.
我尝试了下面的代码
var client = new RestClient("https://fcm.googleapis.com/fcm/send");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "key=mykey");
request.AddParameter("application/json", "\n\n{\"to\" : \"user-segment-name\",\n\"notification\" : {\n \"body\" : \"test message\",\n \"title\" : \"Portugal vs. Denmark\"\n },\n \"priority\":\"high\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Response.Write(response.Content);
Run Code Online (Sandbox Code Playgroud)
我收到的答复如下
{"multicast_id":5837227475989925972,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Run Code Online (Sandbox Code Playgroud) 在Firebase控制台中,我根据各种用户属性设置了受众群体,现在可以通过控制台向不同的用户群体发送通知.是否有办法通过http请求fcm服务器执行相同的操作?"to"字段应该有一个技巧,但我无法理解.