首页 技术 正文
技术 2022年11月16日
0 收藏 851 点赞 3,815 浏览 2673 个字

阿里大于短信平台:https://dysms.console.aliyun.com/dysms.htm

使用教程:https://blog.csdn.net/qq1031893936/article/details/81173878

控制台–>短信服务

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

进去后开通服务,点击添加签名

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

根据自己的情况设置

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

审核通过后,添加模板

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

添加对应的内容

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

需要用到的两个数据:签名名称、模板CODE

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

创建AccessKey

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

实现调接口发验证码:由于使用这个验证码需要购买套餐,所以这里就只封装发短信的模块就行

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

# 阿里大于相关配置
ALIDAYU_APP_KEY = 'LTAI4FmvBxyEb5Sip5b4PbZo' # AccessKey
ALIDAYU_APP_SECRET = '25zBQkqQNXjzwVDHH4m2I6qyoZlxOp' # AccessKeySecret
ALIDAYU_SIGN_NAME = 'cms' # 签名名称
ALIDAYU_TEMPLATE_CODE = 'SMS_178771780' # 模板id

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

# 阿里大于短信验证码sdk
import hashlib
from time import time
import logging
import requestsclass AlidayuAPI(object):
APP_KEY_FIELD = 'ALIDAYU_APP_KEY'
APP_SECRET_FIELD = 'ALIDAYU_APP_SECRET'
SMS_SIGN_NAME_FIELD = 'ALIDAYU_SIGN_NAME'
SMS_TEMPLATE_CODE_FIELD = 'ALIDAYU_TEMPLATE_CODE' def __init__(self, app=None):
self.url = 'https://eco.taobao.com/router/rest'
self.headers = {
'Content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
"Cache-Control": "no-cache",
"Connection": "Keep-Alive",
}
if app:
self.init_app(app) def init_app(self, app):
config = app.config
try:
self.key = config[self.APP_KEY_FIELD]
self.secret = config[self.APP_SECRET_FIELD]
self.sign_name = config[self.SMS_SIGN_NAME_FIELD]
self.api_params = {
'sms_free_sign_name': config[self.SMS_SIGN_NAME_FIELD],
'sms_template_code': config[self.SMS_TEMPLATE_CODE_FIELD],
'extend': '',
'sms_type': "normal",
"method": "alibaba.aliqin.fc.sms.num.send",
"app_key": self.key,
"format": "json",
"v": "2.0",
"partner_id": "",
"sign_method": "md5",
}
except Exception as e:
logging.error(e.args)
raise ValueError('请填写正确的阿里大鱼配置!') def send_sms(self, telephone, **params):
self.api_params['timestamp'] = str(int(time() * 1000))
self.api_params['sms_param'] = str(params)
self.api_params['rec_num'] = telephone newparams = "".join(["%s%s" % (k, v) for k, v in sorted(self.api_params.items())])
newparams = self.secret + newparams + self.secret
sign = hashlib.md5(newparams.encode("utf-8")).hexdigest().upper()
self.api_params['sign'] = sign resp = requests.post(self.url, params=self.api_params, headers=self.headers)
data = resp.json()
try:
result = data['alibaba_aliqin_fc_sms_num_send_response']['result']['success']
return result
except:
print('=' * 10)
print("阿里大于错误信息:", data)
print('=' * 10)
return False

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail
from utils.alidayu import AlidayuAPIdb = SQLAlchemy()
mail = Mail()
alidayu = AlidayuAPI()

一百一十六:CMS系统之使用阿里大于sdk发送短信验证码

from flask import Flask
from apps.cms import bp as cms_bp
from apps.front import bp as front_bp
from apps.common import bp as common_bp
import config
from exts import db, mail, alidayu
from flask_wtf import CSRFProtectdef create_app():
app = Flask(__name__)
app.config.from_object(config) app.register_blueprint(cms_bp)
app.register_blueprint(front_bp)
app.register_blueprint(common_bp) db.init_app(app)
mail.init_app(app)
alidayu.init_app(app)
CSRFProtect(app) return appif __name__ == '__main__':
app = create_app()
app.run(port=8000)
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,084
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,559
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,408
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,181
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,818
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,901