腾讯云短信 redis

开通腾讯云短信mysql

  一、官网注册实名帐号:https://cloud.tencent.com
  二、选取短信服务建立短信应用
  三、申请签名与短信模板 - 经过微信公众号申请redis

腾讯云短信二次封装  libs文件夹下建立txsms包sql

libs/txsms/settings.py      数据库

# 短信应用 SDK AppID - SDK AppID 以1400开头
APP_ID = ...
# 短信应用 SDK AppKey
APP_KEY = "..."
# 短信模板ID,须要在短信控制台中申请
TEMPLATE_ID = ...
# 签名 - 是`签名内容`,而不是`签名ID`
SMS_SIGN= "..."
# 电话前缀
MOBILE_PREFIX = 86

libs/txsms/sms.py  luffyapi终端下  pip install qcloudsms_pydjango

# 经过MacOS ssl安全认证
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

# 获取验证码的功能
import random
def get_code():
    code = ''
    for i in range(4):
        code += str(random.randint(0, 9))
    return code

# 短信发送者
from qcloudsms_py import SmsSingleSender
from .settings import *
sender = SmsSingleSender(APP_ID, APP_KEY)

# 发送验证码
from utils.logging import logger
def send_sms(mobile, code, exp):
    try:
        # 发送短信
        response = sender.send_with_param(MOBILE_PREFIX, mobile, TEMPLATE_ID, (code, exp), sign=SMS_SIGN, extend="", ext="")
        # 成功
        if response and response['result'] == 0:
            return True
        # 失败
        logger.warning('%s - %s' % ('短信发送失败', response['result']))
    except Exception as e:
        # 异常
        logger.warning('%s - %s' % ('短信发送失败', e))
    return False

libs/txsms/__init__.pyapi

from .sms import get_code, send_sms

scripts/t_sms.py数组

from libs import txsms
code = txsms.get_code()
print(code)
print(txsms.send_sms('电话', code, 5))

redis数据库缓存

一、redis是内存 no-sql 数据库,相比mysql等硬盘数据库效率高
二、在内存值配置数据库使用,而不直接使用内存,redis存储的数据是能够管理的
三、memcache也是内存数据库,且django默认采用的就是memcache数据库,用redis替换memcache的路由很简单,后者更强大
    redis支持更多的数据类型
    redis自带缓存机制,出现数据库系统崩溃数据也是能够有找回的功能
    redis能够主动完成数据持久化(自带数据持久化功能)
    redis的数据过时时间机制也能够自身完成安全

redis数据类型微信

  支持的数据类型:String、Hash、List、Set、Sorted Set  String:存储其余类型不能存的全部数据  Hash:存储 key-value 形式数据,相似于字典  List:存储 一系列有序value 形式数据,列表(数组)  Set:存储 一系列无序value 形式数据,集合  Sorted Set:存储 有排列标号value 形式数据,排行

相关文章
相关标签/搜索