def send_phone_code(user_id, verify_token, phone_number):
customer = Customer.objects.get(id=user_id)
# simulating a short delay
sleep(randint(3, 9))
client = TwilioRestClient( # noqa
settings.TWILLO_API_KEY,
settings.TWILLO_AUTH_TOKEN,
)
try:
client.messages.create(
to=phone_number,
from_=settings.TWILLO_FROM_NUMBER,
body="Your Verify Code is {}".format(
verify_token
)
)
# Notify the FE task has completed
Group('phone_verify-%s' % customer.username).send({
'text': json.dumps({
'success': True,
'msg': 'new message sent'
})
})
except TwilioRestException as e:
Group('phone_verify-%s' % customer.username).send({
'text': json.dumps({
'success': False,
'msg': e.msg
})
})
tasks.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录