赞
踩
密钥获取地址:https://console.cloud.tencent.com/cam/capi
#!/bin/python #-*- coding: utf-8 -*- import json, sys from tencentcloud.common import credential from tencentcloud.common.profile.client_profile import ClientProfile from tencentcloud.common.profile.http_profile import HttpProfile from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException from tencentcloud.sms.v20210111 import sms_client, models def sendtxy(msg,phone_id): try: #json str转成list列表形式,resvered是反转,先title后conetent msg_list=list(reversed(json.loads(msg).values())) # 实际中传过来的数据不是list类型的 phone_id_list = eval((json.dumps(phone_id.split(",")))) cred = credential.Credential("xxx" , "yyyy") httpProfile = HttpProfile() httpProfile.endpoint = "xxx" clientProfile = ClientProfile() clientProfile.httpProfile = httpProfile client = sms_client.SmsClient(cred , "ap-nanjing" , clientProfile) # 实例化一个请求对象,每个接口都会对应一个request对象 req = models.SendSmsRequest() params = { # "PhoneNumberSet": [ "182xxxxxxxx", "153xxxxxxxx" ], "PhoneNumberSet": phone_id_list, "SmsSdkAppId": "1400xxxx" , "SignName": "签名名称" , "TemplateId": "模板id" , "TemplateParamSet": msg_list } req.from_json_string(json.dumps(params)) # 返回的resp是一个SendSmsResponse的实例,与请求对象对应 resp = client.SendSms(req) # 输出json格式的字符串回包 print(resp.to_json_string()) except TencentCloudSDKException as err: print(err) if __name__ == "__main__": #当接收到告警信息时,调用下面函数即可 sendtxy(sys.argv[1], sys.argv[2]) #下面试调试 #a=["基础监控】节点基础监控进程消失","\n告警详情: 节点:172.16.xx.xx:9101,主机名:hostname01\n节点:172.21.xx.xx:9101,主机名:hostname02\n告警级别:disaster\n告警模块:测试\n告警时间:2022-11-16 14:52:50" ] #b=["1825510xxxxx"] #sendtxy(a, b)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。