-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_notification.py
58 lines (40 loc) · 1.46 KB
/
send_notification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
import os
import sys
from pprint import pprint
import requests
from dotenv import load_dotenv
from sms_common import build_body, build_headers
# Optional. API callback address of the user for receiving the SMS
# status report, for example, "http://example.com/receiveSMSReport"
STATUS_CALLBACK = ""
def main():
# load configurations from .env file
load_dotenv()
if len(sys.argv) < 6:
usage = r'Usage: python send_notification.py "{receiver}" "{date}" '
usage += r'"{time}" "{people}" "{code}"'
print()
exit(-1)
receiver = sys.argv[1]
date = sys.argv[2]
time = sys.argv[3]
people = sys.argv[4]
code = sys.argv[5]
template_params = f'["{date}","{time}","{people}","{code}"]'
headers = build_headers()
body = build_body(
receiver=receiver,
template_id=os.getenv('NOTIFICATION_TEMPLATE_ID'),
template_params=template_params,
status_callback=STATUS_CALLBACK)
# SMS Sending API (single template, multiple users)
# https://support.huaweicloud.com/intl/en-us/api-msgsms/sms_05_0001.html
url = os.getenv('APP_ACCESS_ADDRESS') + '/sms/batchSendSms/v1'
# Ignore the certificate trust issues to prevent API calling
# failures caused by HTTPS certificate authentication failures
verify = False
response = requests.post(url, data=body, headers=headers, verify=verify)
pprint(json.loads(response.text))
if __name__ == '__main__':
main()