Created
September 27, 2021 21:31
-
-
Save cfra/b4b65df7623114519e1e5baea6a222cd to your computer and use it in GitHub Desktop.
Send SMS using the Huawei HiLink API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
# Version 2, December 2004 | |
# | |
# Copyright (C) 2004 Sam Hocevar 14 rue de Plaisance, 75014 Paris, France | |
# Everyone is permitted to copy and distribute verbatim or modified | |
# copies of this license document, and changing it is allowed as long | |
# as the name is changed. | |
# | |
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
# | |
# 0. You just DO WHAT THE FUCK YOU WANT TO. | |
# | |
import io | |
import sys | |
import requests | |
from lxml import etree | |
dest = sys.argv[1] | |
msg = sys.stdin.read().strip() | |
req = etree.Element('request') | |
req_index = etree.SubElement(req, 'Index') | |
req_index.text = "-1" | |
req_phones = etree.SubElement(req, 'Phones') | |
req_phone = etree.SubElement(req_phones, 'Phone') | |
req_phone.text = dest | |
req_sca = etree.SubElement(req, 'Sca') | |
req_content = etree.SubElement(req, 'Content') | |
req_content.text = msg | |
req_length = etree.SubElement(req, 'Length') | |
req_length.text = "-1" | |
req_reserved = etree.SubElement(req, 'Reserved') | |
req_reserved.text = "-1" | |
req_date = etree.SubElement(req, 'Date') | |
req_date.text = "-1" | |
req_body = etree.tostring(req) | |
r = requests.get('http://192.168.8.1/api/webserver/SesTokInfo') | |
tree = etree.parse(io.BytesIO(r.content)) | |
root = tree.getroot() | |
cookie_name, cookie_value = root.find('SesInfo').text.split('=', 1) | |
token = root.find('TokInfo').text | |
r = requests.post( | |
'http://192.168.8.1/api/sms/send-sms', | |
cookies={ | |
cookie_name: cookie_value | |
}, | |
data=req_body, | |
headers={ | |
'__RequestVerificationToken': token | |
} | |
) | |
if r.status_code != 200: | |
raise RuntimeError(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment