diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendMiniProgramRedpackRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendMiniProgramRedpackRequest.java new file mode 100644 index 0000000000..4215399d4a --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendMiniProgramRedpackRequest.java @@ -0,0 +1,112 @@ +package com.github.binarywang.wxpay.bean.request; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; +import lombok.experimental.Accessors; + +/** + * 发送小程序红包请求参数对象. + * + * @author Binary Wang + */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +@Builder +@XStreamAlias("xml") +@Accessors(chain = true) +public class WxPaySendMiniProgramRedpackRequest extends BaseWxPayRequest { + private static final long serialVersionUID = -2035425086824987567L; + + @Override + protected String[] getIgnoredParamsForSign() { + return new String[]{"sign_type", "sub_appid"}; + } + + /** + * mch_billno. + * 商户订单号(每个订单号必须唯一) + * 组成:mch_id+yyyymmdd+10位一天内不能重复的数字。 接口根据商户订单号支持重入,如出现超时可再调用。 + */ + @XStreamAlias("mch_billno") + private String mchBillNo; + + /** + * send_name. + * 商户名称 + * 红包发送者名称 + */ + @XStreamAlias("send_name") + private String sendName; + + /** + * re_openid. + * 接受红包的用户 用户在wxappid下的openid + */ + @XStreamAlias("re_openid") + private String reOpenid; + + /** + * total_amount. + * 红包总额 + */ + @XStreamAlias("total_amount") + private Integer totalAmount; + + /** + * total_num + * 红包发放总人数 + */ + @XStreamAlias("total_num") + private Integer totalNum; + + /** + * wishing. + * 红包祝福语 + */ + @XStreamAlias("wishing") + private String wishing; + + /** + * act_name. + * 活动名称 + */ + @XStreamAlias("act_name") + private String actName; + + /** + * remark. + * 备注 + */ + @XStreamAlias("remark") + private String remark; + + /** + * 通知用户形式 . + * 通过JSAPI方式领取红包,小程序红包固定传MINI_PROGRAM_JSAPI + */ + @XStreamAlias("notify_way") + private String notifyWay = "MINI_PROGRAM_JSAPI"; + + /** + *
+ * 发放红包使用场景,红包金额大于200时必传 + * PRODUCT_1:商品促销 + * PRODUCT_2:抽奖 + * PRODUCT_3:虚拟物品兑奖 + * PRODUCT_4:企业内部福利 + * PRODUCT_5:渠道分润 + * PRODUCT_6:保险回馈 + * PRODUCT_7:彩票派奖 + * PRODUCT_8:税务刮奖 + *+ */ + @XStreamAlias("scene_id") + private String sceneId; + + @Override + protected void checkConstraints() { + + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySendMiniProgramRedpackResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySendMiniProgramRedpackResult.java new file mode 100644 index 0000000000..bb9bfee8a1 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPaySendMiniProgramRedpackResult.java @@ -0,0 +1,56 @@ +package com.github.binarywang.wxpay.bean.result; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 发送小程序红包的返回结果 + * + * @author Binary Wang + */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@XStreamAlias("xml") +public class WxPaySendMiniProgramRedpackResult extends BaseWxPayResult implements Serializable { + /** + * 商户订单号. + */ + @XStreamAlias("mch_billno") + private String mchBillNo; + + /** + * 公众账号appid. + */ + @XStreamAlias("wxappid") + private String wxAppid; + + /** + * 用户openid. + */ + @XStreamAlias("re_openid") + private String reOpenid; + + /** + * 付款金额. + */ + @XStreamAlias("total_amount") + private int totalAmount; + + /** + * 返回jaspi的入参package的值. + */ + @XStreamAlias("package") + private String packageName; + + /** + * 微信单号. + */ + @XStreamAlias("send_listid") + private String sendListId; + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java index d3fc4be7ff..0534058138 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java @@ -1,16 +1,7 @@ package com.github.binarywang.wxpay.service; -import java.io.File; -import java.util.Date; -import java.util.Map; - import com.github.binarywang.wxpay.bean.WxPayApiData; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryRequest; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryResult; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendRequest; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendResult; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryRequest; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryResult; +import com.github.binarywang.wxpay.bean.coupon.*; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult; @@ -19,6 +10,10 @@ import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.exception.WxPayException; +import java.io.File; +import java.util.Date; +import java.util.Map; + /** *
* 微信支付相关接口. @@ -281,6 +276,19 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri */ WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData) throws WxPayException; + /** + *+ * 发送小程序红包. + * 文档详见: https://pay.weixin.qq.com/wiki/doc/api/tools/miniprogram_hb.php?chapter=13_9&index=2 + * 接口地址:https://api.mch.weixin.qq.com/mmpaymkttransfers/sendminiprogramhb + *+ * + * @param request 请求对象 + * @return the result + * @throws WxPayException the exception + */ + WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) throws WxPayException; + /** * 发送微信红包给个人用户. *diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java index 4c3465f8df..093997e06b 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java @@ -182,7 +182,19 @@ public WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData) throws WxP } - @Override + @Override + public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) + throws WxPayException { + request.checkAndSign(this.getConfig()); + String url = this.getPayBaseUrl() + "/mmpaymkttransfers/sendminiprogramhb"; + String responseContent = this.post(url, request.toXML(), true); + + WxPaySendMiniProgramRedpackResult result = BaseWxPayResult.fromXML(responseContent, WxPaySendMiniProgramRedpackResult.class); + result.checkResult(this, request.getSignType(), true); + return result; + } + + @Override public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException { request.checkAndSign(this.getConfig()); diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImplTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImplTest.java index 13a507d9e5..551b00ee52 100644 --- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImplTest.java +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImplTest.java @@ -1,43 +1,14 @@ package com.github.binarywang.wxpay.service.impl; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Calendar; -import java.util.Date; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.*; - import com.github.binarywang.utils.qrcode.QrcodeUtils; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryRequest; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryResult; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendRequest; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendResult; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryRequest; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryResult; +import com.github.binarywang.wxpay.bean.coupon.*; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResultTest; import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; -import com.github.binarywang.wxpay.bean.request.WxPayAuthcode2OpenidRequest; -import com.github.binarywang.wxpay.bean.request.WxPayMicropayRequest; -import com.github.binarywang.wxpay.bean.request.WxPayOrderReverseRequest; -import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest; -import com.github.binarywang.wxpay.bean.request.WxPayReportRequest; -import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest; -import com.github.binarywang.wxpay.bean.request.WxPayShorturlRequest; -import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; -import com.github.binarywang.wxpay.bean.result.WxPayBillResult; -import com.github.binarywang.wxpay.bean.result.WxPayFundFlowResult; -import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult; -import com.github.binarywang.wxpay.bean.result.WxPayOrderReverseResult; -import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult; -import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult; -import com.github.binarywang.wxpay.bean.result.WxPayRefundResult; -import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult; -import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult; +import com.github.binarywang.wxpay.bean.request.*; +import com.github.binarywang.wxpay.bean.result.*; import com.github.binarywang.wxpay.constant.WxPayConstants.AccountType; import com.github.binarywang.wxpay.constant.WxPayConstants.BillType; import com.github.binarywang.wxpay.constant.WxPayConstants.SignType; @@ -47,6 +18,16 @@ import com.github.binarywang.wxpay.testbase.ApiTestModule; import com.github.binarywang.wxpay.testbase.XmlWxPayConfig; import com.google.inject.Inject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Calendar; +import java.util.Date; import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType; import static org.assertj.core.api.Assertions.assertThat; @@ -461,8 +442,7 @@ public void testSetConfig() throws Exception { @Test public void testReverseOrder() throws Exception { WxPayOrderReverseResult result = this.payService.reverseOrder( - WxPayOrderReverseRequest - .newBuilder() + WxPayOrderReverseRequest.newBuilder() .outTradeNo("1111") .build()); assertNotNull(result); @@ -541,8 +521,7 @@ public void testSendCoupon() throws Exception { @Test public void testQueryCouponStock() throws Exception { WxPayCouponStockQueryResult result = this.payService.queryCouponStock( - WxPayCouponStockQueryRequest - .newBuilder() + WxPayCouponStockQueryRequest.newBuilder() .couponStockId("123") .build()); this.logger.info(result.toString()); @@ -556,8 +535,7 @@ public void testQueryCouponStock() throws Exception { @Test public void testQueryCouponInfo() throws Exception { WxPayCouponInfoQueryResult result = this.payService.queryCouponInfo( - WxPayCouponInfoQueryRequest - .newBuilder() + WxPayCouponInfoQueryRequest.newBuilder() .openid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP4") .couponId("11") .stockId("1121") @@ -632,4 +610,28 @@ public void testGetWxApiData() throws Exception { //see test in testUnifiedOrder() } + @Test + public void testSendMiniProgramRedpack() throws WxPayException { + final WxPaySendMiniProgramRedpackResult result = this.payService + .sendMiniProgramRedpack(new WxPaySendMiniProgramRedpackRequest() + .setReOpenid("ojOQA0y9o-Eb6Aep7uVTdbkJqrP4") + .setTotalAmount(1)); + System.out.println(result); + } + + @Test + public void testDownloadRawBill() { + } + + @Test + public void testTestDownloadRawBill() { + } + + @Test + public void testGetWxPayFaceAuthInfo() { + } + + @Test + public void testFacepay() { + } }