与建行进行善付通支付接口小知识

1.测试环境

目前做的工作都是为了更顺利的与生产环境进行对接。

1.测试环境的申请
2.确认公司服务器ip是否可用,测试ip是否可以连接成功
3. 研究开发文档,辨别文档中的每个字段包含的意义 很多细节,不小心被坑开发过程报错不断
4.前期需要和建行老师沟通,XX接口应该是用哪种方式请求才能正确获取数据。被坑过
5.初步设计数据库,提前构想表结构:比如需要对接支付功能:支付操作日志表,订单表(抓取虚拟数 据),订单支付通知数据记录表,订单状态查询日志表
6.根据建行提供的demo程序,加密解密方式,进行测试项目的开发。
7. 开发完毕后,进行模拟数据的支付测试。

2.生产环境

测试环境没问题后,申请生产环境的开发一般需要三到五天
  1. 和测试环境大差不差,就不多赘述了

3.感觉最坑人的地方

1.刚开始没有老师进行有效沟通,都是使用的后端接口通过http方式访问善付通接口期望获取json串或者html/xml,然并卵,建行的某些接口必须使用前端html页面form表单进行提交进而跳转页面,一些联机接口可以使用后台模拟form表单的形式提交,获取到json串,解析并返回前端html页面,
2.之前找了很多资料,如何使用form表单带返回值提交:第一步需要引入jquery-form.js,百度一搜一大片,第二步,直接看代码
$("#form").ajaxForm(function (data) {
// data 为获取到的接口返回值
}
3.后端模拟form表单提交数据
首先引入jar
这边使用的maven:

	  <dependency>
	      <groupId>org.apache.httpcomponents</groupId>
	      <artifactId>httpclient</artifactId>
	      </dependency>
	 
	  <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
	 <dependency>
	      <groupId>org.apache.httpcomponents</groupId>
	      <artifactId>httpmime</artifactId>
	      </dependency>
	 
	  <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
	  <dependency>
	      <groupId>org.apache.httpcomponents</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 = HttpClients.createDefault();
    try {
    String uri = SZFConstant.URL;
    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 = MultipartEntityBuilder.create()
                  .addPart("ThirdSysID",ThirdSysID)
                  .addPart("TxCode",TxCode)
                  .addPart("Data",Data)
                  .addPart("Auth",Auth)
                  .build();
    
    
          httppost.setEntity(reqEntity);
    
          System.out.println("executing request " + httppost.getRequestLine());
          CloseableHttpResponse response = httpclient.execute(httppost);
          try {            
              System.out.println("----------------------------------------");
              System.out.println(response.getStatusLine());
              HttpEntity resEntity = response.getEntity();
              if (resEntity != null) {
                  System.out.println("Response content length: " + resEntity.getContentLength());
                  System.out.println("Response content length: " + resEntity.getContent());
                  String a=EntityUtils.toString(resEntity);
                  //打印获取到的返回值
                  System.out.println("Response content: " + a);
                  result = a;
              }
              EntityUtils.consume(resEntity);
          } finally {
              response.close();
          }
      } finally {
          httpclient.close();
      }
      return result;
    

    }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值