{"record":{"id":"8eeb6533ede0cfb5","repo":"linlinjava/litemall","slug":"error-8eeb65","errorCode":null,"errorMessage":"微信通知支付失败！","messagePattern":"微信通知支付失败！","errorType":"http","errorClass":"WxPayException","httpStatus":500,"severity":"critical","filePath":"litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java","lineNumber":743,"sourceCode":"     * @return 操作结果\n     */\n    @Transactional\n    public Object payNotify(HttpServletRequest request, HttpServletResponse response) {\n        String xmlResult = null;\n        try {\n            xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());\n        } catch (IOException e) {\n            e.printStackTrace();\n            return WxPayNotifyResponse.fail(e.getMessage());\n        }\n\n        WxPayOrderNotifyResult result = null;\n        try {\n            result = wxPayService.parseOrderNotifyResult(xmlResult);\n\n            if(!WxPayConstants.ResultCode.SUCCESS.equals(result.getResultCode())){\n                logger.error(xmlResult);\n                throw new WxPayException(\"微信通知支付失败！\");\n            }\n            if(!WxPayConstants.ResultCode.SUCCESS.equals(result.getReturnCode())){\n                logger.error(xmlResult);\n                throw new WxPayException(\"微信通知支付失败！\");\n            }\n        } catch (WxPayException e) {\n            e.printStackTrace();\n            return WxPayNotifyResponse.fail(e.getMessage());\n        }\n\n        logger.info(\"处理腾讯支付平台的订单支付\");\n        logger.info(result);\n\n        String orderSn = result.getOutTradeNo();\n        String payId = result.getTransactionId();\n\n        // 分转化成元\n        String totalFee = BaseWxPayResult.fenToYuan(result.getTotalFee());","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/linlinjava/litemall/blob/a1ef964a718b7277925b19ea26afe78ea3a1d325/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java#L725-L761","documentation":"In the WeChat pay-notify handler (WxOrderService.wxNotify), after parsing the notify XML with wxPayService.parseOrderNotifyResult, the service checks result.getResultCode() (business result) against WxPayConstants.ResultCode.SUCCESS. If WeChat reports a non-SUCCESS result_code — e.g. PAY_ERROR, TRADE_FAIL, or a refund/bank-side failure — the handler throws WxPayException('微信通知支付失败！'). The local catch converts it to WxPayNotifyResponse.fail(e.getMessage()), telling WeChat the notify was rejected so it will retry.","triggerScenarios":"WeChat sends a notify whose XML has result_code != SUCCESS (actual payment failure or intermediate failure state); occasionally caused by the two-check order being wrong for cases where result_code is SUCCESS but return_code is not (that variant is error [8]). The raw XML is logged via logger.error(xmlResult) right before the throw, so the exact payload is identifiable in logs.","commonSituations":"Genuine payment failure at the bank/wallet level; sandbox/test environment sending synthetic failure notifications; WeChat platform incidents producing fail result_codes; misconfigured merchant parameters (mch_id, key) causing WeChat to return failure payloads.","solutions":["Inspect the logged xmlResult for the failing notify to see the real result_code and err_code_des — that tells you whether it is a genuine payment failure or a config problem.","Verify merchant config (app-id, mch-id, mch-key, sign type) in the wxPayService bean; mismatched keys produce failure results on notify.","Do not change the code path itself: responding fail is correct so WeChat retries; only act if failures are systematic across orders."],"exampleFix":"// before\nif(!WxPayConstants.ResultCode.SUCCESS.equals(result.getResultCode())){\n    logger.error(xmlResult);\n    throw new WxPayException(\"微信通知支付失败！\");\n}\n\n// after - keep the failure response but capture the reason code\nif(!WxPayConstants.ResultCode.SUCCESS.equals(result.getResultCode())){\n    logger.error(\"微信支付通知失败: result_code={}, err_code={}, err_code_des={}\",\n            result.getResultCode(), result.getErrCode(), result.getErrCodeDes());\n    throw new WxPayException(\"微信通知支付失败！\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    result = wxPayService.parseOrderNotifyResult(xmlResult);\n    if (!WxPayConstants.ResultCode.SUCCESS.equals(result.getResultCode())\n            || !WxPayConstants.ResultCode.SUCCESS.equals(result.getReturnCode())) {\n        logger.error(\"微信通知失败 result_code={} return_code={} xml={}\",\n                result.getResultCode(), result.getReturnCode(), xmlResult);\n        return WxPayNotifyResponse.fail(\"支付结果非SUCCESS\"); // WeChat will retry\n    }\n} catch (WxPayException e) {\n    logger.error(\"微信通知解析失败\", e);\n    return WxPayNotifyResponse.fail(e.getMessage());\n}","preventionTips":["Always log the raw xmlResult with result_code/err_code before failing — the reason code distinguishes genuine payment failure from config errors.","Verify merchant key/id/sign-type configuration when failures cluster across orders rather than a single user."],"tags":["payment","wechat-pay","callback","external-service","litemall"],"backgroundTag":null,"analyzedSha":"a1ef964a718b7277925b19ea26afe78ea3a1d325","analyzedAt":"2026-08-14T12:39:46.078Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}