現在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に以下のように変更するとあり変更してみましたが結果は同じでした。
$streamContext = stream_context_create(array('ssl' => array(
//以下1行をコメントアウトする
//'verify_peer' => isset($this->_sRootCertificationAuthorityFile),
'cafile' => $this->_sRootCertificationAuthorityFile,
'local_cert' => $this->_sProviderCertificateFile
)));
ちなみにrubyではpush通知ができした。以下がコードになります。
require 'rubygems'
require 'apns'
APNS.host = 'gateway.sandbox.push.apple.com'
# APNS.host = 'gateway.push.apple.com' # プロダクションの場合
APNS.pem = '*********.pem'
APNS.port = 2195
device_token = '******************************'# 取得したdeviceTokenをコピー
APNS.send_notification(device_token, :alert => 'メッセージ', :badge => 0, :sound => 'default')
Push Notification用のSSL証明書を作り直せば良いとのブログも拝見したのですが、rubyではうまくいってるのでそうではないと思いますが...
解決方法がわからず困っています。
よろしくお願い致します。
追加情報
pushTest.phpと同じディレクトリに入れています。
setRootCertificationAuthorityは以下の通りです。
$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
/**
* @file
* sample_push.php
*
* Push demo
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://code.google.com/p/apns-php/wiki/License
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to aldo.armiento@gmail.com so we can send you a copy immediately.
*
* @author (C) 2010 Aldo Armiento (aldo.armiento@gmail.com)
* @version $Id: sample_push.php 65 2010-12-13 18:38:39Z aldo.armiento $
*/
// Adjust to your timezone
date_default_timezone_set('Asia/Tokyo');
// Report all PHP errors
error_reporting(-1);
// Using Autoload all classes are loaded on-demand
require_once 'ApnsPHP/Autoload.php';
// Instanciate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
'server_certificates_sandbox.pem'
);
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
// Connect to the Apple Push Notification Service
$push->connect();
// Instantiate a new Message with a single recipient
$message = new ApnsPHP_Message('72cb1ae4707aef1df5e72d6c714ce245925317f85aca21fd7fc070acb193b1c2');
// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier("Message-Badge-3");
// Set badge icon to "3"
$message->setBadge(3);
// Set a simple welcome text
$message->setText('Hello APNs-enabled device!');
// Play the default sound
$message->setSound();
// Set a custom property
$message->setCustomProperty('acme2', array('bang', 'whiz'));
// Set another custom property
$message->setCustomProperty('acme3', array('bing', 'bong'));
// Set the expiry value to 30 seconds
$message->setExpiry(30);
// Add the message to the message queue
$push->add($message);
// Send all messages in the message queue
$push->send();
// Disconnect from the Apple Push Notification Service
$push->disconnect();
// Examine the error message container
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
var_dump($aErrorQueue);
}
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
checkベストアンサー
0
「pushTest.php」というファイルをコマンド実行させることでテストしているようですが、
http://d.hatena.ne.jp/MonteCut/20120827/1346079444
でも
http://www.lancork.net/2013/08/how-to-ios-push-second/
でも、
「sample_push.php」を編集して、それをブラウザでアクセスしてテストするよう説明されています。
「pushTest.php」というファイルが「sample_push.php」を上記サイトの説明通り編集したものであれば、それをブラウザでアクセスしてテストしてみてください。
それで解決しないなら、「pushTest.php」の内容を開示しないと誰もわからないと思います。
(4/20 11:10追記)
あと気になるのは、どのルート証明書を使っているかです。
http://d.hatena.ne.jp/MonteCut/20120827/1346079444
の方は「Entrust Root Certification Authority」を使うように書かれていますが、こちらは少し情報が古いと思います。この記事のコメントに「entrustのサイトからentrust_2048_ca.cerをダウンロードすれば、パッチ無しで動作する」というコメントが入っており、
http://www.lancork.net/2013/08/how-to-ios-push-second/
の方は「Entrust.net Certification Authority (2048)」を使うように書かれています。
こちらの証明書を使用して、'verify_peer'の設定処理はコメントアウトしないのがベストプラクティスではないかと思います。
また、Entrustのルート証明書ダウンロードサイトはリニューアルされており、各記事からの直リンクはリンク切れになっていますが、現在は
https://www.entrust.com/get-support/ssl-certificate-support/root-certificate-downloads/
からダウンロードできるようになっており、そこからダウンロードできる「Entrust.net Certificate Authority (2048)」の有効期限は2029/7/24となっています。
私のMacには有効期限の異なる「Entrust.net Certificate Authority (2048)」が2つダウンロードされているので、おそらくこのルート証明書も最近更新されたのではないかと思います。
もし有効期限の古い「Entrust.net Certificate Authority (2048)」をダウンロードしているのであれば、最新のものに更新してみることをお勧めします。
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.38%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
質問への追記・修正、ベストアンサー選択の依頼
CHERRY
2016/04/19 12:28
PHP のコードで、記載がない部分 setRootCertificationAuthority している部分などは、正しいファイルパスになっているのでしょうか?
tek_tekeo
2016/04/19 12:34
pushTest.phpと同じディレクトリに入れています。
setRootCertificationAuthorityは以下の通りです。
$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 ...
となるので、ファイルパスは正しいと思います。