jiangping
2024-01-16 c2f1aac8acca57f4c21f6fe6718101b01805bc72
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package com.jzq.common.test;
 
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","安徽豆米科技有限公司");
        params.put("identificationType",1);
        params.put("organizationRegNo","913401000967388938");
        params.put("organizationType",0);
        params.put("organizationCode","913401000967388938");
        params.put("organizationRegImg", new File("D://test.png"));
        params.put("legalName","杨龙");
        params.put("emailOrMobile","jp@doumee.com");
        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 void 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://test.pdf"));
        params.put("dealType",5); //指定合同文件签署方式 5 为部分自动签
        params.put("positionType",0); //指定通过表单域方式设置签字位置
        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.setChapteJson("[{\"page\":0,\"chaptes\":[{\"offsetX\":0.12,\"offsetY\":0.23}]},{\"page\":1,\"chaptes\":[{\"offsetX\":0.45,\"offsetY\":0.67}]}]");
            sReq.setNoNeedVerify(1);
//        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);
    }
 
 
    /**
     * 获取签署链接地址
     */
    public void testlink() {
        initParams();
        Map<String, Object> params = bodyParams;
        String url = SERVICE_URL + "/v2/sign/link";
        params.put("applyNo","APL1747073129375088640"); //发起合同签署接口返回的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);
    }
    /**
     * 获取签署链接地址
     */
    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().testApplySign();
//        new JzqHttpApiTest().testlink();
        new JzqHttpApiTest().testlinkFile();
    }
}