我正在为Amazon SNS使用最新的PHP SDK(V3)。当我尝试为平台创建端点(将用户设备注册到平台)时,我遇到了问题。错误说我有一个“InvalidArgumentException”,但我已经对文档进行了双重检查,并且我正在传递正确的参数。请在下面找到我的代码。
try {
$credentials = new Credentials($SNS_ACCESS_KEY, $SNS_SECRET_KEY);
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'us-west-2',
'credentials' => $credentials
]);
$SNSEndPointData = $s3Client->createPlatformEndpoint([
'PlatformApplicationArn' => $SNS_APP_ARN,
'Token' => $device_token
]);
}
catch(exception $e) {
print $e->__toString();
}
如果有人可以帮助或指出我正确的方向,我们将非常感激。
答案 0 :(得分:3)
以下是完整答案,以防万一有兴趣,
require 'vendor/autoload.php';
use Aws\Credentials\Credentials;
use Aws\Sns\SnsClient;
try {
$credentials = new Credentials($SNS_ACCESS_KEY, $SNS_SECRET_KEY);
$client = new SnsClient([
'version' => 'latest',
'region' => 'us-west-2',
'credentials' => $credentials
]);
$SNSEndPointData = $client->createPlatformEndpoint([
'PlatformApplicationArn' => $SNS_APP_ARN,
'Token' => 'phone token'
]);
print $SNSEndPointData;
}
catch(exception $e) {
$message = $e->getMessage();
print $message;
}