import json
import requests
from email.utils import formatdate
from datetime import datetime
from time import mktime
from hashlib import sha1
from collections import OrderedDict
import hashlib
now = datetime.now() stamp = mktime(now.timetuple()) d = formatdate(timeval=stamp, localtime=False, usegmt=True) print(d)
body = { "url": "http://hr.lehuiju.com/file/mdoc/844152e6-e422-441a-8d6e-9c9068450817/86f6876d-33dc-4928-8505-14503f180ef5/673565e9c050496b24b66c49/20241114/8EbE7Dem8w4O7NaM2LaS4TeUfmf31ea63H6pbh9l9afCc9cz9JaKfua65LfJaX2F.docx?e=1731658331&token=mdstorage:KhLUd6TgSe3xOOe2NlQSnlq-lxs=", "filename": "城市经理岗位--熊盛盛--报到通知书 (1).docx" }
APPID = "UBgrqhElbNn7T9Tux5Q1Gjs0"
APPKEY = b"bchStkZJ9xUpbC0qAn85Ru0hKy6OGNW7"
Content_Type = b"application/json"
Date = d.encode("utf-8")
print(Date)
ordered_dict = OrderedDict(sorted(body.items()))
items_str = ''.join([str(k) + str(v) for k, v in ordered_dict.items()])
md5 = hashlib.md5(items_str.encode('utf-8'))
Content_Md5 = md5.hexdigest().encode('utf-8')
print("md5:%s" % Content_Md5)
signature = sha1(APPKEY+Content_Md5+Content_Type+Date).hexdigest()
print(signature)
Authorization = 'WPS-2:%s:%s' % (APPID, signature) print(Authorization)
headers = {
'Date': "%s" % d,
'Content-Md5': "%s" % Content_Md5,
'Content-Type': "application/json; charset=utf-8",
'Authorization': "%s" % Authorization
}
re = requests.post(url="https://solution.wps.cn/api/developer/v1/office/convert/to/pdf", data=json.dumps(body), headers=headers)
data = re.content
print(data)