tasks.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:django-channels-celery-websocket-example 作者: rollokb 项目源码 文件源码
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
            })
        })
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号