gpt4 book ai didi

PHP AWS SNS SDK - 徽章

转载 作者:可可西里 更新时间:2023-10-31 23:30:45 25 4
gpt4 key购买 nike

简单的问题,如何使用 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 AWS SNS SDK - 徽章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27029384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com