当前位置:网站首页>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
———————————————
边栏推荐
- Minio upload file ssl certificate is not trusted
- MySQL8--Windows下使用压缩包安装的方法
- 剑指offer专项突击版 ---- 第1天
- Flask-based three-party login process
- Temporal介绍
- <urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍
- 基于flask的三方登陆的流程
- MYSQL下载及安装完整教程
- MYSQL一站式学习,看完即学完
- 【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试
猜你喜欢
随机推荐
datagrip带参sql查询
Redis 事务学习有感
Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode
Interviewer, don't ask me to shake hands three times and wave four times again
Temporal介绍
剑指offer基础版 ----- 第28天
剑指offer专项突击版 ---- 第2天
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
CentOS7 - yum install mysql
Qt Creator + CMake 运行调试总会自动 build 所有目标
Flink sink redis writes to Redis
pytorch中的一维、二维、三维卷积操作
对list集合进行分页,并将数据显示在页面中
Flink sink ES 写入 ES(带密码)
剑指offer专项突击版 --- 第 4 天
【C语言3个基本结构详解——顺序、选择、循环】
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
【MQ我可以讲一个小时】
MySQL8--Windows下使用压缩包安装的方法
Element concatenation operations in numpy and pytorch: stack, concatenat, cat