123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- from qcloudsms_py import SmsSingleSender
- from qcloudsms_py.httpclient import HTTPError
- import time
- class Client(object):
- def __init__(self):
- appid = 1400278842 # 短信应用 SDK AppID
- appkey = '9514696ecf07081a42b4a19bfaf5bf2e' # 短信应用 SDK AppKey
- self.ssender = SmsSingleSender(appid, appkey)
- self.sms_sign = '泽鹿安全'
- def for_add_vul(self, phone_numbers, find_at, address, vul_id, risk):
- """
- 新增漏洞提醒
- """
- template_id = 479975
- params = [str(find_at), str(address), str(vul_id), str(risk)]
- for phone_number in phone_numbers:
- try:
- result = self.ssender.send_with_param(86, str(phone_number),
- template_id, params,
- sign=self.sms_sign,
- extend='', ext='')
- print(result)
- except HTTPError as e:
- print(e)
- except Exception as e:
- print(e)
- def for_close_task(self, phone_numbers, task_id, date_time, username, state):
- """
- 工单关闭提醒
- """
- template_id = 479977
- params = [str(task_id), str(date_time), str(username), str(state)]
- for phone_number in phone_numbers:
- try:
- result = self.ssender.send_with_param(86, str(phone_number),
- template_id, params,
- sign=self.sms_sign,
- extend='', ext='')
- print(result)
- except HTTPError as e:
- print(e)
- except Exception as e:
- print(e)
- def for_remind_task(self, phone_numbers, task_id, residue_time):
- """
- 工单时限提醒
- """
- template_id = 479982
- params = [str(task_id), str(residue_time)]
- for phone_number in phone_numbers:
- try:
- result = self.ssender.send_with_param(86, str(phone_number),
- template_id, params,
- sign=self.sms_sign,
- extend='', ext='')
- print(result)
- except HTTPError as e:
- print(e)
- except Exception as e:
- print(e)
- def for_claim_task(self, phone_numbers, task_id, username, action):
- """
- 工单状态变化
- """
- template_id = 503921
- year = time.strftime('%Y', time.localtime(int(time.time())))
- month = time.strftime('%m', time.localtime(int(time.time())))
- day = time.strftime('%d', time.localtime(int(time.time())))
- hour = time.strftime('%H', time.localtime(int(time.time())))
- minute = time.strftime('%M', time.localtime(int(time.time())))
- params = [str(task_id)[-8:], str(year), str(month), str(day), str(hour), str(minute), str(username)[-8:],
- action[-8:]]
- for phone_number in phone_numbers:
- try:
- result = self.ssender.send_with_param(86, str(phone_number),
- template_id, params,
- sign=self.sms_sign,
- extend='', ext='')
- print(result)
- except HTTPError as e:
- print(e)
- except Exception as e:
- print(e)
- def for_vul_message(self, phone_numbers, find_at, address):
- """
- 漏洞提醒
- """
- template_id = 630480
- params = [str(find_at), str(address)]
- for phone_number in phone_numbers:
- try:
- result = self.ssender.send_with_param(86, str(phone_number),
- template_id, params,
- sign=self.sms_sign,
- extend='', ext='')
- print(result)
- return result
- except HTTPError as e:
- print(e)
- except Exception as e:
- print(e)
- if __name__ == '__main__':
- # --- init ---
- client = Client()
- # --- test ---
|