Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public interface WxMaXPayService {
*/
WxMaXPayPresentCurrencyResponse presentCurrency(WxMaXPayPresentCurrencyRequest request, WxMaXPaySigParams sigParams) throws WxErrorException;

/**
* 道具直购。
*
* @param request 道具直购请求对象
* @param sigParams 签名参数对象
* @return 道具直购结果
* @throws WxErrorException 直购失败时抛出
*/
WxMaXPayPresentGoodsResponse presentGoods(WxMaXPayPresentGoodsRequest request, WxMaXPaySigParams sigParams) throws WxErrorException;

/**
* 下载对账单。
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ public WxMaXPayPresentCurrencyResponse presentCurrency(WxMaXPayPresentCurrencyRe
return getDetailResponse;
}

@Override
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;
}
Comment on lines +112 to +125
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.

@Override
public WxMaXPayDownloadBillResponse downloadBill(WxMaXPayDownloadBillRequest request, WxMaXPaySigParams sigParams) throws WxErrorException {
final String postBody = request.toJson();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package cn.binarywang.wx.miniapp.bean.xpay;

import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 小游戏道具直购API请求.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaXPayPresentGoodsRequest implements Serializable {
private static final long serialVersionUID = 7495157056049312109L;

/**
* 用户的openid.
*/
@SerializedName("openid")
private String openid;

/**
* 环境。0-正式环境;1-沙箱环境.
*/
@SerializedName("env")
private Integer env;

/**
* 商户订单号.
*/
@SerializedName("order_id")
private String orderId;

/**
* 设备类型。0-安卓;1-iOS.
*/
@SerializedName("device_type")
private Integer deviceType;

/**
* 道具id.
*/
@SerializedName("goods_id")
private String goodsId;

/**
* 道具数量.
*/
@SerializedName("goods_number")
private Integer goodsNumber;

public String toJson() {
return WxMaGsonBuilder.create().toJson(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cn.binarywang.wx.miniapp.bean.xpay;

import cn.binarywang.wx.miniapp.bean.WxMaBaseResponse;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* 小游戏道具直购API响应.
*
* @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.
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaXPayPresentGoodsResponse extends WxMaBaseResponse implements Serializable {
private static final long serialVersionUID = 7495157056049312110L;

/**
* 商户订单号.
*/
@SerializedName("order_id")
private String orderId;

public String toJson() {
return WxMaGsonBuilder.create().toJson(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ public interface XPay {
String NOTIFY_PROVIDE_GOODS_URL =
"https://api.weixin.qq.com/xpay/notify_provide_goods?pay_sig=%s";
String PRESENT_CURRENCY_URL = "https://api.weixin.qq.com/xpay/present_currency?pay_sig=%s";
String PRESENT_GOODS_URL = "https://api.weixin.qq.com/xpay/present_goods?pay_sig=%s";
String DOWNLOAD_BILL_URL = "https://api.weixin.qq.com/xpay/download_bill?pay_sig=%s";
String REFUND_ORDER_URL = "https://api.weixin.qq.com/xpay/refund_order?pay_sig=%s";
String CREATE_WITHDRAW_ORDER_URL =
Expand Down