我正在开发基于 react-native 构建的 iOs 和 Android 应用程序,并使用aws pinpoint进行推送通知。我已经设法使用aws-amplify库获取通知以进行本机反应,并且当我使用 aws-pinpoint 测试工具测试通知时,它可以正常工作。但是我在使用 php 发送通知时遇到问题。
我试过使用这个文档(https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-pinpoint-2016-12-01.html#sendmessages),在 Ios 中它给出了以下错误 :
{
"errorMessage": "Invalid notification",
"channelType": "APNS",
"pushProviderStatusCode": "0",
"pushProviderError": "Notification is malformed"
}
这是我正在尝试的 PHP 代码
$settings=array(
'version' => '2016-12-01', // have tries 'latest' too
'region' => 'us-east-1',
'credentials' => [
'key' => 'XXXXXXXXX',
'secret' => 'XXXXXX',
]
);
$pin = new Aws\Pinpoint\PinpointClient($settings);
$msgios=array(
'ApplicationId' => 'XXXXXXXX',
'MessageRequest' => [
'Addresses' => [
'06fdf172694c5d6461b3d8a20308720674XXXXXXXXX' => [
'BodyOverride' => 'aaa',
'ChannelType' => 'APNS',
'RawContent' => 'bbb',
'Context' => ['ccc' => '222'],
'TitleOverride' => 'ddd',
],
],
'Context' => ['hello'=>'yes', 'value'=>'key'],
'MessageConfiguration' => [
'APNSMessage' => [
'Action' => 'OPEN_APP',
'Badge' => 2,
'Body' => 'Hello There',
'Category' => 'iOS',
'CollapseId' => 'Yes',
'Data' => ['age'=>13,'Name'=>"Saman"],
'MediaUrl' => null,
'PreferredAuthenticationMethod' => '',
'Priority' => '10',
'RawContent' => 'Hello',
'SilentPush' => true,
'Sound' => 'default',
'Substitutions' => [
'ages' => ['10', '13'],
],
'ThreadId' => '10',
'TimeToLive' => 10,
'Title' => 'There',
'Url' => null,
],
'DefaultMessage' => [
'Body' => 'Hello there',
'Substitutions' => [
'ages' => ['10', '13'],
],
],
'DefaultPushNotificationMessage' => [
'Action' => 'OPEN_APP',
'Body' => 'Hello',
'Data' => ['age'=>13,'Name'=>"Saman"],
'SilentPush' => true,
'Substitutions' => [
'ages' => ['10', '13'],
],
'Title' => 'Hello',
'Url' => null,
],
],
'TraceId' => '1024585',
],
);
$result = $pin->sendMessages($msgios);
我从 iOs 得到了上述错误,当我使用“GCM”并将其推送到 android 时,通知即将到达设备(我可以在控制台中看到它),但格式不正确。
iOS 和 Andoird 通知可以在 AWS pinpoint 仪表板中完美运行:
我认为我没有使用正确的语法或 API 版本。感谢你的帮助。