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
14
15
16
17
18
19
20
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
38
39 private String attach;
40
41 private String nonceStr = RandomUtil.generateString(16);
42
43 private String now = DateUtil.timestamp2string();
44
45
46
47
48
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 }