推送包的签名验证失败 - Safari Push

问题描述 投票:1回答:1

我正在尝试使用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的推送包失败消息的签名验证。

在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 apple-push-notifications apns-php safari-push-notifications
1个回答
1
投票

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

现在已经知道,对于safari中的push send,你首先需要做三件事

  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);
}

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

© www.soinside.com 2019 - 2024. All rights reserved.