diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java index a00c9cbade..d60f5cedd5 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/fs/FileUtils.java @@ -1,11 +1,16 @@ package me.chanjar.weixin.common.util.fs; +import org.apache.commons.io.IOUtils; + import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.util.Base64; +import static org.apache.commons.io.FileUtils.openOutputStream; + public class FileUtils { /** @@ -20,10 +25,16 @@ public static File createTmpFile(InputStream inputStream, String name, String ex File resultFile = File.createTempFile(name, '.' + ext, tmpDirFile); resultFile.deleteOnExit(); - org.apache.commons.io.FileUtils.copyToFile(inputStream, resultFile); + copyToFile(inputStream, resultFile); return resultFile; } + private static void copyToFile(final InputStream source, final File destination) throws IOException { + try (InputStream in = source; OutputStream out = openOutputStream(destination)) { + IOUtils.copy(in, out); + } + } + /** * 创建临时文件. * diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/applydata/ContentValue.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/applydata/ContentValue.java index 54e19a4bf9..19c0231921 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/applydata/ContentValue.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/applydata/ContentValue.java @@ -18,10 +18,10 @@ public class ContentValue implements Serializable { private String text; @SerializedName("new_number") - private Double newNumber; + private String newNumber; @SerializedName("new_money") - private Double newMoney; + private String newMoney; private ContentValue.Date date; @@ -43,7 +43,7 @@ public static class Date implements Serializable { private String type; @SerializedName("s_timestamp") - private Double timestamp; + private String timestamp; } @Data diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ApplymentsRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ApplymentsRequest.java index bd021fc571..00516eabb6 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ApplymentsRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ApplymentsRequest.java @@ -792,6 +792,18 @@ public static class SalesSceneInfo implements Serializable { @SerializedName(value = "store_qr_code") private String storeQrCode; + /** + *
+     * 字段名:小程序AppID
+     * 变量名:mini_program_sub_appid
+     * 是否必填:否
+     * 类型:string(256)
+     * 描述:
+     * 
+ */ + @SerializedName(value = "mini_program_sub_appid") + private String miniProgramSubAppid; + } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ApplymentsStatusResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ApplymentsStatusResult.java index b3704d6526..a12c3d4a8d 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ApplymentsStatusResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ApplymentsStatusResult.java @@ -14,6 +14,7 @@ @Data @NoArgsConstructor public class ApplymentsStatusResult implements Serializable { + private static final long serialVersionUID = 1488464536143984732L; /** *
    * 字段名:申请状态
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsNotifyResult.java
new file mode 100644
index 0000000000..0f0196a8ce
--- /dev/null
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/CombineTransactionsNotifyResult.java
@@ -0,0 +1,360 @@
+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.util.List;
+
+/**
+ * 合单支付 通知结果
+ * 
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/combine/chapter3_7.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class CombineTransactionsNotifyResult implements Serializable { + + private static final long serialVersionUID = -4710926828683593250L; + /** + * 源数据 + */ + private NotifyResponse rawData; + + /** + *
+     * 字段名:合单商户appid
+     * 变量名:combine_appid
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  合单发起方的appid。(即电商平台appid)
+     *  示例值:wxd678efh567hg6787
+     * 
+ */ + @SerializedName(value = "combine_appid") + private String combineAppid; + + /** + *
+     * 字段名:合单商户号
+     * 变量名:combine_mchid
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  合单发起方商户号。(即电商平台mchid)
+     *  示例值:1900000109
+     * 
+ */ + @SerializedName(value = "combine_mchid") + private String combineMchid; + + /** + *
+     * 字段名:合单商户订单号
+     * 变量名:combine_out_trade_no
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  合单支付总订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
+     *  示例值:P20150806125346
+     * 
+ */ + @SerializedName(value = "combine_out_trade_no") + private String combineOutTradeNo; + + /** + *
+     * 字段名:+场景信息
+     * 变量名:scene_info
+     * 是否必填:否
+     * 类型:object
+     * 描述:支付场景信息描述
+     * 
+ */ + @SerializedName(value = "scene_info") + private SceneInfo sceneInfo; + + /** + *
+     * 字段名:+子单信息
+     * 变量名:sub_orders
+     * 是否必填:是
+     * 类型:array
+     * 描述:
+     *  最多支持子单条数:50
+     *
+     * 
+ */ + @SerializedName(value = "sub_orders") + private List subOrders; + + /** + *
+     * 字段名:+支付者
+     * 变量名:combine_payer_info
+     * 是否必填:否
+     * 类型:object
+     * 描述:示例值:见请求示例
+     * 
+ */ + @SerializedName(value = "combine_payer_info") + private CombinePayerInfo combinePayerInfo; + + @Data + @NoArgsConstructor + public static class SubOrders implements Serializable { + /** + *
+     * 字段名:子单商户号
+     * 变量名:mchid
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  子单发起方商户号,必须与发起方Appid有绑定关系。(即电商平台mchid)
+     *  示例值:1900000109
+     * 
+ */ + @SerializedName(value = "mchid") + private String mchid; + + /** + *
+     * 字段名:交易类型
+     * 变量名:trade_type
+     * 是否必填:是
+     * 类型:string (16)
+     * 描述:
+     *  枚举值:
+     *  NATIVE:扫码支付
+     *  JSAPI:公众号支付
+     *  APP:APP支付
+     *  MWEB:H5支付
+     *  示例值: JSAPI
+     * 
+ */ + @SerializedName(value = "trade_type") + private String tradeType; + + /** + *
+     * 字段名:交易状态
+     * 变量名:trade_state
+     * 是否必填:是
+     * 类型:string (32)
+     * 描述:
+     *  枚举值:
+     *  SUCCESS:支付成功
+     *  REFUND:转入退款
+     *  NOTPAY:未支付
+     *  CLOSED:已关闭
+     *  USERPAYING:用户支付中
+     *  PAYERROR:支付失败(其他原因,如银行返回失败)
+     *  示例值: SUCCESS
+     * 
+ */ + @SerializedName(value = "trade_state") + private String tradeState; + + /** + *
+     * 字段名:付款银行
+     * 变量名:bank_type
+     * 是否必填:否
+     * 类型:string(16)
+     * 描述:
+     *  银行类型,采用字符串类型的银行标识。
+     *  示例值:CMC
+     * 
+ */ + @SerializedName(value = "bank_type") + private String bankType; + + /** + *
+     * 字段名:附加信息
+     * 变量名:attach
+     * 是否必填:是
+     * 类型:string(128)
+     * 描述:
+     *  附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用。
+     *  示例值:深圳分店
+     * 
+ */ + @SerializedName(value = "attach") + private String attach; + + /** + *
+     * 字段名:支付完成时间
+     * 变量名:success_time
+     * 是否必填:是
+     * 类型:string(16)
+     * 描述:
+     *  订单支付时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss:sss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss:sss表示时分秒毫秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35.120+08:00表示,北京时间2015年5月20日 13点29分35秒。
+     *  示例值:2015-05-20T13:29:35.120+08:00
+     * 
+ */ + @SerializedName(value = "success_time") + private String successTime; + + /** + *
+     * 字段名:微信订单号
+     * 变量名:transaction_id
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  微信支付订单号。
+     *  示例值: 1009660380201506130728806387
+     * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+     * 字段名:子单商户订单号
+     * 变量名:out_trade_no
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
+     *  特殊规则:最小字符长度为6
+     *  示例值:20150806125346
+     * 
+ */ + @SerializedName(value = "out_trade_no") + private String outTradeNo; + + /** + *
+     * 字段名:二级商户号
+     * 变量名:sub_mchid
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:
+     *  二级商户商户号,由微信支付生成并下发。
+     *  注意:仅适用于电商平台 服务商
+     *  示例值:1900000109
+     * 
+ */ + @SerializedName(value = "sub_mchid") + private String subMchid; + + /** + *
+     * 字段名:+订单金额
+     * 变量名:amount
+     * 是否必填:是
+     * 类型:object
+     * 描述:订单金额信息
+     * 
+ */ + @SerializedName(value = "amount") + private Amount amount; + + } + + @Data + @NoArgsConstructor + public static class SceneInfo implements Serializable { + /** + *
+     * 字段名:商户端设备号
+     * 变量名:device_id
+     * 是否必填:否
+     * 类型:string(16)
+     * 描述:
+     *  终端设备号(门店号或收银设备ID)。
+     *  特殊规则:长度最小7个字节
+     *  示例值:POS1:1
+     * 
+ */ + @SerializedName(value = "device_id") + private String deviceId; + + } + + @Data + @NoArgsConstructor + public static class CombinePayerInfo implements Serializable { + /** + *
+     * 字段名:用户标识
+     * 变量名:openid
+     * 是否必填:是
+     * 类型:string(128)
+     * 描述:
+     *  使用合单appid获取的对应用户openid。是用户在商户appid下的唯一标识。
+     *  示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
+     * 
+ */ + @SerializedName(value = "openid") + private String openid; + + } + + @Data + @NoArgsConstructor + public static class Amount implements Serializable { + /** + *
+     * 字段名:标价金额
+     * 变量名:total_amount
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  子单金额,单位为分。
+     *  示例值:100
+     * 
+ */ + @SerializedName(value = "total_amount") + private Integer totalAmount; + + /** + *
+     * 字段名:标价币种
+     * 变量名:currency
+     * 是否必填:是
+     * 类型:string(8)
+     * 描述:
+     *  符合ISO 4217标准的三位字母代码,人民币:CNY。
+     *  示例值:CNY
+     * 
+ */ + @SerializedName(value = "currency") + private String currency; + + /** + *
+     * 字段名:现金支付金额
+     * 变量名:payer_amount
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  订单现金支付金额。
+     *  示例值:10
+     * 
+ */ + @SerializedName(value = "payer_amount") + private Integer payerAmount; + + /** + *
+     * 字段名:现金支付币种
+     * 变量名:payer_currency
+     * 是否必填:是
+     * 类型:string(8)
+     * 描述:
+     *  货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY。
+     *  示例值: CNY
+     * 
+ */ + @SerializedName(value = "payer_currency") + private String payerCurrency; + } + +} 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 61fac62ea9..9cc0d4b33c 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 @@ -16,6 +16,7 @@ @Data @NoArgsConstructor public class CombineTransactionsRequest implements Serializable { + private static final long serialVersionUID = -1242741645939606441L; /** *
    * 字段名:合单商户appid
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/NotifyResponse.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/NotifyResponse.java
new file mode 100644
index 0000000000..4db416bdde
--- /dev/null
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/NotifyResponse.java
@@ -0,0 +1,51 @@
+package com.github.binarywang.wxpay.bean.ecommerce;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 通知数据
+ */
+@Data
+@NoArgsConstructor
+public class NotifyResponse implements Serializable {
+  private static final long serialVersionUID = 341873114458149365L;
+  @SerializedName(value = "id")
+  private String id;
+
+  @SerializedName(value = "create_time")
+  private String createTime;
+
+  @SerializedName(value = "event_type")
+  private String eventType;
+
+  @SerializedName(value = "resource_type")
+  private String resourceType;
+
+  @SerializedName(value = "resource")
+  private Resource resource;
+
+  @SerializedName(value = "summary")
+  private String summary;
+
+  @Data
+  @NoArgsConstructor
+  public static class Resource implements Serializable {
+
+    @SerializedName(value = "algorithm")
+    private String algorithm;
+
+    @SerializedName(value = "ciphertext")
+    private String ciphertext;
+
+    @SerializedName(value = "associated_data")
+    private String associatedData;
+
+    @SerializedName(value = "nonce")
+    private String nonce;
+  }
+
+}
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsNotifyResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsNotifyResult.java
new file mode 100644
index 0000000000..abb4bfe735
--- /dev/null
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsNotifyResult.java
@@ -0,0 +1,592 @@
+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.util.List;
+
+/**
+ * 普通支付 通知结果
+ * 
+ *   文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/e_transactions/chapter3_11.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class PartnerTransactionsNotifyResult implements Serializable { + private static final long serialVersionUID = -6602962275015706689L; + /** + * 源数据 + */ + private NotifyResponse rawData; + + /** + *
+   * 字段名:服务商公众号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; + + /** + *
+   * 字段名:+商户订单号
+   * 变量名:out_trade_no
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一,详见【商户订单号】。
+   * 特殊规则:最小字符长度为6
+   * 示例值:1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "out_trade_no") + private String outTradeNo; + + /** + *
+   * 字段名:微信支付订单号
+   * 变量名:transaction_id
+   * 是否必填:否
+   * 类型:string(32)
+   * 描述:微信支付系统生成的订单号。
+   * 示例值:1217752501201407033233368018
+   * 
+ */ + @SerializedName(value = "transaction_id") + private String transactionId; + + /** + *
+   * 字段名:交易类型
+   * 变量名:trade_type
+   * 是否必填:否
+   * 类型:string(16)
+   * 描述:交易类型,枚举值:
+   *  JSAPI:公众号支付
+   *  NATIVE:扫码支付
+   *  APP:APP支付
+   *  MICROPAY:付款码支付
+   *  MWEB:H5支付
+   *  FACEPAY:刷脸支付
+   *
+   * 示例值: MICROPAY
+   * 
+ */ + @SerializedName(value = "trade_type") + private String tradeType; + + /** + *
+   * 字段名:交易状态
+   * 变量名:trade_state
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:交易状态,枚举值:
+   *  SUCCESS:支付成功
+   *  REFUND:转入退款
+   *  NOTPAY:未支付
+   *  CLOSED:已关闭
+   *  REVOKED:已撤销(付款码支付)
+   *  USERPAYING:用户支付中(付款码支付)
+   *  PAYERROR:支付失败(其他原因,如银行返回失败)
+   *
+   * 示例值:SUCCESS
+   * 
+ */ + @SerializedName(value = "trade_state") + private String tradeState; + + /** + *
+   * 字段名:交易状态描述
+   * 变量名:trade_state_desc
+   * 是否必填:是
+   * 类型:string(256)
+   * 描述:交易状态描述
+   * 示例值:支付失败,请重新下单支付
+   * 
+ */ + @SerializedName(value = "trade_state_desc") + private String tradeStateDesc; + + /** + *
+   * 字段名:付款银行
+   * 变量名:bank_type
+   * 是否必填:否
+   * 类型:string(16)
+   * 描述:银行类型,采用字符串类型的银行标识。
+   * 示例值:CMC
+   * 
+ */ + @SerializedName(value = "bank_type") + private String bankType; + + /** + *
+   * 字段名:附加数据
+   * 变量名:attach
+   * 是否必填:否
+   * 类型:string(128)
+   * 描述:附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用
+   * 示例值:自定义数据
+   * 
+ */ + @SerializedName(value = "attach") + private String attach; + + /** + *
+   * 字段名:支付完成时间
+   * 变量名:success_time
+   * 是否必填:否
+   * 类型:string(64)
+   * 描述:支付完成时间,遵循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秒。
+   * 示例值:2018-06-08T10:34:56+08:00
+   * 
+ */ + @SerializedName(value = "success_time") + private String successTime; + + /** + *
+   * 字段名:+支付者
+   * 变量名:combine_payer_info
+   * 是否必填:否
+   * 类型:object
+   * 描述:示例值:见请求示例
+   * 
+ */ + @SerializedName(value = "combine_payer_info") + private CombinePayerInfo combinePayerInfo; + + /** + *
+   * 字段名:订单金额
+   * 变量名:amount
+   * 是否必填:是
+   * 类型:object
+   * 描述:订单金额信息
+   * 
+ */ + @SerializedName(value = "amount") + private Amount amount; + + /** + *
+   * 字段名:场景信息
+   * 变量名:scene_info
+   * 是否必填:否
+   * 类型:object
+   * 描述:支付场景信息描述
+   * 
+ */ + @SerializedName(value = "scene_info") + private SceneInfo sceneInfo; + + /** + *
+   * 字段名:优惠功能
+   * 变量名:promotion_detail
+   * 是否必填:否
+   * 类型:array
+   * 描述:优惠功能,享受优惠时返回该字段。
+   * 
+ */ + @SerializedName(value = "promotion_detail") + private List promotionDetails; + + @Data + @NoArgsConstructor + public static class SceneInfo implements Serializable { + /** + *
+     * 字段名:商户端设备号
+     * 变量名:device_id
+     * 是否必填:否
+     * 类型:string(16)
+     * 描述:
+     *  终端设备号(门店号或收银设备ID)。
+     *  特殊规则:长度最小7个字节
+     *  示例值:POS1:1
+     * 
+ */ + @SerializedName(value = "device_id") + private String deviceId; + + } + + @Data + @NoArgsConstructor + public static class CombinePayerInfo 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 Amount implements Serializable { + /** + *
+     * 字段名:总金额
+     * 变量名:total
+     * 是否必填:否
+     * 类型:int
+     * 描述:
+     *  订单总金额,单位为分
+     *  示例值:100
+     * 
+ */ + @SerializedName(value = "total") + private Integer total; + + + /** + *
+     * 字段名:用户支付金额
+     * 变量名:payer_total
+     * 是否必填:否
+     * 类型:int
+     * 描述:
+     *  用户支付金额,单位为分。
+     *  示例值:100
+     * 
+ */ + @SerializedName(value = "payer_total") + private Integer payerTotal; + + + /** + *
+     * 字段名:货币类型
+     * 变量名:currency
+     * 是否必填:否
+     * 类型:string(16)
+     * 描述:
+     *  CNY:人民币,境内商户号仅支持人民币。
+     *  示例值:CNY
+     * 
+ */ + @SerializedName(value = "currency") + private String currency; + + + /** + *
+     * 字段名:用户支付币种
+     * 变量名:payer_currency
+     * 是否必填:否
+     * 类型:string(8)
+     * 描述:
+     *  用户支付币种
+     *  示例值: CNY
+     * 
+ */ + @SerializedName(value = "payer_currency") + private String payerCurrency; + } + + @Data + @NoArgsConstructor + public static class PromotionDetail implements Serializable { + + /** + *
+     * 字段名:券ID
+     * 变量名:coupon_id
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述: 券ID
+     * 示例值:109519
+     * 
+ */ + @SerializedName(value = "coupon_id") + private String couponId; + + /** + *
+     * 字段名:优惠名称
+     * 变量名:name
+     * 是否必填:否
+     * 类型:string(64)
+     * 描述: 优惠名称
+     * 示例值:单品惠-6
+     * 
+ */ + @SerializedName(value = "name") + private String name; + /** + *
+     * 字段名:优惠范围
+     * 变量名:scope
+     * 是否必填:否
+     * 类型:string(32)
+     * 描述: 优惠名称
+     * 示例值:
+     *    GLOBAL:全场代金券
+     *    SINGLE:单品优惠
+     * 示例值:GLOBAL
+     * 
+ */ + @SerializedName(value = "scope") + private String scope; + + /** + *
+     * 字段名:优惠类型
+     * 变量名:type
+     * 是否必填:否
+     * 类型:string(32)
+     * 描述:
+     *    CASH:充值
+     *    NOCASH:预充值
+     * 示例值:CASH
+     * 
+ */ + @SerializedName(value = "type") + private String type; + + /** + *
+     * 字段名:优惠券面额
+     * 变量名:amount
+     * 是否必填:是
+     * 类型:int
+     * 描述: 优惠券面额
+     * 示例值:100
+     * 
+ */ + @SerializedName(value = "amount") + private Integer amount; + + /** + *
+     * 字段名:活动ID
+     * 变量名:stock_id
+     * 是否必填:否
+     * 类型:string(32)
+     * 描述:活动ID
+     * 示例值:931386
+     * 
+ */ + @SerializedName(value = "stock_id") + private String stockId; + + /** + *
+     * 字段名:微信出资
+     * 变量名:wechatpay_contribute
+     * 是否必填:否
+     * 类型:int
+     * 描述:微信出资,单位为分
+     * 示例值:0
+     * 
+ */ + @SerializedName(value = "wechatpay_contribute") + private Integer wechatpayContribute; + + /** + *
+     * 字段名:商户出资
+     * 变量名:merchant_contribute
+     * 是否必填:否
+     * 类型:int
+     * 描述:商户出资,单位为分
+     * 示例值:0
+     * 
+ */ + @SerializedName(value = "merchant_contribute") + private Integer merchantContribute; + + /** + *
+     * 字段名:其他出资
+     * 变量名:other_contribute
+     * 是否必填:否
+     * 类型:int
+     * 描述:其他出资,单位为分
+     * 示例值:0
+     * 
+ */ + @SerializedName(value = "other_contribute") + private Integer otherContribute; + + /** + *
+     * 字段名:优惠币种
+     * 变量名:currency
+     * 是否必填:否
+     * 类型:String(16)
+     * 描述:
+     *    CNY:人民币,境内商户号仅支持人民币。
+     * 示例值:CNY
+     * 
+ */ + @SerializedName(value = "currency") + private String currency; + + /** + *
+     * 字段名:单品列表
+     * 变量名:goods_detail
+     * 是否必填:否
+     * 类型:array
+     * 描述:单品列表信息
+     * 
+ */ + @SerializedName(value = "goods_detail") + private List goodsDetails; + + + } + + @Data + @NoArgsConstructor + public static class GoodsDetail implements Serializable { + + /** + *
+     * 字段名:商品编码
+     * 变量名:goods_id
+     * 是否必填:是
+     * 类型:string(32)
+     * 描述:商品编码
+     * 示例值:M1006
+     * 
+ */ + @SerializedName(value = "goods_id") + private String goodsId; + + /** + *
+     * 字段名:商品数量
+     * 变量名:quantity
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  用户购买的数量
+     * 示例值:1
+     * 
+ */ + @SerializedName(value = "quantity") + private Integer quantity; + + /** + *
+     * 字段名:商品单价
+     * 变量名:unit_price
+     * 是否必填:是
+     * 类型:int64
+     * 描述:
+     *  商品单价,单位为分
+     * 示例值:100
+     * 
+ */ + @SerializedName(value = "unit_price") + private Integer unitPrice; + + /** + *
+     * 字段名:商品优惠金额
+     * 变量名:discount_amount
+     * 是否必填:是
+     * 类型:int
+     * 描述:商品优惠金额
+     * 示例值:0
+     * 
+ */ + @SerializedName(value = "discount_amount") + private Integer discountAmount; + + /** + *
+     * 字段名:商品备注
+     * 变量名:goods_remark
+     * 是否必填:否
+     * 类型:string(128)
+     * 描述:商品备注信息
+     * 示例值:商品备注信息
+     * 
+ */ + @SerializedName(value = "goods_remark") + private String goodsRemark; + } + +} 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 index a324b616bd..b1ace4d577 100644 --- 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 @@ -17,7 +17,7 @@ @Data @NoArgsConstructor public class PartnerTransactionsRequest implements Serializable { - + private static final long serialVersionUID = -1550405819444680465L; /** *
    * 字段名:服务商公众号ID
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SignatureHeader.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SignatureHeader.java
new file mode 100644
index 0000000000..bd50ac89d4
--- /dev/null
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/SignatureHeader.java
@@ -0,0 +1,35 @@
+package com.github.binarywang.wxpay.bean.ecommerce;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 微信通知接口头部信息,需要做签名验证
+ * 文档地址: https://wechatpay-api.gitbook.io/wechatpay-api-v3/qian-ming-zhi-nan-1/qian-ming-yan-zheng
+ */
+@Data
+@NoArgsConstructor
+public class SignatureHeader implements Serializable {
+  private static final long serialVersionUID = -6958015499416059949L;
+  /**
+   * 时间戳
+   */
+  private String timeStamp;
+
+  /**
+   * 随机串
+   */
+  private String nonce;
+
+  /**
+   * 已签名字符串
+   */
+  private String signed;
+
+  /**
+   * 证书序列号
+   */
+  private String serialNo;
+}
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/TransactionsResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/TransactionsResult.java
index 3ce288a701..12a22ead74 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/TransactionsResult.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/TransactionsResult.java
@@ -16,7 +16,7 @@
 @Data
 @NoArgsConstructor
 public class TransactionsResult implements Serializable {
-
+  private static final long serialVersionUID = 1760592667519950149L;
   /**
    * 
    * 字段名:预支付交易会话标识 (APP支付、JSAPI支付 会返回)
@@ -97,7 +97,7 @@ public  T getPayInfo(TradeTypeEnum tradeType, String appId, String mchId, Pri
           //签名类型,默认为RSA,仅支持RSA。
           .setSignType("RSA").setPaySign(SignUtils.sign(jsapiResult.getSignStr(), privateKey));
         return (T) jsapiResult;
-      case H5:
+      case MWEB:
         return (T) this.h5Url;
       case APP:
         AppResult appResult = new AppResult();
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 03dd2cb36b..e8bd5ccba4 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
@@ -9,12 +9,22 @@
 @Getter
 @AllArgsConstructor
 public enum TradeTypeEnum {
-
-  APP("/v3/combine-transactions/app","/v3/pay/partner/transactions/app"),
-  JSAPI("/v3/combine-transactions/jsapi","/v3/pay/partner/transactions/jsapi"),
-  NATIVE("/v3/combine-transactions/native","/v3/pay/partner/transactions/native"),
-  H5("/v3/combine-transactions/h5","/v3/pay/partner/transactions/h5")
-  ;
+  /**
+   * APP
+   */
+  APP("/v3/combine-transactions/app", "/v3/pay/partner/transactions/app"),
+  /**
+   * JSAPI
+   */
+  JSAPI("/v3/combine-transactions/jsapi", "/v3/pay/partner/transactions/jsapi"),
+  /**
+   * NATIVE
+   */
+  NATIVE("/v3/combine-transactions/native", "/v3/pay/partner/transactions/native"),
+  /**
+   * MWEB
+   */
+  MWEB("/v3/combine-transactions/h5", "/v3/pay/partner/transactions/h5");
 
   /**
    * 合单url
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 add7c17d1d..67038a8890 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
@@ -54,6 +54,19 @@ public interface EcommerceService {
    */
   ApplymentsStatusResult queryApplyStatusByOutRequestNo(String outRequestNo) throws WxPayException;
 
+  /**
+   * 
+   * 合单支付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/pages/e-combine.shtml
+   * 
+ * + * @param tradeType 支付方式 + * @param request 请求对象 + * @return 微信合单支付返回 + */ + TransactionsResult combine(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException; + /** *
    * 合单支付API(APP支付、JSAPI支付、H5支付、NATIVE支付).
@@ -67,6 +80,30 @@ public interface EcommerceService {
    */
    T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException;
 
+  /**
+   * 
+   * 合单支付通知回调数据处理
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e-combine.shtml
+   * 
+ * + * @param notifyData 通知数据 + * @param header 通知头部数据,不传则表示不校验头 + * @return 解密后通知数据 + */ + CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyData, SignatureHeader header) 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 调起支付需要的参数 + */ + TransactionsResult partner(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException; + /** *
    *  服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付).
@@ -78,4 +115,16 @@ public interface EcommerceService {
    * @return 调起支付需要的参数
    */
    T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException;
+
+  /**
+   * 
+   * 普通支付通知回调数据处理
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/e_transactions.shtml
+   * 
+ * + * @param notifyData 通知数据 + * @param header 通知头部数据,不传则表示不校验头 + * @return 解密后通知数据 + */ + PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) 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 45205ac06a..4dc535b0fe 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 @@ -5,12 +5,17 @@ import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.EcommerceService; import com.github.binarywang.wxpay.service.WxPayService; +import com.github.binarywang.wxpay.v3.util.AesUtils; import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.RequiredArgsConstructor; +import java.io.IOException; import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.security.GeneralSecurityException; +import java.util.Objects; @RequiredArgsConstructor public class EcommerceServiceImpl implements EcommerceService { @@ -41,20 +46,81 @@ public ApplymentsStatusResult queryApplyStatusByOutRequestNo(String outRequestNo } @Override - public T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException { + public TransactionsResult combine(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException { String url = this.payService.getPayBaseUrl() + tradeType.getCombineUrl(); String response = this.payService.postV3(url, GSON.toJson(request)); - TransactionsResult result = GSON.fromJson(response, TransactionsResult.class); + return GSON.fromJson(response, TransactionsResult.class); + } + + @Override + public T combineTransactions(TradeTypeEnum tradeType, CombineTransactionsRequest request) throws WxPayException { + TransactionsResult result = this.combine(tradeType, request); return result.getPayInfo(tradeType, request.getCombineAppid(), request.getCombineMchid(), payService.getConfig().getPrivateKey()); } @Override - public T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException { + public CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { + if(Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)){ + throw new WxPayException("非法请求,头部信息验证失败"); + } + NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class); + NotifyResponse.Resource resource = response.getResource(); + String cipherText = resource.getCiphertext(); + String associatedData = resource.getAssociatedData(); + String nonce = resource.getNonce(); + String apiV3Key = this.payService.getConfig().getApiV3Key(); + try { + String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key); + CombineTransactionsNotifyResult notifyResult = GSON.fromJson(result, CombineTransactionsNotifyResult.class); + notifyResult.setRawData(response); + return notifyResult; + } catch (GeneralSecurityException | IOException e) { + throw new WxPayException("解析报文异常!", e); + } + } + + @Override + public TransactionsResult partner(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 GSON.fromJson(response, TransactionsResult.class); + } + + @Override + public T partnerTransactions(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException { + TransactionsResult result = this.partner(tradeType, request); return result.getPayInfo(tradeType, request.getSpAppid(), request.getSpMchid(), payService.getConfig().getPrivateKey()); } + + @Override + public PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException { + if(Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)){ + throw new WxPayException("非法请求,头部信息验证失败"); + } + NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class); + NotifyResponse.Resource resource = response.getResource(); + String cipherText = resource.getCiphertext(); + String associatedData = resource.getAssociatedData(); + String nonce = resource.getNonce(); + String apiV3Key = this.payService.getConfig().getApiV3Key(); + try { + String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key); + PartnerTransactionsNotifyResult notifyResult = GSON.fromJson(result, PartnerTransactionsNotifyResult.class); + notifyResult.setRawData(response); + return notifyResult; + } catch (GeneralSecurityException | IOException e) { + throw new WxPayException("解析报文异常!", e); + } + } + + private boolean verifyNotifySign(SignatureHeader header, String data) { + String beforeSign = String.format("%s\n%s\n%s\n", + header.getTimeStamp(), + header.getNonce(), + data); + return payService.getConfig().getVerifier().verify(header.getSerialNo(), + beforeSign.getBytes(StandardCharsets.UTF_8), header.getSigned()); + } }