sai*_*oid 1 cron push-notification ios
我正在为Apple设备实现推送通知服务。使用php脚本,仅当php脚本从浏览器中命中时,它才推送通知。当我通过浏览器点击服务器php脚本时,它将通知推送到Apple设备。我的PHP脚本是...
//在Apple设备中发送通知的方法的结尾
function sendNotificationToAppleDevice($token,$message)
{
/////////////////////////////////////////////For apple divice////////////////////////////////
$passphrase='1234';
// Create a stream to the server
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'sample.pem');
stream_context_set_option($streamContext, 'ssl', 'passphrase', $passphrase);
$apns = stream_socket_client( 'ssl://gateway.sandbox.push.apple.com:2195', $error,$errorString,60,STREAM_CLIENT_CONNECT, $streamContext);
// You can access the errors using the variables $error and $errorString
// Now we need to create JSON which can be sent to APNS
$inc=0;
$load = array(
'aps' => array(
'alert' => $message,
'badge' =>$inc,
)
);
$inc++;
$payload = json_encode($load);
// The payload needs to be packed before it can be sent
$apnsMessage = chr(0) . chr(0) . chr(32);
$apnsMessage .= pack('H*', str_replace(' ', '', $token));
$apnsMessage .= chr(0) . chr(strlen($payload)) . $payload;
// Write the payload to the APNS
fwrite($apns, $apnsMessage);
echo "just wrote " . $payload;
// Close the connection
fclose($apns);
}
Run Code Online (Sandbox Code Playgroud)
该脚本运行良好,并且在浏览器命中该脚本时可以成功发送通知。
现在,当我从计划任务的cron作业运行此脚本时,它不会向设备发送任何通知。它引起了......
警告:stream_socket_client():SSL操作失败,代码为1。OpenSSL错误消息:error:14094410:SSL例程:SSL3_READ_BYTES:sslv3 sample.php中的警报握手失败
警告:stream_socket_client():无法在线启用sample.php中的加密
警告:stream_socket_client():无法连接到sample.php中的ssl://gateway.sandbox.push .apple.com:2195(未知错误)
警告:fwrite()期望参数1为资源,在线上sample.php中给出布尔值
警告:fclose()期望参数1为资源,在线上sample.php中给出的布尔值
这个功能和错误有什么问题..请帮助我任何人...
提前致谢。
经过对它的大量研究,我终于发现了漏洞。
您只需更改一行即可使用cron作业使用此方法.. :-)
改变这条线
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'sample.pem');
Run Code Online (Sandbox Code Playgroud)
至
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'your FULL path of pem file');
Run Code Online (Sandbox Code Playgroud)
就我而言
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'C:\Websites\games\project_name\sample.pem');
Run Code Online (Sandbox Code Playgroud)
仅此而已...希望您的问题现在得到解决。
| 归档时间: |
|
| 查看次数: |
1740 次 |
| 最近记录: |