プッシュ通知を送信していますが、メッセージに İ、ş、ç、ğ などの外国語 (私の場合はトルコ語) が含まれている場合、メッセージがデバイスに届きません。
これが私のコードです:
$message = 'THİS is push';
$passphrase = 'mypass';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'MyPemFile.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to Apple service. ' . PHP_EOL;
// Encode the payload as JSON
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
$payload = json_encode($body);
$result = 'Start'.PHP_EOL;
$tokenArray = array('mytoken');
foreach ($tokenArray as $item)
{
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $item) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Failed message'.PHP_EOL;
else
echo 'Successful message'.PHP_EOL;
}
// Close the connection to the server
fclose($fp);
$message 変数を utf8_encode() でエンコードしようとしましたが、「THÝS is push」というメッセージが表示されました。そして、iconv() のような他の方法は私にとってはうまくいきませんでした。トルコ語の文字が切り取られたものもあれば、まったく受信されなかったものもあります。
私も持っています
header('content-type: text/html; charset: utf-8');
と
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
マイページで。値を設定している間は問題は発生しないと思いますが、pack() 関数を使用している可能性があります。
文字を英語に置き換えずにこれを解決するアイデアはありますか?