1. 程式人生 > >java接口對接——別人調用我們接口獲取數據

java接口對接——別人調用我們接口獲取數據

conf alsa exceptio map check ref onu 數據 meta

java接口對接——別人調用我們接口獲取數據,我們需要在我們系統中開發幾個接口,給對方接口規範文檔,包括訪問我們的接口地址,以及入參名稱和格式,還有我們的返回的狀態的情況,

接口代碼:

package com.xx.xxx.yzyhentity.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.atmosphere.plugin.redis.StringUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.xxx.basic.auditproject.auditprojectmaterial.domain.AuditProjectMaterial; import com.xxx.common.util.JsonUtils; import com.xxx.core.xxxFrameDsManager; import com.xxx.core.dao.CommonDao; import com.xxx.core.grammar.Record;
import com.xxx.database.jdbc.config.SplitTableConfig; import com.xxx.frame.service.attach.entity.FrameAttachInfo; import com.xxx.frame.service.metadata.code.api.ICodeItemsService; import com.xxx.frame.service.metadata.code.entity.CodeItems; import com.xxx.frame.service.metadata.sharding.util.ShardingUtil; import com.xxx.ycsrh.api.AuditBkaccFeedback; @RestController @RequestMapping("bkacc") public class RestfulToSzzwzx { @Autowired private ICodeItemsService iCodeItemsService; /** * 政務中心獲取股東信息接口 * @param param * @return * @exception/throws [違例類型] [違例說明] * @see [類、類#方法、類#成員] */ @SuppressWarnings("unused") @RequestMapping(value = "/getSZzwzxOpenShareHolders", method = RequestMethod.POST) public String getSZzwzxOpenShareHolders(@RequestBody String param) { //返回JSON值 JSONObject userareaJson = new JSONObject(); String result = ""; try { xxxFrameDsManager.begin(null); // 參數轉化為json對象 JSONObject jsonObject = (JSONObject) JSONObject.parse(param); // 時間格式化 SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // token驗證 String token = jsonObject.getString("token"); if (GXConstant.checkToken(token)) { JSONObject params = (JSONObject) jsonObject.get("params"); // 業務標識(與開戶申請時推送的ywguid一致) String ywguid = params.getString("ywguid"); // 獲取股東信息列表 // List<Record> listGD = iShareform.getGDTableInfo(ywguid); List<Record> listGD = null; if (listGD != null && listGD.size() > 0) { JSONArray jsonArray = new JSONArray(); for (Record rec : listGD) { JSONObject gdJson = new JSONObject(); // 股東姓名 gdJson.put("shareholdernmae", rec.get("Ctrl1")); // 證件類型 String idtype = rec.get("Ctrl2"); if(StringUtil.isNotBlank(idtype)){ CodeItems codeItems = iCodeItemsService.getCodeItemByCodeName("內資企業身份證件類型", idtype); if(codeItems!=null && StringUtil.isNotBlank(codeItems.getDmAbr1())){ gdJson.put("idtype", codeItems.getDmAbr1()); } else{ gdJson.put("idtype", idtype); } } // 證件號碼 gdJson.put("idno", rec.get("Ctrl3")); // 出資時間 gdJson.put("contributivedate", sdf2.format(rec.get("Ctrl4"))); // 出資方式 gdJson.put("contributivetype", rec.get("Ctrl9")); // 認繳出資額 gdJson.put("contributivenum", rec.get("Ctrl5")); // 認繳出資比例 gdJson.put("contributivepercent", rec.get("Ctrl7")); jsonArray.add(gdJson); userareaJson.put("userarea", jsonArray); } result = JsonUtils.zwdtRestReturn("1", "獲取股東信息接口調用成功!", userareaJson); } else { result = JsonUtils.zwdtRestReturn("0", "接口調用成功,但未查到相關股東數據信息!", userareaJson); } } else { result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:token驗證失敗!", userareaJson); } } catch (Exception e) { e.printStackTrace(); xxxFrameDsManager.rollback(); result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:" + e.toString(), userareaJson); } finally { xxxFrameDsManager.close(); } return result; } /** * 市政務中心獲取開戶申請材料接口 * @param param * @return * @exception/throws [違例類型] [違例說明] * @see [類、類#方法、類#成員] */ @RequestMapping(value = "/getSZzwzxOpenAcountMaterials", method = RequestMethod.POST) public String getSZzwzxOpenAcountMaterials(@RequestBody String param) { // 返回JSON值 JSONObject userareaJson = new JSONObject(); // 材料內son JSONObject materialJson = new JSONObject(); String result = ""; try { xxxFrameDsManager.begin(null); // 參數轉化為json對象 JSONObject jsonObject = (JSONObject) JSONObject.parse(param); // token驗證 String token = jsonObject.getString("token"); if (GXConstant.checkToken(token)) { boolean flag = false; JSONObject params = (JSONObject) jsonObject.get("params"); JSONArray materialsArray = new JSONArray(); // 業務標識(與開戶申請時推送的ywguid一致) String ywguid = params.getString("ywguid"); if (StringUtil.isNotBlank(ywguid)) { // 獲取流程提交得材料 SplitTableConfig conf = ShardingUtil.getSplitTableConfig("audit_project_material"); CommonDao fbMaterialDao = CommonDao.getInstance(conf); String sql = "SELECT * FROM audit_project_material WHERE PROJECTGUID=‘"+ywguid+"‘ AND status >10 "; List<AuditProjectMaterial> projectMaterialList = new ArrayList<AuditProjectMaterial>(); projectMaterialList = fbMaterialDao.findList(sql, AuditProjectMaterial.class); if(projectMaterialList != null && projectMaterialList.size()>0){ for(AuditProjectMaterial auditProjectMaterial : projectMaterialList){ // 獲取流程提交得材料附件 String sql2 = "SELECT * FROM frame_attachinfo WHERE CLIENGGUID = ‘"+auditProjectMaterial.getCliengguid()+"‘;"; List<FrameAttachInfo> attachInfoList = CommonDao.getInstance().findList(sql2, FrameAttachInfo.class); if (attachInfoList != null && attachInfoList.size() > 0) { // 材料內Json JSONObject fileinfoJson = new JSONObject(); fileinfoJson.put("materialname", auditProjectMaterial.getTaskmaterial()); fileinfoJson.put("filesource", "窗口上傳"); JSONArray jsonArray = new JSONArray(); for (FrameAttachInfo attachinfo : attachInfoList) { JSONObject certJson = new JSONObject(); // 附件下載地址 String loadUrl = "http://service.snd.gov.cn/zwfwf9test/gxqzwfw/rest/frame/pages/basic/attach/attachAction/getContent?attachGuid=" + attachinfo.getAttachGuid() + "&isCommondto=true"; // 材料名稱 certJson.put("filename", attachinfo.getAttachFileName()); // 材料內容 certJson.put("filecontent", loadUrl); jsonArray.add(certJson); } fileinfoJson.put("fileinfos", jsonArray); materialsArray.add(fileinfoJson); flag = true; } } } materialJson.put("materials", materialsArray); userareaJson.put("userarea", materialJson); if (flag) { result = JsonUtils.zwdtRestReturn("1", "獲取申報材料接口調用成功!", userareaJson); } else { result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:未查到相關申報材料數據信息!", userareaJson); } } else { result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:未查到相關辦件數據信息!", userareaJson); } } else { result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:token驗證失敗!", userareaJson); } } catch (Exception e) { e.printStackTrace(); xxxFrameDsManager.rollback(); result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:" + e.toString(), userareaJson); } finally { xxxFrameDsManager.close(); } return result; } /** * 錄入市裏返回得銀行開戶反饋信息 * @param param * @return */ @RequestMapping(value = "/pushSZzwzxOpenAcountResult", method = RequestMethod.POST) public String pushSZzwzxOpenAcountResult(@RequestBody String param) { String result = ""; try { xxxFrameDsManager.begin(null); // 參數轉化為json對象 JSONObject jsonObject = (JSONObject) JSONObject.parse(param); //時間格式化 //SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //token驗證 String token = jsonObject.getString("token"); if (GXConstant.checkToken(token)) { JSONObject params = (JSONObject) jsonObject.get("params"); // 業務標識(與開戶申請時推送的ywguid一致) String ywguid = params.getString("ywguid"); // 銀行名稱 String bankname = params.getString("bankname"); // 銀行編號 String bankno = params.getString("bankno"); // 賬戶名稱 String accountname = params.getString("accountname"); // 賬號 String accountnum = params.getString("accountnum"); // 開戶日期 Date accountdate = params.getDate("accountdate"); // 是否同意開戶 String isallow = params.getString("isallow"); // 銀行開戶審核意見 String bankopnion = params.getString("bankopnion"); // 商業銀行開戶審核時間 Date bankopniondate = params.getDate("bankopniondate"); String sql = "SELECT * FROM AUDIT_BKACC_FEEDBACK WHERE YWGUID =‘"+ywguid+"‘ "; AuditBkaccFeedback auditBkaccFeedback = CommonDao.getInstance().find(sql, AuditBkaccFeedback.class); int flag = 1; if(auditBkaccFeedback == null){ auditBkaccFeedback = new AuditBkaccFeedback(); auditBkaccFeedback.setRowguid(UUID.randomUUID().toString()); auditBkaccFeedback.setOperatedate(new Date()); auditBkaccFeedback.setYwguid(ywguid); flag = 0; } if(StringUtil.isNotBlank(bankno)){ auditBkaccFeedback.setBankno(bankno); }else{ return result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:銀行編號(bankno)為空!", ""); } if(StringUtil.isNotBlank(bankname)){ auditBkaccFeedback.setBankname(bankname); } if(StringUtil.isNotBlank(accountname)){ auditBkaccFeedback.setAccountname(accountname); } if(StringUtil.isNotBlank(accountnum)){ auditBkaccFeedback.setAccountnum(accountnum); } if(StringUtil.isNotBlank(accountdate)){ auditBkaccFeedback.setAccountdate(accountdate); } /*else{ return result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:開戶日期(accountdate)為空!", ""); }*/ if(StringUtil.isNotBlank(isallow)){ auditBkaccFeedback.setIsalllow(isallow); }else{ return result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:是否同意開戶(isallow)為空!", ""); } if(StringUtil.isNotBlank(bankopnion)){ auditBkaccFeedback.setBankopinion(bankopnion); }else{ return result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:銀行開戶審核意見(bankopnion)為空!", ""); } if(StringUtil.isNotBlank(bankopniondate)){ auditBkaccFeedback.setBankopniondate(bankopniondate); } if(flag == 0){ CommonDao.getInstance().insert(auditBkaccFeedback); } else { CommonDao.getInstance().update(auditBkaccFeedback); } result = JsonUtils.zwdtRestReturn("1", "接口調用成功,反饋信息已錄入!", ""); } else { return result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:token驗證失敗!", ""); } } catch (Exception e) { e.printStackTrace(); xxxFrameDsManager.rollback(); result = JsonUtils.zwdtRestReturn("0", "接口調用失敗,原因是:" + e.toString(), ""); } finally { xxxFrameDsManager.close(); } return result; } }

給對方的接口地址就是 域名+工程名+rest+類註解+方法註解,我們系統運行著就可以了,給對方調用,開發過程中需要兩邊聯調,可以用postman等工具進行來回接口的調用和數據的互相推送調試完成即可;

java接口對接——別人調用我們接口獲取數據