示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            pnlTest.Visible = true;
        }

        if (String.Compare(Request.RequestType, "POST", StringComparison.OrdinalIgnoreCase) == 0)
        {
            string szMessageType = (Request.Headers["x-amz-sns-message-type"] ?? string.Empty).ToUpperInvariant();
            switch (szMessageType)
            {
            case "NOTIFICATION":
                SNSNotification snsNotification = ReadJSONObject <SNSNotification>();
                if (String.IsNullOrEmpty(snsNotification.Signature) || snsNotification.VerifySignature())
                {
                    // simply creating the object will do all that is necessary.
                    if (new MFBImageInfo(snsNotification) == null)
                    {
                    }
                }
                Response.Clear();
                Response.Write("OK");
                Response.End();
                break;

            case "SUBSCRIPTIONCONFIRMATION":
            {
                SNSSubscriptionConfirmation snsSubscription = ReadJSONObject <SNSSubscriptionConfirmation>();

                // Visit the URL to confirm it.
                if (snsSubscription.VerifySignature())
                {
                    using (WebClient wc = new System.Net.WebClient())
                    {
                        byte[] rgdata = wc.DownloadData(snsSubscription.SubscribeLink);
                        _ = System.Text.UTF8Encoding.UTF8.GetString(rgdata);
                    }
                }
            }
                Response.Clear();
                Response.Write("OK");
                Response.End();
                break;

            case "UNSUBSCRIBECONFIRMATION":
                // Nothing to do for now.
                break;

            default:
                // Test messages/etc. can go here.
                break;
            }
        }
    }
示例#2
0
 protected void btnTestSubscribe_Click(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(txtTestJSONData.Text))
     {
         SNSSubscriptionConfirmation sc = new SNSSubscriptionConfirmation()
         {
             Type             = "SubscriptionConfirmation",
             MessageId        = Guid.NewGuid().ToString(),
             Token            = "thisisthetoken",
             Message          = Resources.Admin.AWSSubscriptionTestMessage,
             SubscribeURL     = "http://google.com",
             SignatureVersion = "1",
             Signature        = "EXAMPLEpH+DcEwjAPg8O9mY8dReBSwksfg2S7WKQcikcNKWLQjwu6A4VbeS0QHVCkhRS7fUQvi2egU3N858fiTDN6bkkOxYDVrY0Ad8L10Hs3zH81mtnPk5uvvolIC1CXGu43obcgFxeL3khZl8IKvO61GWB6jI9b5+gLPoBc1Q=",
             SigningCertURL   = "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem",
             Timestamp        = DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:ssZ", CultureInfo.InvariantCulture),
             TopicArn         = "arn:aws:sns:us-west-2:123456789012:MyTopic"
         };
     }
     else
     {
         SendTestPost(txtTestJSONData.Text, "SubscriptionConfirmation");
     }
 }