是的:这个问题有很多重复,但没有一个答案有帮助.
我正在按照Ali Hafizji关于使用APNS服务进行推送通知的精彩教程.
在开发模式下测试APNS :
aps_development.ceraps_development_key.p12)然后我使用以下命令(使用终端)将两者结合起来:
openssl x509 -in aps_development.cer -inform der -out aps_development.pem
openssl pkcs12 -nocerts -out aps_development_key.pem -in aps_development.p12
cat aps_development.pem aps_development_key.pem > final_aps_development.pem
Run Code Online (Sandbox Code Playgroud)
并且(在服务器上使用ApnsPHP)我可以使用此配置成功发送推送通知:
...
$push = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,'final_aps_development.pem');
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
$push->setProviderCertificatePassphrase('mypassword');
...
Run Code Online (Sandbox Code Playgroud)
旁注:我从https://github.com/jonathanrcarter/push2press获取了entrust_root_certification_authority.pem ,找到正确的地址可能是https://www.entrust.net/downloads/binary/entrust_2048_ca.cer (无论如何它们都是一样的).
在这种情况下,应用程序在调试模式下运行(在设备上,从XCode运行),一切正常.
在生产模式下测试APNS :
为了在生产模式下测试APNS,我将应用程序归档为AdHoc分发,并使用iPhone配置实用程序将其安装在设备上.
我遵循相同的程序aps_production.cer来制作final_aps_production.pem.
Bang,调用发送推送通知的php脚本返回HTML状态代码500.
$push对于生产模式,当然修改了这一代:
...
$push = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION,'final_aps_production.pem');
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
$push->setProviderCertificatePassphrase('mypassword');
...
Run Code Online (Sandbox Code Playgroud)
快速查看/var/log/apache2/error.log表明问题:
PHP …Run Code Online (Sandbox Code Playgroud) 开发环境:
iOS 9.3.2(iPh6ne 6+)......但它适用于iOS 8.x.
Phonegap 6.2.7
Phonegap-plugin-push v1.7.2
PHP7(服务器端) - contentpush - ref
我的情况:
令牌已自动传送到我的服务器
消息已成功发送至ssl://gateway.push.apple.com 2195
设备中没有收到任何警报("")
push.on('notification',function(data){console.log(data.message); alert(""); alert(data.title +"Message:"+ data.message);});
在过去的3天里,我一直在尝试使用我的PHP代码和apns.
到目前为止,我能够发送通知(我只有一个设备,所以我不知道这是否适用于多个设备).
当我尝试测试为2个设备发送一个通知时,第一个是设备令牌无效(由我发明),第二个是我的设备令牌,我无法将通知发送到我的设备...从我读到的,当通知是不可读或错误的,apns关闭连接并发送6字节长的错误,其中第二个字节(status_code)是错误类型.如果没有错误发生,我仍然无法理解apns是否发送status_code 0(没有遇到错误)或者它是否根本不发送任何错误.
到目前为止,我无法找到这个status_code,尽管在互联网上发现了几个代码.
码
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '.\certif\ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Create the payload body
//file_put_contents('logs/debug_not.log', 'body'. "\n", FILE_APPEND);
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
// Encode the payload as JSON
//file_put_contents('logs/debug_not.log', 'json body'. "\n", FILE_APPEND);
$payload = json_encode($body);
$open = true;
foreach ($devices as $device) {
//file_put_contents('logs/debug_not.log', 'inicio ciclo'. "\n", FILE_APPEND);
if($open == true){
//file_put_contents('logs/debug_not.log', 'abrir ligacao'. "\n", FILE_APPEND);
// Open a connection to the APNS server
$fp …Run Code Online (Sandbox Code Playgroud) 我已成功使用APNS-PHP发送PN - 这太棒了!
但是,我对如何将其添加到Code Igniter项目(在将从命令行调用的控制器内部)中有点困惑.
呼叫:
require_once APPPATH.'/third_party/ApnsPHP/Autoload.php';
Run Code Online (Sandbox Code Playgroud)
导致错误:
Fatal error: Uncaught exception 'Exception' with message 'Class file
'XXXXXXX/application/third_party/CI/DB/mysql/result.php' does not
exists' in XXXXXXX/application/third_party/ApnsPHP/Autoload.php:49
Run Code Online (Sandbox Code Playgroud)
我假设它是某种自动加载冲突?但我不太确定!
任何帮助都会很棒 - 我没有太多运气就拖着谷歌!
这是我试图在函数中使用的行:
require_once APPPATH.'/third_party/ApnsPHP/Autoload.php';
Run Code Online (Sandbox Code Playgroud)
这是我为加载Ion Auth的libs添加的__autoload函数:
function __autoload($class)
{
if (strpos($class, 'CI_') !== 0)
{
if (file_exists($file = APPPATH.'core/'.$class.EXT))
{
include $file;
}
else if (file_exists($file = APPPATH.'libraries/'.$class.EXT))
{
include $file;
}
else if (file_exists($file = APPPATH.'core/base_controllers/'.$class.EXT))
{
include $file;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我集成了Push Notification库来发送推送通知.当我在我的本地机器上测试它工作正常,但是当我将库示例代码上传到实时服务器时它会引发我的错误,我在下面粘贴了响应...我发现在整个响应中的真正错误是 - >'错误:无法发送消息ID 1:缺少有效负载(4)'.我需要帮助才能解决此问题.
Thu, 18 Apr 2013 12:58:29 +0200 ApnsPHP[17833]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: INFO: Sending messages queue, run #1: 1 message(s) left in queue.
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: STATUS: Sending message ID 1 [custom identifier: Message-Badge-33] (1/3): 45 bytes.
Thu, 18 Apr 2013 12:58:30 +0200 ApnsPHP[17833]: ERROR: Unable to send message ID 1: Missing payload (4).
Thu, …Run Code Online (Sandbox Code Playgroud) 我使用PHP发送推送消息到apns,我使用"增强通知格式"发送..但我不能得到返回"错误响应包中的代码"任何人都可以帮助我?这是我的代码
<?php
header("Content-Type: text/html; charset=UTF-8");
$deviceToken = "123";
$content = "testing";
if(isset($content))
{
$newContent=substr($content,0,30)."...";
$re_content=iconv("GB2312","UTF-8",$newContent);
$pass = 'Ladder';
$body = array("aps" => array("alert" => $re_content, "badge" => 1, "sound" => 'received5.caf'));
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'dev.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
//$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
stream_set_blocking ($fp, 0);
if (!$fp)
{
print "Failed to connect $err $errstrn";
return;
}
else
{
print "Connection OK\n<br/>";
}
$payload = …Run Code Online (Sandbox Code Playgroud)