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

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 使用AWS .NET SDK进行SNS订阅确认示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图弄清楚如何使用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;
}

猜你在找的asp.Net相关文章