我正在尝试使用PHP实现Safari将通知推到我的服务器(对于我的网站)。
我正在使用康纳开发的库:https://github.com/connorlacombe/Safari-Push-Notifications
但我不断获得许可:“拒绝”在Safari控制台。我在服务器端打印日志(来自这个URL: webServiceURL/version/ log ),发现push包的签名验证失败了消息。
在stackOverflow中,我发现了这些:Safari推送通知证书颁发和苹果网站推送: push包的签名验证失败,但苹果证书没有问题。我已经应用了他们提供的解决方案,但得到了下面的错误消息:在推送通知包中缺少文件。手动下载pushPackage zip文件,我发现应用它们的解决方案(使用openssl_pkcs7_sign方法中的AppleWWDRCA.pem文件)缺少签名文件。
如何解决这个问题?如何在APNS服务中注册?
发布于 2016-11-12 14:09:02
在我的项目中实现Safari推送通知之前,我遇到过这种类型的问题。现在,您正在跟踪这个好的developer.apple.com,但是这个也有参考价值。。
现在已经知道,为了推送狩猎,你首先需要三件事
要创建所需的推送包
然后为Safari中的推送权限编写代码:
window.onload = function () {
if ('safari' in window && 'pushNotification' in window.safari) {
var permissionData = window.safari.pushNotification.permission('web.com.domainname');
checkRemotePermission(permissionData);
}
};
var checkRemotePermission = function (permissionData) {
console.log(permissionData);
if (permissionData.permission === 'default') {
window.safari.pushNotification.requestPermission(
'https://domainname.com',
'web.com.domainname', {},
checkRemotePermission
);
} else if (permissionData.permission === 'denied') {
console.log('denied');
} else if (permissionData.permission === 'granted') {
console.log('granted');
}
};这将通过使用能够发送推送的令牌来为您提供设备令牌。
推送:
$title ="title";//Title of the push
$body = "body";//Body of the Push
$button = "View";//view button
$payload['aps']['alert'] = array(
"title" => $title,
"body" => $body,
"action" => $button
);
$payload['aps']['url-args'] = array(
"www.facebook.com" // the sub part of the url to which the subscriber will be redirect after click on the push .This is Add with the URL u given in the website.json file that is:[ "urlFormatString": "http://%@" ] for this url will be :->http://www.facebook.com
);
for($i=0;$i<1;$i++){
$deviceToken =$deviceToken;//This is the DeviceToken that u stored in the DB before.
$payload = json_encode($payload);
$apnsHost = 'gateway.push.apple.com';
$apnsPort = 2195;
$apnsCert = path/PushCertificates.pem';//Give the path to the ,pem file generated previously from ur registered .p12 file not for the downloaded .p12 file.
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
fclose($apns);
}在这里,我发送推送给多个用户。替换所需的文件,然后这将适用于您。
https://stackoverflow.com/questions/35829158
复制相似问题