- 自用验证码的接收webhook, 基于django-ninja, redis
- 提供/api/getCode和/api/sendSmsMsg 2个接口
- 整体步骤如下:
- 业务方手动或自动触发发送短信验证码, 然后调用SmsCodeWebook的/api/getCode, 等待返回验证码;
- 移动端(android等) 使用工具(如SmsForwarder) 监听手机短信
- 当工具监听到验证码短信时, 调用SmsCodeWebook的/api/sendSmsMsg接口发送短信内容;
- SmsCodeWebook接受到短信内容后, 将验证码从短信中匹配出来, 存到redis中;
- SmsCodeWebook从redis取出key, 返回验证码给业务方。
POST /api/sendSmsMsg
发送验证码短信原文
{
"sms_msg": "请确认本人操作,切勿泄露给他人。您正在新设备上登录,验证码:475431。"
}
POST /api/getCode
获取验证码
{
"phone_number": "13500000000"
}
pip install -r requirements.txt
自行安装
复制settings_example.py, 重命名为settings.py
编辑settings.py
redis_host = '127.0.0.1'
redis_port = '6379'
redis_pass = '123456'
redis_database = '0'
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': f'redis://:{redis_pass}@{redis_host}:{redis_port}/{redis_database}',
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
}
}
}
python manage.py runserver