diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/CombineNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/CombineNotifyResult.java index 111deedb19..aba11d2dc0 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/CombineNotifyResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/CombineNotifyResult.java @@ -250,6 +250,34 @@ public static class SubOrders implements Serializable { */ @SerializedName(value = "out_trade_no") private String outTradeNo; + /** + *
+ * 字段名:子商户应用ID + * 变量名:sub_appid + * 是否必填:是 + * 类型:string[1,32] + * 描述: + * 子商户申请的应用ID,全局唯一。请求基础下单接口时请注意APPID的应用属性,例如公众号场景下, + * 需使用应用属性为公众号的APPID 若sub_openid有传的情况下, + * sub_appid必填,且sub_appid需与sub_openid对应 + * 示例值:wxd678efh567hg6999 + *+ */ + @SerializedName(value = "sub_appid") + private String subAppid; + /** + *
+ * 字段名:二级商户号 + * 变量名:sub_mchid + * 是否必填:是 + * 类型:string[1,32] + * 描述: + * 二级商户商户号,由微信支付生成并下发。服务商子商户的商户号,被合单方。直连商户不用传二级商户号。 + * 示例值:1900000109 + *+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; /** *
* 字段名:订单金额 diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/CombineTransactionsRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/CombineTransactionsRequest.java index 036cfe9872..721d9a39e5 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/CombineTransactionsRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/CombineTransactionsRequest.java @@ -240,6 +240,32 @@ public static class SubOrders implements Serializable { */ @SerializedName(value = "out_trade_no") private String outTradeNo; + /** + *+ * 字段名:订单优惠标记 + * 变量名:goods_tag + * 是否必填:是 + * 类型:string[1,32] + * 描述: + * 订单优惠标记,使用代金券或立减优惠功能时需要的参数,说明详见代金券或立减优惠 + * 示例值:WXG + *+ */ + @SerializedName(value = "goods_tag") + private String goodsTag; + /** + *+ * 字段名:二级商户号 + * 变量名:sub_mchid + * 是否必填:是 + * 类型:string[1,32] + * 描述: + * 二级商户商户号,由微信支付生成并下发。服务商子商户的商户号,被合单方。直连商户不用传二级商户号。 + * 示例值:1900000109 + *+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; /** ** 字段名:商品描述 @@ -264,6 +290,21 @@ public static class SubOrders implements Serializable { */ @SerializedName(value = "settle_info") private SettleInfo settleInfo; + /** + *+ * 字段名:子商户应用ID + * 变量名:sub_appid + * 是否必填:是 + * 类型:string[1,32] + * 描述: + * 子商户申请的应用ID,全局唯一。请求基础下单接口时请注意APPID的应用属性,例如公众号场景下, + * 需使用应用属性为公众号的APPID 若sub_openid有传的情况下, + * sub_appid必填,且sub_appid需与sub_openid对应 + * 示例值:wxd678efh567hg6999 + *+ */ + @SerializedName(value = "sub_appid") + private String subAppid; } @Data @@ -283,6 +324,21 @@ public static class CombinePayerInfo implements Serializable { */ @SerializedName(value = "openid") private String openid; + /** + *+ * 字段名:子用户标识 + * 变量名:sub_openid + * 是否必填:是 + * 类型:string[1,128] + * 描述: + * 服务商模式下,使用某个子商户的Appid获取的对应用户Openid, + * 是用户在该子商户Appid下的唯一标识。openid和sub_openid可以选传其中之一, + * 如果选择传sub_openid,则必须传sub_appid。 + * 示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o + *+ */ + @SerializedName(value = "sub_openid") + private String subOpenid; } @Data diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java index f37d268739..309fb8e752 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java @@ -1,6 +1,5 @@ package com.github.binarywang.wxpay.bean.result; -import com.github.binarywang.wxpay.bean.result.enums.PartnerTradeTypeEnum; import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum; import com.github.binarywang.wxpay.v3.util.SignUtils; import com.google.gson.annotations.SerializedName; @@ -133,32 +132,4 @@ publicT getPayInfo(TradeTypeEnum tradeType, String appId, String mchId, Pri throw new WxRuntimeException("不支持的支付类型"); } } - - public T getPartnerPayInfo(PartnerTradeTypeEnum tradeType, String appId, String mchId, PrivateKey privateKey) { - String timestamp = String.valueOf(System.currentTimeMillis() / 1000); - String nonceStr = SignUtils.genRandomStr(); - switch (tradeType) { - case JSAPI: - JsapiResult jsapiResult = new JsapiResult(); - jsapiResult.setAppId(appId).setTimeStamp(timestamp) - .setPackageValue("prepay_id=" + this.prepayId).setNonceStr(nonceStr) - //签名类型,默认为RSA,仅支持RSA。 - .setSignType("RSA").setPaySign(SignUtils.sign(jsapiResult.getSignStr(), privateKey)); - return (T) jsapiResult; - case H5: - return (T) this.h5Url; - case APP: - AppResult appResult = new AppResult(); - appResult.setAppid(appId).setPrepayId(this.prepayId).setPartnerId(mchId) - .setNoncestr(nonceStr).setTimestamp(timestamp) - //暂填写固定值Sign=WXPay - .setPackageValue("Sign=WXPay") - .setSign(SignUtils.sign(appResult.getSignStr(), privateKey)); - return (T) appResult; - case NATIVE: - return (T) this.codeUrl; - default: - throw new WxRuntimeException("不支持的支付类型"); - } - } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/enums/PartnerTradeTypeEnum.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/enums/PartnerTradeTypeEnum.java deleted file mode 100644 index 4d69b9240e..0000000000 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/enums/PartnerTradeTypeEnum.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.binarywang.wxpay.bean.result.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 支付方式 - * - * @author thinsstar - */ -@Getter -@AllArgsConstructor -public enum PartnerTradeTypeEnum { - /** - * APP - */ - APP("/v3/pay/partner/transactions/app", "/v3/combine-transactions/app", TradeTypeEnum.APP), - /** - * JSAPI 或 小程序 - */ - JSAPI("/v3/pay/partner/transactions/jsapi", "/v3/combine-transactions/jsapi", TradeTypeEnum.JSAPI), - /** - * NATIVE - */ - NATIVE("/v3/pay/partner/transactions/native", "/v3/combine-transactions/native", TradeTypeEnum.NATIVE), - /** - * H5 - */ - H5("/v3/pay/partner/transactions/h5", "/v3/combine-transactions/h5", TradeTypeEnum.H5); - - /** - * 单独下单url - */ - private final String partnerUrl; - - /** - * 合并下单url - */ - private final String combineUrl; - - /** - * 直连支付枚举 - */ - private final TradeTypeEnum directConnTrade; -} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/enums/TradeTypeEnum.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/enums/TradeTypeEnum.java index d22b94801e..18f78c4287 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/enums/TradeTypeEnum.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/enums/TradeTypeEnum.java @@ -14,19 +14,19 @@ public enum TradeTypeEnum { /** * APP */ - APP("/v3/pay/transactions/app", "/v3/combine-transactions/app"), + APP("/v3/pay/transactions/app", "/v3/combine-transactions/app", "/v3/pay/partner/transactions/app"), /** * JSAPI 或 小程序 */ - JSAPI("/v3/pay/transactions/jsapi", "/v3/combine-transactions/jsapi"), + JSAPI("/v3/pay/transactions/jsapi", "/v3/combine-transactions/jsapi", "/v3/pay/partner/transactions/jsapi"), /** * NATIVE */ - NATIVE("/v3/pay/transactions/native", "/v3/combine-transactions/native"), + NATIVE("/v3/pay/transactions/native", "/v3/combine-transactions/native", "/v3/pay/partner/transactions/native"), /** * H5 */ - H5("/v3/pay/transactions/h5", "/v3/combine-transactions/h5"); + H5("/v3/pay/transactions/h5", "/v3/combine-transactions/h5", "/v3/pay/partner/transactions/native"); /** * 单独下单url @@ -37,4 +37,9 @@ public enum TradeTypeEnum { * 合并下单url */ private final String combineUrl; + + /** + * 服务商下单 + */ + private final String basePartnerUrl; } 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 aa20645a31..4384f46fa7 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 @@ -5,14 +5,12 @@ import com.github.binarywang.wxpay.bean.notify.*; import com.github.binarywang.wxpay.bean.request.*; import com.github.binarywang.wxpay.bean.result.*; -import com.github.binarywang.wxpay.bean.result.enums.PartnerTradeTypeEnum; import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.constant.WxPayConstants; import com.github.binarywang.wxpay.exception.WxPayException; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; - import java.io.File; import java.io.InputStream; import java.util.Date; @@ -641,7 +639,7 @@ public interface WxPayService { * @return 返回 {@link com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result}里的内部类或字段 * @throws WxPayException the wx pay exception */ - T createPartnerOrderV3(PartnerTradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException; + T createPartnerOrderV3(TradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException; /** * 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识" @@ -649,8 +647,9 @@ public interface WxPayService { * @param tradeType the trade type * @param request 请求对象,注意一些参数如spAppid、spMchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) * @return the wx pay unified order result + * @throws WxPayException the wx pay exception */ - WxPayUnifiedOrderV3Result unifiedPartnerOrderV3(PartnerTradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException; + WxPayUnifiedOrderV3Result unifiedPartnerOrderV3(TradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request 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 aaa377c9b1..845103c0da 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 @@ -10,7 +10,6 @@ import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; import com.github.binarywang.wxpay.bean.request.*; import com.github.binarywang.wxpay.bean.result.*; -import com.github.binarywang.wxpay.bean.result.enums.PartnerTradeTypeEnum; import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.config.WxPayConfigHolder; @@ -712,15 +711,15 @@ public T createOrderV3(TradeTypeEnum tradeType, WxPayUnifiedOrderV3Request r } @Override - public T createPartnerOrderV3(PartnerTradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException { + public T createPartnerOrderV3(TradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException { WxPayUnifiedOrderV3Result result = this.unifiedPartnerOrderV3(tradeType, request); //获取应用ID String appId = StringUtils.isBlank(request.getSubAppid()) ? request.getSpAppid() : request.getSubAppid(); - return result.getPayInfo(tradeType.getDirectConnTrade(), appId, request.getSubMchId(), this.getConfig().getPrivateKey()); + return result.getPayInfo(tradeType, appId, request.getSubMchId(), this.getConfig().getPrivateKey()); } @Override - public WxPayUnifiedOrderV3Result unifiedPartnerOrderV3(PartnerTradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException { + public WxPayUnifiedOrderV3Result unifiedPartnerOrderV3(TradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException { if (StringUtils.isBlank(request.getSpAppid())) { request.setSpAppid(this.getConfig().getAppId()); } @@ -741,7 +740,7 @@ public WxPayUnifiedOrderV3Result unifiedPartnerOrderV3(PartnerTradeTypeEnum trad request.setSubMchId(this.getConfig().getSubMchId()); } - String url = this.getPayBaseUrl() + tradeType.getPartnerUrl(); + String url = this.getPayBaseUrl() + tradeType.getBasePartnerUrl(); String response = this.postV3(url, GSON.toJson(request)); return GSON.fromJson(response, WxPayUnifiedOrderV3Result.class); }