TOKEN = "k4hqAeOi3pPMnmWURvZJd8jyj8BATR"
EncodingAESKey = "uu06tNJqysIDCpSer1PjXC8nMZAo6fNxDszcBZ8OnaF"
APPID = "8abfUZOvOlQr8Fr"
headers = {
"Content-Type": "application/json",
}
data = '''<xml>
<appid><![CDATA[k4hqAeOi3pPMnmWURvZJd8jyj8BATR]]></appid>
<openid><![CDATA[7hK2MdIzH9Q]]></openid>
<msg><![CDATA[你好]]></msg>
<channel>7</channel>
<kefuname><![CDATA[BobAi]]></kefuname>
</xml>'''
encryp_test = WXBizMsgCrypt(TOKEN, EncodingAESKey, APPID)
nonce = "12345678"
ret, encrypt_xml = encryp_test.EncryptMsg(data, nonce)
url = "https://chatbot.weixin.qq.com/openapi/sendmsg/{TOKEN}".format(TOKEN=TOKEN)
response = requests.post(url, data=json.dumps({"encrypt": encrypt_xml}), headers=headers)
response.status_code
是那里配置错了?
您好 这里换“encrypt”方法试下呢。
import requests
import json
TOKEN = "k4hqAeOi3pPMnmWURvZJd8jyj8BATR"
EncodingAESKey = "uu06tNJqysIDCpSer1PjXC8nMZAo6fNxDszcBZ8OnaF"
APPID = "8abfUZOvOlQr8Fr"
headers = {
"Content-Type": "application/json",
}
data = '''<xml>
<appid><![CDATA[k4hqAeOi3pPMnmWURvZJd8jyj8BATR]]></appid>
<openid><![CDATA[7hK2MdIzH9Q]]></openid>
<msg><![CDATA[你好]]></msg>
<channel>7</channel>
<kefuname><![CDATA[BobAi]]></kefuname>
</xml>'''
key = base64.b64decode(EncodingAESKey+"=")
pt = Prpcrypt(key)
encrypt_result = pt.encrypt(data, APPID)
encrypt = encrypt_result[1]
print(encrypt)
url = "https://chatbot.weixin.qq.com/openapi/sendmsg/{TOKEN}".format(TOKEN=TOKEN)
response = requests.post(url, data=json.dumps({"encrypt": encrypt.decode()}), headers=headers)
print(response.status_code)
b'KCHylbS9wESZTuO1Fr7n0yXLkcXQwGoYPqpCX4MyeT4NhJIz/AM2hmnxrRoApwPJPBHrsOyzrqvAlg1oDBn/P/uBpQRUuf8purbD/jhNdcC3Tomb8ZjnKrAp6qbIR+pqX3DgoS9Hz4QnAr5rvm0KrIvLoQf7fO2jfq+LSZsrz5ndk3XHlpuuQufGrvTg9uuUrl8WuocXMq7k00wgWp1Re4vkN32vwZHtP/xfMsD82FKaKoYzdHXlsptXxLdlj3oM9f4OgYHXNHD2x0o0StJ5LE0wAGaGLcM26aUZN23Egiy3xxeVRSPrV1BIIjRvvAZ2q1Mp6S///Kca/fT8iuPokLZIu2ja9TcrTKZMwJWuQtg6Z2JkrC7DcG4vk2WNA+iK'
503
对于
https://chatbot.weixin.qq.com/openapi/sendmsg/{TOKEN}
接口
TOKEN 选择 k4hqAeOi3pPMnmWURvZJd8jyj8BATR
appid 选择 k4hqAeOi3pPMnmWURvZJd8jyj8BATR
openid 选择 o9U-85qSw4_uogADljxHvsAqKgAM
channel 设置 7
这个参数选择对吗?
'''
data = '''<xml>
<appid><![CDATA[k4hqAeOi3pPMnmWURvZJd8jyj8BATR]]></appid>
<openid><![CDATA[o9U-85qSw4_uogADljxHvsAqKgAM]></openid>
<msg><![CDATA[你好]]></msg>
<channel>7</channel>
<kefuname><![CDATA[BobAi]]></kefuname>
</xml>'''''
'''
https://developers.weixin.qq.com/doc/aispeech/confapi/thirdkefu/sendmsg.html
按照这个guide 想给网页H5 发客服消息,结果返回503
"<xml>\\n<Encrypt><![CDATA[H57KgxAQOxec/99YHPWupHYSzUf9kAyo486OpIK6ufp1he68GuT0mzG73lCYFZNzmktjDVjNSSvsHo8eESGXBA857uJgrzMcs0bDcdJ4piGGoPL8hukGuzf4jsqTdLeFBRwX+T8mhh18/JRr47dpsS/ptifNZzBh1v7WgXQgM//2ZxMPv/snjPn6ZhNiFCKPWRCosf/8jHEwJmdUzQLuQDhgNdv2VtQCEGnz/nKwVIfinWt8tkMrh7oEUx+V5dwx]]></Encrypt>\\n<MsgSignature><![CDATA[24104b8a8b9e763b22c5997ae39ad5ab335d00b1]]></MsgSignature>\\n<TimeStamp>1725978294</TimeStamp>\\n<Nonce><![CDATA[12345678]]></Nonce>\\n</xml>"