Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sap-service
Project
Project
Details
Activity
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
曲欣亮
sap-service
Commits
a4f160d6
Commit
a4f160d6
authored
Aug 13, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
72c9eece
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
0 deletions
+97
-0
TraceService.java
src/main/java/com/egolm/sso/services/TraceService.java
+97
-0
No files found.
src/main/java/com/egolm/sso/services/TraceService.java
0 → 100644
View file @
a4f160d6
package
com
.
egolm
.
sso
.
services
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSONObject
;
import
com.egolm.sso.util.HttpUtil
;
@Component
public
class
TraceService
{
@Value
(
"${systemId}"
)
private
String
systemId
;
@Value
(
"${dataTracking.appId}"
)
private
String
appId
;
@Value
(
"${dataTracking.appSecret}"
)
private
String
appSecret
;
@Value
(
"${dataTracking.username}"
)
private
String
username
;
@Value
(
"${dataTracking.baseUrl}"
)
private
String
baseUrl
;
@Value
(
"${dataTracking.uri.token}"
)
private
String
tokenUri
;
@Value
(
"${dataTracking.uri.insertOrderTracking}"
)
private
String
insertOrderTrackingUri
;
@Value
(
"${dataTracking.isOpen}"
)
private
boolean
isOpen
;
@Value
(
"${dataTracking.tokenExpireMinute}"
)
private
Long
tokenExpireMinute
;
private
static
String
token
;
private
static
Date
tokenCreateTime
;
public
String
getToken
()
{
Date
now
=
new
Date
();
if
(
token
!=
null
&&
tokenCreateTime
!=
null
&&
(
tokenCreateTime
.
getTime
()
+
((
tokenExpireMinute
-
2
)
*
60L
*
1000L
))
>
now
.
getTime
())
{
return
token
;
}
String
requestUrl
=
baseUrl
+
tokenUri
;
Map
<
String
,
Object
>
parameters
=
new
HashMap
<
String
,
Object
>();
parameters
.
put
(
"appId"
,
appId
);
parameters
.
put
(
"appSecret"
,
appSecret
);
parameters
.
put
(
"username"
,
username
);
String
resultText
=
HttpUtil
.
post
(
requestUrl
,
parameters
,
null
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
resultText
);
Boolean
isSuccess
=
jsonObject
.
getBoolean
(
"success"
);
if
(
isSuccess
!=
null
&&
isSuccess
)
{
tokenCreateTime
=
now
;
token
=
jsonObject
.
getString
(
"token"
);
return
token
;
}
else
{
throw
new
TrackingTokenException
(
jsonObject
.
getString
(
"message"
));
}
}
public
String
saveOrderTracking
(
String
traceNo
,
String
orderType
,
String
orderNo
,
String
disCode
,
String
action
,
String
result
,
String
message
,
String
errorMessage
)
{
if
(
isOpen
)
{
String
requestUrl
=
baseUrl
+
insertOrderTrackingUri
;
String
token
=
this
.
getToken
();
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"Authorization"
,
"Bearer "
+
token
);
Map
<
String
,
Object
>
parameters
=
new
HashMap
<
String
,
Object
>();
parameters
.
put
(
"traceNo"
,
traceNo
);
parameters
.
put
(
"orderType"
,
orderType
);
parameters
.
put
(
"orderNo"
,
orderNo
);
parameters
.
put
(
"disCode"
,
disCode
);
parameters
.
put
(
"action"
,
action
);
parameters
.
put
(
"result"
,
result
);
parameters
.
put
(
"message"
,
message
);
parameters
.
put
(
"errorMessage"
,
errorMessage
);
return
HttpUtil
.
postRaw
(
requestUrl
,
parameters
,
headers
);
}
return
null
;
}
public
static
class
TrackingTokenException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
1L
;
public
TrackingTokenException
(
String
msg
)
{
super
(
msg
);
}
}
}
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