Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
leaf-hlcm
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hlcm
leaf-hlcm
Commits
b5087268
Commit
b5087268
authored
Apr 03, 2023
by
gzj34291
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
金格
parent
61875cd6
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
922 additions
and
0 deletions
+922
-0
Byte2Hex.java
src/main/java/com/hand/kinggrid/Byte2Hex.java
+53
-0
ContractWithTemplate.java
src/main/java/com/hand/kinggrid/ContractWithTemplate.java
+187
-0
FileHolder.java
src/main/java/com/hand/kinggrid/FileHolder.java
+40
-0
HttpRequest.java
src/main/java/com/hand/kinggrid/HttpRequest.java
+428
-0
MD5.java
src/main/java/com/hand/kinggrid/MD5.java
+104
-0
MainRequest.java
src/main/java/com/hand/kinggrid/MainRequest.java
+76
-0
StrKit.java
src/main/java/com/hand/kinggrid/StrKit.java
+34
-0
No files found.
src/main/java/com/hand/kinggrid/Byte2Hex.java
0 → 100644
View file @
b5087268
package
com
.
hand
.
kinggrid
;
import
java.util.Formatter
;
/**
* <p>
* 字节 16进制字串转换工具类
* </p>
*
* @author hubin
* @Date 2016-01-20
*/
public
class
Byte2Hex
{
/**
*
* 字节转换为 16 进制字符串
*
* @param b
* 字节
* @return
*/
public
static
String
byte2Hex
(
byte
b
)
{
String
hex
=
Integer
.
toHexString
(
b
);
if
(
hex
.
length
()
>
2
)
{
hex
=
hex
.
substring
(
hex
.
length
()
-
2
);
}
while
(
hex
.
length
()
<
2
)
{
hex
=
"0"
+
hex
;
}
return
hex
;
}
/**
*
* 字节数组转换为 16 进制字符串
*
* @param bytes
* 字节数组
* @return
*/
public
static
String
byte2Hex
(
byte
[]
bytes
)
{
Formatter
formatter
=
new
Formatter
();
for
(
byte
b
:
bytes
)
{
formatter
.
format
(
"%02x"
,
b
);
}
String
hash
=
formatter
.
toString
();
formatter
.
close
();
return
hash
;
}
}
src/main/java/com/hand/kinggrid/ContractWithTemplate.java
0 → 100644
View file @
b5087268
package
com
.
hand
.
kinggrid
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.UUID
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
/**
* 合同相关测试(使用模板)接口
* @author Administrator
*
*/
public
class
ContractWithTemplate
{
//public static final String SERVER_URL = "http://10.203.0.11:8989/tosignserver";
/**
* 信签服务器对接应用ID
*/
//public static final String APP_ID = "ac4a3bd1bf6f44fa86477ac251933259";
/**
* 信签服务器对接应用密钥
*/
// public static final String APP_SECURITY = "7lQ7GC1HSviWAFG6";
public
static
void
main
(
String
[]
args
)
throws
IOException
{
//String contractid = "testte222211";
String
contractid
=
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
//合同编号,随机生成
JSONObject
json
=
generateContract
(
contractid
,
null
);
//System.out.println(json);
if
(
json
.
getInteger
(
"code"
)
==
1
){
//创建成功
downFiles
(
json
.
getJSONArray
(
"doc_last_urls"
),
"d:/"
+
contractid
,
null
,
null
,
null
);
json
=
signContract
(
contractid
,
null
);
json
=
signContract2
(
contractid
,
null
);
if
(
json
.
getInteger
(
"code"
)
==
1
){
//签署成功
downFiles
(
json
.
getJSONArray
(
"record_saved_urls"
),
"d:/"
+
contractid
,
null
,
null
,
null
);
System
.
out
.
println
(
"record_saved_urls:"
+
json
.
getJSONArray
(
"record_saved_urls"
));
}
else
{
System
.
out
.
println
(
json
);
}
}
}
/**
* 下载多个文件保存在文件夹
* @param urls
* @param savePath
* @throws IOException
*/
public
static
final
void
downFiles
(
JSONArray
urls
,
String
savePath
,
String
server_url
,
String
app_id
,
String
app_security
)
throws
IOException
{
for
(
Object
url
:
urls
)
{
downFile
((
String
)
url
,
savePath
,
server_url
,
app_id
,
app_security
);
}
}
/**
* 下载文件保存
* @param url
* @param savePath
* @throws IOException
*/
public
static
final
void
downFile
(
String
url
,
String
savePath
,
String
server_url
,
String
app_id
,
String
app_security
)
throws
IOException
{
HttpRequest
request
=
MainRequest
.
createHttpRequest
(
url
,
server_url
,
app_id
,
app_security
);
//HttpRequest request = new HttpRequest(url);
request
.
send
();
int
code
=
request
.
getResponseCode
();
if
(
code
==
200
){
FileOutputStream
fos
=
null
;
try
{
String
fileName
=
savePath
;
if
((!
savePath
.
endsWith
(
"/"
))
&&
(!
savePath
.
endsWith
(
"\\"
)))
{
fileName
=
fileName
+
"/"
;
}
fileName
=
fileName
+
request
.
getDownFileName
();
File
file
=
new
File
(
fileName
);
fos
=
new
FileOutputStream
(
file
);
request
.
result
(
fos
);
}
finally
{
if
(
fos
!=
null
)
fos
.
close
();
}
}
else
{
System
.
out
.
println
(
"错误信息:"
+
request
.
resultToString
());
}
}
/**
* 使用模板创建合同
* @throws IOException
*/
public
static
JSONObject
generateContract
(
String
contractid
,
String
contract_tpl_code
)
throws
IOException
{
HttpRequest
request
=
MainRequest
.
createHttpRequest
(
"/api/contract/start"
,
null
,
null
,
null
);
//{"姓名":"李东长","cardname_ID":"360111198708080899","year":"2018","month":"01","day":"01"}
JSONObject
docx_metadata
=
new
JSONObject
(
true
);
docx_metadata
.
put
(
"INSURANCE_COMPANY"
,
"信签售后"
);
docx_metadata
.
put
(
"INSURANCE_MAN"
,
"龚琪"
);
docx_metadata
.
put
(
"PLATE_NUM"
,
"京A88888"
);
docx_metadata
.
put
(
"INSURANCE_YEAR"
,
"2018"
);
docx_metadata
.
put
(
"INSURANCE_MONTH"
,
"05"
);
docx_metadata
.
put
(
"INSURANCE_DAY"
,
"21"
);
docx_metadata
.
put
(
"INSURANCE_MONEY"
,
"50000"
);
docx_metadata
.
put
(
"SIGN_YEAR"
,
"2018"
);
docx_metadata
.
put
(
"SIGN_MONTH"
,
"05"
);
docx_metadata
.
put
(
"SIGN_DAY"
,
"21"
);
//quest.addFile("attach_file", new File("d:/t1.pdf"));
//request.addFile("attach_file", new File("d:/t2.gif"));
//request.addFile("attach_file_2", new File("d:/test.docx"));
//request.addParam("contract_tlp_code",contract_tpl_code);
request
.
addParam
(
"contract_tlp_code"
,
"nxs001"
);
request
.
addParam
(
"doc_metadata"
,
docx_metadata
.
toJSONString
());
//设置合同ID
request
.
addParam
(
"contract_id"
,
contractid
);
//设置合同名称参数
request
.
addParam
(
"contract_name"
,
"测试"
);
//设置业务编码参数
request
.
addParam
(
"biz_id"
,
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
));
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//设置业务时间参数
request
.
addParam
(
"biz_time"
,
sdf
.
format
(
new
Date
()));
request
.
send
();
return
JSONObject
.
parseObject
(
request
.
resultToString
());
}
/**
* 签署合同
* @throws IOException
*/
public
static
JSONObject
signContract
(
String
contractid
,
String
signer_code
)
throws
IOException
{
HttpRequest
request
=
MainRequest
.
createHttpRequest
(
"/api/contract/sign"
,
null
,
null
,
null
);
request
.
addParam
(
"contract_id"
,
contractid
);
request
.
addParam
(
"biz_id"
,
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
));
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//设置业务时间参数
request
.
addParam
(
"biz_time"
,
sdf
.
format
(
new
Date
()));
//设置签署人的编码
request
.
addParam
(
"signer_code"
,
signer_code
);
//设置签署位置信息
//request.addParam("signatures", "[{ y:680,x:200,pageno:\"1\"}]");
request
.
send
();
return
JSONObject
.
parseObject
(
request
.
resultToString
());
}
public
static
JSONObject
signContract2
(
String
contractid
,
String
signer_code
)
throws
IOException
{
HttpRequest
request
=
MainRequest
.
createHttpRequest
(
"/api/contract/sign"
,
null
,
null
,
null
);
request
.
addParam
(
"contract_id"
,
contractid
);
request
.
addParam
(
"biz_id"
,
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
));
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//设置业务时间参数
request
.
addParam
(
"biz_time"
,
sdf
.
format
(
new
Date
()));
//设置签署人的编码
request
.
addParam
(
"signer_code"
,
"xurong"
);
//设置签署位置信息
//request.addParam("signatures", "[{ y:680,x:200,pageno:\"1\"}]");
request
.
send
();
return
JSONObject
.
parseObject
(
request
.
resultToString
());
}
}
src/main/java/com/hand/kinggrid/FileHolder.java
0 → 100644
View file @
b5087268
package
com
.
hand
.
kinggrid
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
public
class
FileHolder
{
private
String
filename
;
private
File
file
;
private
InputStream
is
;
public
FileHolder
(
File
file
)
{
this
.
filename
=
file
.
getName
();
this
.
file
=
file
;
}
public
FileHolder
(
String
filename
,
InputStream
is
)
{
this
.
filename
=
filename
;
this
.
is
=
is
;
}
public
InputStream
getInputStream
()
throws
FileNotFoundException
{
if
(
is
==
null
){
return
new
FileInputStream
(
file
);
}
return
is
;
}
public
String
getFilename
()
{
return
filename
;
}
}
src/main/java/com/hand/kinggrid/HttpRequest.java
0 → 100644
View file @
b5087268
This diff is collapsed.
Click to expand it.
src/main/java/com/hand/kinggrid/MD5.java
0 → 100644
View file @
b5087268
package
com
.
hand
.
kinggrid
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.security.MessageDigest
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
java.util.TreeMap
;
import
java.util.logging.Logger
;
public
class
MD5
{
private
static
final
Logger
logger
=
Logger
.
getLogger
(
"MD5"
);
/**
* @Description 字符串加密为MD5 中文加密一致通用,必须转码处理: plainText.getBytes("UTF-8")
* @param plainText
* 需要加密的字符串
* @return
*/
public
static
String
toMD5
(
String
plainText
)
{
StringBuffer
rlt
=
new
StringBuffer
();
try
{
rlt
.
append
(
md5String
(
plainText
.
getBytes
(
"UTF-8"
)));
}
catch
(
UnsupportedEncodingException
e
)
{
logger
.
severe
(
" CipherHelper toMD5 exception."
);
e
.
printStackTrace
();
}
return
rlt
.
toString
();
}
/**
* MD5 参数签名生成算法
*
* @param HashMap<String,String>
* params 请求参数集,所有参数必须已转换为字符串类型
* @param String
* secret 签名密钥
* @return 签名
* @throws IOException
*/
public
static
String
getSignature
(
HashMap
<
String
,
String
>
params
,
String
secret
)
{
Map
<
String
,
String
>
sortedParams
=
new
TreeMap
<
String
,
String
>(
params
);
Set
<
Entry
<
String
,
String
>>
entrys
=
sortedParams
.
entrySet
();
StringBuilder
basestring
=
new
StringBuilder
();
for
(
Entry
<
String
,
String
>
param
:
entrys
)
{
basestring
.
append
(
param
.
getKey
()).
append
(
"="
).
append
(
param
.
getValue
());
}
return
getSignature
(
basestring
.
toString
(),
secret
);
}
/**
* MD5 参数签名生成算法
*
* @param String
* sigstr 签名字符串
* @param String
* secret 签名密钥
* @return 签名
* @throws IOException
*/
public
static
String
getSignature
(
String
sigstr
,
String
secret
)
{
StringBuilder
basestring
=
new
StringBuilder
(
sigstr
);
basestring
.
append
(
"#"
);
basestring
.
append
(
toMD5
(
secret
));
return
toMD5
(
basestring
.
toString
());
}
public
static
byte
[]
md5Raw
(
byte
[]
data
)
{
byte
[]
md5buf
=
null
;
try
{
MessageDigest
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
md5buf
=
md5
.
digest
(
data
);
}
catch
(
Exception
e
)
{
md5buf
=
null
;
logger
.
severe
(
"md5Raw error."
);
e
.
printStackTrace
();
}
return
md5buf
;
}
public
static
String
md5String
(
byte
[]
data
)
{
String
md5Str
=
""
;
try
{
MessageDigest
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
byte
[]
buf
=
md5
.
digest
(
data
);
for
(
int
i
=
0
;
i
<
buf
.
length
;
i
++)
{
md5Str
+=
Byte2Hex
.
byte2Hex
(
buf
[
i
]);
}
}
catch
(
Exception
e
)
{
md5Str
=
null
;
logger
.
severe
(
"md5String error."
);
e
.
printStackTrace
();
}
return
md5Str
;
}
}
\ No newline at end of file
src/main/java/com/hand/kinggrid/MainRequest.java
0 → 100644
View file @
b5087268
package
com
.
hand
.
kinggrid
;
public
class
MainRequest
{
/**
* 信签服务器地址
*/
//public static final String SERVER_URL = "http://171.34.78.70:8081:8081/tosignserver";
//public static final String SERVER_URL = "http://10.203.0.11:8989/tosignserver";
// public static final String SERVER_URL = "http://171.34.78.70:8081/tosignpub";
/**
* 信签服务器对接应用ID
*/
//public static final String APP_ID = "king";
// public static final String APP_ID = "ac4a3bd1bf6f44fa86477ac251933259";
//public static final String APP_ID = "f12a2c19e72348998b159df903b9b379";
/**
* 信签服务器对接应用密钥
*/
//public static final String APP_SECURITY = "e3f55030d473095d";
// public static final String APP_SECURITY = "7lQ7GC1HSviWAFG6";
//public static final String APP_SECURITY = "SK60MXsN7dzv1iIM";
//public static final String APP_ID = "f12a2c19e72348998b159df903b9b379";
/**
* 测试签署用户编码
*/
//public static final String SIGNER_CODE= "hlzlUser";
//public static final String SIGNER_CODE= "lidongzhang";
/**
* 模板创建合同使用的模板编码
*/
//public static final String CONTRACT_TPL_CODE= "testTemplate";
public
static
void
main
(
String
[]
args
)
{
}
/**
* 生成信签请求操作对象
* @param url
* @return
*/
public
static
HttpRequest
createHttpRequest
(
String
url
,
String
server_url
,
String
app_id
,
String
app_security
){
String
requestUrl
=
url
;
if
(!
url
.
toUpperCase
().
startsWith
(
"HTTP"
)){
if
(
server_url
.
endsWith
(
"/"
)){
requestUrl
=
server_url
.
substring
(
0
,
server_url
.
length
()-
1
)+
url
;
}
else
{
requestUrl
=
server_url
+
url
;
}
}
HttpRequest
httpRequest
=
new
HttpRequest
(
requestUrl
);
/**
* 如果是云服务,需要添加应用id到header
* 如果是私有云,可以不用设置
*/
httpRequest
.
addHeader
(
"app_id"
,
app_id
);
String
time
=
System
.
currentTimeMillis
()+
""
;
httpRequest
.
addHeader
(
"time"
,
time
);
httpRequest
.
addHeader
(
"sign"
,
MD5
.
toMD5
(
app_id
+
"."
+
time
+
'.'
+
app_security
));
return
httpRequest
;
}
}
src/main/java/com/hand/kinggrid/StrKit.java
0 → 100644
View file @
b5087268
package
com
.
hand
.
kinggrid
;
public
class
StrKit
{
public
static
boolean
notBlank
(
String
str
)
{
return
!
isBlank
(
str
);
}
public
static
boolean
isBlank
(
String
str
)
{
if
(
str
==
null
)
{
return
true
;
}
int
len
=
str
.
length
();
if
(
len
==
0
)
{
return
true
;
}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
switch
(
str
.
charAt
(
i
))
{
case
' '
:
case
'\t'
:
case
'\n'
:
case
'\r'
:
// case '\b':
// case '\f':
break
;
default
:
return
false
;
}
}
return
true
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment