【发布时间】:2021-04-28 13:29:57
【问题描述】:
我正在使用 php 代码发送推送通知,而 ios 没有收到通知,所以我不知道确切的问题是什么,请帮忙。
public static function ios_push($device_token,$title,$msg,$description,$type = "",$r_type = "")
{
\Log::info('device_token', ['context' => $device_token]);
\Log::info($device_token);
$badge_count =2;
$streamContext = stream_context_create();
$connectTimeout = 60;
stream_context_set_option($streamContext, 'ssl', 'passphrase',IPHONE_CERTIFICATE_PASSWORD);
\Log::info(IPHONE_CERTIFICATE_TYPE);
if(IPHONE_CERTIFICATE_TYPE == "Development")
{
//For Development
stream_context_set_option($streamContext, 'ssl', 'local_cert',IOS_PUSH_DEV_PEM_PATH);
$apns = stream_socket_client('ssl://gateway.push.apple.com:2195', $error, $errorString, $connectTimeout, STREAM_CLIENT_CONNECT |STREAM_CLIENT_PERSISTENT, $streamContext);
}
else
{
//For Production
stream_context_set_option($streamContext, 'ssl', 'local_cert',WWW_ROOT_PATH.IOS_PUSH_DEV_PEM_PATH);
$apns = stream_socket_client('ssl://gateway.push.apple.com:2195', $error, $errorString, $connectTimeout, STREAM_CLIENT_CONNECT |STREAM_CLIENT_PERSISTENT, $streamContext);
}
if (!$apns) {
\Log::info('Error : '.$error.' '.$errorString);
} else {
\Log::info("success");
}
$music = 'default';
$payload['aps'] = array('alert' => ['title'=>$title,'body'=>$msg], 'badge' => $badge_count,'title'=>$description,'sound'=> $music , 'notification_type' => $type);
//$payload['aps'] = array('alert' => "vikas", 'badge' => $badge_count,'sound'=> $music , 'notification_type' => $type);
// $data['notification_type'] = $notification_type;
// $data['sender_first_name'] = $sender_first_name;
// $data['sender_last_name'] = $sender_last_name;
// $data['sender_user_id'] = $sender_user_id;
$data['sound'] = $music;
$data['title'] = $title;
$data['notification_type'] = $type;
$data['report_type'] = !empty($r_type) ? substr($r_type, 0, -8) : "";
$payload['data'] = $data;
$payload = json_encode($payload);
\Log::info('Log message', ['payload' => json_encode($payload)]);
$apnsMessage = chr(0) . pack('n', 32) . pack('H*', $device_token) . pack('n', strlen($payload)) . $payload;
$fwriteRes = fwrite($apns, $apnsMessage, strlen($apnsMessage));
fclose($apns);
return true;
}
这是我的功能
但是IOS在手机端没有收到任何通知
那是什么问题
2195 端口的问题已接近,这是为什么呢?
【问题讨论】:
-
是的!!!!我得到了解决方案!耶熙
-
下面我把我的问题的答案请参考这个答案如果有人没有收到 ios 推送通知或在 ios 推送通知中收到错误。
-
IOS 推送通知旧代码已更改,这就是通知将停止的原因。
-
已解决 - HTTP/2 iOs 推送通知 Laravel Helper 类 - 为我工作 github.com/webblufter/…
标签: php swift laravel push-notification apple-push-notifications