第三方合同接口示例记录
public static String contractSign(Contract contract,Userbasicsinfo loanUser,Userbasicsinfo tenderUser,HttpServletRequest request){ String osName = System.getProperties().getProperty("os.name").toLowerCase(); String outputPath = null; String downloadPath = null; if(osName.startsWith("win")){ outputPath = "D:\\contract_" + contract.getContractNo() + ".doc"; downloadPath = "D:\\contract_" + contract.getContractNo() + ".pdf"; }else{ File dir = new File("/home/p2ptemp/"); if(!dir.exists()){ dir.mkdirs(); } outputPath = "/home/p2ptemp/contract_" + contract.getContractNo() + ".doc"; downloadPath = "/home/p2ptemp/contract_" + contract.getContractNo() + ".pdf"; } try { boolean bool = HtmlToDoc.writeWordFileString(getContractEmptyHtml(contract.getContent()), outputPath); if(bool){ //2. 发起人签章 Userrelationinfo loanRela = loanUser.getUserrelationinfo(); String response = FddClient.invokeSyncPersonAuto(loanUser.getName(),loanRela.getEmail() , loanRela.getCardId(), loanRela.getPhone()); Map<String,String> map = JSON.parseObject(response, Map.class); String customer_id = map.get("customer_id"); String cnum = "ZC"+System.currentTimeMillis(); response = FddClient.invokeUploadDocs(cnum, new File(outputPath), "", ".doc"); response = FddClient.invokeExtSignAuto("ZCSIGN"+cnum, customer_id, "", "", "1", "3", cnum, "xxx合同", loanUser.getName(), "", ""); map = JSON.parseObject(response, Map.class); String downloadUrl = map.get("download_url"); //2.5 下载 FddDownload.download(downloadUrl, downloadPath); response = FddClient.invokeContractFilling(cnum); //3. 投资人签章 Userrelationinfo tenderRela = tenderUser.getUserrelationinfo(); response = FddClient.invokeSyncPersonAuto(tenderUser.getName(),tenderRela.getEmail() , tenderRela.getCardId(), tenderRela.getPhone()); map = JSON.parseObject(response, Map.class); customer_id = map.get("customer_id"); cnum = "ZC"+System.currentTimeMillis(); response = FddClient.invokeUploadDocs(cnum, new File(downloadPath), "", ".pdf"); response = FddClient.invokeExtSignAuto("ZCSIGN"+cnum, customer_id, "", "", "1", "3", cnum, "xxx合同", tenderUser.getName(), "", ""); map = JSON.parseObject(response, Map.class); downloadUrl = map.get("download_url"); //4. 合同归档 response = FddClient.invokeContractFilling(cnum); return downloadUrl; } } catch (Exception e) { e.printStackTrace(); } return null; } public static String getContractEmptyHtml(String content) { String path = ProjectPathUtils.getClassesPath(); path = path.replaceAll("/classes", "")+"views/contract/detail.jsp"; if(path.indexOf("/")!=0&&path.indexOf(":")!=1){ path = "/"+path; } File file = new File(path); FileInputStream fis = null; InputStreamReader read = null; BufferedReader bufferedReader = null; try{ fis = new FileInputStream(file); read = new InputStreamReader(fis,"UTF-8"); bufferedReader = new BufferedReader(read); StringBuilder lineTxt = new StringBuilder(""); String tempLine = null; while((tempLine = bufferedReader.readLine()) != null){ lineTxt.append(tempLine); } String returnValue = lineTxt.toString(); int index = returnValue.indexOf("<!DOCTYPE "); returnValue = returnValue.substring(index, returnValue.length()).replace("${content}", content); return returnValue; }catch(Exception ex){ } return null; }
以上代码在工作上使用到了,记录一下下