当前位置:网站首页>The process and specific code of sending SMS verification code using flask framework
The process and specific code of sending SMS verification code using flask framework
2022-07-31 05:34:00 【The flowers are blooming in the south of the city^】
1. Flow chart of obtaining SMS verification code

2. Ronglian Cloud Configuration
Register an account on Ronglian Cloud's official website and use three IDs to send SMS verification codes
ACCOUNT SID (Master Account ID)
AUTH TOKEN (Account Authorization Token)
AppID (AppID)

3. Add test phone number (required)

4. Install Ronglian Cloud SDK on the flask backend
pip install ronglian_sms_sdk
Send SMS to call configuration
import jsonfrom ronglian_sms_sdk import SmsSDK def send_message(sms_code,mobile,expire=5):sms_sdk = SmsSDK(accId='8aaf03013************************',appId='8aaf07087f77bf96017fddbf5f3e3334',accToken='b2033c3b6d3b4dd6b931a138a8246af1')tid = '1'datas = ("%s"%sms_code,"%s"%expire) res = sms_sdk.sendMessage(tid=tid,mobile=mobile,datas=datas)resd=json.loads(res)return resd
Send verification code view
Here is to use the mobile phone number as the key when saving into redis
import redisfrom flask import jsonifyfrom flask_restful import Resource,reqparse # Generate and store SMS verification code class Scode(Resource):def get(self):paser = reqparse.RequestParser()Paser.add_argument('mobile') args = paser.parse_args()mobile = args.get('mobile') sms_code = random.randint(100000,999999)send_message(sms_code,mobile) # Store the verification code in redisr = redis.Redis(host='localhost',db=0,port=6379)sms_key = "sms_code:%s"%mobiler.set(sms_key,sms_code,ex=300) print("<<>>",sms_code) Return jsonify(msg = "The verification code has been sent, please pay attention to check",code=200)
Trigger the function to get the verification code and send it successfully
———————————————
边栏推荐
- [mysql improves query efficiency] Mysql database query is slow to solve the problem
- 剑指offer专项突击版 ---- 第2天
- Lock wait timeout exceeded解决方案
- C语言教程(三)-if和循环
- Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
- a different object with the same identifier value was already associated with the session
- MySQL (updating)
- 剑指offer基础版 ----- 第25天
- [MQ I can speak for an hour]
- CentOS7 - yum install mysql
猜你喜欢
随机推荐
剑指offer专项突击版 --- 第 4 天
基于web3.0使用钱包Metamask的三方登陆
Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
C语言指针详解
uni-app进阶之生命周期【day8】
mysql 的简单运用命令
【一起学Rust】Rust学习前准备——注释和格式化输出
Linux系统安装mysql(rpm方式安装)
Simple command of mysql
【MySQL8入门到精通】基础篇- Linux系统静默安装MySQL,跨版本升级
如何将项目部署到服务器上(全套教程)
Go中间件
MYSQL下载及安装完整教程
MySQL8.0.26安装配置教程(windows 64位)
剑指offer基础版 ---- 第26天
对list集合进行分页,并将数据显示在页面中
关于LocalDateTime的全局返回时间带“T“的时间格式处理
剑指offer基础版 --- 第24天
mysql5.7.35安装配置教程【超级详细安装教程】
剑指offer基础版 --- 第22天








