当前位置:网站首页>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
———————————————
边栏推荐
- 初涉C语言
- Redis 事务学习有感
- 第7章 网络层第3次练习题答案(第三版)
- Unity mobile game performance optimization series: performance tuning for the CPU side
- 三次握手与四次挥手
- Sword Point Offer Special Assault Edition ---- Day 1
- 【C语言趣味小游戏——猜数字】
- 为什么要用Flink,怎么入门使用Flink?
- 一文了解大厂的DDD领域驱动设计
- Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
猜你喜欢

剑指offer专项突击版 ---- 第 6 天

Shell重油常压塔模拟仿真与控制

Temporal介绍
![<urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍](/img/a4/8c75fab6a9858c5ddec25f6a8300fb.png)
<urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍

Interviewer, don't ask me to shake hands three times and wave four times again

【MQ我可以讲一个小时】

Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.

剑指offer基础版 ----- 第28天

关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)

Anaconda配置环境指令
随机推荐
MySQL-如何分库分表?一看就懂
实验7 UDP与TCP对比
Paginate the list collection and display the data on the page
第7章 网络层第1次练习题答案(第三版)
数据库上机实验3 连接查询和分组查询
剑指offer基础版--- 第23天
Redis管道技术/分区
关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
剑指offer基础版 ----- 第28天
Sword Point Offer Special Assault Edition ---- Day 2
Redis first meeting
If the account number or password is entered incorrectly for many times, the account will be banned.
联盟链的真实场景在哪里
C语言教程(二)-printf及c自带的数据类型
About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
剑指offer基础版 ----第31天
Quickly master concurrent programming --- the basics
Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
Lock wait timeout exceeded解决方案
Refinement of the four major collection frameworks: Summary of List core knowledge