PHP AWS SNS SDK – 徽章
作者:互联网
简单的问题,如何使用AWS SNS在推送通知中发送徽章编号?
我发现它必须以某种方式以json格式进行格式化,但不知道该怎么做.
AWS文档没有该信息,或者至少我没有找到它.
谢谢!
到目前为止,我的代码有效:
$sns = SnsClient::factory(array(
'key' => $this->app()->getConfig()->get('aws.sns.key'),
'secret' => $this->app()->getConfig()->get('aws.sns.secret'),
'region' => $this->app()->getConfig()->get('aws.sns.region'),
));
$payload = [
'Message' => $this->_message,
'TargetArn' => $this->_device->getDeviceArn()
];
$sns->publish($payload);
解决方法:
首先,看看这个AWS开发者论坛
article
总结一下这篇文章,在你的例子中,_message需要看起来像这样:
{"APNS":"{\"aps\":{\"alert\":\"<message>\"}}"}
你需要添加
'MessageStructure' => 'json',
到$payload
这是我用于构建消息JSON的代码:
$contents = array();
$contents['badge'] = "1";
$contents['alert'] = addslashes($push_message);
$contents['sound'] = "default";
$push = array("aps" => $contents);
$push_json = json_encode($push);
$json = json_encode(array('APNS' => $push_json));
$sns->publish(array('MessageStructure' => 'json',
'Message' => $json,
'TargetArn' => $endpointArn));
希望这可以帮助!
标签:php,amazon-web-services,amazon-sns 来源: https://codeday.me/bug/20190708/1402855.html