From 2153bb2ebb46eabd448cc8d09b10584b44bbc00c Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 15 Jul 2026 16:29:52 +0800 Subject: [PATCH] fix(wechat): handle API errors instead of silently returning null h5_url - Check HTTP status code, raise exception on non-200 - Raise exception if h5_url missing from response - Fix description field to use .get() instead of direct key access - Remove unreachable return None Previously WeChat API errors (param errors, amount issues, etc.) would return None, causing the frontend to show: https://token.opencomputing.cn/null Now errors are properly raised and shown to the user. --- .gitignore | 3 +++ unipay/providers/wechat.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3bbe7b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +*.pyc +*.pyo diff --git a/unipay/providers/wechat.py b/unipay/providers/wechat.py index 55f359d..9e34947 100644 --- a/unipay/providers/wechat.py +++ b/unipay/providers/wechat.py @@ -172,9 +172,14 @@ class WechatGateway(Gateway): "Content-Type": "application/json" }) as resp: ret = await resp.json() - return ret.get("h5_url") - - return None + if resp.status != 200: + err_code = ret.get("code", "UNKNOWN") + err_msg = ret.get("message", str(ret)) + raise Exception(f"WeChat API error (HTTP {resp.status}): [{err_code}] {err_msg}") + h5_url = ret.get("h5_url") + if not h5_url: + raise Exception(f"WeChat API response missing h5_url: {json.dumps(ret, ensure_ascii=False)}") + return h5_url # ----------------------------------------------------- async def refund(self, payload: Dict[str, Any]) -> Dict[str, Any]: