gau*_*lik 6 php push-notification apple-push-notifications ios ios10
我已在旧版本的ios中发送通知.但在较新的版本中我无法创建.pem文件.有人告诉我,不再需要pem文件从服务器发送通知.但运气不好,我无法找到任何关于此的链接.有人请指导我如何在较新版本的ios中从服务器发送推送通知.自上周以来,我一直在发送通知.请帮忙.这是我正在使用的代码
private function pushnotification($deviceToken, $message, $type, $badge, $userid, $jobid) {
$passphrase = '123456';
$ctx = stream_context_create();
// $file = base_path(). "/public/WenderCastPush.pem";
//stream_context_set_option($ctx, 'ssl', 'local_cert', $file);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
stream_context_set_option($ctx, 'ssl', 'verify_peer_name', false);
stream_context_set_option($ctx, 'ssl', 'allow_self_signed', true);
//stream_context_set_option($ctx, 'ssl','ciphers', 'TLSv1');
// 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);
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
$body['aps'] = array(
//'badge' => +1,
'alert' => $message,
'sound' => 'default',
//'title' => $message,
'type' => $type,
'userid' => $userid ,
'jobid' => $jobid,
);
// Encode the payload as JSON
$payload = json_encode($body);
$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));
if (!$result)
$responce = 'Message not delivered' . PHP_EOL;
else
$responce = 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
return $responce;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1606 次 |
| 最近记录: |