diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsRequest.java index 3b138b488..61fac62ea 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsRequest.java @@ -8,7 +8,10 @@ import java.io.Serializable; import java.util.List; /** - * 合单支付 对象 + * 合单支付API + *
+ * 文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e-combine.shtml
+ * 
*/ @Data @NoArgsConstructor diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsRequest.java new file mode 100644 index 000000000..a324b616b --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsRequest.java @@ -0,0 +1,654 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.List; + +/** + * 普通支付(电商收付通)API + *
+ * 文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e_transactions.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class PartnerTransactionsRequest implements Serializable { + + /** + *
+   * 字段名:服务商公众号ID
+   * 变量名:sp_appid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  服务商申请的公众号或移动应用appid
+   *  示例值:wx8888888888888888
+   * 
+ */ + @SerializedName(value = "sp_appid") + private String spAppid; + + /** + *
+   * 字段名:服务商户号
+   * 变量名:sp_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  服务商户号,由微信支付生成并下发
+   *  示例值:1230000109
+   * 
+ */ + @SerializedName(value = "sp_mchid") + private String spMchid; + + /** + *
+   * 字段名:子商户公众号ID
+   * 变量名:sub_appid
+   * 是否必填:否
+   * 类型:string(32)
+   * 描述:
+   *  子商户申请的公众号或移动应用appid。
+   *  示例值:wxd678efh567hg6999
+   * 
+ */ + @SerializedName(value = "sub_appid") + private String subAppid; + /** + *
+   * 字段名:二级商户号
+   * 变量名:sub_mchid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  二级商户的商户号,有微信支付生成并下发。
+   *  示例值:1900000109
+   * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+   * 字段名:商品描述
+   * 变量名:description
+   * 是否必填:是
+   * 类型:string(127)
+   * 描述:
+   *  商品描述
+   *  示例值:Image形象店-深圳腾大-QQ公仔
+   * 
+ */ + @SerializedName(value = "description") + private String description; + + /** + *
+   * 字段名:商户订单号
+   * 变量名:out_trade_no
+   * 是否必填:是
+   * 类型:string(127)
+   * 描述:
+   *  商户系统内部订单号, 只能是数字、大小写字母_-*且在同一个商户号下唯一,详见【商户订单号】
+   *  特殊规则:最小字符长度为6
+   *  示例值:1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "out_trade_no") + private String out_trade_no; + + /** + *
+   * 字段名:交易结束时间
+   * 变量名:time_expire
+   * 是否必填:否
+   * 类型:string(14)
+   * 描述:
+   *  订单失效时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
+   *  示例值:2019-12-31T15:59:60+08:00
+   * 
+ */ + @SerializedName(value = "time_expire") + private String timeExpire; + + /** + *
+   * 字段名:附加数据
+   * 变量名:attach
+   * 是否必填:否
+   * 类型:string(128)
+   * 描述:
+   *  附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用。
+   *  示例值:自定义数据
+   * 
+ */ + @SerializedName(value = "attach") + private String attach; + + /** + *
+   * 字段名:通知地址
+   * 变量名:notify_url
+   * 是否必填:是
+   * 类型:string(127)
+   * 描述:
+   *  通知URL必须为直接可访问的URL,不允许携带查询串。
+   *  示例值:https://www.weixin.qq.com/wxpay/pay.php
+   * 
+ */ + @SerializedName(value = "notify_url") + private String notifyUrl; + + /** + *
+   * 字段名:订单优惠标记
+   * 变量名:goods_tag
+   * 是否必填:否
+   * 类型:string(32)
+   * 描述:
+   *  订单优惠标记
+   *  示例值:WXG
+   * 
+ */ + @SerializedName(value = "goods_tag") + private String goodsTag; + + /** + *
+   * 字段名:+结算信息
+   * 变量名:settle_info
+   * 是否必填:否
+   * 类型:Object
+   * 描述:结算信息
+   * 
+ */ + @SerializedName(value = "settle_info") + private SettleInfo settleInfo; + + /** + *
+   * 字段名:订单金额
+   * 变量名:amount
+   * 是否必填:是
+   * 类型:object
+   * 描述:
+   *  订单金额信息
+   * 
+ */ + @SerializedName(value = "amount") + private Amount amount; + + /** + *
+   * 字段名:优惠功能
+   * 变量名:detail
+   * 是否必填:否
+   * 类型:object
+   * 描述:
+   *  优惠功能
+   * 
+ */ + @SerializedName(value = "detail") + private Discount detail; + + /** + *
+   * 字段名:支付者
+   * 变量名:payer
+   * 是否必填:是(仅JSAPI支付必传)
+   * 类型:object
+   * 描述:
+   *  支付者信息
+   * 
+ */ + @SerializedName(value = "payer") + private Payer payer; + + /** + *
+   * 字段名:场景信息
+   * 变量名:scene_info
+   * 是否必填:是(仅H5支付必传)
+   * 类型:object
+   * 描述:
+   *  支付场景描述
+   * 
+ */ + @SerializedName(value = "scene_info") + private SceneInfo sceneInfo; + + @Data + @NoArgsConstructor + public static class Discount implements Serializable { + + /** + *
+     * 字段名:订单原价
+     * 变量名:cost_price
+     * 是否必填:否
+     * 类型:int64
+     * 描述:
+     *  1、商户侧一张小票订单可能被分多次支付,订单原价用于记录整张小票的交易金额。
+     *  2、当订单原价与支付金额不相等,则不享受优惠。
+     *  3、该字段主要用于防止同一张小票分多次支付,以享受多次优惠的情况,正常支付订单不必上传此参数。
+     *  示例值:608800
+     * 
+ */ + @SerializedName(value = "cost_price") + private Integer costPrice; + + /** + *
+     * 字段名:商品小票ID
+     * 变量名:invoice_id
+     * 是否必填:否
+     * 类型:string(32)
+     * 描述:
+     *  商品小票ID
+     *  示例值:微信123
+     * 
+ */ + @SerializedName(value = "invoice_id") + private Integer invoiceId; + + /** + *
+     * 字段名:单品列表
+     * 变量名:goods_detail
+     * 是否必填:否
+     * 类型:array
+     * 描述:
+     *  单品列表信息
+     *  条目个数限制:【1,undefined】
+     * 
+ */ + @SerializedName(value = "goods_detail") + private List goodsDetails; + } + + @Data + @NoArgsConstructor + public static class Amount implements Serializable { + + /** + *
+     * 字段名:总金额
+     * 变量名:total
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  订单总金额,单位为分。
+     *  示例值:100
+     * 
+ */ + @SerializedName(value = "total") + private Integer total; + + /** + *
+     * 字段名:币类型
+     * 变量名:currency
+     * 是否必填:否
+     * 类型:string(16)
+     * 描述:
+     *  CNY:人民币,境内商户号仅支持人民币。
+     *  示例值:CNY
+     * 
+ */ + @SerializedName(value = "currency") + private String currency; + + } + + @Data + @NoArgsConstructor + public static class Payer implements Serializable { + + /** + *
+     * 字段名:用户服务标识
+     * 变量名:sp_openid
+     * 是否必填:是
+     * 类型:string(128)
+     * 描述:
+     *  用户在服务商appid下的唯一标识。
+     *  示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
+     * 
+ */ + @SerializedName(value = "sp_openid") + private String spOpenid; + + /** + *
+     * 字段名:用户子标识
+     * 变量名:sub_openid
+     * 是否必填:否
+     * 类型:string(128)
+     * 描述:
+     *  用户在子商户appid下的唯一标识。
+     *  示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
+     * 
+ */ + @SerializedName(value = "sub_openid") + private String subOpenid; + + } + + @Data + @NoArgsConstructor + public static class SettleInfo implements Serializable{ + /** + *
+     * 字段名:是否指定分账
+     * 变量名:profit_sharing
+     * 是否必填:否
+     * 类型:bool
+     * 描述:
+     *  是否分账,与外层profit_sharing同时存在时,以本字段为准。
+     *  true:是
+     *  false:否
+     *  示例值:true
+     * 
+ */ + @SerializedName(value = "profit_sharing") + private Boolean profitSharing; + + /** + *
+     * 字段名:补差金额
+     * 变量名:subsidy_amount
+     * 是否必填:否
+     * 类型:int64
+     * 描述:
+     *  SettleInfo.profit_sharing为true时,该金额才生效。
+     *    注意:单笔订单最高补差金额为5000元
+     *  示例值:10
+     * 
+ */ + @SerializedName(value = "subsidy_amount") + private BigDecimal subsidyAmount; + + } + + @Data + @NoArgsConstructor + public static class GoodsDetail implements Serializable { + + /** + *
+     * 字段名:商户侧商品编码
+     * 变量名:merchant_goods_id
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  由半角的大小写字母、数字、中划线、下划线中的一种或几种组成。
+     * 示例值:商品编码
+     * 
+ */ + @SerializedName(value = "merchant_goods_id") + private String merchantGoodsId; + + /** + *
+     * 字段名:微信侧商品编码
+     * 变量名:wechatpay_goods_id
+     * 是否必填:否
+     * 类型:string(32)
+     * 描述:
+     *  微信支付定义的统一商品编号(没有可不传)
+     * 示例值:1001
+     * 
+ */ + @SerializedName(value = "wechatpay_goods_id") + private String wechatpayGoodsId; + + /** + *
+     * 字段名:商品名称
+     * 变量名:goods_name
+     * 是否必填:否
+     * 类型:string(256)
+     * 描述:
+     *  商品的实际名称
+     * 示例值:iPhoneX 256G
+     * 
+ */ + @SerializedName(value = "goods_name") + private String goodsName; + + /** + *
+     * 字段名:商品数量
+     * 变量名:quantity
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  用户购买的数量
+     * 示例值:1
+     * 
+ */ + @SerializedName(value = "quantity") + private Integer quantity; + + /** + *
+     * 字段名:商品单价
+     * 变量名:unit_price
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  商品单价,单位为分
+     * 示例值:828800
+     * 
+ */ + @SerializedName(value = "unit_price") + private Integer unitPrice; + } + + @Data + @NoArgsConstructor + public static class SceneInfo implements Serializable { + /** + *
+     * 字段名:商户端设备号
+     * 变量名:device_id
+     * 是否必填:否
+     * 类型:string(16)
+     * 描述:
+     *  终端设备号(门店号或收银设备ID)。
+     *  特殊规则:长度最小7个字节
+     *  示例值:POS1:1
+     * 
+ */ + @SerializedName(value = "device_id") + private String deviceId; + + /** + *
+     * 字段名:用户终端IP
+     * 变量名:payer_client_ip
+     * 是否必填:是
+     * 类型:string(45)
+     * 描述:
+     *  用户端实际ip
+     *  格式: ip(ipv4+ipv6)
+     *  示例值:14.17.22.32
+     * 
+ */ + @SerializedName(value = "payer_client_ip") + private String payerClientIp; + + /** + *
+     * 字段名:H5场景信息
+     * 变量名:h5_info
+     * 是否必填:否(H5支付必填)
+     * 类型:object
+     * 描述:
+     *  H5场景信息
+     * 
+ */ + @SerializedName(value = "h5_info") + private H5Info h5Info; + + /** + *
+     * 字段名:商户门店信息
+     * 变量名:store_info
+     * 是否必填:否(H5支付必填)
+     * 类型:object
+     * 描述:
+     *  商户门店信息
+     * 
+ */ + @SerializedName(value = "store_info") + private StoreInfo storeInfo; + + } + + @Data + @NoArgsConstructor + public static class H5Info implements Serializable { + + /** + *
+     * 字段名:场景类型
+     * 变量名:type
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  场景类型,枚举值:
+     *  iOS:IOS移动应用;
+     *  Android:安卓移动应用;
+     *  Wap:WAP网站应用;
+     *  示例值:iOS
+     * 
+ */ + @SerializedName(value = "type") + private String type; + + /** + *
+     * 字段名:应用名称
+     * 变量名:app_name
+     * 是否必填:否
+     * 类型:string(64)
+     * 描述:
+     *  应用名称
+     *  示例值:王者荣耀
+     * 
+ */ + @SerializedName(value = "app_name") + private String appName; + + /** + *
+     * 字段名:网站URL
+     * 变量名:app_url
+     * 是否必填:否
+     * 类型:string(128)
+     * 描述:
+     *  网站URL
+     *  示例值:https://pay.qq.com
+     * 
+ */ + @SerializedName(value = "app_url") + private String appUrl; + + /** + *
+     * 字段名:iOS平台BundleID
+     * 变量名:bundle_id
+     * 是否必填:否
+     * 类型:string(128)
+     * 描述:
+     *  iOS平台BundleID
+     *  示例值:com.tencent.wzryiOS
+     * 
+ */ + @SerializedName(value = "bundle_id") + private String bundleId; + + /** + *
+     * 字段名:Android平台PackageName
+     * 变量名:package_name
+     * 是否必填:否
+     * 类型:string(128)
+     * 描述:
+     *  Android平台PackageName
+     *  示例值:com.tencent.tmgp.sgame
+     * 
+ */ + @SerializedName(value = "package_name") + private String packageName; + + } + + @Data + @NoArgsConstructor + public static class StoreInfo implements Serializable { + + /** + *
+     * 字段名:门店编号
+     * 变量名:id
+     * 是否必填:否
+     * 类型:string(32)
+     * 描述:
+     *  商户侧门店编号
+     * 示例值:0001
+     * 
+ */ + @SerializedName(value = "id") + private String id; + + /** + *
+     * 字段名:门店名称
+     * 变量名:name
+     * 是否必填:是
+     * 类型:string(256)
+     * 描述:
+     *  商户侧门店名称
+     * 示例值:腾讯大厦分店
+     * 
+ */ + @SerializedName(value = "name") + private String name; + + /** + *
+     * 字段名:地区编码
+     * 变量名:area_code
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  地区编码,详细请见省市区编号对照表(https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter4_1.shtml)。
+     * 示例值:440305
+     * 
+ */ + @SerializedName(value = "area_code") + private String areaCode; + + /** + *
+     * 字段名:详细地址
+     * 变量名:address
+     * 是否必填:是
+     * 类型:string(512)
+     * 描述:
+     *  详细的商户门店地址
+     * 示例值:广东省深圳市南山区科技中一道10000号
+     * 
+ */ + @SerializedName(value = "address") + private String address; + + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/TransactionsResult.java similarity index 94% rename from weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsResult.java rename to weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/TransactionsResult.java index cd4edc9d5..3ce288a70 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/TransactionsResult.java @@ -1,7 +1,6 @@ package com.github.binarywang.wxpay.bean.ecommerce; import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum; -import com.github.binarywang.wxpay.v3.util.AesUtils; import com.github.binarywang.wxpay.v3.util.SignUtils; import com.google.gson.annotations.SerializedName; import lombok.Data; @@ -10,17 +9,13 @@ import lombok.experimental.Accessors; import java.io.Serializable; import java.security.PrivateKey; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -import java.util.UUID; /** * 合单支付 JSAPI支付结果响应 */ @Data @NoArgsConstructor -public class CombineTransactionsResult implements Serializable { +public class TransactionsResult implements Serializable { /** *
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/enums/TradeTypeEnum.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/enums/TradeTypeEnum.java
index c65600ecf..03dd2cb36 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/enums/TradeTypeEnum.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/enums/TradeTypeEnum.java
@@ -19,9 +19,9 @@ public enum TradeTypeEnum {
   /**
    * 合单url
    */
-  private String combineUrl;
+  private final String combineUrl;
   /**
    * 单独下单url
    */
-  private String partnerUrl;
+  private final String partnerUrl;
 }
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java
index c9faaeddf..add7c17d1 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java
@@ -56,14 +56,26 @@ public interface EcommerceService {
 
   /**
    * 
-   * 合单下单-JS支付API.
+   * 合单支付API(APP支付、JSAPI支付、H5支付、NATIVE支付).
    * 请求URL:https://api.mch.weixin.qq.com/v3/combine-transactions/jsapi
-   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/combine/chapter3_2.shtml
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e-combine.shtml
    * 
* + * @param tradeType 支付方式 * @param request 请求对象 - * @return 预支付交易会话标识, 数字和字母。微信生成的预支付会话标识,用于后续接口调用使用。 + * @return 调起支付需要的参数 */ T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException; + /** + *
+   *  服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付).
+   *  请求URL:https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi
+   *  文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/transactions_sl.shtml
+   *  
+ * @param tradeType 支付方式 + * @param request 请求对象 + * @return 调起支付需要的参数 + */ + T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException; } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java index 18f51a45c..45205ac06 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java @@ -9,7 +9,6 @@ import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; -import org.apache.commons.lang3.StringUtils; import java.net.URI; @@ -45,10 +44,17 @@ public class EcommerceServiceImpl implements EcommerceService { public T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException { String url = this.payService.getPayBaseUrl() + tradeType.getCombineUrl(); String response = this.payService.postV3(url, GSON.toJson(request)); - CombineTransactionsResult result = GSON.fromJson(response, CombineTransactionsResult.class); + TransactionsResult result = GSON.fromJson(response, TransactionsResult.class); return result.getPayInfo(tradeType, request.getCombineAppid(), request.getCombineMchid(), payService.getConfig().getPrivateKey()); } - + @Override + public T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException { + String url = this.payService.getPayBaseUrl() + tradeType.getPartnerUrl(); + String response = this.payService.postV3(url, GSON.toJson(request)); + TransactionsResult result = GSON.fromJson(response, TransactionsResult.class); + return result.getPayInfo(tradeType, request.getSpAppid(), + request.getSpMchid(), payService.getConfig().getPrivateKey()); + } }