与建行进行善付通支付接口小知识
- 1.测试环境
- 目前做的工作都是为了更顺利的与生产环境进行对接。
- 2.生产环境
- 测试环境没问题后,申请生产环境的开发==一般需要三到五天==:
- 3.感觉最坑人的地方
1.测试环境
目前做的工作都是为了更顺利的与生产环境进行对接。
1.测试环境的申请
2.确认公司服务器ip是否可用,测试ip是否可以连接成功
3. 研究开发文档,辨别文档中的每个字段包含的意义 很多细节,不小心被坑开发过程报错不断
4.前期需要和建行老师沟通,XX接口应该是用哪种方式请求才能正确获取数据。被坑过
5.初步设计数据库,提前构想表结构:比如需要对接支付功能:支付操作日志表,订单表(抓取虚拟数 据),订单支付通知数据记录表,订单状态查询日志表
6.根据建行提供的demo程序,加密解密方式,进行测试项目的开发。
7. 开发完毕后,进行模拟数据的支付测试。
2.生产环境
测试环境没问题后,申请生产环境的开发一般需要三到五天:
- 和测试环境大差不差,就不多赘述了
3.感觉最坑人的地方
1.刚开始没有老师进行有效沟通,都是使用的后端接口通过http方式访问善付通接口期望获取json串或者html/xml,然并卵,建行的某些接口必须使用前端html页面form表单进行提交进而跳转页面,一些联机接口可以使用后台模拟form表单的形式提交,获取到json串,解析并返回前端html页面,
2.之前找了很多资料,如何使用form表单带返回值提交:第一步需要引入,百度一搜一大片,第二步,直接看代码
$("#form").ajaxForm(function (data) {
// data 为获取到的接口返回值
}
3.后端模拟form表单提交数据
首先引入jar
这边使用的maven:
<dependency>
<groupId></groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!-- /artifact//httpmime -->
<dependency>
<groupId></groupId>
<artifactId>httpmime</artifactId>
</dependency>
<!-- /artifact//httpcore -->
<dependency>
<groupId></groupId>
<artifactId>httpcore</artifactId>
</dependency>
/**
-
thirdSysID:第三方系统ID
-
txCode:交易码
-
data:加密数据
-
auth:签名
*/
public String postFormData(String thirdSysID,String txCode,String data,String auth)throws Exception{
String result = “”;
CloseableHttpClient httpclient = ();
try {
String uri = ;
HttpPost httppost = new HttpPost(uri);StringBody ThirdSysID = new StringBody(thirdSysID, ContentType.TEXT_PLAIN); StringBody TxCode = new StringBody(txCode, ContentType.TEXT_PLAIN); StringBody Data = new StringBody(data, ContentType.TEXT_PLAIN); StringBody Auth = new StringBody(auth, ContentType.TEXT_PLAIN); HttpEntity reqEntity = () .addPart("ThirdSysID",ThirdSysID) .addPart("TxCode",TxCode) .addPart("Data",Data) .addPart("Auth",Auth) .build(); (reqEntity); ("executing request " + ()); CloseableHttpResponse response = (httppost); try { ("----------------------------------------"); (()); HttpEntity resEntity = (); if (resEntity != null) { ("Response content length: " + ()); ("Response content length: " + ()); String a=(resEntity); //打印获取到的返回值 ("Response content: " + a); result = a; } (resEntity); } finally { (); } } finally { (); } return result;
}