聚合支付快捷支付接口代码详解
今天,我先讲一下快捷支付接口代码,一方面给自己做一个记录,方便日后查看,另一方面也是方便一些基础不是很强的技术人员在对接支付的时候,省去一些码代码的时间。
下面是快捷支付接口代码:
JAVA代码示例:
首先将需要收集的参数都写成json格式的字符串。
String valueObj = "{
"version": "10",
"cmd_id": "123123",
"mer_cust_id": "123123123123",//入驻商户id
"user_cust_id": "321321321321321",//入驻商户下级商户ID
"order_id": "1234567",//订单编号
"order_date": "20180327",
"trans_amt": "6.95",
"bind_card_id": "1000000085",//商户已绑定绑定卡号
"sms_code": "111111",//短信验证码
"div_detail": "[{'divCustId':'123123123123','divAcctId':'45841','divAmt':'6.92','divFreezeFg':'01'},{'divCustId':'321321321321','divAcctId':'12345','divAmt':'0.03','divFreezeFg':'00'}]",//分账串信息
"bg_ret_url": "http://192.168.100.110:8001/npayCallBack/asyncHandle.json",//地址可以询问对方运营
"ret_url": "",
"mer_priv": "test",
"extension": "test"
}";
String testUrl = "http://192.168.100.110:8083/npay/merchantRequest";//地址可以询问对方运营
// 加签用pfx文件
String pfxFileName = "888888-汇付测试商户.pfx";
// 加签用密码
String pfxFilePwd = "888888";
// 进行base64转换
String
base64RequestParams =
Base64.encodeBase64String(valueObj.getBytes(Charset.forName("utf-8")));
// 加签
SignResultsignResult = CFCASignature.signature("/app/etc/product/" + pfxFileName,
pfxFilePwd,base64RequestParams, "utf-8");
String checkValue =
signResult.getSign();
String cmdId = "123";//交易指令ID
String merCustId = "123123123123";//入驻商户id
String version = "10";
String contentType = "application/x-www-form-urlencoded";
String charset = "UTF-8";
String postStr = "cmd_id=" + cmdId + "&version=" + version + "&mer_cust_id=" + merCustId + "&check_value=" + checkValue;
jodd.http.HttpRequest httpRequest =jodd.http.HttpRequest.post(testUrl).charset(charset);
jodd.http.HttpResponse httpResponse =httpRequest.contentType(contentType).body(postStr).send();
String body = httpResponse.bodyText();
//响应解密
JSONObject jsonObject
= JSON.parseObject(body);
String sign =
jsonObject.getString("check_value");
String cerName = "CFCA_ACS_OCA31.cer";//文件可以询问对方运营
VerifyResult
verifyResult = CFCASignature.verifyMerSign("100001", sign, "utf-8", "/app/etc/product/" + cerName);
String content = new String(verifyResult.getContent(),
Charset.forName("utf-8"));
String decrptyContent
= newString(Base64.decodeBase64(content), Charset.forName("utf-8"));
成功响应:
{
"cmd_id": "123",
"resp_code": "123000",
"resp_desc": "交易成功",
"mer_cust_id" : "123123123123",
"order_date": "20180327",
"order_id": "10000000001",
.......
}
失败响应:
{
"cmd_id": "123",
"resp_code": "123003",
"resp_desc": "交易失败",
"mer_cust_id" : "123123123123",
"order_date": "20180327",
"order_id": "10000000001",
.......
}
加签方法:
private static String sign(String valueObj) {
// 加签用pfx文件
String pfxFileName = "888888-汇付测试商户.pfx";
// 加签用密码
String pfxFilePwd = "888888";
// 进行base64转换
String base64RequestParams
= Base64.encodeBase64String(valueObj.getBytes(Charset.forName("utf-8")));
// 加签
SignResult signResult
= CFCASignature.signature("/app/etc/product/" + pfxFileName, pfxFilePwd,base64RequestParams, "utf-8");
if ("000".equals(signResult.getCode())) {
return signResult.getSign();
} else {
return "加签失败";
}
}
好了,今天就记录到这里,相关的报错信息在接口文档中也有,根据提示调试吧。所有的接口编号、接口名称、提示都在页面上,用起来非常方便。个人认为这是其宣称“全程自助对接”的关键之处,这些也许能帮对接使用支付的公司减少不少开发、运营的成本。
文章来源:https://blog.csdn.net/xiucaiyao/article/details/82660680