用PHP脚本苹果推送通知 [英] apple push notification with php script

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

问题描述

我能够连接到APNS并通过插入值数据库只检查我得到信息传递的消息,但没有显示任何通知....有谁能够告诉我在哪里我错了...

  $ deviceToken ='************';
$有效载荷['APS'] =阵列('警报'=>'这是警报文本,徽章
= GT; 1,声音= GT; '默认'); $有效载荷= json_en code($负载);$密码='***';
$ 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','密​​码',$密码);$ APNS =在stream_socket_client('SSL://'$ apnsHost':'$ apnsPort,$错误,$为errorString,2,STREAM_CLIENT_CONNECT,$ streamContext);如果(!$ APNS)
    {
     $查询= $为errorString; $查询=INSERT INTO tbl_checkData(friend_nickname)VALUES('$支票'); $结果= mysql_query($查询); }其他{
     $检查=连接; $查询=INSERT INTO tbl_checkData(friend_nickname)VALUES('$支票'); $结果= mysql_query($查询); }$ apnsMessage = CHR(0)。包(N,32)。包(H *',str_replace函数('','',$ deviceToken))。包(N的strlen($有效载荷))。 $有效载荷;//字符(0)。字符(0)。字符(32)。包(H *',str_replace函数('','',$ deviceToken))。字符(0)。字符(strlen的($有效载荷))。 $有效载荷;$结果= FWRITE($ APNS,$ apnsMessage);如果(!$结果)
    {
     $检查='邮件未送达; $查询=INSERT INTO tbl_checkData(friend_nickname)VALUES('$支票'); $结果= mysql_query($查询);
            }其他{$检查='发表留言'; $查询=INSERT INTO tbl_checkData(friend_nickname)VALUES('$支票'); $结果= mysql_query($查询);
     }在此输入codeFCLOSE($ APNS);


解决方案

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

从这个URL删除沙箱,它会运行...
我测试...

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';

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

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

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