Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-process-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ce7e0246
authored
Sep 19, 2023
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]代码提交
1 parent
5200f221
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
193 additions
and
0 deletions
platform-process/src/main/java/cn/com/glsx/process/modules/sop/java/Controller1.java
platform-process/src/test/java/cn/com/glsx/test/TestApplication.java
platform-process/src/main/java/cn/com/glsx/process/modules/sop/java/Controller1.java
0 → 100644
View file @
ce7e024
package
cn
.
com
.
glsx
.
process
.
modules
.
sop
.
java
;
import
com.alibaba.fastjson.JSON
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.util.DefaultUriBuilderFactory
;
import
org.springframework.web.util.UriBuilder
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.security.GeneralSecurityException
;
import
java.security.MessageDigest
;
import
java.util.*
;
public
class
Controller1
{
private
final
static
String
appKey
=
"48e5e13229b82c1b4e6e8c96151f0637"
;
private
final
static
String
secret
=
"c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b"
;
private
final
static
String
baseurl
=
"http://rop-merchant.test.glsx.com.cn/rop-merchants/router"
;
private
final
static
String
method
=
"merchants.api.open.findStaffListByMerchantNo"
;
public
static
JSON
execute
(
JSON
param
)
{
JSON
post
=
null
;
// 将JSON字符串转换为Map
// 将Map中的数据放入MultiValueMap中
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>();
params
.
add
(
"merchantNo"
,
"44210895"
);
try
{
post
=
post
(
params
,
JSON
.
class
,
baseurl
,
method
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
System
.
out
.
println
(
JSON
.
toJSONString
(
post
));
return
post
;
}
private
static
void
addBaseParam
(
MultiValueMap
<
String
,
String
>
paramsMap
,
String
method
)
{
paramsMap
.
add
(
"v"
,
"1.0.0"
);
paramsMap
.
add
(
"method"
,
method
);
paramsMap
.
add
(
"name"
,
"zhouhb"
);
}
public
static
<
T
>
T
get
(
MultiValueMap
<
String
,
String
>
paramsMap
,
Class
<
T
>
responseType
,
String
baseurl
,
String
method
)
throws
Exception
{
addBaseParam
(
paramsMap
,
method
);
MultiValueMap
<
String
,
String
>
params
=
getSysParams
();
params
.
putAll
(
paramsMap
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
params
.
toSingleValueMap
().
entrySet
())
{
if
(
StringUtils
.
isEmpty
(
entry
.
getValue
()))
{
params
.
remove
(
entry
.
getKey
());
}
}
String
sign
=
sign
(
params
.
toSingleValueMap
(),
secret
);
params
.
add
(
"sign"
,
sign
);
RestTemplate
rest
=
new
RestTemplate
();
RopUriTemplateHandler
uriTemplateHandler
=
new
RopUriTemplateHandler
(
baseurl
);
uriTemplateHandler
.
setDefaultUriVariables
(
params
.
toSingleValueMap
());
rest
.
setUriTemplateHandler
(
uriTemplateHandler
);
T
forObject
=
rest
.
getForObject
(
baseurl
,
responseType
,
params
.
toSingleValueMap
());
return
forObject
;
}
public
static
<
T
>
T
post
(
MultiValueMap
<
String
,
String
>
paramsMap
,
Class
<
T
>
responseType
,
String
baseurl
,
String
method
)
throws
Exception
{
addBaseParam
(
paramsMap
,
method
);
MultiValueMap
<
String
,
String
>
params
=
getSysParams
();
params
.
putAll
(
paramsMap
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
params
.
toSingleValueMap
().
entrySet
())
{
if
(
StringUtils
.
isEmpty
(
entry
.
getValue
()))
{
params
.
remove
(
entry
.
getKey
());
}
}
String
sign
=
sign
(
params
.
toSingleValueMap
(),
secret
);
params
.
add
(
"sign"
,
sign
);
return
new
RestTemplate
().
postForObject
(
baseurl
,
params
,
responseType
);
}
public
static
MultiValueMap
<
String
,
String
>
getSysParams
()
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>(
16
);
params
.
add
(
"appKey"
,
appKey
);
params
.
add
(
"format"
,
"json"
);
return
params
;
}
public
static
MultiValueMap
<
String
,
String
>
getSysParamsE
()
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>(
16
);
params
.
add
(
"app_key"
,
appKey
);
params
.
add
(
"format"
,
"json"
);
params
.
add
(
"timestamp"
,
System
.
currentTimeMillis
()
+
""
);
return
params
;
}
static
class
RopUriTemplateHandler
extends
DefaultUriBuilderFactory
{
public
RopUriTemplateHandler
(
String
baseUriTemplate
)
{
super
(
baseUriTemplate
);
}
@Override
public
URI
expand
(
String
uriTemplate
,
Map
<
String
,
?>
uriVars
)
{
UriBuilder
builder
=
uriString
(
uriTemplate
);
if
(
uriVars
!=
null
&&
!
uriVars
.
isEmpty
())
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>();
for
(
Map
.
Entry
<
String
,
?>
entry
:
uriVars
.
entrySet
())
{
params
.
add
(
entry
.
getKey
(),
entry
.
getValue
().
toString
());
}
builder
.
queryParams
(
params
);
}
return
builder
.
build
(
uriVars
);
}
}
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
String
secret
)
{
return
sign
(
paramValues
,
(
List
)
null
,
secret
);
}
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
List
<
String
>
ignoreParamNames
,
String
secret
)
{
try
{
StringBuilder
sb
=
new
StringBuilder
();
List
<
String
>
paramNames
=
new
ArrayList
(
paramValues
.
size
());
paramNames
.
addAll
(
paramValues
.
keySet
());
Iterator
var5
;
String
paramName
;
if
(
ignoreParamNames
!=
null
&&
ignoreParamNames
.
size
()
>
0
)
{
var5
=
ignoreParamNames
.
iterator
();
while
(
var5
.
hasNext
())
{
paramName
=
(
String
)
var5
.
next
();
paramNames
.
remove
(
paramName
);
}
}
Collections
.
sort
(
paramNames
);
sb
.
append
(
secret
);
var5
=
paramNames
.
iterator
();
while
(
var5
.
hasNext
())
{
paramName
=
(
String
)
var5
.
next
();
sb
.
append
(
paramName
).
append
((
String
)
paramValues
.
get
(
paramName
));
}
sb
.
append
(
secret
);
byte
[]
sha1Digest
=
getSHA1Digest
(
sb
.
toString
());
return
byte2hex
(
sha1Digest
);
}
catch
(
IOException
var7
)
{
return
null
;
}
}
private
static
byte
[]
getSHA1Digest
(
String
data
)
throws
IOException
{
Object
var1
=
null
;
try
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA-1"
);
byte
[]
bytes
=
md
.
digest
(
data
.
getBytes
(
"UTF-8"
));
return
bytes
;
}
catch
(
GeneralSecurityException
var3
)
{
throw
new
IOException
(
var3
);
}
}
private
static
String
byte2hex
(
byte
[]
bytes
)
{
StringBuilder
sign
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
bytes
.
length
;
++
i
)
{
String
hex
=
Integer
.
toHexString
(
bytes
[
i
]
&
255
);
if
(
hex
.
length
()
==
1
)
{
sign
.
append
(
"0"
);
}
sign
.
append
(
hex
.
toUpperCase
());
}
return
sign
.
toString
();
}
}
\ No newline at end of file
\ No newline at end of file
platform-process/src/test/java/cn/com/glsx/test/TestApplication.java
View file @
ce7e024
...
@@ -8,6 +8,7 @@ import cn.com.glsx.process.modules.entity.User;
...
@@ -8,6 +8,7 @@ import cn.com.glsx.process.modules.entity.User;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.service.SopDataSourceService
;
import
cn.com.glsx.process.modules.service.SopDataSourceService
;
import
cn.com.glsx.process.modules.service.UserDemoService
;
import
cn.com.glsx.process.modules.service.UserDemoService
;
import
cn.com.glsx.process.modules.sop.java.Controller1
;
import
cn.com.glsx.process.plugin.dbconn.FlowDataAdapterImpl
;
import
cn.com.glsx.process.plugin.dbconn.FlowDataAdapterImpl
;
import
cn.com.glsx.process.plugin.dbconn.SopBizAdapter
;
import
cn.com.glsx.process.plugin.dbconn.SopBizAdapter
;
import
cn.com.glsx.process.plugin.java.DynamicEngine
;
import
cn.com.glsx.process.plugin.java.DynamicEngine
;
...
@@ -135,4 +136,13 @@ public class TestApplication {
...
@@ -135,4 +136,13 @@ public class TestApplication {
SopStruct
sopStruct
=
new
SopStruct
();
SopStruct
sopStruct
=
new
SopStruct
();
sopInstNodeExecuteJobHandler
.
execute
(
sopInstNode
,
sopStruct
);
sopInstNodeExecuteJobHandler
.
execute
(
sopInstNode
,
sopStruct
);
}
}
@Test
public
void
testJava
(){
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"merchantNo"
,
"44210895"
);
Controller1
.
execute
(
jsonObject
);
}
}
}
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment