无法通过AWS SNS服务接收任何已发布数据或订阅URL

问题描述 投票:0回答:1

我正在尝试使用SNS服务使用http协议订阅主题

以下是我在服务器上放置的一段PHP代码:-

<?php

require 'vendor/autoload.php';
require 'Aws/Sns/Message.php';
require 'Aws/Sns/MessageValidator.php';
require 'GuzzleHttp/Client.php';

use Aws\Sns\Message;
use Aws\Sns\MessageValidator;
use GuzzleHttp\Client;


// Make sure the request is POST
  if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
      file_put_contents("notification.txt", "Error 405\n", FILE_APPEND);
      http_response_code(405);
      die;
  }

try {
    $message = Message::fromRawPostData();
    file_put_contents("notification.txt", "\r\n-------\r\n", FILE_APPEND);
    file_put_contents("notification.txt", $_REQUEST , FILE_APPEND);
    $validator = new MessageValidator();
    $validator->validate($message);
} catch (Exception $e) {
    // Pretend we're not here if the message is invalid.
    file_put_contents("notification.txt", 'SNS Message Validation Error: ' . $e->getMessage() . "\n".$e->getTraceAsString()."\n", FILE_APPEND);
    echo($e);
    http_response_code(404);
    die();
}

/*
if ($message->get('Type') === 'SubscriptionConfirmation') {
    // Send a request to the SubscribeURL to complete subscription
    (new Client)->get($message->get('SubscribeURL'))->send();
    file_put_contents("notification.txt", "Subscription\n", FILE_APPEND);
} elseif ($message->get('Type') === 'Notification') {
    ob_start();
    var_dump($message);
    $result = ob_get_clean();
    file_put_contents("notification.txt", $result, FILE_APPEND);
}
*/

[当我尝试通过从AWS门户调用“确认订阅”时,我收到了呼叫,但是没有包含订阅URL的标头或正文。谁能帮助我遵循正确的方向?

php amazon-web-services amazon-ses
1个回答
0
投票

感谢@Damir Kasipovic上面的评论。从

更改代码
file_put_contents("notification.txt", $_REQUEST , FILE_APPEND); with 

对此

file_put_contents("notification.txt", file_get_contents('php://input') , FILE_APPEND)

帮助我从通话中提取数据

{
"Type": "SubscriptionConfirmation",
"MessageId": "cc0fb4d8-***********-542a9f3dbb33",
"Token": "2336412f37fb687f5d51e6************4795716f01db42d3b1",
"TopicArn": "arn:aws:sns:**********Downloaded",
"Message": "You have chosen to subscribe to the topic arn:aws:sns:*****nTo confirm the subscription, visit the SubscribeURL included in this message.",
"SubscribeURL": "https://sns.us-east-1.amazonaws.com/*************1",
"Timestamp": "2019-11-25T12:55:40.335Z",
"SignatureVersion": "1",
"Signature": "L2uX+OF1f39np2******************h0lmw==",
"SigningCertURL": "https://sns.us-east-1.amazonaws.com/*******************.pem"

}

© www.soinside.com 2019 - 2024. All rights reserved.