Created
January 30, 2014 09:31
-
-
Save pimpreneil/8705307 to your computer and use it in GitHub Desktop.
Function to create an Apple APNS command 3 push payload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// token: An apple token | |
// message: The message to push | |
// id: The push message identifier | |
// expiry: Push expiration date | |
// priority: Priority (5 or 10) | |
public function createPayload($token, $message, $identifier, $expiry, $priority) | |
{ | |
$body = json_encode(array('aps' => array('alert' => $message)), JSON_UNESCAPED_UNICODE); | |
$packedToken = pack("H*", $token); | |
$tokenData = chr(1) . pack('n',strlen($packedToken)) . $packedToken; | |
$payloadBody = chr(2) . pack('n',strlen($body)) . $body; | |
$packedIdentifier = pack("N", $identifier); | |
$identifier = chr(3) . pack('n',strlen($packedIdentifier)) . $packedIdentifier; | |
$packedExpiry = pack("N", $expiry); | |
$expiry = chr(4) . pack('n',strlen($packedExpiry)) . $packedExpiry; | |
$packedPriority = chr($priority); | |
$priority = chr(5) . pack('n',strlen($packedPriority)) . $packedPriority; | |
$payload = $tokenData.$payloadBody.$identifier.$expiry.$priority; | |
return chr(2) . pack("N", strlen($payload)) . $payload; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment