Skip to content

Add raw JSON preservation capability to v3 API results for accessing undefined fields #3659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 24, 2025

Problem

微信支付v3 API经常会返回新的字段,但这些字段可能还没有在WxJava的Result类中定义。例如,微信支付批次详情接口返回的card_id字段在FavorStocksGetResult类中就没有定义。当官方API更新时,开发者无法访问这些新增字段,只能等待框架更新。

Solution

添加了原始JSON内容保存功能,允许开发者访问API返回的任何字段,即使这些字段未在Result类中定义。

核心实现

  1. 新增BaseWxPayV3Result基类

    • 提供rawJsonString字段保存原始API响应
    • 提供安全的getter/setter方法
    • 遵循v2结果类中xmlString的设计模式
  2. 更新Result类继承结构

    • FavorStocksGetResult - 查询批次详情
    • FavorStocksCreateResult - 创建代金券批次
    • FavorCouponsGetResult - 查询代金券详情
  3. 修改服务实现

    • GSON.fromJson()后调用setRawJsonString()保存原始内容
    • 保持现有API完全不变

使用示例

// 正常使用已定义的字段
FavorStocksGetResult result = marketingFavorService.getFavorStocksV3(stockId, mchId);
String stockName = result.getStockName();

// 访问未定义的card_id字段
String rawJson = result.getRawJsonString();
if (rawJson != null) {
    JsonElement jsonElement = JsonParser.parseString(rawJson);
    if (jsonElement.getAsJsonObject().has("card_id")) {
        String cardId = jsonElement.getAsJsonObject().get("card_id").getAsString();
        // 使用card_id...
    }
}

特性

  • 向后兼容: 现有代码无需任何修改
  • 零性能影响: 只在需要时访问原始JSON
  • 安全设计: 包含完整的错误处理和null安全检查
  • 易于扩展: 其他v3结果类可以轻松采用相同模式

测试覆盖

  • 基本功能测试:JSON保存和访问
  • 继承关系验证
  • 空值安全测试
  • 实际使用场景模拟
  • 特定字段访问测试(如card_id)

Fixes #3565.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 24, 2025 08:07
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
…ests

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] v3请求结果能不能保留原始内容返回 Add raw JSON preservation capability to v3 API results for accessing undefined fields Jul 24, 2025
@Copilot Copilot AI requested a review from binarywang July 24, 2025 08:18
Copilot finished work on behalf of binarywang July 24, 2025 08:18
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.

v3请求结果能不能保留原始内容返回
2 participants