1)官网注册实名账号:https://cloud.tencent.com
2)选取短信服务创建短信应用
3)申请签名与短信模板 - 通过微信公众号申请
### 未封装版# 短信应用 SDK AppID - SDK AppID 以1400开头 appid = ... # 短信应用 SDK AppKey appkey = "..." # 短信模板ID,需要在短信控制台中申请 template_id = ... # 签名 - 是`签名内容`,而不是`签名ID` sms_sign = "..." # 需要发送短信的手机号码 phone_number = ['...'] from utils.logging import logger from qcloudsms_py import SmsSingleSender import random def get_code(): code = '' for i in range(4): code += str(random.randint(0, 9)) return code if __name__ == '__main__': ssender = SmsSingleSender(appid, appkey) # 短信模板中的占位符实际的值 code = get_code() print(code) params = [ code, 5] try: result = ssender.send_with_param(86, phone_numbers[1],template_id, params, sign=sms_sign, extend="", ext="") print(result) if result and result['result'] == 0: print('短信发送成功') except Exception as e: print(e) logger.warning(e) print("短信发送失败")