带有 php 脚本的苹果推送通知 [英] apple push notification with php script

查看:29
本文介绍了带有 php 脚本的苹果推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够连接到 apns 并通过将值插入数据库来检查我收到消息已发送"消息但它没有显示任何通知....谁能告诉我我错在哪里...

I am able to connected to the apns and by inserting the values to database for just check i am getting "message delivered" message but it's not showing any notification....can anybody tell me where i am mistaken...

$deviceToken = '**********************';


$payload['aps'] = array('alert' => 'This is the alert text', 'badge'
=> 1, 'sound' => 'default'); $payload = json_encode($payload);

$passphrase = '***';


$apnsHost = 'gateway.sandbox.push.apple.com'; $apnsPort = 2195; $apnsCert = 'ck.pem';

$streamContext = stream_context_create(); stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert); stream_context_set_option($streamContext, 'ssl', 'passphrase',$passphrase );

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

if (!$apns)
    {
     $check = $errorString;      $query = "INSERT INTO tbl_checkData(friend_nickname) VALUES('$check') ";    $result=mysql_query($query);           } else{ 
     $check = "connected";   $query = "INSERT INTO tbl_checkData(friend_nickname) VALUES('$check') ";    $result=mysql_query($query);    }

$apnsMessage = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;

//chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;

$result=fwrite($apns, $apnsMessage);

if (!$result)
    {
     $check = 'Message not delivered' ;      $query = "INSERT INTO tbl_checkData(friend_nickname) VALUES('$check') ";    $result=mysql_query($query);       
            } else {     $check = 'Message delivered' ;      $query = "INSERT INTO tbl_checkData(friend_nickname) VALUES('$check') ";    $result=mysql_query($query);    
     }

enter code here

fclose($apns);

推荐答案

$apnsHost = 'gateway.sandbox.push.apple.com';

$apnsHost = 'gateway.sandbox.push.apple.com';

从此网址中删除沙箱,它将运行...我已经测试过了...

remove sandbox from this url and it will run... i have tested it...

这篇关于带有 php 脚本的苹果推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆