Helius
2020-12-27 c9d3b0ba1200977070326476fa52ab971f2ede1b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.matrix.component.wechat.externalInterface.protocol.rsaProtocal;
 
 
import com.matrix.component.wechat.externalInterface.common.RandomStringGenerator;
import com.matrix.component.wechat.externalInterface.common.Signature;
import com.matrix.component.wechat.externalInterface.common.WechatConfigure;
 
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 公钥请求类
 *
 * @author  wzy
 */
public class JsApiRSAReqData {
 
    private String mch_id;
    private String nonce_str;
    private String sign;
    private String sign_type;
 
 
    public JsApiRSAReqData() {
        this.mch_id = WechatConfigure.mchID;
        this.nonce_str = RandomStringGenerator.getRandomStringByLength(32);
        this.sign = Signature.getSign(toMap());
        this.sign_type = "MD5";
    }
 
    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<String, Object>();
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            Object obj;
            try {
                obj = field.get(this);
                if (obj != null) {
                    map.put(field.getName(), obj);
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
}