-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_verification_code.py
53 lines (35 loc) · 1.31 KB
/
send_verification_code.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
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) < 3:
print(r'Usage: python send_verification_code.py "{receiver}" "{code}"')
exit(-1)
receiver = sys.argv[1]
code = sys.argv[2]
template_params = f'["{code}"]'
headers = build_headers()
body = build_body(
receiver=receiver,
template_id=os.getenv('VERIFICATION_CODE_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()