如何使用 clickatell 用希伯来语发送短信

发布于 2024-07-21 07:04:58 字数 54 浏览 9 评论 0原文

如何通过 Clickatell 发送希伯来语短信?

它以乱码形式到达设备。

How can I send an SMS in hebrew through Clickatell?

It arrives on the device as gibberish.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

好倦 2024-07-28 07:04:58

我找不到任何有效的示例,所以我编写了自己的示例:

试试这个:

UnicodeEncoding unicode = new UnicodeEncoding(true, false);
return string.Concat(unicode.GetBytes(val).Select(c => string.Format("{0:x2}", c)));

I couldn't find any working example so, i wrote my own:

Try this:

UnicodeEncoding unicode = new UnicodeEncoding(true, false);
return string.Concat(unicode.GetBytes(val).Select(c => string.Format("{0:x2}", c)));
迷爱 2024-07-28 07:04:58

是unicode的吗? 如果我没记错的话,它们需要将 unicode 转义为十六进制表示形式。 这应该在他们的文档中。

然而,当我这样做时,我发现这并不是唯一的问题,许多手机不支持正确显示 unicode 字符。

此外,发送 unicode 可能会产生更高的成本,因为它可能会被分割。

Is it in unicode ? If I remember correctly they require unicode to be escaped into hexadecimal representation. This should be in their docs.

However, I found out when I did this that this is not the only issue, many phones do not support displaying unicode characters properly.

Also, sending unicode may incur a higher cost since it may be split up.

从﹋此江山别 2024-07-28 07:04:58

将您的消息编码为 un​​icode,请参阅此常见问题解答页面

Encode your message as unicode, see this FAQ page for details.

酒与心事 2024-07-28 07:04:58

遇到同样的问题...您需要编码为 un​​icode,然后转换为十六进制。 奇怪的是,您需要获取最后一个值并将其附加到前面才能使其正常工作。 我通过将我的代码结果与他们的在线工具的输出进行比较发现了这一点。

    private string ToUnicode(string val)
    {
        Encoding utf8 = Encoding.UTF8;
        Encoding unicode = Encoding.Unicode;

        byte[] utf8Bytes = utf8.GetBytes(val);

        byte[] unicodeBytes = Encoding.Convert(utf8, unicode, utf8Bytes);

        var result = ByteArrayToString(unicodeBytes);
        result = result.Substring(result.Length - 2, 2) + result.Substring(0, result.Length - 2);
        return result;
    }

    public static string ByteArrayToString(byte[] ba)
    {
        StringBuilder hex = new StringBuilder(ba.Length * 2);
        foreach (byte b in ba)
            hex.AppendFormat("{0:x2}", b);
        return hex.ToString();
    }

Ran into the same issue... you need to encode to unicode and then convert to hex. The strange thing is that you need to take the last value and append it to the front in order to get it to work. I found this out by comparing the results of my code against the output of their online tool.

    private string ToUnicode(string val)
    {
        Encoding utf8 = Encoding.UTF8;
        Encoding unicode = Encoding.Unicode;

        byte[] utf8Bytes = utf8.GetBytes(val);

        byte[] unicodeBytes = Encoding.Convert(utf8, unicode, utf8Bytes);

        var result = ByteArrayToString(unicodeBytes);
        result = result.Substring(result.Length - 2, 2) + result.Substring(0, result.Length - 2);
        return result;
    }

    public static string ByteArrayToString(byte[] ba)
    {
        StringBuilder hex = new StringBuilder(ba.Length * 2);
        foreach (byte b in ba)
            hex.AppendFormat("{0:x2}", b);
        return hex.ToString();
    }
才能让你更想念 2024-07-28 07:04:58

我对阿拉伯语使用了以下逻辑。IT 需要更多测试。 语言是VB.Net
<代码> <代码>

    If txtArabic.Text.Trim.Length > 0 Then

        Dim unicodeString As String = txtArabic.Text
        Dim unicode As Encoding = Encoding.Unicode
        ' Convert the string into a byte array. 
        Dim unicodeBytes As Byte() = unicode.GetBytes(unicodeString)

        Dim sb As String = ToUnicode(txtArabic.Text)

    End If

>
这是转换部分

私有函数 ToUnicode(ByVal strVal As String)

    Dim unicode As Encoding = New UnicodeEncoding(True, False)
    ' Encoding.Unicode
    Dim utf8 As Encoding = Encoding.UTF8
    Dim utf8Bytes() As Byte = unicode.GetBytes(strVal)
    Dim unicodeBytes() As Byte = Encoding.Convert(utf8, unicode, utf8Bytes)
    Dim result As String = ByteArrayToString(unicodeBytes)

    Return result
End Function

Private Function ByteArrayToString(ByVal ba() As Byte)
    Dim hex As StringBuilder = New StringBuilder(ba.Length)
    For i As Integer = 0 To ba.Length - 1

        If (((i - 2) Mod 4.0) = 0) Then
        Else

            hex.AppendFormat("{0:x00}", ba(i))
            ' hex.Append(ba(i))
        End If
        '   hex.Append("-")
    Next
    Return hex.ToString
End Function

I used following logic for arabic .. IT needs more testing . Language is VB.Net

    If txtArabic.Text.Trim.Length > 0 Then

        Dim unicodeString As String = txtArabic.Text
        Dim unicode As Encoding = Encoding.Unicode
        ' Convert the string into a byte array. 
        Dim unicodeBytes As Byte() = unicode.GetBytes(unicodeString)

        Dim sb As String = ToUnicode(txtArabic.Text)

    End If


Here is the conversion part

Private Function ToUnicode(ByVal strVal As String)

    Dim unicode As Encoding = New UnicodeEncoding(True, False)
    ' Encoding.Unicode
    Dim utf8 As Encoding = Encoding.UTF8
    Dim utf8Bytes() As Byte = unicode.GetBytes(strVal)
    Dim unicodeBytes() As Byte = Encoding.Convert(utf8, unicode, utf8Bytes)
    Dim result As String = ByteArrayToString(unicodeBytes)

    Return result
End Function

Private Function ByteArrayToString(ByVal ba() As Byte)
    Dim hex As StringBuilder = New StringBuilder(ba.Length)
    For i As Integer = 0 To ba.Length - 1

        If (((i - 2) Mod 4.0) = 0) Then
        Else

            hex.AppendFormat("{0:x00}", ba(i))
            ' hex.Append(ba(i))
        End If
        '   hex.Append("-")
    Next
    Return hex.ToString
End Function

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文