ApplySignFileSample.java
11.4 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package com.example.demo.common;
import com.example.demo.domain.ReceivingObject;
import com.example.demo.domain.SignResult;
import com.example.demo.domain.SignatoryData;
import com.junziqian.api.JunziqianClient;
import com.junziqian.api.bean.Signatory;
import com.junziqian.api.common.DealType;
import com.junziqian.api.common.IdentityType;
import com.junziqian.api.common.SignLevel;
import com.junziqian.api.request.ApplySignFileRequest;
import com.junziqian.api.response.ApplySignResponse;
import org.ebaoquan.rop.thirdparty.com.alibaba.fastjson.JSONArray;
import org.ebaoquan.rop.thirdparty.com.alibaba.fastjson.JSONObject;
import org.ebaoquan.rop.thirdparty.com.google.common.collect.Sets;
import org.ebaoquan.rop.utils.spring.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/**
* Created by wlinguo on 2016-05-16.
*/
//public class ApplySignFileSample {
public class ApplySignFileSample {
public SignResult Sample(MultipartFile file, ReceivingObject receivingObject ) throws IOException {
String SERVICE_URL = "http://api.junziqian.com/services";
// 请填入你的APPKey
String APP_KEY = "dda683a619751e69";
// 请填入你的APPSecret
String APP_SECRET = "34a07facdda683a619751e69c4a887b8";
JunziqianClient client = new JunziqianClient(SERVICE_URL, APP_KEY, APP_SECRET);
// System.out.println("ahahahaha");
// SignResult signResult = new SignResult();
// signResult.setApplyNo("wahahahahahah");
//
// return signResult;
File convFile = new File(file.getOriginalFilename());
convFile.createNewFile();
FileOutputStream fos = new FileOutputStream(convFile);
fos.write(file.getBytes());
fos.close();
// BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(file.getInputStream(), "utf-8"));
// String str;
// while ((str = bufferedReader.readLine()) != null && !"".equals(str)) {
// System.out.println(str);
// }
// bufferedReader.close();
// CommonsMultipartFile cf= (CommonsMultipartFile)file;
// DiskFileItem fi = (DiskFileItem)cf.getFileItem();
// File files = (File)file;
SignResult signResult = new SignResult();
ApplySignFileRequest.Builder builder = new ApplySignFileRequest.Builder();
String agreementName = receivingObject.getAgreementName();
System.out.println(agreementName);
String contractAmountStr = receivingObject.getAgreementAmount();
Double contractAmount = Double.parseDouble(contractAmountStr);
builder.withContractName(agreementName); // 合同名称,必填 *
builder.withContractAmount(contractAmount); // 合同金额 *
//1、本地文件方式
// builder.withFile("/Users/xuwenhao/Downloads/借款协议2.pdf");
//2、字节流方式
//File file = new File("D:\\tmp\\买卖合同.pdf");
builder.withFile(convFile.getName(), FileCopyUtils.copyToByteArray(convFile)); //合同文件
// //上传签约附件,目前最大只支持上传3份附件
// builder.withAttachFile1("D:\\tmp\\借款基础信息.xlsx");
// builder.withAttachFile2("D:\\tmp\\bbbb.jpg");
// builder.withAttachFile3("D:\\tmp\\shenqingshu.png");
HashSet<Signatory> signatories = Sets.newHashSet();
List<SignatoryData> signatoryDataList = receivingObject.getData();
List<SignatoryData> signatoryPersonList = new ArrayList<>();
List<SignatoryData> signatoryCompanyList = new ArrayList<>();
for(int i=0;i<signatoryDataList.size();i++){
if(signatoryDataList.get(i).getType().equals("person")){
signatoryPersonList.add(signatoryDataList.get(i));
}else if(signatoryDataList.get(i).getType().equals("company")){
signatoryCompanyList.add(signatoryDataList.get(i));
}
}
for(int j=0;j<signatoryPersonList.size();j++){
String name = signatoryPersonList.get(j).getName();
String idNo = signatoryPersonList.get(j).getIdNo();
String mobile = signatoryPersonList.get(j).getMobile();
Double page = Double.parseDouble(signatoryPersonList.get(j).getPage());
Double offsetX = Double.parseDouble(signatoryPersonList.get(j).getOffsetX());
Double offsetY = Double.parseDouble(signatoryPersonList.get(j).getOffsetY());
Signatory signatory = new Signatory();
signatory.setFullName(name); //姓名
signatory.setSignatoryIdentityType(IdentityType.IDCARD); //证件类型
signatory.setIdentityCard(idNo); //证件号码
signatory.setMobile(mobile);
JSONArray chapteJsonArray=new JSONArray();
JSONObject pageJson=new JSONObject();
pageJson.put("page", page);
JSONArray chaptes=new JSONArray();
pageJson.put("chaptes", chaptes);
chapteJsonArray.add(pageJson);
JSONObject chapte=new JSONObject();
chapte.put("offsetX", offsetX);
chapte.put("offsetY", offsetY);
chaptes.add(chapte);
signatory.withChapteJson(chapteJsonArray);
signatory.setSignLevel(1); //0:标准图形章 1:公章或手写
signatories.add(signatory);
}
for(int k=0;k<signatoryCompanyList.size();k++){
Double page = Double.parseDouble(signatoryCompanyList.get(k).getPage());
Double offsetX = Double.parseDouble(signatoryCompanyList.get(k).getOffsetX());
Double offsetY = Double.parseDouble(signatoryCompanyList.get(k).getOffsetY());
Signatory signatory = new Signatory();
signatory.setFullName("七彩投资(苏州)有限公司"); //姓名
signatory.setSignatoryIdentityType(IdentityType.BIZLIC); //证件类型
signatory.setIdentityCard("913205083310094721");//证件号码(营业执照号或统一社会信用代码)
signatory.setEmail("chrisniceboat@163.com");//企业账户注册邮箱
signatory.setMobile("15062592832");//企业代表手机
JSONArray chapteJsonArray3 = new JSONArray();
JSONObject pageJson3 = new JSONObject();
pageJson3.put("page", page);
JSONArray chaptes3 = new JSONArray();
pageJson3.put("chaptes", chaptes3);
chapteJsonArray3.add(pageJson3);
JSONObject chapte3 = new JSONObject();
chapte3.put("offsetX", offsetX);
chapte3.put("offsetY", offsetY);
chaptes3.add(chapte3);
signatory.withChapteJson(chapteJsonArray3);
signatory.setSignLevel(1); //0:标准图形章 1:公章或手写
signatories.add(signatory);
}
// /**
// * 签约方1
// */
// Signatory signatory = new Signatory();
// signatory.setFullName("徐文豪"); //姓名
// signatory.setSignatoryIdentityType(IdentityType.IDCARD); //证件类型
// signatory.setIdentityCard("320981199307111710"); //证件号码
// signatory.setMobile("18896525239");
//
// /*
// * 设置签约方1的签章位置,签约位置平台自行设置
// * 签字位置 (以文件页左上角(0.0,0.0)为基准,按百分比进行设置)offsetX,offsetY(x,y为比例,值范设置为0-1之间) page为页码,page从0开始计数,
// * 每页为一个数组,每页不能超过10个签字位置
// */
// JSONArray chapteJsonArray=new JSONArray();
// JSONObject pageJson=new JSONObject();
// pageJson.put("page", 1);
// JSONArray chaptes=new JSONArray();
// pageJson.put("chaptes", chaptes);
// chapteJsonArray.add(pageJson);
// JSONObject chapte=new JSONObject();
// chapte.put("offsetX", 0.20);
// chapte.put("offsetY", 0.68);
// chaptes.add(chapte);
//// chapte=new JSONObject();
//// chapte.put("offsetX", 0.52);
//// chapte.put("offsetY", 0.75);
//// chaptes.add(chapte);
// signatory.withChapteJson(chapteJsonArray);
// signatory.setSignLevel(1); //0:标准图形章 1:公章或手写
// signatories.add(signatory);
//
//
// /**
// * 签约方3
// */
// signatory = new Signatory();
// signatory.setFullName("史文斌"); //姓名
// signatory.setSignatoryIdentityType(IdentityType.IDCARD); //证件类型
// signatory.setIdentityCard("32058619850321881X"); //证件号码
// signatory.setMobile("15162499345");
// JSONArray chapteJsonArray2 = new JSONArray();
// JSONObject pageJson2 = new JSONObject();
// pageJson2.put("page", 1);
// JSONArray chaptes2 = new JSONArray();
// pageJson2.put("chaptes", chaptes2);
// chapteJsonArray2.add(pageJson2);
// JSONObject chapte2 = new JSONObject();
// chapte2.put("offsetX", 0.20);
// chapte2.put("offsetY", 0.73);
// chaptes2.add(chapte2);
// signatory.withChapteJson(chapteJsonArray2);
// signatory.setSignLevel(1); //0:标准图形章 1:公章或手写
//
// signatories.add(signatory);
// /**
// * 签约方2
// */
// signatory = new Signatory();
// signatory.setFullName("七彩投资"); //姓名
// signatory.setSignatoryIdentityType(IdentityType.BIZLIC); //证件类型
// signatory.setIdentityCard("500903000035447");//证件号码(营业执照号或统一社会信用代码)
// signatory.setEmail("qicaitouzi@www.bccto.me");//企业账户注册邮箱
// signatory.setMobile("15062592832");//企业代表手机
// JSONArray chapteJsonArray3 = new JSONArray();
// JSONObject pageJson3 = new JSONObject();
// pageJson3.put("page", 1);
// JSONArray chaptes3 = new JSONArray();
// pageJson3.put("chaptes", chaptes3);
// chapteJsonArray3.add(pageJson3);
//
// JSONObject chapte3 = new JSONObject();
// chapte3.put("offsetX", 0.20);
// chapte3.put("offsetY", 0.73);
// chaptes3.add(chapte3);
// signatory.withChapteJson(chapteJsonArray3);
//
// signatory.setSignLevel(1); //0:标准图形章 1:公章或手写
//
// signatories.add(signatory);
//
//
//
builder.withSignatories(signatories); // 添加签约人
builder.withSignLevel(SignLevel.GENERAL.getCode()); // 签字类型,这里选择标准图形章
//builder.withRemark("这里是备注信息,不超过500个字符"); //备注
//builder.withPreRecored("前执记录,会计录到日志中!");
builder.withServerCa(1);//使用云证书,0 不使用,1 使用
builder.withDealType(DealType.AUTH_SIGN);//自动签
ApplySignResponse response = client.applySignFile(builder.build());
// LogUtils.logResponse(response);
// System.out.println(response.isSuccess());
signResult.setSuccess(response.isSuccess());
signResult.setApplyNo(response.getApplyNo());
return signResult;
}
}