Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

用户反馈无法找到小游戏道具直购功能支持。根据微信官方文档,添加 present_goods API 实现。

新增内容

  • API 接口WxMaXPayService.presentGoods()
  • 请求 BeanWxMaXPayPresentGoodsRequest - 包含 openid、env、order_id、device_type、goods_id、goods_number
  • 响应 BeanWxMaXPayPresentGoodsResponse - 返回 order_id
  • URL 常量WxMaApiUrlConstants.XPay.PRESENT_GOODS_URL

使用示例

WxMaXPayPresentGoodsRequest request = WxMaXPayPresentGoodsRequest.builder()
    .openid("oUpF8uMuAJO_M2pxb1Q9zNjWeS6o")
    .env(0)
    .orderId("ORDER_20231219001")
    .deviceType(0)
    .goodsId("ITEM_001")
    .goodsNumber(1)
    .build();

WxMaXPayPresentGoodsResponse response = wxMaService.getXPayService()
    .presentGoods(request, sigParams);

实现模式与现有虚拟支付 API(如 presentCurrency)保持一致。

Original prompt

This section details on the original issue you should resolve

<issue_title>请问小游戏的道具直购有支持吗?我没找到</issue_title>
<issue_description>这是道具直购的文档:
https://developers.weixin.qq.com/minigame/dev/guide/open-ability/virtual-payment/goods.html</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: 全部用中文
需要用中文,包括PR标题和分析总结过程


💡 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 changed the title [WIP] Add support for direct purchase of game props 添加小游戏道具直购(present_goods)API支持 Dec 19, 2025
Copilot AI requested a review from binarywang December 19, 2025 17:29
@binarywang binarywang marked this pull request as ready for review December 20, 2025 03:51
Copilot AI review requested due to automatic review settings December 20, 2025 03:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 为微信小游戏虚拟支付模块新增道具直购(present_goods)API 支持,解决用户反馈的功能缺失问题。实现方式与现有的代币直购(presentCurrency)API 保持一致,遵循项目现有的代码风格和架构模式。

主要变更:

  • 新增 presentGoods API 接口及其请求/响应对象
  • 完善的字段注释和文档说明
  • 遵循现有 XPay 服务的实现模式

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
WxMaApiUrlConstants.java 新增道具直购 API 的 URL 常量定义
WxMaXPayPresentGoodsRequest.java 新建道具直购请求对象,包含 openid、env、order_id、device_type、goods_id、goods_number 等字段
WxMaXPayPresentGoodsResponse.java 新建道具直购响应对象,返回 order_id
WxMaXPayService.java 在服务接口中添加 presentGoods 方法声明
WxMaXPayServiceImpl.java 实现 presentGoods 方法,包含请求发送、响应解析和错误处理逻辑

Comment on lines +112 to +125
public WxMaXPayPresentGoodsResponse presentGoods(WxMaXPayPresentGoodsRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
final String uri = sigParams.signUriWithPay(PRESENT_GOODS_URL, postBody);
String responseContent = this.service.post(uri, postBody);
WxMaXPayPresentGoodsResponse getDetailResponse = WxMaGsonBuilder.create()
.fromJson(responseContent, WxMaXPayPresentGoodsResponse.class);

if (getDetailResponse.getErrcode() != 0) {
throw new WxErrorException(
new WxError(getDetailResponse.getErrcode(), getDetailResponse.getErrmsg()));
}

return getDetailResponse;
}
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新增的 presentGoods 方法缺少对应的测试用例。建议在 WxMaXPayServiceImplTest 中添加 testPresentGoods 方法,参考 testPresentCurrency 的实现模式。

Copilot uses AI. Check for mistakes.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Data
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method overrides WxMaBaseResponse.canEqual; it is advisable to add an Override annotation.

Copilot uses AI. Check for mistakes.
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.

请问小游戏的道具直购有支持吗?我没找到

2 participants