智能对话文档中设置批量导入(普通)技能接口404?
调用的接口地址https://openai.weixin.qq.com/openapi/batchimportskill/bZckp5aTH2HydICjBAdpmBBdT47brr
xml加密完成,按文档要求将加密后的数据,以字段 encrypt 放入body中,接口返回404,
其中headers的设置是{‘Content-Type’, ‘application/json’}
如果不设置headers接口返回
{‘errcode’: 1013, ‘errmsg’: ‘decrypt error, please use the correct way to encrypt the params.’}
貌似这种需要在body中添加加密xml字段的接口都是如此,前面使用发送客服消息接口也是报一样的错误
开发语言python代码片段
def batchimportskill(self):
urls = [
"https://openai.weixin.qq.com/openapi/batchimportskill/bZckp5aTH2HydICjBAdpmBBdT47brr"
]
headers = {
"Content-Type": "application/json;charset=UTF-8"
}
param = {'managerid': "mzZqGup3tUs"}
skill_xml_list = []
for i in range(0, 2):
skill_xml_list.append(
f"""<skill><skillname><![CDATA[技能名称1]]></skillname><title><![CDATA[标准问题3]]></title><question><![CDATA[相似问题1]]></question><answer><![CDATA[1]]></answer></skill>""")
s_nonce = ''.join(random.sample('zyxwvutsrqponmlkjihgfedcba', 10))
xml = f"""<xml><managerid><![CDATA[{param['managerid']}]]></managerid>{''.join(skill_xml_list)}</xml>"""
cryptor = WXBizMsgCrypt(self.TOKEN, self.EncodingAESKey, self.APPID)
code, encrypt_xml = cryptor.EncryptMsg(xml, s_nonce)
print(encrypt_xml)
if code == 0:
skill_xml_encrypt = {
'encrypt': encrypt_xml
}
data = json.dumps(skill_xml_encrypt, ensure_ascii=False).encode('utf-8')
tasks = [grequests.post(u, data=data, headers=headers) for u in urls]
resp = grequests.map(tasks, size=3)
print(resp)
if resp is None:
return False
if resp[0].status_code == 200:
resp_dict = json.loads(resp[0].content.decode(encoding='utf-8'))
print(resp_dict)
else:
return False