Digitally connected world use automated messages in heavy way. Bills, rent, One Time Passwords there are unlimited scopes of an Automated text.
数字连接的世界大量使用自动消息。 账单,租金,一次性密码无限范围的自动文本。
Suppose you own a mini store and a new item arrives and you want to notify 50 to 100 of your clients. How would you do?, Easy— Text them, Automatically.
假设您拥有一家迷你商店,并且有一个新商品到达,并且您想通知50到100个客户。 您会怎么做?,轻松—自动给他们发短信。
Lets setup a SMS Client for quick learning, I found this website www.textlocal.in with reasonable prices in India. It is providing Bulk message options.
让我们设置一个SMS客户端以便快速学习,我在印度找到了价格合理的这个网站www.textlocal.in 。 它提供了群发消息选项。
Create an Account, They give 10 credits, so lets get trying.
创建一个帐户 ,他们会给10点积分,所以让我们尝试一下。
After Sign-up go to Settings >API > Generate a new API Key and save it somewhere safe. You can allow Specific IPs for security, But lets keep the fields empty for now.
注册后,转到“设置”>“ API”>“ 生成新的API密钥”并将其保存在安全的地方。 您可以允许使用特定IP进行安全保护,但是现在让字段为空。
Requests will go to link https://api.textlocal.in/{command} with command-name in command and data in headers.
请求将转到链接https://api.textlocal.in/{command} 在命令中使用command-name,在header中使用data 。
Lets Start Coding Part
让我们开始编码部分
Libraries : For now Just One > “import requests”
图书馆:目前只有“一个”>“ 导入请求”
import requests
url = ‘https://api.textlocal.in/'params = {‘username’:’yourusername@mailid.com’,
‘apiKey’:’yourGenerated-APIKey’
}
Lets write some Functions():
让我们写一些Functions():
def check_balance(url):
url = url+'balance'
response = requests.get(url,params=params)
return response.json()
def send_sms(url,params):
url=url+'send' #Phone numbers inside braces {} in commas
numbers={'9911111xxxx'}
message = {'Hi, This is a Sample message'}
params['numbers'] = numbers
params['message'] = message response = requests.post(url,params=params)
return response.json()
def inbox(url):
url = url+'get_inboxes'
response = requests.get(url,params=params)
return response.json()
Thats it, Code finished!! In 5 minutes you can setup SMS message for single or bulk messages.
就是这样,代码完成了!! 在5分钟内,您可以为单个或批量消息设置SMS消息。
In Next Part I will show you to make a quick app to send message, and OTP confirmation too.
在下一部分中,我将向您展示一个快速的应用程序来发送消息以及OTP确认。
到那时,再见!!!! (Till then, Good Bye!!!!)
翻译自: https://medium.com/@abhinavsharma150/set-up-a-text-message-api-with-python-in-5-minutes-fdfc46b744c3