我正在发送从PHP到ios的推送通知.它工作正常,这是我的代码:
$passphrase = '';
$badge = 1;
$path = base_path('path/to/certificate.pem');
$ctx = stream_context_create();
stream_context_set_option($ctx,'ssl','local_cert',$path);
stream_context_set_option($ctx,'passphrase',$passphrase);
$fp = stream_socket_client(
'ssl://gateway.sandBox.push.apple.com:2195',$err,$errstr,60,STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT,$ctx
);
if (!$fp) {
self::SavePush($device_token,$message,$device_id,$device_type,$user_id,"pending","normal",null);
}
//echo 'Connected to APNS' . PHP_EOL;
$body['aps'] = array(
'alert' => $message,'badge' => $badge,'sound' => 'default'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n',32) . pack('H*',$device_token) . pack('n',strlen($payload)) . $payload;
$result = fwrite($fp,$msg,strlen($msg));
//print_r($result);exit;
if (!$result) {
self::SavePush($device_token,null,$result);
} else {
self::SavePush($device_token,"sent",$result);
}
fclose($fp);
现在我遇到的问题是,我无法确定通知是否失败,因为$result在每种情况下都包含一个整数,成功或失败.我已经传递了一个随机数字作为标记,它返回115或65之类的整数,每次都会改变.所以!$结果不会工作.我怎么知道通知是否失败?
最后
以上就是腼腆树叶最近收集整理的关于ios php 推送消息,PHP:向ios发送推送通知的全部内容,更多相关ios内容请搜索靠谱客的其他文章。
发表评论 取消回复