我需要用我的电报机发送含有表情符号的信息。
因此,我复制/粘贴表情符号:nine:
,例如,在我的消息文本中,并将其发送给用户,但表情符号不起作用。
这是我的示例代码和函数:
function tel_send($key, $t, $c)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot" . $key . "/sendMessage");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "cache=" . (time() / rand(1, time() - 100)) . "&text=" . $t . "&chat_id=" . $c);
$ss = curl_exec($ch);
curl_close($ch);
return $ss;
}
tel_send($key, "My number - :nine:", $val['message']['chat']['id']);
那么,我的问题是:我怎样才能通过电报机器人发送表情呢?
发布于 2015-07-15 13:30:01
发布于 2016-01-05 11:09:50
几天前我也遇到了同样的问题。解决方案是使用这个表中的Bytes (UTF-8)表示法:http://apps.timwhitlock.info/emoji/tables/unicode
例子:
带着微笑的笑脸
XF0\x9F\x98\x89眨眼
发布于 2016-11-21 08:53:32
参见emojis及其UTF-8代码,此处:http://apps.timwhitlock.info/emoji/tables/unicode。
然后,您必须使用以下代码将UTF-8代码转换为电报就绪响应文本:
<?php
function telegram_emoji($utf8emoji) {
preg_replace_callback(
'@\\\x([0-9a-fA-F]{2})@x',
function ($captures) {
return chr(hexdec($captures[1]));
},
$utf8emoji
);
return $utf8emoji;
}
$utf8emoji = '\xF0\x9F\x98\x81';
$telegramReadyResponse = 'Hi user ' . telegram_emoji($utf8emoji);
https://stackoverflow.com/questions/31430587
复制相似问题