【问题标题】:Signature verification of push package failed - Safari Push推送包签名验证失败 - Safari Push
【发布时间】:2016-03-06 16:07:23
【问题描述】:

我正在尝试使用 PHP 在我的服务器(对于我的网站)中实现 Safari 推送通知。

我正在按照 Apple 的以下教程进行操作: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/NotificationProgrammingGuideForWebsites/PushNotifications/PushNotifications.html

我正在使用 Connor 开发的库: https://github.com/connorlacombe/Safari-Push-Notifications

但我不断获得许可:在 Safari 控制台“拒绝”。我正在服务器端打印日志(来自此 URL:webServiceURL/version/log),发现来自 Apple 的 Signature verification of push package failed 消息。

在 stackOverflow 中我发现了这些:Safari push notifications certificate issueApple website push: Signature verification of push package failed, but apple certificates are ok。我已应用他们提供的解决方案,但收到以下错误消息:推送通知包中缺少文件。手动下载 pushPackage zip 文件我发现应用他们的解决方案缺少 SIGNATURE 文件(在 openssl_pkcs7_sign 方法中使用 AppleWWDRCA.pem 文件)。

如何解决这个问题?如何注册 APNS 服务?

【问题讨论】:

  • 我也有同样的问题。包中请求的所有文件。但是它会记录“推送通知包中缺少文件。”你能解决这个问题吗?
  • 我遇到了不同的问题。我想在移动设备中有 Safari 推送通知。但是不支持iOS。但是,“推送通知包中缺少文件。”指出您应用的压缩过程不正确。

标签: safari apple-push-notifications apns-php safari-push-notifications


【解决方案1】:

在我的项目中实现 Safari 推送通知之前,我遇到过此类问题。 现在,您正在关注 developer.apple.com 那个不错的,但是 this one is also good for reference

现在已经知道,要在 Safari 中推送发送,您首先需要三件事

  1. 在 Mac 中创建 fileName.cer 文件和 CSR 文件。
  2. 使用 CSR 文件创建一个 p12 文件。
  3. 构建推送包

创建你需要的推送包

  1. 创建 icon.iconset 将有 6 个图标,这些图标显示在推送通知中。
  2. 现在创建 website.json 文件,这是推送中最重要的文件。

然后是 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);
}

我在这里为多个用户发送推送。 替换所需的文件,然后这将为您工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 2013-10-28
    • 2020-11-02
    相关资源
    最近更新 更多