N
N
n1kto3112020-11-09 22:08:07
Python
n1kto311, 2020-11-09 22:08:07

How to send sms using unicode via api gateway?

In general, I chose a site to send SMS on behalf of my company. But by default, there is no way to send SMS in Russian. I wrote to support, here's what they told me. But I can't figure out what the code should look like. Can someone show an example? With filled lines for example. Help me please. I am attaching the default code and the answer to my appeal to the question. Thanks for answers.5fa99346760c5529331875.png5fa9934d99c0a576114630.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Drill, 2020-11-10
@n1kto311

In principle, technical support gave you a ready-made code.
It is necessary to encode the SMS body itself in UCS-2.
UCS-2 is a character encoding standard in which characters are represented by 16 fixed length bits (2 bytes). It is used as a fallback in many GSM networks when the message cannot be encoded with GSM-7 or when the language requires more than 128 characters to display (eg UTF-8).
View Unicode UCS-2 Code Chart

from binascii import hexlify

url = "..."
querystring = {..., ...,}
headers = {...}

content = querystring['content'].encode('utf-16-be')
querystring['content'] = hexlify(content).decode('utf-8')

responce = request.....

For example:

from binascii import hexlify
querystring = {'content': 'Привет'}
content = querystring['content'].encode('utf-16-be')
querystring['content'] = hexlify(content).decode('utf-8')
print(querystring)

In [4]:
{'content': '041f04400438043204350442'}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question