|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.PostConstruct; | 
|---|
|  |  |  | import java.io.File; | 
|---|
|  |  |  | import java.io.FileOutputStream; | 
|---|
|  |  |  | import java.io.InputStream; | 
|---|
|  |  |  | import java.io.OutputStream; | 
|---|
|  |  |  | import java.net.URI; | 
|---|
|  |  |  | import java.net.URL; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.IdentityHashMap; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.UUID; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <ul> | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void initParams(){ | 
|---|
|  |  |  | long ts=System.currentTimeMillis(); | 
|---|
|  |  |  | long ts=System.currentTimeMillis()/1000; | 
|---|
|  |  |  | String nonce=DigestUtils.md5Hex(System.currentTimeMillis()+""); | 
|---|
|  |  |  | String sign=DigestUtils.sha256Hex("nonce"+nonce+"ts"+ts+"app_key"+APP_KEY+"app_secret"+APP_SECRET); | 
|---|
|  |  |  | bodyParams=new IdentityHashMap<>(); | 
|---|
|  |  |  | bodyParams.put("ts",ts); | 
|---|
|  |  |  | bodyParams.put("ts",System.currentTimeMillis()/1000); | 
|---|
|  |  |  | bodyParams.put("app_key",APP_KEY); | 
|---|
|  |  |  | bodyParams.put("sign",sign); | 
|---|
|  |  |  | bodyParams.put("nonce",nonce);//这只只是为了生成一个随机值 | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param creditCode | 
|---|
|  |  |  | * @param legalName | 
|---|
|  |  |  | * @param email | 
|---|
|  |  |  | * @param businessimg | 
|---|
|  |  |  | * @param businessimgPath | 
|---|
|  |  |  | * @param notifyUrl | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public boolean organizationCreate (String fullname,String creditCode,String legalName,String email,File  businessimg,String notifyUrl){ | 
|---|
|  |  |  | public boolean organizationCreate (String fullname,String creditCode,String legalName,String email,String businessimgPath, String notifyUrl){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | initParams(); | 
|---|
|  |  |  | File  businessimg =netFileToLoclFile(businessimgPath); | 
|---|
|  |  |  | if(businessimg == null || !businessimg.isFile() || !businessimg.exists()){ | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map<String, Object>  params=bodyParams; | 
|---|
|  |  |  | String url=SERVICE_URL+"/v2/user/organizationCreate"; | 
|---|
|  |  |  | params.put("name",fullname); | 
|---|
|  |  |  | 
|---|
|  |  |  | params.put("legalName",legalName); | 
|---|
|  |  |  | params.put("emailOrMobile",email); | 
|---|
|  |  |  | String str= HttpClientUtils.init().getPost(url,null,params,true); | 
|---|
|  |  |  | businessimg.delete(); | 
|---|
|  |  |  | saveInterfaceLog(url,"【电子签】发起企业认证申请",JSONObject.toJSONString(params),str); | 
|---|
|  |  |  | JSONObject json = JSONObject.parseObject(str); | 
|---|
|  |  |  | if(json!=null && json.getBoolean("success")){ | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param creditCode | 
|---|
|  |  |  | * @param legalName | 
|---|
|  |  |  | * @param email | 
|---|
|  |  |  | * @param businessimg | 
|---|
|  |  |  | * @param businessimgPath | 
|---|
|  |  |  | * @param notifyUrl | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public boolean organizationReApply(String fullname,String creditCode,String legalName,String email,File  businessimg,String notifyUrl){ | 
|---|
|  |  |  | public boolean organizationReApply(String fullname,String creditCode,String legalName,String email,String businessimgPath,String notifyUrl){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | File  businessimg = new File(new URI(businessimgPath)); | 
|---|
|  |  |  | if(businessimg == null|| !businessimg.isFile() || !businessimg.exists()){ | 
|---|
|  |  |  | return false ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | initParams(); | 
|---|
|  |  |  | Map<String, Object>  params=bodyParams; | 
|---|
|  |  |  | String url=SERVICE_URL+"/v2/user/organizationReapply"; | 
|---|
|  |  |  | params.put("name",fullname); | 
|---|
|  |  |  | 
|---|
|  |  |  | params.put("legalName",legalName); | 
|---|
|  |  |  | params.put("emailOrMobile",email); | 
|---|
|  |  |  | String str= HttpClientUtils.init().getPost(url,null,params,true); | 
|---|
|  |  |  | businessimg.delete(); | 
|---|
|  |  |  | saveInterfaceLog(url,"【电子签】重新发起企业认证申请",JSONObject.toJSONString(params),str); | 
|---|
|  |  |  | JSONObject json = JSONObject.parseObject(str); | 
|---|
|  |  |  | if(json!=null && json.getBoolean("success")){ | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 网络文件转本地临时文件 | 
|---|
|  |  |  | * @param fileUrl | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static File netFileToLoclFile(String fileUrl)  { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | URL url = new URL(fileUrl); | 
|---|
|  |  |  | InputStream inputStream = url.openConnection().getInputStream(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | File file = File.createTempFile( "temp",""+UUID.randomUUID().toString()+fileUrl.substring(fileUrl.lastIndexOf("."))); // 指定保存到本地的文件名及路径 | 
|---|
|  |  |  | OutputStream outputStream = new FileOutputStream(file); | 
|---|
|  |  |  | byte[] buffer = new byte[1024]; | 
|---|
|  |  |  | int bytesRead; | 
|---|
|  |  |  | while ((bytesRead = inputStream.read(buffer)) != -1) { | 
|---|
|  |  |  | outputStream.write(buffer, 0, bytesRead); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | outputStream.close(); | 
|---|
|  |  |  | inputStream.close(); | 
|---|
|  |  |  | return file; | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询企业签约状态 审批状态,0正在申请1通过2驳回 | 
|---|
|  |  |  | * @param email | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public int  organizationAuditStatus (String email){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | initParams(); | 
|---|
|  |  |  | Map<String, Object>  params=bodyParams; | 
|---|
|  |  |  | String url=SERVICE_URL+"/v2/user/organizationAuditStatus"; | 
|---|
|  |  |  | params.put("emailOrMobile",email); | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 发起签约 | 
|---|
|  |  |  | * @param name | 
|---|
|  |  |  | * @param file | 
|---|
|  |  |  | * @param fileUrl | 
|---|
|  |  |  | * @param fullname | 
|---|
|  |  |  | * @param creditCoe | 
|---|
|  |  |  | * @param email | 
|---|
|  |  |  | * @param postionJson | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String applySign(String name,File file,String fullname,String creditCoe,String email,String postionJson){ | 
|---|
|  |  |  | public String applySign(String name,String fileUrl,String fullname,String creditCoe,String email,String postionJson,String singId,String notifyUrl){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | initParams(); | 
|---|
|  |  |  | String url=SERVICE_URL+"/v2/sign/applySign"; | 
|---|
|  |  |  | Map<String, Object>  params=bodyParams; | 
|---|
|  |  |  | params.put("contractName",name); //合同名称 | 
|---|
|  |  |  | params.put("serverCa",1); //使用云证书 | 
|---|
|  |  |  | params.put("file",file); | 
|---|
|  |  |  | //          params.put("file",file); | 
|---|
|  |  |  | params.put("url",fileUrl); | 
|---|
|  |  |  | params.put("dealType",5); //指定合同文件签署方式 5 为部分自动签 | 
|---|
|  |  |  | params.put("positionType",0); //指定通过表单域方式设置签字位置 | 
|---|
|  |  |  | params.put("fileType",0); | 
|---|
|  |  |  | params.put("positionType",2); //指定通过表单域方式设置签字位置 | 
|---|
|  |  |  | params.put("fileType",1); | 
|---|
|  |  |  | params.put("needQifengSign",1); | 
|---|
|  |  |  | params.put("notifyUrl",notifyUrl); | 
|---|
|  |  |  | JSONArray signatories=new JSONArray(); | 
|---|
|  |  |  | SignatoryReq sReq=new SignatoryReq(); | 
|---|
|  |  |  | sReq.setFullName(fullname); //企业姓名 | 
|---|
|  |  |  | 
|---|
|  |  |  | sReq.setIdentityCard(creditCoe);//营业执照号 | 
|---|
|  |  |  | sReq.setEmail(email); //在君子签注册认证的邮箱 | 
|---|
|  |  |  | //        sReq.setChapteJson("[{\"page\":0,\"chaptes\":[{\"offsetX\":0.12,\"offsetY\":0.23}]},{\"page\":1,\"chaptes\":[{\"offsetX\":0.45,\"offsetY\":0.67}]}]"); | 
|---|
|  |  |  | sReq.setChapteJson(postionJson); | 
|---|
|  |  |  | //          sReq.setChapteJson(postionJson); | 
|---|
|  |  |  | sReq.setSearchKey(postionJson); | 
|---|
|  |  |  | sReq.setSignId(singId); | 
|---|
|  |  |  | sReq.setNoNeedVerify(1); | 
|---|
|  |  |  | signatories.add(sReq); | 
|---|
|  |  |  | params.put("signatories",signatories.toJSONString()); | 
|---|
|  |  |  | System.out.println("================"+JSONObject.toJSONString(params)); | 
|---|
|  |  |  | String str= HttpClientUtils.init().getPost(url,null,params,true); | 
|---|
|  |  |  | System.out.println(str); | 
|---|
|  |  |  | saveInterfaceLog(url,"【电子签】发起签约",JSONObject.toJSONString(params),str); | 
|---|
|  |  |  | JSONObject json = JSONObject.parseObject(str); | 
|---|
|  |  |  | if(json!=null && json.getBoolean("success")){ | 
|---|
|  |  |  | return  json.getString("data"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 发起签约 | 
|---|
|  |  |  | * @param name | 
|---|
|  |  |  | * @param fileUrl | 
|---|
|  |  |  | * @param file | 
|---|
|  |  |  | * @param creditCoe | 
|---|
|  |  |  | * @param email | 
|---|
|  |  |  | * @param postionJson | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String applySignLocalFile(String name,String fullname,String file,String creditCoe,String email,String postionJson,String singId,String notifyUrl){ | 
|---|
|  |  |  | try {    initParams(); | 
|---|
|  |  |  | String url=SERVICE_URL+"/v2/sign/applySign"; | 
|---|
|  |  |  | Map<String, Object>  params=bodyParams; | 
|---|
|  |  |  | params.put("contractName",name); //合同名称 | 
|---|
|  |  |  | params.put("serverCa",1); //使用云证书 | 
|---|
|  |  |  | params.put("file",new File(file)); | 
|---|
|  |  |  | params.put("dealType",5); //指定合同文件签署方式 5 为部分自动签 | 
|---|
|  |  |  | params.put("positionType",1); //指定通过表单域方式设置签字位置 | 
|---|
|  |  |  | params.put("fileType",0); | 
|---|
|  |  |  | params.put("needQifengSign",1); | 
|---|
|  |  |  | params.put("notifyUrl",notifyUrl); | 
|---|
|  |  |  | JSONArray signatories=new JSONArray(); | 
|---|
|  |  |  | SignatoryReq sReq=new SignatoryReq(); | 
|---|
|  |  |  | sReq.setFullName(fullname); //企业姓名 | 
|---|
|  |  |  | sReq.setIdentityType(11); //证件类型 | 
|---|
|  |  |  | sReq.setIdentityCard(creditCoe);//营业执照号 | 
|---|
|  |  |  | sReq.setEmail(email); //在君子签注册认证的邮箱 | 
|---|
|  |  |  | //        sReq.setChapteJson("[{\"page\":0,\"chaptes\":[{\"offsetX\":0.12,\"offsetY\":0.23}]},{\"page\":1,\"chaptes\":[{\"offsetX\":0.45,\"offsetY\":0.67}]}]"); | 
|---|
|  |  |  | //          sReq.setChapteJson(postionJson); | 
|---|
|  |  |  | sReq.setSearchKey(postionJson); | 
|---|
|  |  |  | sReq.setSignId(singId); | 
|---|
|  |  |  | sReq.setSearchConvertExtend("{\"fixX\":10,\"fixY\":-50}"); | 
|---|
|  |  |  | sReq.setNoNeedVerify(1); | 
|---|
|  |  |  | signatories.add(sReq); | 
|---|
|  |  |  | params.put("signatories",signatories.toJSONString()); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param creditCode | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String signLink(String applyNo,String name,String creditCode) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | try {    initParams(); | 
|---|
|  |  |  | Map<String, Object> params = bodyParams; | 
|---|
|  |  |  | String url = SERVICE_URL + "/v2/sign/link"; | 
|---|
|  |  |  | params.put("applyNo",applyNo); //发起合同签署接口返回的APL编号 | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String  linkFile(String applyNo) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | try {    initParams(); | 
|---|
|  |  |  | Map<String, Object> params = bodyParams; | 
|---|
|  |  |  | String url = SERVICE_URL + "/v2/sign/linkFile"; | 
|---|
|  |  |  | //构建请求参数 | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 上传企业自定义印章(返回印章ID) | 
|---|
|  |  |  | * @param signName | 
|---|
|  |  |  | * @param signImgFile | 
|---|
|  |  |  | * @param path | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String  uploadEntSign(String signName,File signImgFile ) { | 
|---|
|  |  |  | public String  uploadEntSign(String signName,String path,String email ) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | try {    initParams(); | 
|---|
|  |  |  | File signImgFile =netFileToLoclFile(path); | 
|---|
|  |  |  | Map<String, Object> params = bodyParams; | 
|---|
|  |  |  | String url = SERVICE_URL + "/v2/user/uploadEntSign"; | 
|---|
|  |  |  | //构建请求参数 | 
|---|
|  |  |  | params.put("signName",signName); | 
|---|
|  |  |  | params.put("signImgFile",signImgFile); | 
|---|
|  |  |  | params.put("email",email); | 
|---|
|  |  |  | String str= HttpClientUtils.init().getPost(url,null,params,true); | 
|---|
|  |  |  | System.out.println(str); | 
|---|
|  |  |  | saveInterfaceLog(url,"【电子签】上传企业自定义印章",JSONObject.toJSONString(params),str); | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public boolean  deleteEntSign(String signId ) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | try {    initParams(); | 
|---|
|  |  |  | Map<String, Object> params = bodyParams; | 
|---|
|  |  |  | String url = SERVICE_URL + "/v2/user/deleteEntSign"; | 
|---|
|  |  |  | //构建请求参数 | 
|---|