首页 > 解决方案 > 关于 devicetoken 的 APNS 问题不适用于 PHP 中的主题和错误的设备令牌

问题描述

我正在尝试使用此 PHP 客户端库为 VOIP 集成 APNS 的发送:

composer require edamov/pushok

我遵循了如何在$options数组中提供正确值的步骤,我无法在此处披露。

当我尝试在以下代码中转储变量时:

$options = [
    'key_id' => $keyid, // The Key ID obtained from Apple developer account
    'team_id' => $teamid, // The Team ID obtained from Apple developer account
    'app_bundle_id' => $bundleid, // The bundle ID for app obtained from Apple developer account
    'private_key_path' => $keyfile, // Path to private key
    'private_key_secret' => null // Private key secret
];

$authProvider = AuthProvider\Token::create($options);
$alert = Alert::create()->setTitle('Hello!');
$alert = $alert->setBody('First push notification');

$payload = Payload::create()->setAlert($alert);

//set notification sound to default
$payload->setSound('default');

$deviceTokens = [$token];

$notifications = [];
foreach ($deviceTokens as $deviceToken) {
    $notifications[] = new Notification($payload,$deviceToken);
}

$client = new \Pushok\Client($authProvider, $production = false);
$client->addNotifications($notifications);

$responses = $client->push(); // returns an array of ApnsResponseInterface (one Response per Notification)

var_dump($responses);

这是我得到的:

array (size=1)
  0 => 
    object(Pushok\Response)[1564]
      private 'apnsId' => string '7EEEWAYS-BE3F-P0RK-J3RK-706FC55D5ABS' (length=36)
      private 'deviceToken' => string 'wlo83peah2f2ql686sfitzasro2wghri85x2l128t7gqysoba9jaezsve0y0nvpm' (length=64)
      private 'statusCode' => int 400
      private 'errorReason' => string 'DeviceTokenNotForTopic' (length=22)
      private 'error410Timestamp' => string '' (length=0)

尽管我认为数组中HTTP400 DeviceTokenNotForTopic提供的值是正确的,但我想询问或寻求帮助我为什么会收到错误?$options

另外,我刚刚发现,当我从这里更改 $client 的第二个参数的值时:

$client = new \Pushok\Client($authProvider, $production = false);
$client->addNotifications($notifications);

对此

$client = new \Pushok\Client($authProvider, $production = true);
$client->addNotifications($notifications);

我收到BadDeviceToken HTTP400错误消息:

array (size=1)
  0 => 
    object(Pushok\Response)[1564]
      private 'apnsId' => string '733TWAYS-S0UR-F1SH-CH0W-706FC55D5ABS' (length=36)
      private 'deviceToken' => string 'wlo83peah2f2ql686sfitzasro2wghri85x2l128t7gqysoba9jaezsve0y0nvpm' (length=64)
      private 'statusCode' => int 400
      private 'errorReason' => string 'BadDeviceToken' (length=14)
      private 'error410Timestamp' => string '' (length=0)

提前致谢。

标签: phpcakephp-3.0apns-php

解决方案


推荐阅读