Notification Safari qui n'apparait pas

SuperCed

Membre d’élite
Club MacG
20 Juin 2001
1 183
51
41
superced.rb38.eu
Hello,

j'essaye d'utilise le push via inscription depuis safari.

J'ai créé le pushpackage et il semble fonctionner car je reçois bien les notifications (avec le token) comme quoi la personne s'abonne ou se désabonne.

Ensuite, je me connecte sur le gateway de Apple et j'arrive à envoyer ma notification push.

Celle-ci est bien reçu, je le vois sur mon ordi dans le apsd.log .
Par contre, elle n'est jamais affichée.

Je ne comprends pas pourquoi.

Voici le message dans apsd.log :
Bloc de code:
ar 21 12:13:47 ced apsd[87062]: : Outstanding data received: <0a000000 c4010020 392432f9 2c7f7a26 fc721dd3 3c53beb7 2f3d31a1 78be6ea1 877f8878 0008a71b 020014d8 26b758cb 77782a8b a0bf0140 5897deec 5c245604 00040000 00000500 04ffffff ff060008 143dd786 a89dcf01 07000100 03006a7b 22617073 223a7b22 616c6572 74223a7b 22746974 6c65223a 22746f74 6f222c22 626f6479 223a2274 61746122 2c226163 74696f6e 223a2276 69657722 7d7d2c22 75726c2d 61726773 223a5b22 68747470 3a5c2f5c 2f777777 2e737061 72746f6f 2e636f6d 5c2f225d 7d> (length 201)
>Mar 21 12:13:47 ced apsd[87062]: : Stream processing: complete yes, invalid no, length parsed 201, parameters {
>  APSProtocolCommand = 10;
>  APSProtocolMessageExpiry = "2106-02-07 06:28:15 +0000";
>  APSProtocolMessageID = <00000000>;
>  APSProtocolMessageTimestamp = 1458558827692412673;
>  APSProtocolPayload = <7b226170 73223a7b 22616c65 7274223a 7b227469 746c6522 3a22746f 746f222c 22626f64 79223a22 74617461 222c2261 6374696f 6e223a22 76696577 227d7d2c 2275726c 2d617267 73223a5b 22687474 703a5c2f 5c2f7777 772e7370 6172746f 6f2e636f 6d5c2f22 5d7d>;
>  APSProtocolToken = <392432f9 2c7f7a26 fc721dd3 3c53beb7 2f3d31a1 78be6ea1 877f8878 0008a71b>;
>  APSProtocolTopicHash =;
>  }
>Mar 21 12:13:47 ced apsd[87062]: : Message has token <392432f9 2c7f7a26 fc721dd3 3c53beb7 2f3d31a1 78be6ea1 877f8878 0008a71b> (tokenName 501 darkWakeEnabled)
>Mar 21 12:13:47 ced apsd[87062]: : Received high priority message for topic 'web.com.machin' with payload '{type = immutable dict, count = 2,
>  entries =>
>  0 : aps = {type = immutable dict, count = 1,
>  entries =>
>  0 : alert = {type = immutable dict, count = 3,
>  entries =>
>  0 : title = toto
>  1 : action = view
>  2 : body = tata
>  }
>
>  }
>
>  2 : url-args = (
>  "http://www.machin.com/"
>  )
>  }
>  '
>Mar 21 12:13:47 ced apsd[87062]: asked to store incoming message with guid D3C514C7-38F0-4AFE-80E6-4B8188B98244 environment
>Mar 21 12:13:47 ced apsd[87062]: : Stream processing: complete no, invalid no, length parsed 0, parameters (null)
>Mar 21 12:13:47 ced apsd[87062]: APSMessageStore - New message record [{}] has ID [590].
>Mar 21 12:13:47 ced apsd[87062]: calling completion block for incoming message D3C514C7-38F0-4AFE-80E6-4B8188B98244
>Mar 21 12:13:47 ced apsd[87062]: : Sending acknowledgement message with response 0 and messageId <00000000> (0)
>Mar 21 12:13:47 ced apsd[87062]: _notifyForIncomingMessage with guid D3C514C7-38F0-4AFE-80E6-4B8188B98244
>Mar 21 12:13:47 ced apsd[87062]: : Enabling interactive power assertions due to receiving an interactive push on connection
>Mar 21 12:13:47 ced apsd[87062]: Changing to power assertion type InteractivePushServiceTask
>Mar 21 12:13:47 ced apsd[87062]: Dispatching high priority message: { count = 2, contents =
>  "message" => { count = 1, contents =
>  "ECF19A18-7AA6-4141-B4DC-A2E5123B2B5C" => : { length = 4096 bytes, contents = 0x62706c697374313513a2010000000000801200000000d87f... }
>  }
>  "message-type" => : 26
>  }>
>Mar 21 12:13:47 ced apsd[87062]: informed that acknowledges incoming message with guid D3C514C7-38F0-4AFE-80E6-4B8188B98244
>Mar 21 12:13:47 ced apsd[87062]: Removing incoming message with guid D3C514C7-38F0-4AFE-80E6-4B8188B98244
>Mar 21 12:13:47 ced apsd[87062]: APSMessageStore - APSIncomingMessageRecordDeleteMessageForGUID D3C514C7-38F0-4AFE-80E6-4B8188B98244
>Mar 21 12:13:48 ced AddressBookSourceSync[87071]: ApplePushService: Flushing any queuedDelegateBlocks 0

et le code php qui lance le push:

Bloc de code:
$push_apple = 'ssl://gateway.push.apple.com:2195';
$passphrase = 'XXXXXXXXX';
$certificate = 'apns_safari.pem';


$ctx = stream_context_create();
if ( $ctx === FALSE ) {
 $error = "Error with stream context";
 if ( $debug ) {
 echo $error.'
'.PHP_EOL;
}
} else {
$stream_success = stream_context_set_option( $ctx, 'ssl', 'local_cert', DIR_FS_CATALOG.'includes/mobile/'.$certificate );
if ( $stream_success === FALSE ) {
$error = "Error with stream context option local_cert";
if ( $debug ) {
echo $error.'
'.PHP_EOL;
}
} else {
$stream_success = stream_context_set_option( $ctx, 'ssl', 'passphrase', $passphrase );
if ( $stream_success === FALSE ) {
$error = "Error with stream context option ssl";
if ( $debug ) {
echo $error.'
'.PHP_EOL;
}
}
}
}

// Open a connection to the APNS server
if ( !$error ) {

$fp = stream_socket_client(
$push_apple, $err,
$errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx );
if ( $fp === FALSE ) {
$error = "Failed to connect debug: $err $errstr";
if ( $debug ) {
echo $error.'
'.PHP_EOL;
}
} else {

if ( $debug ) {
echo 'Connected to APNS
'.PHP_EOL;
}

$title = 'toto';
$message = 'tata';


// Create the payload body
// We are using an intermediary page (last_newsletters.php) to be able
// to check whether or not the user has read the newsletter.
$body = array(
'aps' => array(
'alert' => array(
'title' => $title,
'body' => $message,
'action' => 'view',
),

),
'url-args' => array('http://www.machin.com/'),
);

 // Encode the payload as JSON
 $payload = json_encode( $body );


 // Build the binary notification
 $msg = chr( 0 ).pack( 'n', 32 ).pack( 'H*', '392432F92C7F7A26FC721DD33C53BEB72F3D31A178BE6EA1877F88780008A71B' ).pack( 'n', strlen( $payload ) ).$payload;

 // Send it to the server
  $result = fwrite( $fp, $msg, strlen( $msg ) );

  echo $result;
 if ( !$result ) {

 if ( $debug ) {
  echo 'Message not delivered (token='.'392432F92C7F7A26FC721DD33C53BEB72F3D31A178BE6EA1877F88780008A71B'.')
'.PHP_EOL;
  }
 $invalidDeviceTokens[] = $ios_id;

  } else {

  if ( $debug ) {
  echo 'Message successfully delivered (token='.'392432F92C7F7A26FC721DD33C53BEB72F3D31A178BE6EA1877F88780008A71B'.')
'.PHP_EOL;
  //$result2 = fread( $fp, 1024 );
  //echo $result2;
 }

 }


 // Close the connection to the server
 fclose( $fp );
 }
  }

 if ( $error ) {
  $body = $error;
 $result = '';
  }
 echo $body;