How to quickly open Tencent cloud messaging services: https://cloud.tencent.com/document/product/382/37745
Indirect configured using python: https://cloud.tencent.com/document/product/382/11672
Personal use of experience (the example below is my personal project used)
Encapsulated into a package
settings.py
# SMS application AppID SDK APPID = 1,400,009,099 # SDK AppID at the beginning of 1400 # messaging applications AppKey SDK APPKEY = " 9ff91d87c2cd7cd0ea762f141975d1df37481d48700d70ac37470aefc60f9bad " # SMS templates ID, need to apply for the SMS console TEMPLATE_ID = 7839 # NOTE: this is only an example of template ID`7839` the real need to apply the template ID in the message console # signature SMS_SIGN = " Tencent cloud " # NOTE: signature parameters used are `` signature content, rather than `signature ID`. Here's signature "Tencent cloud" is just an example, the real need to apply for signature in SMS console
sms.py
from qcloudsms_py Import SmsSingleSender from .settings Import * from luffyapi.utils.logging Import Logger Import Random # ssl security verification system mac Import ssl ssl._create_default_https_context = ssl._create_unverified_context sender = SmsSingleSender(APPID,APPKEY) class Send_sms: def __init__(self,mobile,exp): self.mobile = mobile self.code = self.get_code() self.exp = exp # SMS module DEF send_sms (Self): the try : response = sender.send_with_param(86, self.mobile, TEMPLATE_ID, (self.code, self.exp), sign=SMS_SIGN, extend="", ext="") except Exception as e: logger.error('sms error: %s' % e) return False if response and response['result'] == 0: return True logger.error('sms error:%s' % response['errmsg']) return False # Random verification code generating module DEF GET_CODE (Self): self.code = '' for i in range(4): self.code += str(random.randint(0, 9)) return self.code
__init__.py
from .sms import Send_sms
remind:
Do not forget to install the module qcloudsms_py, following instructions
pip install qcloudsms_py
How to quickly open Tencent cloud messaging services: https://cloud.tencent.com/document/product/382/37745
Indirect configured using python: https://cloud.tencent.com/document/product/382/11672
Personal use of experience (the example below is my personal project used)
Encapsulated into a package
settings.py
# SMS application AppID SDK APPID = 1,400,009,099 # SDK AppID at the beginning of 1400 # messaging applications AppKey SDK APPKEY = " 9ff91d87c2cd7cd0ea762f141975d1df37481d48700d70ac37470aefc60f9bad " # SMS templates ID, need to apply for the SMS console TEMPLATE_ID = 7839 # NOTE: this is only an example of template ID`7839` the real need to apply the template ID in the message console # signature SMS_SIGN = " Tencent cloud " # NOTE: signature parameters used are `` signature content, rather than `signature ID`. Here's signature "Tencent cloud" is just an example, the real need to apply for signature in SMS console
sms.py
from qcloudsms_py Import SmsSingleSender from .settings Import * from luffyapi.utils.logging Import Logger Import Random # ssl security verification system mac Import ssl ssl._create_default_https_context = ssl._create_unverified_context sender = SmsSingleSender(APPID,APPKEY) class Send_sms: def __init__(self,mobile,exp): self.mobile = mobile self.code = self.get_code() self.exp = exp # SMS module DEF send_sms (Self): the try : response = sender.send_with_param(86, self.mobile, TEMPLATE_ID, (self.code, self.exp), sign=SMS_SIGN, extend="", ext="") except Exception as e: logger.error('sms error: %s' % e) return False if response and response['result'] == 0: return True logger.error('sms error:%s' % response['errmsg']) return False # Random verification code generating module DEF GET_CODE (Self): self.code = '' for i in range(4): self.code += str(random.randint(0, 9)) return self.code
__init__.py
from .sms import Send_sms
remind:
Do not forget to install the module qcloudsms_py, following instructions
pip install qcloudsms_py