你好请问下,我用python请求的但是返回code码20002 应用不存在 该应用我申请的测试500次 AppID:SX20241114PDAAVN

阅读次数 1

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)

2 Answers

您好,你是用的appid和appkey不对吧,可以检查下控制台的AppID,AppSecret是否使用正确

AppID:SX20241114PDAAVN AppSecret:MYyysVsbsWOQoLBeiXdXJPRMFtNNngYw

我的应用就这两个值,刚才顺序放错了 现在提示:md5有问题 b'{"code":30003,"message":"InvalidSignature","hint":"md5 not match. expect: 35f3ec1b496d9aeecf5d4eb9155c8724, actual: b'4749a73a8fe75c19b88768565a6e699f'","extra":""}'

建议可以看看文档先自行解决哈, 文档里描述比较清楚了,https://solution.wps.cn/docs/convert/to-jpg.html#header 初步看是你对body进行了重排导致的,可以先重点看看文档哈

get请求是请求的uri,不是url,其他类型请求是对body数据进行md5