我在使用APNS和PHP时遇到问题,并收到以下消息:
stream_socket_client(): Failed to enable crypto
Run Code Online (Sandbox Code Playgroud)
这个问题有时只会发生,有时候实际上会发送推送.
由于我在10次迭代的循环上有测试脚本,我有时会得到这个:
stream_socket_client(): SSL: Connection reset by peer
Run Code Online (Sandbox Code Playgroud)
我正在使用沙盒服务器进行测试 tls://gateway.sandbox.push.apple.com:2195
这是我尝试过的:
sslv3://和tls://.644755似乎我在Google和SO上找到的所有解决方案都是人们完全没有问题.
我觉得这项服务的速度有限吗?因为我们等待了一段时间(大约15分钟)然后再次尝试,并且能够成功地推送大约100条消息,直到我再次开始收到该消息.
我正在使用https://code.google.com/p/apns-php/上提供的apns php服务器.
我已经设置了推送通知证书但我的代码仍然在连接时抛出错误.
这有什么问题?以下是我获取设备令牌的方法:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
#if !TARGET_IPHONE_SIMULATOR
// Prepare the Device Token for Registration (remove spaces and < >)
NSString *deviceToken = [[[[devToken description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
NSLog(@"%@", deviceToken);
#endif
}
Run Code Online (Sandbox Code Playgroud)
这是我运行服务器时的错误:
Sat, 11 May 2013 13:37:53 -0700 ApnsPHP[18198]: INFO: Trying
ssl://gateway.push.apple.com:2195...
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Connected to ssl://gateway.push.apple.com:2195.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Sending messages queue, run #1: 1 message(s) …Run Code Online (Sandbox Code Playgroud) php objective-c push-notification apple-push-notifications apns-php
我正在尝试使用连接到的简单PHP工具向我的手机发送推送通知ssl://gateway.push.apple.com:2195,但连接失败并出现以下错误:
Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in <Users/.../file.php> on line 30
Warning: stream_socket_client(): Failed to enable crypto in <Users/.../file.php> on line 30
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in <Users/.../file.php> on line 30
Failed to connect: 0
Run Code Online (Sandbox Code Playgroud)
这一切都始于我升级到macOS Sierra的GM种子.macOS Sierra有哪些新功能会影响SSL连接?我该如何解决这个问题?
编辑 - 使用增强的二进制格式
结果我没有使用增强的二进制格式,所以我改变了我的代码.
<?php
$message = $_POST['message'];
$passphrase = $_POST['pass'];
//Connect to db
if ($db_found) {
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'x.pem');
stream_context_set_option($streamContext, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $error, $errorString, 15, STREAM_CLIENT_CONNECT, $streamContext);
stream_set_blocking ($fp, 0);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS for Push Notification' . PHP_EOL;
// Keep push alive (waiting for delivery) for …Run Code Online (Sandbox Code Playgroud) Apple将APNs Auth Key更改为p8后,当前的库(如https://github.com/immobiliare/ApnsPHP) 仍然使用旧的pem和cert文件进行连接
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
'server_certificates_bundle_sandbox.pem'
);
// Set the Provider Certificate passphrase
// $push->setProviderCertificatePassphrase('test');
// 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()
Run Code Online (Sandbox Code Playgroud)
使用Node.js示例(https://eladnava.com/send-push-notifications-to-ios-devices-using-xcode-8-and-swift-3/),我可以像这样发送:
var apnProvider = new apn.Provider({
token: {
key: 'APNsAuthKey_Q34DLF6Z6J.p8', // Path to the key p8 file
keyId: 'Q34DLF6Z6J', // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/certificate/key)
teamId: 'RLAHF6FL89', // The Team ID …Run Code Online (Sandbox Code Playgroud) 我正在使用Apples iOS增强通知格式批量发送推送通知,并使用本文中描述的PHP解决方案:https://stackoverflow.com/a/10059000/300129
此时的经验是,当我发送推送通知时,某些设备正在接收消息,而某些设备则没有.结果不一致.有时设备X会收到通知,有时设备X不会收到通知.我正在记录所有内容,但我没有得到任何错误响应.
对正在发生的事情的任何想法都会非常有帮助.
嗨,我正在使用apns发送IOS推送通知,并在php中卷曲,并收到此错误消息。
我也定义了“ CURL_HTTP_VERSION_2_0”,但仍然出现此错误:
意外的HTTP / 1.x请求:POST / 3 / device /
这是我的代码:
$key_file = XXXXXX';
$secret = null;
$private_key = JWKFactory::createFromKeyFile($key_file, $secret, [
'kid' => '3W6B5LQQHX',
'alg' => 'ES256',
'use' => 'sig',
]);
$payload = [
'iss' => 'RUK725A7V4',
'iat' => time(),
];
$header = [
'alg' => 'ES256',
'kid' => $private_key->get('kid'),
];
$jws = JWSFactory::createJWSToCompactJSON(
$payload, $private_key, $header
);
if (!defined('CURL_HTTP_VERSION_2_0')) {
define('CURL_HTTP_VERSION_2_0', 3);
}
$http2_server = 'https://api.development.push.apple.com';
$app_bundle_id = 'com.MD.example';
$token = $device->device_id;
$url = "{$http2_server}/3/device/{$token}";
// headers …Run Code Online (Sandbox Code Playgroud) 我是iPhone应用程序中Apple推送通知服务的新手.我已经学过这些教程和苹果文档,
我们正在将通知从我们的服务器(PHP)推送到Apple推送通知服务器,APNS会将通知推送到设备.在这种情况下,我们如何知道通知是否成功地从我们的服务器传递了用户?如果我们向所有订阅用户(超过100个用户)发送通知,我们是否可以为这100个用户提供递送报告?
这是一个深夜.我只是花了10个小时在google/stackoverflow搜索和实验.似乎我讨厌Apple推送通知.我非常沮丧,并会感激任何帮助.
谢谢.
用于发送两周前成功运行的Apple推送通知的PHP代码现在停止工作并抛出以下错误:
PHP Warning: stream_socket_client(): Failed to enable crypto in /home/...
PHP Warning: stream_socket_client(): unable to connect to ssl://gateway.push.apple.com:2195 (Unknown error) in /home/...
Run Code Online (Sandbox Code Playgroud)
它停止在两个单独的服务器上工作,这些服务器使用单独的脚本进行APN发送.
服务器:带有PHP 5.4.32的CentOS 6.5和带有PHP 5.5.9的Ubuntu 14.04.3
APN:在生产模式下
证书:使用700多个推送通知进行测试.
其中一台服务器使用https://github.com/immobiliare/ApnsPHP,其他 - https://github.com/antongorodezkiy/wp-apn,在localhost上我测试了简单文件而不使用任何第三方代码.
对于以下所有情况,我使用相同的活动设备令牌和相同的生产PEM证书.
但是,即使这个简单的代码也无法在服务器和localhost上运行,并返回与上面相同的错误:
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '/absolute/path/to/apn_prod.pem');
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
Run Code Online (Sandbox Code Playgroud)
我还尝试使用stream_context_set_option()选项,包括entrust_2048_ca.cer等,甚至本文中的一些选项.虽然提供的代码在2015年8月之前没有任何修改.
连接使用openssl( …
我使用apns与http2协议发送推送通知,我使用的代码类似于这篇文章:https://stackoverflow.com/a/34831873/1546652
当我的应用程序正确安装时,apns http2 api在发送消息时工作正常,我的回复是这样的风格:{"response":"","httpcode":200}
问题是,当我卸载应用程序并向无效registrationId发送推送时,我没有收到状态410,也没有响应"原因:未注册",仍然收到状态为200的真实响应.
在apns http2中取消应用程序时,如何获得410状态和对应响应?