苹果推送通知外商重音字符未接受 [英] Apple Push Notifications With Foreign Accent Characters Not Receiving

查看:122
本文介绍了苹果推送通知外商重音字符未接受的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要送推送通知,当消息包含外文​​字符(土耳其在我的情况),如I,S,C,G ......该消息未到达的设备。

I'm sending push notifications and when the message contains foreign characters (Turkish in my case) like İ, ş, ç, ğ... The message does not arrive to devices.

下面是我的code:

$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);

我曾尝试与utf8_en code $编码变量消息(),但为THYS是推收到消息。和其他类似方式的iconv()并没有为我工作,他们中的一些裁剪土耳其的人物,一些没有得到的。

I have tried encoding $message variable with utf8_encode() but the message received as "THÝS is push". And other ways like iconv() didn't work for me, some of them cropped Turkish characters, some didn't receive at all.

我也有

header('content-type: text/html; charset: utf-8');

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

在我的网页。我不认为当我用包()函数的设定值,但也许会出现的问题。

in my page. I don't think the problem appears while I set the value but maybe with pack() function.

任何想法来解决这个没有用英文字符替换?

Any ideas to solve this without replacing characters with English?

推荐答案

所有我需要做的就是用下面的脚本替换​​土耳其字符:

All I had to do was replacing the Turkish characters with following script:

function tr_to_utf($text) {   
    $text = trim($text);    
    $search = array('Ü','Ş','Ğ','Ç','İ','Ö','ü','ş','ğ','ç','ı','ö');  
    $replace = array('Ãœ','Å','&#286;','Ç','Ä°','Ö','ü','ÅŸ','ÄŸ','ç','ı','ö');
    $new_text = str_replace($search,$replace,$text);    
    return $new_text;  
}

现在它正在与没有问题。

Now it is working with no problems.

这是源

这篇关于苹果推送通知外商重音字符未接受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆