-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms.py
40 lines (34 loc) · 1.27 KB
/
sms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
""" for token see passwords.json
https://ssl.smsapi.com/#/payments/transfer/success
"""
from smsapi.client import SmsApiComClient
from smsapi.exception import SmsApiException
from flask_babel import _
import json
import logging
logging.basicConfig(level=logging.INFO)
def send_code(phone, code):
""" code = str, phone number with country code 33607182594 """
token = json.load(open("keys.json", "r"))["sms_token"]
logging.info("trying to send %s to %s", code, phone)
try:
client = SmsApiComClient(access_token=token)
send_results = client.sms.send(to=phone, message=_(
"# Your verification code is : ") + code)
for result in send_results:
logging.info('result = %s %s %s', result.id,
result.points, result.error)
return True
except SmsApiException as e:
logging.error('%s', e.message)
return False
def check_phone(phone):
token = json.load(open("keys.json", "r"))["sms_token"]
try:
client = SmsApiComClient(access_token=token)
client.sms.send(to=phone, message=_(
"Your phone number has been verified."))
return True
except SmsApiException as e:
logging.error('sms api message = %s', e.message)
return False