From 8dffbd4fdbbb0c12abe444a4e24b38178327836e Mon Sep 17 00:00:00 2001 From: dingzhiwei Date: Thu, 24 Oct 2019 09:25:31 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20#1248=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=88=B7=E8=84=B8=E6=94=AF=E4=BB=98=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加获取微信刷脸调用凭证接口 * 增加微信刷脸接口 1. 获取刷脸支付凭证接口 2. 刷脸支付接口 --- .../request/WxPayFaceAuthInfoRequest.java | 126 +++++++++ .../bean/request/WxPayFacepayRequest.java | 177 +++++++++++++ .../bean/result/WxPayFaceAuthInfoResult.java | 38 +++ .../wxpay/bean/result/WxPayFacepayResult.java | 245 ++++++++++++++++++ .../wxpay/service/WxPayService.java | 33 +++ .../service/impl/BaseWxPayServiceImpl.java | 21 ++ 6 files changed, 640 insertions(+) create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayFaceAuthInfoRequest.java create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayFacepayRequest.java create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayFaceAuthInfoResult.java create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayFacepayResult.java diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayFaceAuthInfoRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayFaceAuthInfoRequest.java new file mode 100644 index 000000000..eb53e38c6 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayFaceAuthInfoRequest.java @@ -0,0 +1,126 @@ +package com.github.binarywang.wxpay.bean.request; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; +import me.chanjar.weixin.common.annotation.Required; + +/** + *
+ *  获取微信刷脸调用凭证请求对象类
+ *  详见文档:https://pay.weixin.qq.com/wiki/doc/wxfacepay/develop/sdk-android.html#获取数据-getwxpayfacerawdata
+ * Created by Jmdhappy on 2019-09-04.
+ * 
+ * + * @author XxPay + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor +@XStreamAlias("xml") +public class WxPayFaceAuthInfoRequest extends BaseWxPayRequest { + + /** + *
+   * 字段名:门店编号
+   * 变量名:store_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 示例值:1001
+   * 描述:门店编号, 由商户定义, 各门店唯一
+   * 
+ */ + @Required + @XStreamAlias("store_id") + private String storeId; + + /** + *
+   * 字段名:门店名称
+   * 变量名:store_name
+   * 是否必填:是
+   * 类型:string(128)
+   * 示例值:骏易科技
+   * 描述:门店名称,由商户定义。(可用于展示)
+   * 
+ */ + @Required + @XStreamAlias("store_name") + private String storeName; + + /** + *
+   * 字段名:终端设备编号
+   * 变量名:device_id
+   * 是否必填:是
+   * 类型:string(32)
+   * 示例值:
+   * 描述:终端设备编号,由商户定义。
+   * 
+ */ + @Required + @XStreamAlias("device_id") + private String deviceId; + + /** + *
+   * 字段名:附加字段
+   * 变量名:attach
+   * 是否必填:是
+   * 类型:string
+   * 示例值:
+   * 描述:附加字段。字段格式使用Json
+   * 
+ */ + @XStreamAlias("attach") + private String attach; + + /** + *
+   * 字段名:初始化数据
+   * 变量名:attach
+   * 是否必填:是
+   * 类型:string(2048)
+   * 示例值:
+   * 描述:初始化数据。由微信人脸SDK的接口返回。
+   * 
+ */ + @Required + @XStreamAlias("rawdata") + private String rawdata; + + /** + *
+   * 字段名:当前时间
+   * 变量名:now
+   * 是否必填:否
+   * 类型:String(10)
+   * 示例值:1239878956
+   * 描述:取当前时间,10位unix时间戳。 例如:1239878956
+   * 
+ */ + @Required + @XStreamAlias("now") + private String now; + + /** + *
+   * 字段名:接口版本号.
+   * 变量名:version
+   * 是否必填:是
+   * 类型:String
+   * 示例值:1.0
+   * 描述:版本号。固定为1
+   * 
+ */ + @Required + @XStreamAlias("version") + private String version; + + @Override + protected void checkConstraints() { + //do nothing + } + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayFacepayRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayFacepayRequest.java new file mode 100644 index 000000000..2c70a8945 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayFacepayRequest.java @@ -0,0 +1,177 @@ +package com.github.binarywang.wxpay.bean.request; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.*; +import me.chanjar.weixin.common.annotation.Required; + +/** + *
+ *  提交刷脸支付请求对象类
+ *  详见文档:微信人脸支付商户开发文档
+ * Created by Jmdhappy on 2019-09-05.
+ * 
+ * + * @author XxPay + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Builder(builderMethodName = "newBuilder") +@NoArgsConstructor +@AllArgsConstructor +@XStreamAlias("xml") +public class WxPayFacepayRequest extends BaseWxPayRequest { + + /** + *
+   * 字段名:设备号.
+   * 变量名:device_info
+   * 是否必填:否
+   * 类型:String(32)
+   * 示例值:013467007045764
+   * 描述:终端设备号(商户自定义,如门店编号)
+   * 
+ */ + @XStreamAlias("device_info") + private String deviceInfo; + + /** + *
+   * 字段名:商品描述.
+   * 变量名:body
+   * 是否必填:是
+   * 类型:String(128)
+   * 示例值:image形象店-深圳腾大- QQ公仔
+   * 描述:商品或支付单简要描述,格式要求:门店品牌名-城市分店名-实际商品名称
+   * 
+ **/ + @Required + @XStreamAlias("body") + private String body; + + /** + *
+   * 字段名:商品详情.
+   * 变量名:detail
+   * 是否必填:否
+   * 类型:String(8192)
+   * 示例值:
+   * 描述:商品详细列表,使用Json格式,传输签名前请务必使用CDATA标签将JSON文本串保护起来。
+ **/ + @XStreamAlias("detail") + private String detail; + + /** + *
+   * 字段名:附加数据.
+   * 变量名:attach
+   * 是否必填:否
+   * 类型:String(127)
+   * 示例值:说明
+   * 描述:附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
+   * 
+ **/ + @XStreamAlias("attach") + private String attach; + + /** + *
+   * 字段名:商户订单号.
+   * 变量名:out_trade_no
+   * 是否必填:是
+   * 类型:String(32)
+   * 示例值:1217752501201407033233368018
+   * 描述:商户系统内部的订单号,32个字符内、可包含字母;更换授权码必须要换新的商户订单号 其他说明见商户订单号
+   * 
+ **/ + @Required + @XStreamAlias("out_trade_no") + private String outTradeNo; + + /** + *
+   * 字段名:总金额.
+   * 变量名:total_fee
+   * 是否必填:是
+   * 类型:Int
+   * 示例值:888
+   * 描述:订单总金额,单位为分,只能为整数,详见支付金额
+   * 
+ **/ + @Required + @XStreamAlias("total_fee") + private Integer totalFee; + + /** + *
+   * 字段名:货币类型.
+   * 变量名:fee_type
+   * 是否必填:否
+   * 类型:String(16)
+   * 示例值:CNY
+   * 描述:符合ISO4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+   * 
+ **/ + @XStreamAlias("fee_type") + private String feeType; + + /** + *
+   * 字段名:终端IP.
+   * 变量名:spbill_create_ip
+   * 是否必填:是
+   * 类型:String(16)
+   * 示例值:127.0.0.1
+   * 描述:调用微信支付API的机器IP
+   * 
+ **/ + @Required + @XStreamAlias("spbill_create_ip") + private String spbillCreateIp; + + /** + *
+   * 字段名:商品标记.
+   * 变量名:goods_tag
+   * 是否必填:否
+   * 类型:String(32)
+   * 示例值:1234
+   * 描述:商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
+   * 
+ **/ + @XStreamAlias("goods_tag") + private String goodsTag; + + /** + *
+   * 字段名:用户标识.
+   * 变量名:openid
+   * 是否必填:是
+   * 类型:String(128)
+   * 示例值:oUpF8uMuAJO_M2pxb1Q9zNjWeS6o
+   * 描述:用户在商户appid 下的唯一标识
+   * 
+ */ + @Required + @XStreamAlias("openid") + private String openid; + + /** + *
+   * 字段名:人脸凭证.
+   * 变量名:face_code
+   * 是否必填:是
+   * 类型:String(128)
+   * 示例值:
+   * 描述:人脸凭证,用于刷脸支付
+   * 
+ **/ + @Required + @XStreamAlias("face_code") + private String faceCode; + + @Override + protected void checkConstraints() { + //do nothing + } + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayFaceAuthInfoResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayFaceAuthInfoResult.java new file mode 100644 index 000000000..95dcf71eb --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayFaceAuthInfoResult.java @@ -0,0 +1,38 @@ +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; + +/** + *
+ * 获取微信刷脸调用凭证返回结果.
+ * 详见文档:https://pay.weixin.qq.com/wiki/doc/wxfacepay/develop/sdk-android.html#获取数据-getwxpayfacerawdata
+ * 
+ * + * @author Jmdhappy + */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@XStreamAlias("xml") +public class WxPayFaceAuthInfoResult extends BaseWxPayResult implements Serializable { + + private static final long serialVersionUID = -65138145275211272L; + + /** + * SDK调用凭证. + */ + @XStreamAlias("authinfo") + private String authinfo; + + /** + * authinfo的有效时间, 单位秒. + */ + @XStreamAlias("expires_in") + private String expiresIn; + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayFacepayResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayFacepayResult.java new file mode 100644 index 000000000..27e33d7bf --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayFacepayResult.java @@ -0,0 +1,245 @@ +package com.github.binarywang.wxpay.bean.result; + +import com.thoughtworks.xstream.annotations.XStreamAlias; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + *
+ * 提交书刷脸支付接口响应结果对象类
+ * Created by Jmdhappy on 2019-09-05.
+ * 
+ * + * @author XxPay + */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@XStreamAlias("xml") +public class WxPayFacepayResult extends BaseWxPayResult { + + private static final long serialVersionUID = -4116580976046716911L; + + /** + *
+   * 设备号.
+   * device_info
+   * 否
+   * String(32)
+   * 013467007045764
+   * 调用接口提交的终端设备号
+   * 
+ */ + @XStreamAlias("device_info") + private String deviceInfo; + + /** + *
+   * 用户标识.
+   * openid
+   * 是
+   * String(128)
+   * Y
+   * 用户在商户appid 下的唯一标识
+   * 
+ **/ + @XStreamAlias("openid") + private String openid; + + /** + *
+   * 是否关注公众账号.
+   * is_subscribe
+   * 是
+   * String(1)
+   * Y
+   * 用户是否关注公众账号,仅在公众账号类型支付有效,取值范围:Y或N;Y-关注;N-未关注
+   * 
+ **/ + @XStreamAlias("is_subscribe") + private String isSubscribe; + + /** + *
+   * 用户子标识.
+   * sub_openid
+   * 否
+   * String(128)
+   * Y
+   * 子商户appid下用户唯一标识,如需返回则请求时需要传sub_appid
+   * 
+ **/ + @XStreamAlias("sub_openid") + private String subOpenid; + + /** + *
+   * 是否关注子公众账号.
+   * sub_is_subscribe
+   * 是
+   * String(1)
+   * Y
+   * 用户是否关注子公众账号,仅在公众账号类型支付有效,取值范围:Y或N;Y-关注;N-未关注
+   * 
+ **/ + @XStreamAlias("sub_is_subscribe") + private String subsSubscribe; + + /** + *
+   * 交易类型.
+   * trade_type
+   * 是
+   * String(16)
+   * FACEPAY
+   * 支付类型为 FACEPAY(即刷脸支付)
+   * 
+ **/ + @XStreamAlias("trade_type") + private String tradeType; + + /** + *
+   * 付款银行.
+   * bank_type
+   * 是
+   * String(32)
+   * CMC
+   * 银行类型,采用字符串类型的银行标识,值列表详见银行类型
+   * 
+ **/ + @XStreamAlias("bank_type") + private String bankType; + + /** + *
+   * 货币类型.
+   * fee_type
+   * 否
+   * String(16)
+   * CNY
+   * 符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+   * 
+ **/ + @XStreamAlias("fee_type") + private String feeType; + + /** + *
+   * 订单金额.
+   * total_fee
+   * 是
+   * Int
+   * 888
+   * 订单总金额,单位为分,只能为整数,详见支付金额
+   * 
+ **/ + @XStreamAlias("total_fee") + private Integer totalFee; + + /** + *
+   * 现金支付货币类型.
+   * cash_fee_type
+   * 否
+   * String(16)
+   * CNY
+   * 符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
+   * 
+ **/ + @XStreamAlias("cash_fee_type") + private String cashFeeType; + + /** + *
+   * 现金支付金额.
+   * cash_fee
+   * 是
+   * Int
+   * 100
+   * 订单现金支付金额,详见支付金额
+   * 
+ **/ + @XStreamAlias("cash_fee") + private Integer cashFee; + + /** + *
+   * 微信支付订单号.
+   * transaction_id
+   * 是
+   * String(32)
+   * 1217752501201407033233368018
+   * 微信支付订单号
+   * 
+ **/ + @XStreamAlias("transaction_id") + private String transactionId; + + /** + *
+   * 商户订单号.
+   * out_trade_no
+   * 是
+   * String(32)
+   * 1217752501201407033233368018
+   * 商户系统的订单号,与请求一致。
+   * 
+ **/ + @XStreamAlias("out_trade_no") + private String outTradeNo; + + /** + *
+   * 商品详情.
+   * detail
+   * 否
+   * String(8192)
+   * 与提交数据一致
+   * 实际提交的返回
+   * 
+ **/ + @XStreamAlias("detail") + private String detail; + + /** + *
+   * 商家数据包.
+   * attach
+   * 否
+   * String(128)
+   * 123456
+   * 商家数据包,原样返回
+   * 
+ **/ + @XStreamAlias("attach") + private String attach; + + /** + *
+   * 营销详情.
+   * promotion_detail
+   * 否
+   * String(6000)
+   * 示例见下文
+   * 新增返回,单品优惠功能字段,需要接入请见详细说明
+   * 
+ **/ + @XStreamAlias("promotion_detail") + private String promotionDetail; + + /** + *
+   * 支付完成时间.
+   * time_end
+   * 是
+   * String(14)
+   * 20141030133525
+   * 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。详见时间规则
+   * 
+ **/ + @XStreamAlias("time_end") + private String timeEnd; + +} 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 555362e66..d3fc4be7f 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 @@ -704,4 +704,37 @@ public interface WxPayService { * @throws WxPayException the wx pay exception */ String queryComment(WxPayQueryCommentRequest request) throws WxPayException; + + /** + *
+   * 获取微信刷脸支付凭证.
+   * 接口请求链接:https://payapp.weixin.qq.com/face/get_wxpayface_authinfo
+   * 文档地址:https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_5
+   * 
+ * + * @param request the request + * @return the wx pay get face authinfo result + * @throws WxPayException the wx pay exception + */ + WxPayFaceAuthInfoResult getWxPayFaceAuthInfo(WxPayFaceAuthInfoRequest request) throws WxPayException; + + /** + *
+   * 提交刷脸支付.
+   * 文档地址:https://share.weiyun.com/5dxUgCw
+   * 应用场景:
+   * 用户在商超,便利店,餐饮等场景,在屏幕上通过刷脸完成支付。
+   * 步骤1:用户在自助收银机上点击“刷脸支付”;
+   * 步骤2:发起人脸识别,摄像头自动抓取识别用户人脸,提示用户输入11位手机号码;
+   * 步骤3:商户收银系统提交刷脸支付;
+   * 步骤4:微信支付后台收到支付请求,验证人脸信息,返回支付结果给商户收银系统。
+   * 是否需要证书:不需要。
+   * 
+ * + * @param request the request + * @return the wx pay facepay result + * @throws WxPayException the wx pay exception + */ + WxPayFacepayResult facepay(WxPayFacepayRequest 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 13473a5d4..4c3465f8d 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 @@ -788,4 +788,25 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { return responseContent; } + @Override + public WxPayFaceAuthInfoResult getWxPayFaceAuthInfo(WxPayFaceAuthInfoRequest request) throws WxPayException { + request.checkAndSign(this.getConfig()); + String url = "https://payapp.weixin.qq.com/face/get_wxpayface_authinfo"; + String responseContent = this.post(url, request.toXML(), false); + WxPayFaceAuthInfoResult result = BaseWxPayResult.fromXML(responseContent, WxPayFaceAuthInfoResult.class); + result.checkResult(this, request.getSignType(), true); + return result; + } + + @Override + public WxPayFacepayResult facepay(WxPayFacepayRequest request) throws WxPayException { + request.checkAndSign(this.getConfig()); + + String url = this.getPayBaseUrl() + "/pay/facepay"; + String responseContent = this.post(url, request.toXML(), false); + WxPayFacepayResult result = BaseWxPayResult.fromXML(responseContent, WxPayFacepayResult.class); + result.checkResult(this, request.getSignType(), true); + return result; + } + }