View Javadoc
1   package com.foxinmy.weixin4j.pay.payment.face;
2   
3   import com.foxinmy.weixin4j.pay.model.WeixinPayAccount;
4   import com.foxinmy.weixin4j.pay.sign.WeixinPaymentSignature;
5   import com.foxinmy.weixin4j.pay.type.SignType;
6   import com.foxinmy.weixin4j.util.*;
7   import com.foxinmy.weixin4j.xml.XmlStream;
8   
9   import java.util.HashMap;
10  import java.util.Map;
11  
12  /**
13   * 微信刷脸支付, 获取调用凭证(get_wxpayface_authinfo)API接口请求参数封装
14   *
15   * @className PayfaceAuthinfoRequest
16   * @author kit(kit_21cn@21cn.com)
17   * @date 2019年9月18日
18   * @since JDK 1.6
19   * @see <a href="https://pay.weixin.qq.com/wiki/doc/wxfacepay/develop/sdk-android.html#获取调用凭证-get-wxpayface-authinfo">
20   *     获取调用凭证-get-wxpayface-authinfo</a>
21   */
22  public class PayfaceAuthinfoRequest {
23      private WeixinPayAccount payAccount;
24      /**
25       * 门店编号, 由商户定义, 各门店唯一。
26       */
27      private String storeId;
28      /**
29       * 门店名称,由商户定义。(可用于展示)
30       */
31      private String storeName;
32      /**
33       * 终端设备编号,由商户定义。
34       */
35      private String deviceId;
36      /**
37       * 附加字段。字段格式使用Json
38       */
39      private String attach;
40  
41      private String nonceStr = RandomUtil.generateString(16);
42  
43      private String now = DateUtil.timestamp2string();
44      /**
45       * 初始化数据。由微信人脸SDK的接口返回。
46       *
47       * @see <a href="https://pay.weixin.qq.com/wiki/doc/wxfacepay/develop/sdk-android.html#获取数据-getwxpayfacerawdata">
48       *  *     获取数据-getwxpayfacerawdata</a>
49       */
50      private String rawdata;
51  
52      private WeixinPaymentSignature paymentSignature;
53  
54      public PayfaceAuthinfoRequest(WeixinPayAccount account, String storeId, String storeName, String deviceId,
55                                    String attach, String rawdata){
56          this.payAccount = account;
57          this.deviceId = deviceId;
58          this.rawdata = rawdata;
59          this.storeId = storeId;
60          this.storeName = storeName;
61          this.attach = attach;
62          this.paymentSignature = new WeixinPaymentSignature(account.getPaySignKey());
63      }
64  
65      public String toRequestString(){
66          Map paramsMap = getRequestParam();
67          return XmlStream.map2xml(paramsMap);
68      }
69  
70      private Map<String, String> getRequestParam(){
71          Map<String, String> map = new HashMap<String, String>();
72          map.put("appid", payAccount.getId());
73          map.put("mch_id", payAccount.getMchId());
74          if(StringUtil.isNotBlank(payAccount.getSubId())) {
75              map.put("sub_appid", payAccount.getSubId());
76          }
77          if(StringUtil.isNotBlank(payAccount.getSubMchId())){
78              map.put("sub_mch_id", payAccount.getSubMchId());
79          }
80          map.put("now", now);
81          map.put("version", "1");
82          map.put("sign_type", SignType.MD5.name());
83          map.put("nonce_str", nonceStr);
84          map.put("store_id", storeId);
85          map.put("store_name", storeName);
86          map.put("device_id", deviceId);
87          map.put("rawdata", rawdata);
88          if(StringUtil.isNotBlank(attach)) {
89              map.put("attach", attach);
90          }
91          String sign = paymentSignature.sign(map);
92          map.put("sign", sign);
93  
94          return map;
95      }
96  }