31

これは、SOで回答が得られていないため、私が求めている新しいものです。

登録済みのデバイスにプッシュを送信するために Amazon SNS プッシュを使用しています。すべて正常に動作しています。アプリの最初の起動時にデバイスを登録でき、プッシュなどを送信できます。直面している問題は、特定のページを開きたいということです。プッシュでアプリを開いたとき。ペイロードで追加のパラメーターを送信したいのですが、それができません。

私はこのリンクを試しました:- http://docs.aws.amazon.com/sns/latest/api/API_Publish.html

私が知る限り、ペイロードを渡すことができるキーは1つだけです。つまり、「メッセージ」です。

私はこのようなペイロードを渡したい:-

{
    aps = {
            alert = "My Push text Msg";
          };
    "id" = "123",
    "s" = "section"
}

または他の形式でも問題ありません。アプリで使用できるように、ペイロードとともに2〜3個の値を渡したかっただけです。

プッシュを送信するために使用しているコードは次のとおりです:-

// Load the AWS SDK for PHP
if($_REQUEST)
{
    $title=$_REQUEST["push_text"];

    if($title!="")
    {
        require 'aws-sdk.phar';


        // Create a new Amazon SNS client
        $sns = Aws\Sns\SnsClient::factory(array(
            'key'    => '...',
            'secret' => '...',
            'region' => 'us-east-1'
        ));

        // Get and display the platform applications
        //print("List All Platform Applications:\n");
        $Model1 = $sns->listPlatformApplications();

        print("\n</br></br>");*/

        // Get the Arn of the first application
        $AppArn = $Model1['PlatformApplications'][0]['PlatformApplicationArn'];

        // Get the application's endpoints
        $Model2 = $sns->listEndpointsByPlatformApplication(array('PlatformApplicationArn' => $AppArn));

        // Display all of the endpoints for the first application
        //print("List All Endpoints for First App:\n");
        foreach ($Model2['Endpoints'] as $Endpoint)
        {
          $EndpointArn = $Endpoint['EndpointArn'];
          //print($EndpointArn . "\n");
        }
        //print("\n</br></br>");

        // Send a message to each endpoint
        //print("Send Message to all Endpoints:\n");
        foreach ($Model2['Endpoints'] as $Endpoint)
        {
          $EndpointArn = $Endpoint['EndpointArn'];

          try
          {
            $sns->publish(array('Message' => $title,
                    'TargetArn' => $EndpointArn));

            //print($EndpointArn . " - Succeeded!\n");
          }
          catch (Exception $e)
          {
            //print($EndpointArn . " - Failed: " . $e->getMessage() . "!\n");
          }
        }
    }
}
?>

任意のヘルプやアイデアをいただければ幸いです。前もって感謝します。

4

4 に答える 4

8

Lambda 関数 (Node.js) からの呼び出しは次のようになります。

exports.handler = function(event, context) {

  var params = {
    'TargetArn' : $EndpointArn,
    'MessageStructure' : 'json',
    'Message' : JSON.stringify({
      'default' : $title,
      'APNS' : JSON.stringify({
        'aps' : { 
          'alert' : $title,
          'badge' : '0',
          'sound' : 'default'
        },
        'id' : '123',
        's' : 'section',
      }),
      'APNS_SANDBOX' : JSON.stringify({
        'aps' : { 
          'alert' : $title,
          'badge' : '0',
          'sound' : 'default'
        },
        'id' : '123',
        's' : 'section',
      })
    })
  };

  var sns = new AWS.SNS({apiVersion: '2010-03-31', region: 'us-east-1' });
  sns.publish(params, function(err, data) {
    if (err) {
      // Error
      context.fail(err);
    }
    else {
      // Success
      context.succeed();
    }
  });
}

プロトコルを 1 つだけ指定することで簡素化できAPNSますAPNS_SANDBOX

于 2016-01-12T04:35:09.293 に答える