Exemple #1
0
def send_sms_multi(phone_num_list, template_id, param_list):
    """
    批量发送短信
    :param phone_num_list:手机号列表
    :param template_id:腾讯云短信模板ID
    :param param_list:短信模板所需参数列表,例如:【验证码:{1},描述:{2}】,则传递参数 [888,666]按顺序去格式化模板
    :return:
    """
    appid = settings.TENCENT_SMS_APP_ID  # 自己应用ID
    appkey = settings.TENCENT_SMS_APP_KEY  # 自己应用Key
    sms_sign = settings.TENCENT_SMS_SIGN

    sender = SmsMultiSender(appid, appkey)
    try:
        response = sender.send_with_param(86,
                                          phone_num_list,
                                          template_id,
                                          param_list,
                                          sign=sms_sign)
    except HTTPError as e:
        response = {'result': 1000, 'errmsg': "网络异常发送失败"}
    return response


# if __name__ == '__main__':
#     result1 = send_sms_single("15131255089", 548760, [666, ])
#     print(result1)
#
#     result2 = send_sms_single( ["15131255089", "15131255089", "15131255089", ],548760, [999, ])
#     print(result2)
Exemple #2
0
def send_more_with_template(params):
    msender = SmsMultiSender(appid, appkey)
    # params = ["8888", "登录", "0"]
    try:
        result = msender.send_with_param(86, phone_numbers, template_id, params, sign=sms_sign, extend="", ext="")
    except HTTPError as e:
        print(e)
    except Exception as e:
        print(e)

    print(result)
Exemple #3
0
def send_sms_multi(phone_num_list, template_id, param_list):
    sender = SmsMultiSender(appid, appkey)
    try:
        response = sender.send_with_param(86,
                                          phone_num_list,
                                          template_id,
                                          param_list,
                                          sign=sms_sign)
    except HTTPError as e:
        response = {'result': 1000, 'errmsg': "网络异常发送失败"}
    return response
Exemple #4
0
def send_sms(appid, appkey, template_id,  phone_numbers, sms_content):
    msender = SmsMultiSender(appid, appkey)
    params = [sms_content]
    try:
      result = msender.send_with_param(86, phone_numbers,
          template_id, params, extend="", ext="")
    except HTTPError as e:
      print(e)
    except Exception as e:
      print(e)
    print(result)
Exemple #5
0
def send_sms_multi(phone_num_list, template_id, param_list):
    """
    批量发送短信
    :param phone_num_list:手机号列表
    :param template_id:腾讯云短信模板ID
    :param param_list:短信模板所需参数列表,例如:【验证码:{1},描述:{2}】,则传递参数 [888,666]按顺序去格式化模板
    :return:
    """
    appid = TENCENT_SMS_APPID  # 自己应用ID
    appkey = TENCENT_SMS_APPKEY  # 自己应用Key
    sms_sign = TENCENT_SMS_SIGN  # 自己腾讯云创建签名时填写的签名内容(使用公众号的话这个值一般是公众号全称或简称)
    sender = SmsMultiSender(appid, appkey)
    try:
        response = sender.send_with_param(86, phone_num_list, template_id, param_list, sign=sms_sign)
    except HTTPError as e:
        response = {'result': 1000, 'errmsg': "网络异常发送失败"}
    return response
Exemple #6
0
def send_sms_multi(phone_num_list, template_id, param_list):
    """
    批量发送短信
    :param phone_num_list:手机号列表
    :param template_id:腾讯云短信模板ID
    :param param_list:短信模板所需参数列表,例如:【验证码:{1},描述:{2}】,则传递参数 [888,666]按顺序去格式化模板
    :return:
    """
    appid = settings.TENCENT_SMS_APP_ID
    appkey = settings.TENCENT_SMS_APP_KEY
    sms_sign = settings.TENCENT_SMS_SIGN
    sender = SmsMultiSender(appid, appkey)
    try:
        response = sender.send_with_param(86, phone_num_list, template_id, param_list, sign=sms_sign)
    except HTTPError as e:
        response = {'result': 1000, 'errmsg': "网络异常发送失败"}
    return response
Exemple #7
0
def send_sms_multi(phone_num_list, template_id, param_list):
    """
    批量发送短信
    :param phone_num_list:手机号列表
    :param template_id:腾讯云短信模板ID
    :param param_list:短信模板所需参数列表,例如:【验证码:{1},描述:{2}】,则传递参数 [888,666]按顺序去格式化模板
    :return:
    """
    appid = 112142311
    appkey = "8cc5b87123y423423412387930004"
    sms_sign = "Python之路"
    sender = SmsMultiSender(appid, appkey)
    try:
        response = sender.send_with_param(86, phone_num_list, template_id, param_list, sign=sms_sign)
    except HTTPError as e:
        response = {'result': 1000, 'errmsg': "网络异常发送失败"}
    return response
Exemple #8
0
def send_sms_multi(phone_num_list, template_id, param_list):
    appid = settings.TENCENT_SMS_APP_ID  # SDK AppID 以1400开头
    # 短信应用 SDK AppKey
    appkey = settings.TENCENT_SMS_APP_KEY
    # 签名
    sms_sign = settings.TENCENT_SMS_APP_SIGN
    sender = SmsMultiSender(appid, appkey)
    try:
        response = sender.send_with_param(86,
                                          phone_num_list,
                                          template_id,
                                          param_list,
                                          sign=sms_sign,
                                          extend="",
                                          ext="")
    except HTTPError as e:
        response = {'result': 1000, 'errmsg': '网络异常发送失败'}
    return response
Exemple #9
0
def send_sms_multi(phone_num_list, template_id, param_list):
    """
    批量發送短信
    :param phone_num:手機號
    :param template_id:騰訊雲短信模板ID
    :param param_list:短信模板所需參數列表,例如:[驗證碼:{1}, 描述:{2}],則傳遞 參數[888, 666]按順尋去格式化模板
    :return:
    """
    appid = TENCENT_SMS_APP_ID
    appkey = TENCENT_SMS_APP_KEY
    sms_sign = TENCENT_SMS_SIGN

    sender = SmsMultiSender(appid, appkey)
    try:
        response = sender.send_with_param(86, phone_num_list, template_id, param_list, sign=sms_sign)
    except HTTPError as e:
        response = {'result': 1000, 'errmsg': "網絡異常發送失敗 "}
    return response
Exemple #10
0
def send_sms_multi(phone_num_list, template_id, param_List):
    """
    批量发送短信
    :param phone_num_list: 手机号列表
    :param template_id: 腾讯云短信模板ID
    :param param_List: 短信模板所需参数列表
    :return:
    """
    appid = settings.TENCENT_SMS_APP_ID  # 自己应用ID
    appkey = settings.TENCENT_SMS_APP_KEY  # 自己应用key
    sms_sign = settings.TENCENT_SMS_SIGN
    sender = SmsMultiSender(appid, appkey)
    try:
        response = sender.send_with_param(86,
                                          phone_num_list,
                                          template_id,
                                          param_List,
                                          sign=sms_sign)
    except HTTPError as e:
        response = {'result': 1000, 'errmsg': '网络异常发送失败'}
    return response
Exemple #11
0
class SmsService(object):
    def __init__(self, appid, appkey, sign):
        """

        :param appid: sms appid
        :param appkey: sms appkey
        :param sign: 短信签名
        """
        self.sender = SmsMultiSender(appid, appkey)
        self.sign = sign

    def send_msg(self, tos, template_id, *params):
        """
        :param template_id: 短信模板id
        :param tos: phone number, list
        :param params: 模板的占位符值
        :return: None
        """
        if not tos:
            return None
        try:
            result = self.sender.send_with_param(86,
                                                 tos,
                                                 template_id,
                                                 params=params,
                                                 sign=self.sign)
            if result['result'] != 0:
                logging.error('Failed to send sms due to: {}'.format(
                    result['errmsg']))
            else:
                for d in result['detail']:
                    if d['result'] != 0:
                        logging.error(
                            'Failed to send sms to {} due to: {}'.format(
                                d['mobile'], d['errmsg']))
        except HTTPError as e:
            logging.error('Failed to send sms due to HTTPError: {}'.format(e))
        except Exception as e:
            logging.error('Failed to send sms due to Error: {}'.format(e))
    def sendMsg(self, params):
        '''
        发送短信消息,传入的params 是短信的参数
        '''

        # 参数赋值
        self.setConfig()
        # print('------ A')
        # print(self.appkey)
        # print('------ B')

        # 短信应用 SDK AppID
        appid = self.appid  # SDK AppID 以1400开头
        # 短信应用 SDK AppKey
        appkey = self.appkey
        # 需要发送短信的手机号码
        phone_numbers = self.phone_numbers
        # 短信模板ID,需要在短信控制台中申请
        template_id = self.template_id  # NOTE: 这里的模板 ID`7839`只是示例,真实的模板 ID 需要在短信控制台中申请
        # 签名
        sms_sign = self.sms_sign  # NOTE: 签名参数使用的是`签名内容`,而不是`签名ID`。这里的签名"腾讯云"只是示例,真实的签名需要在短信控制台中申请
        # 短信区域,中国区域填写86就对了
        sms_zone = self.sms_zone

        msender = SmsMultiSender(appid, appkey)
        # params = ["页面校对失败"]

        result = msender.send_with_param(sms_zone,
                                         phone_numbers,
                                         template_id,
                                         params,
                                         sign=sms_sign,
                                         extend="",
                                         ext="")

        return result
Exemple #13
0
 def send_message_by_tencent(self, service, phone_arr):
     """
     通过腾讯云发送消息至用户
     短信模板示例: 您有新的消息通知:发起人:{1},内容为:{2},请及时登录系统处理!
     :param service: 
     :param phone_arr:
     :return: 
     """
     template_id, sms_sign, timeout = self._get_config_template(
         service, 'send_message')
     if not template_id or not sms_sign or not timeout:
         return {
             "state": False,
             'msg': "在(短信服务配置)中没有找到可用于(用于Odoo通知消息)的模板,请联系管理员设置!"
         }
     msender = SmsMultiSender(service.app_id, service.app_key)
     # 传递短信模板参数{1}为验证码, {2}为有效时长
     params = [self.env.user.name, self.message]
     try:
         result = msender.send_with_param(86,
                                          phone_arr,
                                          template_id,
                                          params,
                                          sign=sms_sign,
                                          extend="",
                                          ext="")
         logging.info("tencent-sms-result:{}".format(result))
         if result['result'] == 0:
             return {"state": True}
         else:
             return {
                 "state": False,
                 'msg': "发送消息失败!,Error:{}".format(result['errmsg'])
             }
     except Exception as e:
         return {"state": False, 'msg': "发送消息失败,Error:{}".format(str(e))}
Exemple #14
0
def send_tsms_multi(phones, template_id, params):
    msender = SmsMultiSender(TSMS_APP_ID, TSMS_APP_KEY)
    try:
        msender.send_with_param(86, phones, template_id, params)
    except Exception as e:
        print(e)