asp.net-mvc – 使用AWS .NET SDK进行SNS订阅确认示例

我试图弄清楚如何使用AWS .NET SDK来确认订阅SNS主题. 订阅是通过HTTP进行的 端点将位于.net mvc网站中. 我在任何地方找不到任何.net示例? 一个工作的例子太棒了. 我正在尝试这样的事情 Dim snsclient As New Amazon.SimpleNotificationService.AmazonSimple

我试图弄清楚如何使用AWS .NET SDK来确认订阅SNS主题.

订阅是通过HTTP进行的

端点将位于.net mvc网站中.

我在任何地方找不到任何.net示例?

一个工作的例子太棒了.

我正在尝试这样的事情

Dim snsclient As New Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient(ConfigurationSettings.AppSettings("AWSAccessKey"),ConfigurationSettings.AppSettings("AWSSecretKey"))

    Dim TopicArn As String = "arn:aws:sns:us-east-1:991924819628:post-delivery"


    If Request.Headers("x-amz-sns-message-type") = "SubscriptionConfirmation" Then

        Request.InputStream.Seek(0,0)
        Dim reader As New System.IO.StreamReader(Request.InputStream)
        Dim inputString As String = reader.ReadToEnd()

        Dim jsSerializer As New System.Web.Script.Serialization.JavaScriptSerializer
        Dim message As Dictionary(Of String,String) = jsSerializer.Deserialize(Of Dictionary(Of String,String))(inputString)

        snsclient.ConfirmSubscription(New Amazon.SimpleNotificationService.Model.ConfirmSubscriptionRequest With {.AuthenticateOnUnsubscribe = False,.Token = message("Token"),.TopicArn = TopicArn})


   End If

解决方法

以下是使用MVC WebApi 2和最新AWS .NET SDK的工作示例.

var jsonData = Request.Content.ReadAsStringAsync().Result;
var snsMessage = Amazon.SimpleNotificationService.Util.Message.ParseMessage(jsonData);

//verify the signaure using AWS method
if(!snsMessage.IsMessageSignatureValid())
    throw new Exception("Invalid signature");

if(snsMessage.Type == Amazon.SimpleNotificationService.Util.Message.MESSAGE_TYPE_SUBSCRIPTION_CONFIRMATION)
{
    var subscribeUrl = snsMessage.SubscribeURL;
    var webClient = new WebClient();
    webClient.DownloadString(subscribeUrl);
    return "Successfully subscribed to: " + subscribeUrl;
}

作者: dawei

【声明】:永州站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部