現在Push通知を受け取ることができるアプリを開発しております。
ApnsPHPというライブラリを用いてpush通知させたいのですが、
以下のように出力されます。
$ php pushTest.php Tue, 19 Apr 2016 11:28:33 +0900 ApnsPHP[11004]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195... Tue, 19 Apr 2016 11:28:34 +0900 ApnsPHP[11004]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195': (0)
StackOverflowに以下のように変更するとあり変更してみましたが結果は同じでした。
php
1$streamContext = stream_context_create(array('ssl' => array( 2//以下1行をコメントアウトする 3//'verify_peer' => isset($this->_sRootCertificationAuthorityFile), 4'cafile' => $this->_sRootCertificationAuthorityFile, 5'local_cert' => $this->_sProviderCertificateFile 6)));
ちなみにrubyではpush通知ができした。以下がコードになります。
ruby
1require 'rubygems' 2require 'apns' 3 4APNS.host = 'gateway.sandbox.push.apple.com' 5# APNS.host = 'gateway.push.apple.com' # プロダクションの場合 6APNS.pem = '*********.pem' 7APNS.port = 2195 8 9device_token = '******************************'# 取得したdeviceTokenをコピー 10APNS.send_notification(device_token, :alert => 'メッセージ', :badge => 0, :sound => 'default')
Push Notification用のSSL証明書を作り直せば良いとのブログも拝見したのですが、rubyではうまくいってるのでそうではないと思いますが...
解決方法がわからず困っています。
よろしくお願い致します。
追加情報
pushTest.phpと同じディレクトリに入れています。
setRootCertificationAuthorityは以下の通りです。
php
1$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
仮にファイルパスが間違っていた場合,
$php pushTest.php Fatal error: Uncaught exception 'ApnsPHP_Exception' with message 'Unable to read Certificate Authority file '../entrust_root_certification_authority.pem'' in ...
となるので、ファイルパスは正しいかと思います。
2016/04/20 追記
「pushTest.php」の内容は以下になります。
「server_certificates_sandbox.pem」と「entrust_root_certification_authority.pem」はpushTest.phpと同じ階層にあります。
php
1<?php 2/** 3 * @file 4 * sample_push.php 5 * 6 * Push demo 7 * 8 * LICENSE 9 * 10 * This source file is subject to the new BSD license that is bundled 11 * with this package in the file LICENSE.txt. 12 * It is also available through the world-wide-web at this URL: 13 * http://code.google.com/p/apns-php/wiki/License 14 * If you did not receive a copy of the license and are unable to 15 * obtain it through the world-wide-web, please send an email 16 * to aldo.armiento@gmail.com so we can send you a copy immediately. 17 * 18 * @author (C) 2010 Aldo Armiento (aldo.armiento@gmail.com) 19 * @version $Id: sample_push.php 65 2010-12-13 18:38:39Z aldo.armiento $ 20 */ 21 22// Adjust to your timezone 23date_default_timezone_set('Asia/Tokyo'); 24 25// Report all PHP errors 26error_reporting(-1); 27 28// Using Autoload all classes are loaded on-demand 29require_once 'ApnsPHP/Autoload.php'; 30 31// Instanciate a new ApnsPHP_Push object 32$push = new ApnsPHP_Push( 33 ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, 34 'server_certificates_sandbox.pem' 35); 36 37// Set the Root Certificate Autority to verify the Apple remote peer 38$push->setRootCertificationAuthority('entrust_root_certification_authority.pem'); 39 40// Connect to the Apple Push Notification Service 41$push->connect(); 42 43// Instantiate a new Message with a single recipient 44$message = new ApnsPHP_Message('72cb1ae4707aef1df5e72d6c714ce245925317f85aca21fd7fc070acb193b1c2'); 45 46// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method 47// over a ApnsPHP_Message object retrieved with the getErrors() message. 48$message->setCustomIdentifier("Message-Badge-3"); 49 50// Set badge icon to "3" 51$message->setBadge(3); 52 53// Set a simple welcome text 54$message->setText('Hello APNs-enabled device!'); 55 56// Play the default sound 57$message->setSound(); 58 59// Set a custom property 60$message->setCustomProperty('acme2', array('bang', 'whiz')); 61 62// Set another custom property 63$message->setCustomProperty('acme3', array('bing', 'bong')); 64 65// Set the expiry value to 30 seconds 66$message->setExpiry(30); 67 68// Add the message to the message queue 69$push->add($message); 70 71// Send all messages in the message queue 72$push->send(); 73 74// Disconnect from the Apple Push Notification Service 75$push->disconnect(); 76 77// Examine the error message container 78$aErrorQueue = $push->getErrors(); 79if (!empty($aErrorQueue)) { 80 var_dump($aErrorQueue); 81}
回答1件
あなたの回答
tips
プレビュー