protected function createPayload($messageId, $expiry, $token, $message)
{
if ($this->jsonUnescapedUnicode) {
// Validate PHP version
if (!version_compare(PHP_VERSION, '5.4.0', '>=')) {
throw new \LogicException(sprintf('Can\'t use JSON_UNESCAPED_UNICODE option on PHP %s. Support PHP >= 5.4.0', PHP_VERSION));
}
// WARNING:
// Set otpion JSON_UNESCAPED_UNICODE is violation
// of RFC 4627
// Because required validate charsets (Must be UTF-8)
$encoding = mb_detect_encoding($message['aps']['alert']);
if ($encoding != 'UTF-8' && $encoding != 'ASCII') {
throw new \InvalidArgumentException(sprintf('Message must be UTF-8 encoding, "%s" given.', mb_detect_encoding($message['aps']['alert'])));
}
$jsonBody = json_encode($message, JSON_UNESCAPED_UNICODE);
} else {
$jsonBody = json_encode($message);
}
$token = preg_replace("/[^0-9A-Fa-f]/", "", $token);
$payload = chr(1) . pack("N", $messageId) . pack("N", $expiry) . pack("n", 32) . pack("H*", $token) . pack("n", strlen($jsonBody)) . $jsonBody;
return $payload;
}