我无法在PHP中获得AWS SNS Http连接的确认.我的应用程序是在Laravel 5.1上开发的
在AWS中,我创建了一个主题并添加了订阅.我已选择端点作为HTTP并提供URL http://myurl.com/sns.
public function getSnsMessage()
{
$message = Message::fromrawPostData();
$validator = new MessageValidator();
// Validate the message and log errors if invalid.
try {
$validator->validate($message);
}catch (InvalidSnsMessageException $e) {
// Pretend we're not here if the message is invalid.
http_response_code(404);
error_log('SNS Message Validation Error: ' . $e->getMessage());
die();
}
// Check the type of the message and handle the subscription.
if ($message['Type'] === 'SubscriptionConfirmation') {
// Confirm the subscription by sending a GET request to the SubscribeURL
file_get_contents(public_path() . '/awssns.txt','SUB URL MESSAGE = '.$message['SubscribeURL'].PHP_EOL, FILE_APPEND );
}
}
我的路径文件条目是:
Route::get('/sns', [
'as' => 'sns',
'uses' => 'SnsEndpointController@getSnsMessage',
]);
在浏览器中,当我调用URL – http://myurl.com/sns时,我收到以下错误.
RuntimeException in Message.PHP line 35:SNS message type header not provided.
1. in Message.PHP line 35
2. at Message::fromrawPostData() in SnsEndpointController.PHP line 26
3. at SnsEndpointController->getSnsMessage(object(Request))
4. at call_user_func_array(array(object(SnsEndpointController),
'getSnsMessage'), array(object(Request))) in Controller.PHP line 256
我的作曲家中有以下内容:
"aws/aws-sdk-PHP-laravel": "^3.1",
"aws/aws-PHP-sns-message-validator": "^1.2"
解决方法:
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrftoken as BaseVerifier;
class VerifyCsrftoken extends BaseVerifier
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'sns' // your call back URL
];
}
Route::post('sns', 'SnsEndpointController@getSnsMessage')->name('snsendpointcontroller.getsnsmessage');
编辑你的方法
public function getSnsMessage()
{
//All Of your code here
error_log($message['SubscribeURL']); // To check your are receiving URL
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。