Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法根据AWS SNS服务接收任何发布的数据或订阅URL_Php_Amazon Web Services_Amazon Ses - Fatal编程技术网

Php 无法根据AWS SNS服务接收任何发布的数据或订阅URL

Php 无法根据AWS SNS服务接收任何发布的数据或订阅URL,php,amazon-web-services,amazon-ses,Php,Amazon Web Services,Amazon Ses,我正试图利用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 Gu

我正试图利用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);
}
*/

感谢上面的@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"

}

替换
文件内容(“notification.txt”,“$”请求,文件内容)带有
文件内容(“notification.txt”,文件内容(“notification.txt”)php://input'),文件_-APPEND)