{"id":1457,"date":"2017-12-29T23:07:30","date_gmt":"2017-12-29T14:07:30","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=1457"},"modified":"2018-02-06T13:44:35","modified_gmt":"2018-02-06T04:44:35","slug":"awsphp-aws-sdk-for-php-aws-sns%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6apns%e3%82%92ios%e3%83%87%e3%83%90%e3%82%a4%e3%82%b9%e3%81%ab%e9%80%81%e4%bf%a1%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/awsphp-aws-sdk-for-php-aws-sns%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6apns%e3%82%92ios%e3%83%87%e3%83%90%e3%82%a4%e3%82%b9%e3%81%ab%e9%80%81%e4%bf%a1%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95\/","title":{"rendered":"[aws\/php] AWS SDK for PHP + AWS SNS\u3092\u4f7f\u7528\u3057\u3066APNs\u3092iOS\u30c7\u30d0\u30a4\u30b9\u306b\u9001\u4fe1\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>AWS SDK for PHP + AWS SNS\u3092\u4f7f\u7528\u3057\u3066APNs\u3092iOS\u30c7\u30d0\u30a4\u30b9\u306b\u9001\u4fe1\u3059\u308b\u65b9\u6cd5\u306f\u4ee5\u4e0b\u306e\u901a\u308a<\/p>\n<p>\u524d\u63d0\u6761\u4ef6\uff1a\u30a2\u30d7\u30ea\u5074\u3001AWS SNS\u306a\u3069\u306e\u901a\u77e5\u74b0\u5883\u306f\u65e2\u306b\u69cb\u7bc9\u6e08\u307f\u3068\u3059\u308b<\/p>\n<p>\u901a\u77e5\u74b0\u5883\u69cb\u7bc9\u306f\u4e0b\u8a18\u8a18\u4e8b\u53c2\u7167<\/p>\n<p><a href=\"http:\/\/blue-bear.jp\/kb\/awsswift4-aws-sns-cognito-ios10%e3%81%a7%e3%82%b5%e3%83%bc%e3%83%90%e3%83%ac%e3%82%b9%e3%81%a7apns%e3%82%92push%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95\/\">[AWS\/Swift4] AWS SNS + Cognito + iOS10\u3067\u30b5\u30fc\u30d0\u30ec\u30b9\u3067APNs\u3092push\u3059\u308b\u65b9\u6cd5<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>AWS SDK for PHP\u306e\u5c0e\u5165<\/h2>\n<p>bitnami\u306ephp\u74b0\u5883\u306bAWS SDK for PHP\u3092\u5c0e\u5165\u3059\u308b<\/p>\n<p>\u901a\u77e5\u3092\u5b9f\u884c\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u6a2a\u3001\u3082\u3057\u304f\u306f~\/apps\/wordpress\/htdocs\u306b\u79fb\u52d5\u3059\u308b<\/p>\n<h3>Composer\u3092\u4f7f\u7528\u3057\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre class=\"\">curl -sS https:\/\/getcomposer.org\/installer | php<\/pre>\n<pre class=\"\">php composer.phar require aws\/aws-sdk-php<\/pre>\n<p>\u6b63\u5e38\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u308b\u3068\u3001\u30b3\u30de\u30f3\u30c9\u3092\u767a\u884c\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u306bvender\u3068\u3044\u3046\u30d5\u30a9\u30eb\u30c0\u304c\u3067\u304d\u3066\u3044\u308b\u306f\u305a\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>php\u30b3\u30fc\u30c9<\/h2>\n<p>APNs\u901a\u77e5\u767a\u884c\u4f9d\u983c\u3092AWS SNS\u306b\u5bfe\u3057\u3066\u767a\u884c\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u88c5<\/p>\n<p>\u524d\u3082\u3063\u3066\u3001AWS SNS\u306b\u5bfe\u3057\u3066\u30a2\u30af\u30bb\u30b9\u6a29\u3092\u6301\u3063\u3066\u3044\u308bAWS IAM\u30e6\u30fc\u30b6\u3092\u4f5c\u6210\u3057\u3066\u304a\u304d\u3001\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u30fb\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30ad\u30fc\u3092\u767a\u884c\u3057\u3066\u304a\u304f\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;?php\r\n \r\nrequire 'vendor\/autoload.php';\r\nuse Aws\\Sns\\SnsClient;\r\n \r\n$sns = SnsClient::factory(array(\r\n 'version' =&gt; 'latest',\r\n 'key' =&gt; 'AWS SNS\u3078\u306e\u30a2\u30af\u30bb\u30b9\u6a29\u3092\u6301\u3063\u3066\u3044\u308bIAM\u306e\u30a2\u30af\u30bb\u30b9\u30ad\u30fc',\r\n 'secret' =&gt; 'AWS SNS\u3078\u306e\u30a2\u30af\u30bb\u30b9\u6a29\u3092\u6301\u3063\u3066\u3044\u308bIAM\u306e\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30ad\u30fc',\r\n 'region' =&gt; 'ap-northeast-1'\/\/\u30ea\u30fc\u30b8\u30e7\u30f3\u540d\r\n ));\r\n \r\n$iOS_AppArn = 'AWS SNS\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3ARN'; \r\n \r\n$iOS_model = $sns-&gt;listEndpointsByPlatformApplication(array('PlatformApplicationArn' =&gt; $iOS_AppArn));\r\n \r\n\/\/\u901a\u77e5\u30e1\u30c3\u30bb\u30fc\u30b8\r\n$alert=\"AWS SNS\u3088\u308a\u767a\u884c\";\r\n \r\n\/\/ \u305d\u308c\u305e\u308c\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3078\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u308b\r\nforeach ($iOS_model['Endpoints'] as $endpoint)\r\n {\r\n $endpointArn = $endpoint['EndpointArn'];\r\n try\r\n {\r\n $sns-&gt;publish(array(\r\n 'TargetArn' =&gt; $endpointArn,\r\n 'MessageStructure' =&gt; 'json',\r\n 'Message' =&gt; json_encode(array(\r\n 'APNS_SANDBOX' =&gt; json_encode(array(\r\n 'aps' =&gt; array(\r\n 'alert' =&gt; $alert,\r\n 'sound' =&gt; 'default',\r\n 'badge' =&gt; 1\r\n ),\r\n \/\/ \u30ab\u30b9\u30bf\u30e0\r\n 'custom_text' =&gt; \"\u30ab\u30b9\u30bf\u30e0\u30c6\u30ad\u30b9\u30c8\",\r\n ))\r\n ))\r\n ));\r\n echo \"ok\";\r\n }\r\n catch (Exception $e)\r\n {\r\n $e-&gt;getMessage();\r\n }\r\n }\r\n \r\n?&gt;<\/pre>\n<p>\u30d6\u30e9\u30a6\u30b6\u3067\u8a72\u5f53\u30d5\u30a1\u30a4\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u901a\u77e5\u304c\u98db\u3076\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u300c$sns-&gt;listEndpointsByPlatformApplication\u300d\u3067\u53d6\u5f97\u3067\u304d\u308bendpoint\u6570\u306f100\u304c\u6700\u5927\u3067\u3001100\u4ee5\u4e0aendpoint\u304c\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u8fd4\u308a\u5024\u306b\u300cNextToken\u300d\u304c\u4ed8\u3044\u3066\u3044\u308b\u3002<\/p>\n<p>\u305d\u306eNextToken\u3092\u6307\u5b9a\u3057\u3066\u518d\u5ea6\u53d6\u5f97\u3059\u308b\u3068\u6b21\u306e100\u4ef6\u306eendpoint\u304c\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true\">do {\r\n \/\/ We only get 100 subscribers, if there's a nextToken, get the next 100\r\n if( $nextToken ) {\r\n $result = $client-&gt;listEndpointsByPlatformApplication(array(\r\n 'PlatformApplicationArn' =&gt; $gcm_arn,\r\n 'NextToken' =&gt; $nextToken\r\n ));\r\n } else {\r\n \/\/ Run this the first time, since there's no nextToken yet\r\n $result = $client-&gt;listEndpointsByPlatformApplication(array(\r\n 'PlatformApplicationArn' =&gt; $gcm_arn\r\n ));\r\n }\r\n\r\n $nextToken = $result['NextToken'];\r\n\r\n} while( $nextToken );<\/pre>\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/gist.github.com\/scottopolis\/df0e42b02c39564dc21b\" target=\"_blank\">https:\/\/gist.github.com\/scottopolis\/df0e42b02c39564dc21b<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>AWS SDK for PHP + AW<\/p>\n","protected":false},"author":1,"featured_media":1458,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,6],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1457"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=1457"}],"version-history":[{"count":9,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1457\/revisions"}],"predecessor-version":[{"id":1597,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/1457\/revisions\/1597"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/1458"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=1457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=1457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=1457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}