【发布时间】:2019-02-02 00:21:28
【问题描述】:
几年前我在 Codeigniter(php) 的项目中实现了推送通知,直到 10 天前一切正常。我的.pem 文件在我的本地服务器以及在线通知工具上运行良好。
错误:“stream_socket_client():无法连接到 ssl://gateway.push.apple.com:2195(连接 拒绝)”。
我正在使用以下功能:
public function applePushSend($deviceToken, $msg){
$mode ='prod';
$ctx = stream_context_create();
if($mode=='dev'){
$gateway = 'ssl://gateway.sandbox.push.apple.com:2195';
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert_dev.pem');
}else{
$gateway = 'ssl://gateway.push.apple.com:2195';
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert_prod.pem');
}
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp){
}else{
$alert = array();
$alert['title'] = "My Message";
$alert['body'] = $msg;
$body['aps']['alert'] = $alert;
$body['aps']['badge'] = 1;
$body['aps']['sound'] = 'default';
$body['notificationtypeid'] = 4;
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$pushresult = fwrite($fp, $msg, strlen($msg));
}
fclose($fp);
return($pushresult);
}
【问题讨论】:
-
您的证书是否可能已过期?这有关于如何使用 .pem 文件检查它的说明:stackoverflow.com/questions/21297853/…
-
只检查pem文件路径,且端口开启。
标签: php codeigniter push-notification