Hello,
There is a problem sending cyrillic push-notifications to APNService using PHP Laravel 5.2 framework web-server.
Tried two methods, both works only with latin symbols, cyrillic symbol messages not delivering to device.
First one using https://github.com/davibennun/laravel-push-notification package:
foreach (Appuser::where('os_type', 'ios')->where('push_token', '!=', NULL)->pluck('push_token')->toArray() as $device_token)
$tokens[] = PushNotification::Device($device_token);
$devices = PushNotification::DeviceCollection($tokens);
$text = $request->text;
$collection = PushNotification::app('appNameIOS')
->to($devices)
->send(PushNotification::Message($text));
foreach ($collection->pushManager as $push) {
print_r($push->getAdapter()->getResponse());
Second - no libray method:
$sound = 'default';
$development = false;
$payload = array();
$payload["aps"] = array('alert' => $request->text, 'sound' => $sound);
$payload = json_encode($payload);
$payload = preg_replace_callback('/\\\\u([0-9a-f]{4})/i',
function ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
},
$payload
);
$apns_url = NULL;
$apns_cert = NULL;
$apns_port = 2195;
if ($development) {
$apns_url = 'gateway.sandbox.push.apple.com';
$apns_cert = storage_path() . '/apns-dev.pem';
} else {
$apns_url = 'gateway.push.apple.com';
$apns_cert = storage_path() . '/apns-dev.pem';
}
$success = array();
$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', $apns_cert);
stream_context_set_option($stream_context, 'ssl', 'passphrase', 'qweQWE');
$apns = stream_socket_client('ssl://' . $apns_url . ':' . $apns_port, $error, $error_string, 2, STREAM_CLIENT_CONNECT, $stream_context);
$count = 0;
foreach(Appuser::where('os_type', 'ios')->where('push_token', '!=', NULL)->pluck('push_token')->toArray() as $token) {
$apns_message = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $token)) . chr(0) . chr(strlen($payload)) . $payload;
if (fwrite($apns, $apns_message)) {
$success[$token] = "sent";
$count++;
} else {
$success[$token] = "failed";
}
}
print_r($success);
fclose($apns);
Thanks.