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 __init__(self, appid, appkey, sign):
        """

        :param appid: sms appid
        :param appkey: sms appkey
        :param sign: 短信签名
        """
        self.sender = SmsMultiSender(appid, appkey)
        self.sign = sign
Exemple #3
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 #4
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 #5
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 #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):
    """
    批量发送短信
    :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 #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):
    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 #11
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 #12
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))}
    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 #14
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))
Exemple #15
0
def AlertHandler():
    body = request.get_data()
    logger.debug(body)
    try:
        v = json.loads(body)
    except Exception as err:
        logger.warn("json decode error, err=%s, body=%s" % (err, body))
        return '{"code":1,"msg":"json decode error"}'
    else:
        if "state" in v and v["state"] == "alerting":
            if "evalMatches" in v:
                value_str = ""
                for i in range(len(v["evalMatches"])):
                    if "value" not in v["evalMatches"][i]:
                        continue
                    value = v["evalMatches"][i]["value"]
                    if value < 0:
                        # value如果小于0表明数据回退了,这里忽略告警
                        return '{"code":0,"msg":"ok"}'
                    if "tags" not in v["evalMatches"][i]:
                        if value_str == "":
                            value_str += "当前值%d已超出" % value
                        else:
                            value_str += ",当前值%d已超出" % value
                    else:
                        tags = v["evalMatches"][i]["tags"]
                        if "host" in tags:
                            host = tags["host"]
                            if value_str == "":
                                value_str += "%s当前值%d已超出" % (host, value)
                            else:
                                value_str += ",%s当前值%d已超出" % (host, value)
                        else:
                            if value_str == "":
                                value_str += "当前值%d已超出" % value
                            else:
                                value_str += ",当前值%d已超出" % value

                rule_name = ""
                if "ruleName" in v:
                    rule_name = v["ruleName"]
                else:
                    return '{"code":2,"msg":"missing ruleName"}'

                alert_str = "%s,%s" % (rule_name, value_str)
                time_str = " [" + time.strftime('%m-%d %H:%M', time.localtime(time.time())) + "]"
                msg = alert_str + time_str
                logger.warn(msg)

                # message目前保存的是负责人,多个负责人用;分隔
                message = ""
                if "message" in v:
                    message = v["message"]
                managers = message.split(";")
                phone_nums = []
                for i in range(len(managers)):
                    person = managers[i]
                    if person in GlobalConfig.sms_phone_nums:
                        phone_num = GlobalConfig.sms_phone_nums[person]
                        phone_nums.append(phone_num)
                if GlobalConfig.sms_send == True and len(phone_nums) > 0:
                    msender = SmsMultiSender(GlobalConfig.sms_appid, GlobalConfig.sms_appkey)
                    try:
                        result = msender.send(0, "86", phone_nums, msg)
                    except HTTPError as e:
                        logger.warn("msender err=%s" % e)
                    except Exception as e:
                        logger.warn("msender err=" % e)
        return '{"code":0,"msg":"ok"}'
Exemple #16
0
app.mysql_pool = PooledDB(creator=pymysql, **mysql_config, **pool_config)

# 初始化打印机
pymemobird.http_proxy = app.config['PROXY']['http_proxy']
_key = app.config['PRINTER']['access_key']
_id = app.config['PRINTER']['user_identify']
_user = pymemobird.User(_key, _id)
_machine = app.config['PRINTER']['memobird_id']
_device = pymemobird.Device(_machine)
_device.bind_user(_user)
app.printer = _device

# 初始化SMS
_appid = app.config['SMS']['appid']
_appkey = app.config['SMS']['appkey']
app.sms = SmsMultiSender(_appid, _appkey)

# 初始化路由
app.register_blueprint(webpage_blue, url_prefix='/webpage')
app.register_blueprint(network_blue, url_prefix='/network')
app.register_blueprint(message_blue, url_prefix='/message')
app.register_blueprint(monitor_blue, url_prefix='/monitor')
app.register_blueprint(payment_blue, url_prefix='/payment')
CORS(app, supports_credentials=True, resources={r"/*": {"origins": "*"}})


@app.route('/')
def hello_world():
    return Kit.common_rsp("Hello, world!")

Exemple #17
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)
Exemple #18
0
from qcloudsms_py import SmsMultiSender
from qcloudsms_py.httpclient import HTTPError

from tools.sms_config import appid, appkey, phone_numbers

sms_type = 0  # Enum{0: 普通短信, 1: 营销短信}
msender = SmsMultiSender(appid, appkey)
try:
    result = msender.send(sms_type,
                          "86",
                          phone_numbers,
                          "【腾讯云】您的验证码是: 5678",
                          extend="",
                          ext="")
except HTTPError as e:
    print(e)
except Exception as e:
    print(e)

print(result)