Tencent launched Cloud SMS
1, the official website of the real-name registration account: HTTPS: //cloud.tencent.com
2, select Create a text messaging service application
3, signed application and SMS templates - through micro-channel public number application
Tencent cloud messaging secondary package libs folder, create a package txsms
libs/txsms/settings.py
# AppID SMS app SDK - SDK AppID beginning to 1400 APP_ID = ... # SMS app SDK AppKey APP_KEY = "..." # SMS template ID, you need to apply for the SMS console TEMPLATE_ID = ... # Signature - is `` signature content, rather than `signature ID` SMS_SIGN= "..." # Telephone Prefix MOBILE_PREFIX = 86
libs / txsms / sms.py luffyapi the terminal pip install qcloudsms_py
# Safety certification by MacOS ssl import ssl ssl._create_default_https_context = ssl._create_unverified_context # Obtain functional verification code import random def get_code(): code = '' for i in range(4): code += str(random.randint(0, 9)) return code # SMS sender from qcloudsms_py import SmsSingleSender from .settings import * sender = SmsSingleSender(APP_ID, APP_KEY) # Send the verification code from utils.logging import logger def send_sms(mobile, code, exp): try: # send messages response = sender.send_with_param(MOBILE_PREFIX, mobile, TEMPLATE_ID, (code, exp), sign=SMS_SIGN, extend="", ext="") # Successful if response and response['result'] == 0: return True # Fail logger.warning ( ' % S -% S ' % ( ' Message not sent ' , Response [ ' Result ' ])) except Exception as e: # Abnormal logger.warning ( ' % S -% S ' % ( ' Message not sent ' , E)) return False
libs/txsms/__init__.py
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 ( ' phone ' , code, . 5 ))
redis database
. 1, the memory redis no-sql database, high efficiency compared to a database mysql a hard disk
2, in the configuration database memory value without directly using the memory, data storage is redis manageable
3, memcache memory is a database, and django memcache database is used by default, memcache replaced by redis routing is very simple, which is more powerful
redis supports more data types
redis own caching mechanism, there is also a database system crash data can be retrieved function
redis can complete the data initiative persistence (data persistence comes with features)
Redis data expiration time mechanism itself can be completed
redis data types
Supported data types: String, Hash, List, the Set, the Set the Sorted
String: all other types of data storage can not be stored
Hash: store key-value in the form of data, similar to the Dictionary
List: storing data in the form of a series of orderly value, the list ( array)
the set: storing data in the form of a series of random value, set
Sorted set: storing a reference value are arranged in the form of data, ranking