Air
2024-11-04 a1f06d31b7b4cac569c34bdfbb68de77f2858ffe
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.nova.sankuai.infra.utils.huifubao;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.nova.sankuai.infra.utils.huifubao.common.HttpUtil;
import com.nova.sankuai.infra.utils.huifubao.common.MyKey;
import com.nova.sankuai.infra.utils.huifubao.common.SignEncrypt;
import org.bouncycastle.util.encoders.Base64;
 
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
import static com.nova.sankuai.infra.utils.huifubao.common.HttpUtil.parseJsonResponse;
 
/**
 *
 * 该接口为快捷签约查询接口,用于查询商户在快捷签约平台上已签约的银行卡信息和快捷签约码。
 *
 */
public class SignQuery {
    public static void main(String[] args) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date now = new Date();
        String time = sdf.format(now);
        //公共请求参数
        String timestamp = time;
        //具体业务接口名称
        String method = "heepay.agreement.bank.sign.query";
        //    版本号:固定值 1.0
        String version ="1.0";
        //请求商户ID
        String merch_id = "1664502";
 
 
        //业务参数 商户签约单号
        String out_trade_no = "798456132";
        //biz组装
        JSONObject biz_content = new JSONObject();
        biz_content.put("out_trade_no",out_trade_no);
 
        //签名串组装
        String OldSign = "biz_content=" + biz_content
                + "&merch_id=" + merch_id
                +"&method=" + method
                +"&timestamp=" + timestamp
                +"&version=" + version;
 
        System.out.println("签名串:--------->"+OldSign);
 
        SignEncrypt signEncrypt = new SignEncrypt();
 
        String privateKeystr = MyKey.privateKeystr;
 
        //密钥配置
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        byte[] privateKeyPath = Base64.decode(privateKeystr.getBytes());
        PrivateKey privateKey = keyFactory.generatePrivate(new PKCS8EncodedKeySpec(privateKeyPath));
 
        //加签
        String sign = signEncrypt.sign(OldSign, privateKey);
 
        Map<String, String> map = new HashMap<>();
        map.put("biz_content", String.valueOf(biz_content));
        map.put("merch_id",merch_id);
        map.put("method",method);
        map.put("timestamp",timestamp);
        map.put("version",version);
        map.put("sign",sign);
        String a = JSON.toJSONString(map);
        System.out.println("最终请求参数--------->"+a);
 
        HttpUtil httpUtil = new HttpUtil();
        String Result = httpUtil.sendJsonHttpPost("https://Pay.Heepay.com/API/PageSign/Index.aspx",a);
        System.out.println("响应结果--------->"+Result);
        //解析返回参数
        JsonNode jsonNode = parseJsonResponse(Result);
        String sub_msg = jsonNode.get("sub_msg").asText();
 
        if ("签约成功".equals(sub_msg)){
            String data = jsonNode.get("data").asText();
            String DecryptedData = signEncrypt.decrypt(data,privateKey);
            JsonNode DecryptedData1 = parseJsonResponse(DecryptedData);
            System.out.println("返回签约人信息--------->"+DecryptedData1);
        }else {
            System.out.println("输出失败sub_msg:--------->"+sub_msg);
        }
 
    }
}