升级到PHP 5.6后,尝试连接到服务器时出错fsockopen()...
服务器(主机)上的证书是自签名的
PHP警告:fsockopen():SSL操作失败,代码为1. OpenSSL错误消息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败
if($fp = fsockopen($host, $port, $errno, $errstr, 20)){
$this->request = 'POST '.substr($this->url, strlen($this->host)).' HTTP/1.1'.$crlf
.'Host: '.$this->host.$crlf
.'Content-Length: '.$content_length.$crlf
.'Connection: Close'.$crlf.$crlf
.$body;
fwrite($fp, $this->request);
while($line = fgets($fp)){
if($line !== false){
$this->response .= $line;
}
}
fclose($fp);
}
Run Code Online (Sandbox Code Playgroud)
# cd /etc/ssl/certs/
# wget http://curl.haxx.se/ca/cacert.pem
Run Code Online (Sandbox Code Playgroud)
php.ini中
openssl.cafile = "/etc/ssl/certs/cacert.pem"
Run Code Online (Sandbox Code Playgroud)
但脚本仍无法正常工作
这有效
echo file_get_contents("/etc/ssl/certs/cacert.pem");
Run Code Online (Sandbox Code Playgroud)
$contextOptions = array(
'ssl' => array(
'verify_peer' => true, // You could skip all of the trouble by changing this …Run Code Online (Sandbox Code Playgroud) 我已经为我的应用程序实现了示例推送通知服务.
现在我在沙盒环境中测试.
当我手动调用PHP脚本通过APN推送通知时,我收到通知.
当我使用crontab编写调度程序来自动传递通知时,我没有收到通知.我收到的邮件错误是:
PHP Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in /Users/aspire/Desktop/SimplePush/simplepush.php on line 21
PHP Warning: stream_socket_client(): Failed to enable crypto in /Users/aspire/Desktop/SimplePush/simplepush.php on line 21
PHP Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/aspire/Desktop/SimplePush/simplepush.php on line 21
Failed to connect: 0
Run Code Online (Sandbox Code Playgroud)
有人可以解释问题是什么吗?
我正在尝试使用连接到的简单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连接?我该如何解决这个问题?
有多个示例,您应该如何设置项目以添加使用"媒体附件"技术来显示图像的丰富通知.我已经阅读了大部分内容,但我错过了一些内容,因为我的项目没有显示任何带有此负载的丰富通知(使用APNS-Tool和Boodle进行测试):
{
"aps":{
"alert":{
"title": "Rich test",
"body": "Dancing Banana"
},
"mutable-content": 1
}
}
Run Code Online (Sandbox Code Playgroud)
通知可见,但在3D Touch上,没有显示其他信息(如图像或修改后的标题).通知扩展断点和NSLog消息也不起作用.
这是我的演示项目:https://github.com/gklka/RichTest
我做了什么:
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:UNAuthorizationOptionAlert completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
NSLog(@"Granted");
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
NSLog(@"Error registering: %@", error);
}
}];
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"Token: %@", deviceToken);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Error: %@", error);
}
添加banana.gif …
objective-c push-notification apple-push-notifications ios10
在尝试执行我的php脚本以向我的iphone发送推送通知后,我收到此错误.
我尝试了一切,没有任何作用.我相信这意味着我ck.pem错了,但我不确定它是key.pem还是cert.pem是错误的.
请帮忙
脚本
// This this a fake device id:
$deviceToken = '9870h8v088bj29u080af894jj67klfgcv9mmm79k8e4l23456h908743n093e359';
// fake password:
$passphrase = '123456';
// Put your alert message here:
$message = 'New Message';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload …Run Code Online (Sandbox Code Playgroud) php ×3
apache ×1
apns-php ×1
crontab ×1
ios ×1
ios10 ×1
iphone ×1
macos-sierra ×1
objective-c ×1
openssl ×1