gpt4 book ai didi

javascript - 如何在 Twilio SMS 请求中指定 unicode 消息正文?

转载 作者:行者123 更新时间:2023-11-30 06:38:27 25 4
gpt4 key购买 nike

According to Twilio ,他们现在在 RESTful SMS 接口(interface)中支持 unicode 字符。但是,我不清楚如何在 Javascript 中利用它(在 Node 中)。

当我发送带有西类牙语翻译(默认为 UTF-8)的 SMS 消息时,该消息将在收件人手机上被分成三条消息。我猜根本原因是我需要在请求中发送一个 unicode 消息正文。

如何将 Javascript 字符串转换为 unicode?我尝试过逐字翻译...

function toUnicode(theString) {
var unicodeString = '';
for (var i=0; i < theString.length; i++) {
var theUnicode = theString.charCodeAt(i).toString(16).toUpperCase();
while (theUnicode.length < 4) {
theUnicode = '0' + theUnicode;
}
theUnicode = '\\u' + theUnicode;
unicodeString += theUnicode;
}
return unicodeString;
}

...但这会产生一个消息正文,该正文被解释为超过 160 个字符的限制。

最佳答案

如果您以 Unicode 格式发送消息,则需要 16 位编码。 SMS 中 16 位编码的限制是 70 个字符。这是因为 SMS 信令协议(protocol)限制为 140 个八位字节,如果您使用 7 位编码,则转换为正常的 160 个字符。这是 SMS 协议(protocol)的限制,而不是 Twilio。我不确定您的问题是如何发送 Unicode,还是为什么它会打断我的消息。

关于javascript - 如何在 Twilio SMS 请求中指定 unicode 消息正文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13075151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com