amazon-web-services - 如何从 WCF 休息服务向 Kindle Fire 发送推送通知

标签 amazon-web-services push-notification wcf-rest kindle-fire

我想从 WCF 休息服务向 Kindle Fire 发送推送通知。

我使用了 PushSharp 库,但它无法正常工作。您能否建议不使用 PushSharp 库的其他方法?

我使用下面的代码在kindle上发送通知,它给出错误400,

   private void sendNotification(String registrationID)
    {
        String message = "{data\": {\"NTY\":\"-1\",\"NOTY\": \"2\"}}";
        String title="title";

        String accessToken = "";
        accessToken = UpdateAccessToken();
        HttpWebRequest httpWReq =
             (HttpWebRequest)WebRequest.Create("https://api.amazon.com/messaging/registrations/" + registrationID + "/messages");

        Encoding encoding = new UTF8Encoding();
        string postData = "{\"data\":{\"message\":\"" + message + "\",\"title\":\"" + title + "\"},\"consolidationKey\":\"Some Key\",\"expiresAfter\":86400}";
        byte[] data = encoding.GetBytes(postData);

        httpWReq.ProtocolVersion = HttpVersion.Version11;
        httpWReq.Method = "POST";
        httpWReq.ContentType = "application/json";//charset=UTF-8";
        httpWReq.Headers.Add("X-Amzn-Type-Version",
                                           "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="13707c7e3d727e72697c7d3d7776657a70763d7e76606072747a7d743d52575e5e76606072747653223d23" rel="noreferrer noopener nofollow">[email protected]</a>");
        httpWReq.Headers.Add("X-Amzn-Accept-Type",
                                        "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1774787a39767a766d7879397372617e7472397a72646476707e79703956535a44727973457264627b6357263927" rel="noreferrer noopener nofollow">[email protected]</a>");
        httpWReq.Headers.Add(HttpRequestHeader.Authorization,
            "Bearer " + accessToken);
        httpWReq.ContentLength = data.Length;


        Stream stream = httpWReq.GetRequestStream();
        stream.Write(data, 0, data.Length);
        stream.Close();

        HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
        string s = response.ToString();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        String jsonresponse = "";
        String temp = null;
        while ((temp = reader.ReadLine()) != null)
        {
            jsonresponse += temp;
        }

    }

最佳答案

PushSharp 依赖于 Android 版 Google Cloud Messaging,但 Kindle 不支持该功能。您需要实现 Amazon Device Messaging (ADM) 版本 ( https://developer.amazon.com/public/apis/engage/device-messaging ) 或利用 Amazon 的简单通知服务 (SNS) 来定位 Kindle 和其他平台(https://aws.amazon.com/sns/)

关于amazon-web-services - 如何从 WCF 休息服务向 Kindle Fire 发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21603560/

相关文章:

java - Maven部署打包并上传到AWS-Lambda

Android 从服务器更新 TextView(News feed)

RestSharp 用法

amazon-web-services - AWS Lambda 函数在查询 Athena 时失败

amazon-web-services - AWS ELB 终端问题背后的 Jupyter notebook

android - Android 4.4 的推送通知服务

ios - Google FCM 是否支持基于 HTTP 2 的 Apple APNs API?

javascript - Ajax调用restful WS总是出错(fiddler得到良好的响应)

java - 如何从服务器进行 Restful 调用?

c# - 在 AWS Lambda serverless.template 文件中设置 EndpointConfiguration