libs->tx_sms->send_sms.py
- from qcloudsms_py import SmsMultiSender, SmsSingleSender
- from qcloudsms_py.httpclient import HTTPError
- import ssl
- ssl._create_default_https_context = ssl._create_unverified_context
- def get_code():
-     import random
-     return str(random.randint(100000, 999999))
- def send_message(phone_num, template_param_list, template_id='951999'):
-     """
-         phone_num:手机号
-         template_id:短信模板ID
-         template_param_list:短信模板需要的参数:例如(参数1,参数2)
-     """
-     appid = '1400519000'  # 应用列表:SDK App
-     appkey = 'db79dbade68a6f06d5594f7fabffeb87'  # 应用列表:App Key
-     sms_sign = '小蜗'  # 腾讯云创建的签名
-     sender = SmsSingleSender(appid, appkey)
-     try:
-         response = sender.send_with_param(86, phone_num, template_id, template_param_list, sign=sms_sign)
-         print(response)
-     except HTTPError as e:
-         response = {'code': 500, 'errmsg': "网络异常发送失败"}
-     return response
- if __name__ == '__main__':
-     send_message(phone_num='17615405023',template_param_list=[get_code()])
调用
- from libs.tx_sms import send_sms
- code = send_sms.get_code()
- phone = '17615405023'
- send_sms.send_message(phone_num=phone,template_param_list=[gcode,])