1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
from .settings import appid,appkey,template_id,sms_sign from qcloudsms_py import SmsSingleSender from luffyapi.utils.logger import logger import random def get_code(): code = '' for i in range(6): code += str(random.randint(0,9)) print(code) return code
def send_code(phone,code,): ssender = SmsSingleSender(appid, appkey) params = [code,'3'] # 当模板没有参数时,`params = []` try: result = ssender.send_with_param(86, phone,template_id, params, sign=sms_sign, extend="", ext="") if result.get('result') == 0: return True else: return False except Exception as e: logger.error('手机号:%s,短信发送异常:%s' %(phone,str(e)))
|