Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 22, 2025

问题描述

WxMaIntracityServiceImpl.balanceQuery 方法中的验证逻辑存在错误,当 wxStoreId 为 null 且 payModeAPPCOMPONENT 时,会错误地阻止合法的 API 调用。

原始错误代码

if (wxStoreId == null && (payMode != null && payMode != PayMode.STORE)) {
    throw new IllegalArgumentException("payMode是PAY_MODE_STORE或null时,必须传递wxStoreId");
}

这个条件判断是反的,导致在以下情况下抛出异常:

  • wxStoreId 为 null payModeAPPCOMPONENT

但根据 API 文档和 BasicWxMaStoreChargeRefundRequest.java 中的注释说明,wxStoreId 只有在 payModeSTOREnull(默认为 STORE)时才是必需的。

问题示例

修复前,以下合法调用会错误地抛出异常:

// 这个调用应该是合法的,但会抛出 IllegalArgumentException
intracityService.balanceQuery(null, "service123", PayMode.APP);

用户不得不通过传入一个虚假的 wxStoreId 值来绕过这个问题。

解决方案

修正了验证条件,使其正确地仅在 payModeSTOREnull 时才要求 wxStoreId

if (wxStoreId == null && (payMode == null || payMode == PayMode.STORE)) {
    throw new IllegalArgumentException("payMode是PAY_MODE_STORE或null时,必须传递wxStoreId");
}

修复后的行为

  • balanceQuery(null, serviceId, null) → 抛出异常(默认 STORE 模式需要 wxStoreId)
  • balanceQuery(null, serviceId, PayMode.STORE) → 抛出异常(STORE 模式需要 wxStoreId)
  • balanceQuery(null, serviceId, PayMode.APP) → 通过验证(不需要 wxStoreId)
  • balanceQuery(null, serviceId, PayMode.COMPONENT) → 通过验证(不需要 wxStoreId)
  • balanceQuery("store123", serviceId, 任意模式) → 通过验证(已提供 wxStoreId)

影响说明

无破坏性变更 - 原本能正常工作的代码继续正常工作,之前被错误阻止的合法用法现在可以正常使用了。

修复 #3704


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] WxMaIntracityServiceImpl.balanceQuery 的判断条件写的有问题 Fix validation logic in WxMaIntracityServiceImpl.balanceQuery for PayMode handling Sep 22, 2025
Copilot finished work on behalf of binarywang September 22, 2025 16:37
Copilot AI requested a review from binarywang September 22, 2025 16:37
@wzkris
Copy link

wzkris commented Sep 23, 2025

LGTM @binarywang

@binarywang binarywang added this to the 4.7.9 milestone Sep 24, 2025
@binarywang binarywang marked this pull request as ready for review November 15, 2025 08:56
@binarywang
Copy link
Owner

@copilot 请用中文重新描述问题和处理过程

Copy link
Contributor Author

Copilot AI commented Nov 15, 2025

@copilot 请用中文重新描述问题和处理过程

已将 PR 描述更新为中文版本。主要说明了:

  1. 问题:验证逻辑反了,错误地阻止了 PayMode.APP 和 PayMode.COMPONENT 的合法调用
  2. 解决方案:修正条件判断,使其仅在 payMode 为 STORE 或 null 时才要求 wxStoreId
  3. 修复后的各种场景行为说明

Copilot finished work on behalf of binarywang November 15, 2025 09:01
@binarywang binarywang merged commit 57e12de into develop Nov 15, 2025
2 checks passed
@binarywang binarywang deleted the copilot/fix-3704 branch November 15, 2025 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants