【问题标题】:APNS PHP Push Notification not working. Gets timed outAPNS PHP 推送通知不起作用。超时
【发布时间】:2014-10-09 15:38:41
【问题描述】:

我正在尝试在生产环境中发送推送通知,但它不起作用。下面是我正在尝试的代码,它会超时。没有错误,没有异常被抛出。 这有什么问题?

注意:当我使用 Sandbox(ENVIRONMENT_SANDBOX) 和开发证书文件发送推送通知时,它可以工作。但是生产证书文件和ENVIRONMENT_PRODUCTION 不起作用。

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

/**
 * @param string $device_token   unique device token
 * @param string $custom_message message that needs to be pushed
 * @param string $push_service   which service to use ( ApnsPHP/UrbanAirship )
 *
 * @return bool
 * @throws ApnsPHP_Exception
 * @throws ApnsPHP_Message_Exception
 * @throws ApnsPHP_Push_Exception
 * @throws Exception
 */
function send_apple_push_notification_test( $device_token, $custom_message, $push_service = 'ApnsPHP' ) {

    if ( empty( $device_token ) || empty( $custom_message ) ) {
        return false;
    }

    // Report all PHP errors
    error_reporting( -1 );

    // Adjust to your time-zone
    date_default_timezone_set( 'America/New_York' );

    // Using Autoload all classes are loaded on-demand
    require_once 'includes/ApnsPHP/Autoload.php';

    try {

        // Instantiate a new ApnsPHP_Push object
        $push = new ApnsPHP_Push(
            ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION, '/home/xxxxx/public_html/wp-content/themes/yyyyyy/includes/ApnsPHP-pem/AppPushNotify.pem'
        );

        // Set the Root Certificate Authority to verify the Apple remote peer
        $push->setRootCertificationAuthority( '/home/xxxxx/public_html/wp-content/themes/yyyyyy/includes/ApnsPHP-pem/Entrust_Root_Certification_Authority.pem' );

        // Connect to the Apple Push Notification Service
        $push->connect();

        // Instantiate a new Message with a single recipient
        $message = new ApnsPHP_Message_Custom( (string) $device_token );

        // Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
        // over a ApnsPHP_Message object retrieved with the getErrors() message.
        $message->setCustomIdentifier( "xxxyyyzzz-" . time() );

        // Set a simple welcome text
        $message->setText( (string) $custom_message );

        // Play the default sound
        $message->setSound();

        // Set the expiry value to 30 seconds
        $message->setExpiry( 60 );

        // Set the "View" button title.
        $message->setActionLocKey( 'See the message.' );

        // Add the message to the message queue
        $push->add( $message );

        // Send all messages in the message queue
        $push->send();

        // Disconnect from the Apple Push Notification Service
        $push->disconnect();

        // Examine the error message container
        $aErrorQueue = $push->getErrors();
        print_r( $aErrorQueue );

        return true;

    } catch ( Exception $e ) {
        print_r( $e->getMessage() );
    }

    return false;
}

echo "start";
send_apple_push_notification_test( '20fcc5090eb1f539ac0fddd345r4d0c50e5bca071b742d3d9833f16dd97adeb', 'Test Msg for Production' );

【问题讨论】:

  • 这看起来是一个很好的问题,但我怀疑有很多 PHP 开发人员具有所需的经验来回答它。希望我能帮忙。
  • 通过它。谢谢安迪。

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


【解决方案1】:

要使用生产环境,您的应用必须使用您的分发证书进行签名。对此进行测试的唯一方法是提交到 App Store 并下载应用程序的 App Store 版本;或使用 AdHoc 构建。当您的应用使用您的开发证书签名时,您无法使用生产推送环境。

如果您已完成所有这些操作,请确保您在生产环境中使用的设备令牌与您从开发环境中获得的设备令牌不同。它们会有所不同。

【讨论】:

  • 是的,我都做了。使用生产证书并生成带有生产详细信息的设备令牌。最初,我将开发的设备令牌与生产 .pem 文件一起使用,这会引发错误。现在,我已经使用生产详细信息制作了设备令牌和 .pem 文件,它不会引发任何错误/异常,而是在特定时间后超时。
  • 您使用的是 AdHoc 构建吗?这是使用生产证书进行测试的唯一方法。否则将无法正常工作。
  • 我尝试过使用 dev、adhoc 和 store。 :( 仍然无法正常工作。为什么它没有抛出任何错误??(headbang)
  • 增加 ssl 握手超时。我的 java 代码中有这个问题。
猜你喜欢
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-29
相关资源
最近更新 更多