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
|
+"×tamp=" + 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);
|
}
|
|
}
|
}
|