import hashlib
import http.client
from datetime import datetime
from email.utils import formatdate
conn = http.client.HTTPSConnection("solution.wps.cn")
payload = "{\"url\":\"https://arxiv.org/pdf/2309.08872.pdf\"}"
payload = payload.encode('utf-8')
now = datetime.now()
rfc1123_date = formatdate(timeval=now.timestamp(), localtime=False, usegmt=True)
url = "/api/developer/v1/office/pdf/convert/to/docx"
md5 = hashlib.md5()
# 更新md5对象
md5.update(payload)
md5_data = md5.hexdigest()
sha1 = hashlib.sha1()
app_key = "********************"
content_type = "application/json"
data = app_key + md5_data + content_type + rfc1123_date
# 更新sha1对象
sha1.update(data.encode('utf-8'))
sha1_data = sha1.hexdigest()
headers = {
'Date': rfc1123_date,
'Content-Md5': md5_data,
'Content-Type': content_type,
'Authorization': "WPS-2" + ":" + "**********" + ":" + sha1_data
}
conn.request("POST", url, payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))