's'
This commit is contained in:
9
main.py
9
main.py
@@ -597,10 +597,15 @@ async def _handle_wechat_request(request: Request, app_id: Optional[str], backgr
|
||||
logger.info("回包明文(加密前): %s", resp_json_str)
|
||||
|
||||
# 8. 加密响应
|
||||
# XML 回调场景使用当前会话 appid(公众号 appid)加密,避免与开放 API appid 不一致导致平台解密失败。
|
||||
response_app_id = APP_ID
|
||||
# - /?app_id=... 的第三方服务接口请求通常使用纯AES明文加密(不拼接 appid)
|
||||
# - XML 回调场景使用会话 appid 封装加密
|
||||
# - 其余 JSON 场景默认使用纯AES,提升兼容性
|
||||
response_app_id: Optional[str] = None
|
||||
if str(data.get("_payload_format", "")) == "xml":
|
||||
response_app_id = str(data.get("ChannelId", "") or data.get("appid", "")).strip() or APP_ID
|
||||
elif app_id:
|
||||
response_app_id = None
|
||||
logger.info("响应加密模式: %s", "envelope" if response_app_id else "plain")
|
||||
try:
|
||||
encrypted_resp = aes_encrypt_base64(resp_json_str, ENCODING_AES_KEY, response_app_id)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user