xqcloudsms.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. from qcloudsms_py import SmsSingleSender
  2. from qcloudsms_py.httpclient import HTTPError
  3. import time
  4. class Client(object):
  5. def __init__(self):
  6. appid = 1400278842 # 短信应用 SDK AppID
  7. appkey = '9514696ecf07081a42b4a19bfaf5bf2e' # 短信应用 SDK AppKey
  8. self.ssender = SmsSingleSender(appid, appkey)
  9. self.sms_sign = '泽鹿安全'
  10. def for_add_vul(self, phone_numbers, find_at, address, vul_id, risk):
  11. """
  12. 新增漏洞提醒
  13. """
  14. template_id = 479975
  15. params = [str(find_at), str(address), str(vul_id), str(risk)]
  16. for phone_number in phone_numbers:
  17. try:
  18. result = self.ssender.send_with_param(86, str(phone_number),
  19. template_id, params,
  20. sign=self.sms_sign,
  21. extend='', ext='')
  22. print(result)
  23. except HTTPError as e:
  24. print(e)
  25. except Exception as e:
  26. print(e)
  27. def for_close_task(self, phone_numbers, task_id, date_time, username, state):
  28. """
  29. 工单关闭提醒
  30. """
  31. template_id = 479977
  32. params = [str(task_id), str(date_time), str(username), str(state)]
  33. for phone_number in phone_numbers:
  34. try:
  35. result = self.ssender.send_with_param(86, str(phone_number),
  36. template_id, params,
  37. sign=self.sms_sign,
  38. extend='', ext='')
  39. print(result)
  40. except HTTPError as e:
  41. print(e)
  42. except Exception as e:
  43. print(e)
  44. def for_remind_task(self, phone_numbers, task_id, residue_time):
  45. """
  46. 工单时限提醒
  47. """
  48. template_id = 479982
  49. params = [str(task_id), str(residue_time)]
  50. for phone_number in phone_numbers:
  51. try:
  52. result = self.ssender.send_with_param(86, str(phone_number),
  53. template_id, params,
  54. sign=self.sms_sign,
  55. extend='', ext='')
  56. print(result)
  57. except HTTPError as e:
  58. print(e)
  59. except Exception as e:
  60. print(e)
  61. def for_claim_task(self, phone_numbers, task_id, username, action):
  62. """
  63. 工单状态变化
  64. """
  65. template_id = 503921
  66. year = time.strftime('%Y', time.localtime(int(time.time())))
  67. month = time.strftime('%m', time.localtime(int(time.time())))
  68. day = time.strftime('%d', time.localtime(int(time.time())))
  69. hour = time.strftime('%H', time.localtime(int(time.time())))
  70. minute = time.strftime('%M', time.localtime(int(time.time())))
  71. params = [str(task_id)[-8:], str(year), str(month), str(day), str(hour), str(minute), str(username)[-8:],
  72. action[-8:]]
  73. for phone_number in phone_numbers:
  74. try:
  75. result = self.ssender.send_with_param(86, str(phone_number),
  76. template_id, params,
  77. sign=self.sms_sign,
  78. extend='', ext='')
  79. print(result)
  80. except HTTPError as e:
  81. print(e)
  82. except Exception as e:
  83. print(e)
  84. def for_vul_message(self, phone_numbers, find_at, address):
  85. """
  86. 漏洞提醒
  87. """
  88. template_id = 630480
  89. params = [str(find_at), str(address)]
  90. for phone_number in phone_numbers:
  91. try:
  92. result = self.ssender.send_with_param(86, str(phone_number),
  93. template_id, params,
  94. sign=self.sms_sign,
  95. extend='', ext='')
  96. print(result)
  97. return result
  98. except HTTPError as e:
  99. print(e)
  100. except Exception as e:
  101. print(e)
  102. if __name__ == '__main__':
  103. # --- init ---
  104. client = Client()
  105. # --- test ---