File tree Expand file tree Collapse file tree 5 files changed +124
-0
lines changed
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp Expand file tree Collapse file tree 5 files changed +124
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,16 @@ public interface WxMaXPayService {
7171 */
7272 WxMaXPayPresentCurrencyResponse presentCurrency (WxMaXPayPresentCurrencyRequest request , WxMaXPaySigParams sigParams ) throws WxErrorException ;
7373
74+ /**
75+ * 道具直购。
76+ *
77+ * @param request 道具直购请求对象
78+ * @param sigParams 签名参数对象
79+ * @return 道具直购结果
80+ * @throws WxErrorException 直购失败时抛出
81+ */
82+ WxMaXPayPresentGoodsResponse presentGoods (WxMaXPayPresentGoodsRequest request , WxMaXPaySigParams sigParams ) throws WxErrorException ;
83+
7484 /**
7585 * 下载对账单。
7686 *
Original file line number Diff line number Diff line change @@ -108,6 +108,22 @@ public WxMaXPayPresentCurrencyResponse presentCurrency(WxMaXPayPresentCurrencyRe
108108 return getDetailResponse ;
109109 }
110110
111+ @ Override
112+ public WxMaXPayPresentGoodsResponse presentGoods (WxMaXPayPresentGoodsRequest request , WxMaXPaySigParams sigParams ) throws WxErrorException {
113+ final String postBody = request .toJson ();
114+ final String uri = sigParams .signUriWithPay (PRESENT_GOODS_URL , postBody );
115+ String responseContent = this .service .post (uri , postBody );
116+ WxMaXPayPresentGoodsResponse getDetailResponse = WxMaGsonBuilder .create ()
117+ .fromJson (responseContent , WxMaXPayPresentGoodsResponse .class );
118+
119+ if (getDetailResponse .getErrcode () != 0 ) {
120+ throw new WxErrorException (
121+ new WxError (getDetailResponse .getErrcode (), getDetailResponse .getErrmsg ()));
122+ }
123+
124+ return getDetailResponse ;
125+ }
126+
111127 @ Override
112128 public WxMaXPayDownloadBillResponse downloadBill (WxMaXPayDownloadBillRequest request , WxMaXPaySigParams sigParams ) throws WxErrorException {
113129 final String postBody = request .toJson ();
Original file line number Diff line number Diff line change 1+ package cn .binarywang .wx .miniapp .bean .xpay ;
2+
3+ import cn .binarywang .wx .miniapp .json .WxMaGsonBuilder ;
4+ import com .google .gson .annotations .SerializedName ;
5+ import lombok .AllArgsConstructor ;
6+ import lombok .Builder ;
7+ import lombok .Data ;
8+ import lombok .NoArgsConstructor ;
9+
10+ import java .io .Serializable ;
11+
12+ /**
13+ * 小游戏道具直购API请求.
14+ *
15+ * @author <a href="https://github.com/binarywang">Binary Wang</a>
16+ */
17+ @ Data
18+ @ Builder
19+ @ NoArgsConstructor
20+ @ AllArgsConstructor
21+ public class WxMaXPayPresentGoodsRequest implements Serializable {
22+ private static final long serialVersionUID = 7495157056049312109L ;
23+
24+ /**
25+ * 用户的openid.
26+ */
27+ @ SerializedName ("openid" )
28+ private String openid ;
29+
30+ /**
31+ * 环境。0-正式环境;1-沙箱环境.
32+ */
33+ @ SerializedName ("env" )
34+ private Integer env ;
35+
36+ /**
37+ * 商户订单号.
38+ */
39+ @ SerializedName ("order_id" )
40+ private String orderId ;
41+
42+ /**
43+ * 设备类型。0-安卓;1-iOS.
44+ */
45+ @ SerializedName ("device_type" )
46+ private Integer deviceType ;
47+
48+ /**
49+ * 道具id.
50+ */
51+ @ SerializedName ("goods_id" )
52+ private String goodsId ;
53+
54+ /**
55+ * 道具数量.
56+ */
57+ @ SerializedName ("goods_number" )
58+ private Integer goodsNumber ;
59+
60+ public String toJson () {
61+ return WxMaGsonBuilder .create ().toJson (this );
62+ }
63+ }
Original file line number Diff line number Diff line change 1+ package cn .binarywang .wx .miniapp .bean .xpay ;
2+
3+ import cn .binarywang .wx .miniapp .bean .WxMaBaseResponse ;
4+ import cn .binarywang .wx .miniapp .json .WxMaGsonBuilder ;
5+ import com .google .gson .annotations .SerializedName ;
6+ import lombok .AllArgsConstructor ;
7+ import lombok .Builder ;
8+ import lombok .Data ;
9+ import lombok .NoArgsConstructor ;
10+
11+ import java .io .Serializable ;
12+
13+ /**
14+ * 小游戏道具直购API响应.
15+ *
16+ * @author <a href="https://github.com/binarywang">Binary Wang</a>
17+ */
18+ @ Data
19+ @ Builder
20+ @ NoArgsConstructor
21+ @ AllArgsConstructor
22+ public class WxMaXPayPresentGoodsResponse extends WxMaBaseResponse implements Serializable {
23+ private static final long serialVersionUID = 7495157056049312110L ;
24+
25+ /**
26+ * 商户订单号.
27+ */
28+ @ SerializedName ("order_id" )
29+ private String orderId ;
30+
31+ public String toJson () {
32+ return WxMaGsonBuilder .create ().toJson (this );
33+ }
34+ }
Original file line number Diff line number Diff line change @@ -875,6 +875,7 @@ public interface XPay {
875875 String NOTIFY_PROVIDE_GOODS_URL =
876876 "https://api.weixin.qq.com/xpay/notify_provide_goods?pay_sig=%s" ;
877877 String PRESENT_CURRENCY_URL = "https://api.weixin.qq.com/xpay/present_currency?pay_sig=%s" ;
878+ String PRESENT_GOODS_URL = "https://api.weixin.qq.com/xpay/present_goods?pay_sig=%s" ;
878879 String DOWNLOAD_BILL_URL = "https://api.weixin.qq.com/xpay/download_bill?pay_sig=%s" ;
879880 String REFUND_ORDER_URL = "https://api.weixin.qq.com/xpay/refund_order?pay_sig=%s" ;
880881 String CREATE_WITHDRAW_ORDER_URL =
You can’t perform that action at this time.
0 commit comments