From 014e9a15e5d9ebbc8d0fe1691d8601a04dd2b17f Mon Sep 17 00:00:00 2001 From: zzhyyyyy <2685922758@qq.com> Date: Fri, 17 Jul 2026 22:51:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(wx-finance):=20DecryptData=20=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E8=AF=AF=E4=BC=A0=E7=9A=84=20sdk=20=E5=8F=A5=E6=9F=84?= =?UTF-8?q?(=E5=8F=82=E6=95=B0=E9=94=99=E4=BD=8D=E8=87=B4=2010008)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DecryptData 与 GetChatData 不同, 不接收 sdk 句柄(纯解密函数、3 个参数)。之前 binding 多传了 self._sdk 作首参 → 参数整体错位、encrypt_key 收到 sdk 指针 → DecryptData 返 10008(解析 encrypt_key 出错)。云上实测:去掉 sdk 句柄后 ret=0、成功解出明文(external 用户发给成员的 msgtype=weapp 美团小程序卡片)。 - argtypes 从 4 参(含 c_void_p sdk)改为 3 参(encrypt_key, encrypt_msg, msg_slice) - decrypt() 调用去掉 self._sdk Co-Authored-By: Claude Opus 4.8 --- app/integrations/wx_finance_sdk.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/integrations/wx_finance_sdk.py b/app/integrations/wx_finance_sdk.py index b6e92a3..5bbe98a 100644 --- a/app/integrations/wx_finance_sdk.py +++ b/app/integrations/wx_finance_sdk.py @@ -50,9 +50,9 @@ class WxFinanceSdk: ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_void_p, ] lib.GetChatData.restype = ctypes.c_int - lib.DecryptData.argtypes = [ - ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p, - ] + # ⚠️ DecryptData 不吃 sdk 句柄(与 GetChatData 不同, 它是纯解密函数)——只有 3 个参数, + # 多传 sdk 会让参数错位、encrypt_key 收到 sdk 指针 → DecryptData 返 10008(解析 encrypt_key 出错)。 + lib.DecryptData.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p] lib.DecryptData.restype = ctypes.c_int lib.NewSlice.restype = ctypes.c_void_p lib.FreeSlice.argtypes = [ctypes.c_void_p] @@ -87,7 +87,7 @@ class WxFinanceSdk: aes_key = self._priv.decrypt(base64.b64decode(encrypt_random_key_b64), padding.PKCS1v15()) slc = self._lib.NewSlice() try: - ret = self._lib.DecryptData(self._sdk, aes_key, encrypt_chat_msg.encode(), slc) + ret = self._lib.DecryptData(aes_key, encrypt_chat_msg.encode(), slc) if ret != 0: raise WxFinanceError(f"DecryptData 失败 ret={ret}") return json.loads(self._slice_bytes(slc).decode("utf-8"))