当前位置:网站首页>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
———————————————
边栏推荐
- 剑指offer基础版 ---- 第29天
- 数据库上机实验6 数据库完整性
- Minio upload file ssl certificate is not trusted
- TOGAF之架构标准规范(一)
- Quickly master concurrent programming --- the basics
- MySQL-如何分库分表?一看就懂
- 1D, 2D, 3D convolution operations in pytorch
- C语言的文件操作(一)
- docker安装postgresSQL和设置自定义数据目录
- Input length must be multiple of 8 when decrypting with padded cipher
猜你喜欢
随机推荐
精解四大集合框架:List 核心知识总结
wpf ScrowViewer水平滚动
datagrip带参sql查询
数据库上机实验5 数据库安全性
基于web3.0使用钱包Metamask的三方登陆
1D, 2D, 3D convolution operations in pytorch
MySQL8.0安装教程,在Linux环境安装MySQL8.0教程,最新教程 超详细
剑指offer专项突击版 ---- 第1天
Element concatenation operations in numpy and pytorch: stack, concatenat, cat
Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
三次握手与四次挥手
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
【C语言3个基本结构详解——顺序、选择、循环】
数据库学习笔记
C语言教程(三)-if和循环
Data set partitioning and cross-validation
Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
Quickly master concurrent programming --- the basics
Workflow番外篇
【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试