【发布时间】:2017-02-16 07:18:38
【问题描述】:
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', "pushNEWPEM12.pem");
stream_context_set_option($ctx, 'ssl', 'passphrase',$passphrase);
// 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);
if (empty($fp))
exit("Failed to connect: $err $errstr" . PHP_EOL);
// Create the payload body
$body['aps'] = array(
'alert' => array(
'title' => 'Together',
'body' => $offer_title,
"content-available" => 1
),
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
// Close the connection to the server
fclose($fp);
if (!$result)
return 'Message not delivered' . PHP_EOL;
else
return 'Message successfully delivered' . PHP_EOL;
}
//错误在终端是
Mac-mini:PushNotification vol$ php simplepush.php
警告:stream_socket_client():SSL 操作失败,代码为 1。OpenSSL 错误消息: 错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:第 21 行 /Users/vol/Desktop/PushNotification/simplepush.php 中的证书验证失败
警告:stream_socket_client():无法在第 21 行的 /Users/vol/Desktop/PushNotification/simplepush.php 中启用加密
警告:stream_socket_client():无法连接到第 21 行 /Users/vol/Desktop/PushNotification/simplepush.php 中的 ssl://gateway.sandbox.push.apple.com:2195(未知错误) 连接失败:0 Vol-Mac-mini:PushNotification vol$
`我正在处理推送通知。如果我使用开发证书/配置文件并在终端中进行测试,则会显示如下错误。
【问题讨论】:
-
显示你的 php 代码
-
要在生产环境中使用它,您只需进行两项更改,将 url 更改为生产 url 并更改实时凭证的 .pem 文件。
-
@Bhavin 你能解释一下你的答案吗?
-
@Loki - 您的 .pem 文件用于生产或开发
-
还有一件事生产APNS,我们无法检查,临时我们可以检查,生产APNS只有在上线后才能工作
标签: ios cocoa-touch push-notification apple-push-notifications apns-php