欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java调用别人接口推送数据

程序员文章站 2024-01-10 09:47:16
...

/**
* 调用XXX市接口推送银行开户信息
* ywguid 即为 projectguid
* @exception/throws [违例类型] [违例说明]
* @see [类、类#方法、类#成员]
*/
public void pushToSZOpenAcountApplyinfo(String projectguid) {
try {
YzyhEntityServiceImpl yzyhEntityServiceImpl = new YzyhEntityServiceImpl();
System.out.println("===================引入银行印章流程得实体service" + yzyhEntityServiceImpl);
YzyhEntity yzyhEntity = yzyhEntityServiceImpl.getYzyhEntityByProjectguid(projectguid);
//时间格式化
SimpleDateFormat sdf2 = new SimpleDateFormat(“yyyy-MM-dd 00:00:00”);
if (yzyhEntity != null) {
RestfulService restfulservice = new RestfulService();
JSONObject jobparasjson = new JSONObject();
JSONObject jobjparas = new JSONObject();
jobparasjson.put(“token”, “xxx_WebSerivce_**##0601”);
//业务标识
jobjparas.put(“ywguid”, projectguid);
//存款人名称
jobjparas.put(“acctna”, StringUtil.isBlank(yzyhEntity.getAcctna()) ? “” : yzyhEntity.getAcctna());
//证明文件种类
if (StringUtil.isNotBlank(yzyhEntity.getIdtftp())) {
jobjparas.put(“idtftp”, yzyhEntity.getIdtftp());
} else {
jobjparas.put(“idtftp”, “M”);
}
String areacode = “”;
//证明文件编号
jobjparas.put(“idtfno”, StringUtil.isBlank(yzyhEntity.getIdtfno()) ? “” : yzyhEntity.getIdtfno());
//证明文件有效期
jobjparas.put(“matudt”, StringUtil.isBlank(yzyhEntity.getMatudt()) ? “2099-12-30 00:00:00”
: sdf2.format(yzyhEntity.getMatudt()));
//地址
// String address = yzyhEntity.get(“Ctrl66”) + “省(市/区)”;
// address += yzyhEntity.get(“Ctrl67”) + “市(区/盟/州)”;
// address += yzyhEntity.get(“Ctrl68”) + “县”;
// address += yzyhEntity.get(“Ctrl69”) + “乡(镇/街道)”;
// address += yzyhEntity.get(“Ctrl70”) + “村(路)”;
// address += yzyhEntity.get(“Ctrl71”) + “号”;
//id有效期
jobjparas.put(“lwiddt”, StringUtil.isBlank(yzyhEntity.getLwiddt()) ? “2099-12-30 00:00:00”
: sdf2.format(yzyhEntity.getLwiddt()));
//证件编号
jobjparas.put(“lwidno”, yzyhEntity.getLwidno());
//基本账户开户许可核准号
jobjparas.put(“dtittp”, “ACO1”);
//代理人证件有效期
jobjparas.put(“pxmudt”, StringUtil.isBlank(yzyhEntity.getPxmudt()) ? “2099-12-30 00:00:00”
: sdf2.format(yzyhEntity.getPxmudt()));
//业务代码
jobjparas.put(“qxcode”, yzyhEntity.getQxcode());
jobparasjson.put(“params”, jobjparas);
System.out.println(“开户申请参数:” + jobparasjson);
//调用市政上报接口
String result = restfulservice.getTaskinfo(jobparasjson.toString());
System.out.println("=======开户申请信息返回值:" + result);
if (StringUtil.isBlank(result)) {
System.out.println("=开户申请信息推送失败
=");
}
JSONObject jsonresult = (JSONObject) JSONObject.parse(result);
String custom = jsonresult.getString(“custom”);
JSONObject jsoncustom = (JSONObject) JSONObject.parse(custom);
String code = jsoncustom.getString(“code”);
if (“1”.equals(code)) {
System.out.println("==============开户申请返回结果:" + jsoncustom.getString(“text”));
} else {
System.out.println("==============开户申请返回结果:" + jsoncustom.getString(“text”));
}
}
} catch (Exception e) {
e.printStackTrace();
System.out.print(e.toString());
}
}
所调用的所调用的restful接口,包含http模拟请求代码的service层业务逻辑实施层代码:
package com.xxx.xxxxx.yzyhentity.action;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;

import com.xxx.basic.bizlogic.sysconf.systemparameters.service.FrameConfigService9;
/**

  • 接口请求

  • [功能详细描述]

  • @see [相关类/方法]

  • @since [产品/模块版本]
    */
    public class RestfulService
    {

    private static String SZRESTFULURL;

    private static String pushSZzwzxOpenAcountApplyinfo = “szbank/pushSZzwzxOpenAcountApplyinfo”;//开户申请推送市政务服务中心商业银行

    static {
    SZRESTFULURL = new FrameConfigService9().getFrameConfigValue(“苏州市restful接口地址”);
    }

    /**

    • 开户申请推送市政务服务中心商业银行
    • [功能详细描述]
    • @param param ,为调用别人接口的入参
    • @return
    • @exception/throws [违例类型] [违例说明]
    • @see [类、类#方法、类#成员]
      */
      public String getTaskinfo(String param) {
      String url = SZRESTFULURL + pushSZzwzxOpenAcountApplyinfo;
      System.out.println("=============开户申请信息推送地址:"+url);
      return sendPost(url, param);
      }

    /**

    • http模拟请求
      */
      public String sendPost(String url, String param) {
      try {
      String result = null;
      String loginresturl = url;
      HttpClient httpClient = new HttpClient();
      PostMethod post = new PostMethod(loginresturl);
      HttpMethod method = post;
      System.out.println("=============开户申请信息推送地址:"+url);
      if (param != null) {
      RequestEntity se = new StringRequestEntity(param, “application/json”, “UTF-8”);
      post.setRequestEntity(se);
      }
      try {
      httpClient.executeMethod(method);
      String restresponse = method.getResponseBodyAsString();
      System.out.println("===================restresponse:" + restresponse);
      result=restresponse;
      } catch (Exception e) {
      e.printStackTrace();

       } finally {
           post.releaseConnection();
           
       }
       return result;
      

      } catch (Exception e) {
      e.printStackTrace();
      return null;
      }
      }

}