PHP的AWS SNS SDK - 徽章 [英] PHP AWS SNS SDK - Badge

查看:693
本文介绍了PHP的AWS SNS SDK - 徽章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题,如何发送证件号码在推送通知,使用AWS SNS?

我发现,它必须JSON格式莫名其妙地格式化,但不知道该怎么做。

AWS文档没有这方面的信息,或者至少我没有发现它。

谢谢!

我的code,到目前为止,它的工作原理:

  $ SNS = SnsClient ::工厂(阵列(
        '键'=> $这个 - >的应用程序() - >的getconfig() - >获得(aws.sns.key),
        秘密=> $这个 - >的应用程序() - >的getconfig() - >获得(aws.sns.secret),
        '区域'=> $这个 - >的应用程序() - >的getconfig() - >获得(aws.sns.region),
    ));

    $负载= [
        '信息'=> $这个 - > _Message,
        TargetArn'=> $这个 - > _device-> getDeviceArn()
    ]。

    $ SNS->公布($有效载荷);
 

解决方案

首先,来看看这个AWS开发者论坛 文章

要总结这篇文章时,在你的榜样,_Message需要看起来像这样:

  {APNS:{\APS \:{\戒备\:\<消息> \}}
 

和你需要添加

 'MessageStructure'=> JSON,
 

$载荷

这是在code口用于构建信息JSON:

  $内容=阵列();
    $内容['徽章'] =1;
    $内容['警告'] =和addslashes($ push_message);
    $内容['声音'] =默认;
    $推=阵列(APS=> $内容);
    $ push_json = json_en code($推送);

    $ JSON = json_en code(阵列('APNS'=> $ push_json));

    $ SNS->公布(阵列('MessageStructure'=>JSON,
            '信息'=> $ JSON,
            TargetArn'=> $ endpointArn));
 

希望这有助于!

Simple question, how to send badge number in push notifications, using AWS SNS ?

I found out that it has to be formatted in the json format somehow, but not sure how to do it.

AWS docs don't have that info, or at least I didn't found it.

Thanks!

My code so far, which works:

    $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);

解决方案

First of all, take a look at this AWS Developer Forum article

To sum that article up, in your example, _message needs to look something like this:

{"APNS":"{\"aps\":{\"alert\":\"<message>\"}}"}

and you need to add

'MessageStructure' => 'json',

to $payload

This is the code I use for building the message 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));

Hope this helps!

这篇关于PHP的AWS SNS SDK - 徽章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆