I am trying to send push notification in a production environment but it is not working. Below is the code I'm trying and it expires. No errors, no exceptions thrown. What's bad about it?
Note. . When I send a push notification using Sandbox ( ENVIRONMENT_SANDBOX) and the development certificate files, it works. However, production certificate files ENVIRONMENT_PRODUCTIONdo not work.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
function send_apple_push_notification_test( $device_token, $custom_message, $push_service = 'ApnsPHP' ) {
if ( empty( $device_token ) || empty( $custom_message ) ) {
return false;
}
error_reporting( -1 );
date_default_timezone_set( 'America/New_York' );
require_once 'includes/ApnsPHP/Autoload.php';
try {
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION, '/home/xxxxx/public_html/wp-content/themes/yyyyyy/includes/ApnsPHP-pem/AppPushNotify.pem'
);
$push->setRootCertificationAuthority( '/home/xxxxx/public_html/wp-content/themes/yyyyyy/includes/ApnsPHP-pem/Entrust_Root_Certification_Authority.pem' );
$push->connect();
$message = new ApnsPHP_Message_Custom( (string) $device_token );
$message->setCustomIdentifier( "xxxyyyzzz-" . time() );
$message->setText( (string) $custom_message );
$message->setSound();
$message->setExpiry( 60 );
$message->setActionLocKey( 'See the message.' );
$push->add( $message );
$push->send();
$push->disconnect();
$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' );
source
share