| package com.jzq; | 
|   | 
| import com.alibaba.fastjson.JSONArray; | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.jzq.common.ResultInfo; | 
| import com.jzq.common.bean.sign.OrganizationCreateReq; | 
| import com.jzq.common.bean.sign.SignatoryReq; | 
| import com.jzq.common.http.HttpClientUtils; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.apache.commons.codec.digest.DigestUtils; | 
| import org.apache.commons.lang3.StringUtils; | 
|   | 
| import java.io.File; | 
| import java.util.HashMap; | 
| import java.util.HashSet; | 
| import java.util.IdentityHashMap; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * <ul> | 
|  * <li>项目名称 : 后台服务</li> | 
|  * <li>文件名称 : JzqHttpApiTest</li> | 
|  * <li>创建时间 : 2019/8/23 9:14</li> | 
|  * <li>描 述 :  用于jzq的api服请求 | 
|  * </ul> | 
|  * | 
|  * @author yfx | 
|  * @title 用于jzq的api服请求 | 
|  */ | 
| @Slf4j | 
| public class JzqHttpApiTest { | 
|   | 
|     /** | 
|      * 君子签测试环境key和接口地址: | 
|      * appKey:dcb4bd535a09df3c | 
|      * appSecret:b87c346edcb4bd535a09df3ca8c45d9a | 
|      * services_url:https://api.sandbox.junziqian.com | 
|      * 开发文档: https://s.junziqian.com/api_doc/index.html | 
|      */ | 
|     String SERVICE_URL="https://api.sandbox.junziqian.com"; | 
|     String APP_KEY="dcb4bd535a09df3c"; | 
|     String APP_SECRET="b87c346edcb4bd535a09df3ca8c45d9a"; | 
|   | 
|     //请求的body内参数 | 
|     Map<String, Object> bodyParams; | 
|   | 
|     public void initParams(){ | 
|         log.warn("测试前请确认APP_KEY,APP_SECRET,LOCAL_URL等配置是否正确"); | 
|         log.info("APP_KEY:"+APP_KEY); | 
|         log.info("APP_SECRET:"+APP_SECRET); | 
|         log.info("SERVICE_URL:"+SERVICE_URL); | 
|         long ts=System.currentTimeMillis(); | 
|         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("app_key",APP_KEY); | 
|         bodyParams.put("sign",sign); | 
|         bodyParams.put("nonce",nonce);//这只只是为了生成一个随机值 | 
|     } | 
|   | 
|     /** | 
|      * 1.ping服务 | 
|      */ | 
|     public void testPing(){ | 
|         initParams(); | 
|         Map<String, Object>  params=bodyParams; | 
|         String url=SERVICE_URL+"/v2/ping"; | 
|         //所有参数装入了body中 | 
|         String str= HttpClientUtils.init().getPost(url,null,params,false); | 
|         log.info("返回结果为:"+str); | 
|         ResultInfo ri= JSONObject.parseObject(str,ResultInfo.class); | 
|     } | 
|   | 
|   | 
|   | 
|   | 
|     /** | 
|      * 发起签约 (君子签后台配置模版ID发起) | 
|      */ | 
|     public void testOrganizationCreate (){ | 
|         initParams(); | 
| //        req.setLegalIdentityCard("5002401XXXXXXXXX");//法人证件号 | 
| //        req.setLegalMobile("153XXXXXXXX"); | 
|         Map<String, Object>  params=bodyParams; | 
|         String url=SERVICE_URL+"/v2/user/organizationCreate"; | 
|         params.put("name","安徽豆米科技有限公司1"); | 
|         params.put("identificationType",1); | 
|         params.put("organizationRegNo","913401000967388931"); | 
|         params.put("organizationType",0); | 
|         params.put("organizationCode","913401000967388931"); | 
|         params.put("organizationRegImg", new File("D://test.png")); | 
|         params.put("legalName","杨龙1"); | 
|         params.put("emailOrMobile","jp1@doumee.com"); | 
|   | 
|         System.out.println(JSONObject.toJSONString(params)); | 
|         String str= HttpClientUtils.init().getPost(url,null,params,true); | 
|         System.out.println(str); | 
|     } | 
|     /** | 
|      * 发起签约 (君子签后台配置模版ID发起) | 
|      */ | 
|     public void testOrganizationAuditStatus (){ | 
|         initParams(); | 
|         Map<String, Object>  params=bodyParams; | 
|         String url=SERVICE_URL+"/v2/user/organizationAuditStatus"; | 
|         params.put("emailOrMobile","jp@doumee.com"); | 
|         String str= HttpClientUtils.init().getPost(url,null,params,true); | 
|         System.out.println(str); | 
|     } | 
|     /** | 
|      * 发起签约 (君子签后台配置模版ID发起) | 
|      */ | 
|     public String testApplySign(){ | 
|         String url=SERVICE_URL+"/v2/sign/applySign"; | 
|         initParams(); | 
|         Map<String, Object>  params=bodyParams; | 
|         params.put("contractName","测试合同发起"); //合同名称 | 
|         params.put("serverCa",1); //使用云证书 | 
|         params.put("file",new File("D://test2.pdf")); | 
|         params.put("dealType",5); //指定合同文件签署方式 5 为部分自动签 | 
|         params.put("positionType",2); //指定通过表单域方式设置签字位置 | 
|         params.put("fileType",0); | 
|         params.put("needQifengSign",1); | 
|         JSONArray signatories=new JSONArray(); | 
|         SignatoryReq sReq=new SignatoryReq(); | 
|         sReq.setFullName("安徽豆米科技有限公司"); //企业姓名 | 
|         sReq.setIdentityType(11); //证件类型 | 
|         sReq.setIdentityCard("913401000967388938");//营业执照号 | 
|         sReq.setEmail("jp@doumee.com"); //在君子签注册认证的邮箱 | 
|         JSONArray array = new JSONArray(); | 
|         JSONObject j = new JSONObject(); | 
|         JSONObject j1 = new JSONObject(); | 
|         j1.put("page","1"); | 
|         j.put("page","1"); | 
|         j.put("page","1"); | 
|         array.add(j); | 
|         sReq.setSearchKey("投保人签字(盖章):;投保人(签章):"); | 
| //        sReq.setChapteJson("[{\"page\":0,\"chaptes\":[{\"offsetX\":0.12,\"offsetY\":0.23}]},{\"page\":1,\"chaptes\":[{\"offsetX\":0.45,\"offsetY\":0.67}]}]"); | 
|             sReq.setNoNeedVerify(1); | 
|             sReq.setSearchConvertExtend("{\"fixX\":10,\"fixY\":-50}"); | 
| //        sReq.setChapteName("ebq"); //企业盖章位置 | 
|         signatories.add(sReq); | 
|         params.put("signatories",signatories.toJSONString()); | 
|         System.out.println(signatories.toJSONString()); | 
|         String str= HttpClientUtils.init().getPost(url,null,params,true); | 
|         System.out.println(str); | 
|         JSONObject json = JSONObject.parseObject(str); | 
|         if(json!=null && json.getBoolean("success")){ | 
|             return  json.getString("data"); | 
|         } | 
|         return null; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获取签署链接地址 | 
|      */ | 
|     public void testlink(String no) { | 
|         initParams(); | 
|         Map<String, Object> params = bodyParams; | 
|         String url = SERVICE_URL + "/v2/sign/link"; | 
|         params.put("applyNo",no); //发起合同签署接口返回的APL编号 | 
|         params.put("fullName","安徽豆米科技有限公司"); //发起合同签署接口需要手动签署对象的姓名 | 
|         params.put("identityCard","913401000967388938"); //发起合同签署接口中需要手动签署对象的证件号 | 
|         params.put("identityType",11); //证件类型,个人1 ,企业11 | 
|         String str= HttpClientUtils.init().getPost(url,null,params,true); | 
|         try { | 
|   | 
|         }catch (Exception e){ | 
|   | 
|         } | 
|         System.out.println(str); | 
|     } | 
|   | 
|     /** | 
|      * 上传企业自定义印章(返回印章ID) | 
|      * @param signName | 
|      * @param signImgFile | 
|      */ | 
|     public String  uploadEntSign(String signName,File signImgFile,String email ) { | 
|   | 
|         try { | 
|             initParams(); | 
|             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); | 
|             JSONObject json = JSONObject.parseObject(str); | 
|             if(json!=null && json.getBoolean("success")){ | 
|                 return  json.getString("data"); | 
|             } | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|         } | 
|         return  null; | 
|     } | 
|     /** | 
|      * 获取签署链接地址 | 
|      */ | 
|     public void testlinkFile() { | 
|         initParams(); | 
|         Map<String, Object> params = bodyParams; | 
|         String url = SERVICE_URL + "/v2/sign/linkFile"; | 
|         //构建请求参数 | 
|         params.put("applyNo","APL1747073129375088640"); //发起合同签署接口返回的APL编号 | 
|         String str= HttpClientUtils.init().getPost(url,null,params,true); | 
|         try { | 
|   | 
|         }catch (Exception e){ | 
|   | 
|         } | 
|         System.out.println(str); | 
|     } | 
|   | 
|   | 
|     public static void main(String[] args) { | 
|         new JzqHttpApiTest().testOrganizationCreate(); | 
| //        new JzqHttpApiTest().testOrganizationAuditStatus(); | 
| //        new JzqHttpApiTest().uploadEntSign("豆米科技公章新",new File("D://sing.png"),"jp@doumee.com"); | 
|   | 
| //        new JzqHttpApiTest().testlink( new JzqHttpApiTest().testApplySign()); | 
| //        new JzqHttpApiTest().testlinkFile(); | 
|     } | 
|   | 
|   | 
| } |