Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
member-api
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
曲欣亮
member-api
Commits
56e6ff0a
Commit
56e6ff0a
authored
Aug 28, 2018
by
曲欣亮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改文档,增加新的翻译接口,修改签名算法
parent
7f199290
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
73 deletions
+54
-73
ImportJson.java
src/main/java/com/egolm/lang/ImportJson.java
+0
-58
LanguageController.java
src/main/java/com/egolm/lang/LanguageController.java
+49
-3
SwaggerConfig.java
src/main/java/com/egolm/lang/config/SwaggerConfig.java
+1
-1
OpenInterceptor.java
...va/com/egolm/lang/config/interceptor/OpenInterceptor.java
+1
-8
SigUtil.java
src/main/java/com/egolm/lang/config/interceptor/SigUtil.java
+3
-3
No files found.
src/main/java/com/egolm/lang/ImportJson.java
deleted
100644 → 0
View file @
7f199290
package
com
.
egolm
.
lang
;
import
java.io.File
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.egolm.common.FileUtil
;
import
com.egolm.common.GsonUtil
;
import
com.egolm.common.HttpUtil
;
import
com.egolm.lang.config.interceptor.SigUtil
;
public
class
ImportJson
{
public
static
void
main
(
String
[]
args
)
throws
UnsupportedEncodingException
{
String
json
=
new
String
(
FileUtil
.
fileToBytes
(
new
File
(
"/home/quxl/Desktop/APOS.Language.900.json"
)),
"GBK"
);
Map
<
String
,
Object
>
map
=
GsonUtil
.
toMap
(
json
);
for
(
String
key
:
map
.
keySet
())
{
Map
<?,
?>
cmap
=
(
Map
<?,
?>)
map
.
get
(
key
);
String
Caption
=
(
String
)
cmap
.
get
(
"Caption"
);
cmap
.
remove
(
"Caption"
);
Map
<
String
,
Object
>
tmp
=
new
HashMap
<
String
,
Object
>();
tmp
.
put
(
"sCaption"
,
Caption
);
List
<
Object
>
ary
=
new
ArrayList
<
Object
>();
for
(
Object
ckey
:
cmap
.
keySet
())
{
String
sText
=
(
String
)
ckey
;
String
sTarget
=
null
;
if
(
cmap
.
get
(
ckey
)
instanceof
String
)
{
sTarget
=
(
String
)
cmap
.
get
(
ckey
);
}
else
{
sTarget
=
(
String
)((
Map
<?,
?>)
cmap
.
get
(
ckey
)).
get
(
""
);
}
Map
<
String
,
String
>
doc
=
new
HashMap
<
String
,
String
>();
doc
.
put
(
"sText"
,
sText
);
doc
.
put
(
"sTarget"
,
sTarget
);
ary
.
add
(
doc
);
}
tmp
.
put
(
"sDocuments"
,
ary
);
String
sContentText
=
GsonUtil
.
toJson
(
tmp
);
String
sLink
=
"APOS"
;
String
appid
=
"44EB5B79174D45F48BF32C09E6F0C4AA"
;
String
secret
=
"4117B10F6D48494595EE5D567333BB32"
;
Map
<
String
,
Object
>
parameters
=
new
HashMap
<
String
,
Object
>();
parameters
.
put
(
"sLink"
,
sLink
+
"/"
+
key
);
parameters
.
put
(
"appid"
,
appid
);
parameters
.
put
(
"sContentText"
,
sContentText
);
String
sig
=
SigUtil
.
sig
(
parameters
,
secret
);
parameters
.
put
(
"sig"
,
sig
);
String
result
=
HttpUtil
.
post
(
"http://localhost:8090/lang/api/update"
,
parameters
);
System
.
out
.
println
(
result
);
}
}
}
src/main/java/com/egolm/lang/LanguageController.java
View file @
56e6ff0a
...
@@ -271,7 +271,7 @@ public class LanguageController {
...
@@ -271,7 +271,7 @@ public class LanguageController {
}
}
@ResponseBody
@ResponseBody
@PostMapping
(
"translate"
)
@PostMapping
(
"translate
ByArray
"
)
@ApiOperation
(
"翻译文档"
)
@ApiOperation
(
"翻译文档"
)
@ApiImplicitParams
({
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"header"
,
name
=
"appid"
,
dataType
=
"string"
,
required
=
false
,
value
=
"appid"
),
@ApiImplicitParam
(
paramType
=
"header"
,
name
=
"appid"
,
dataType
=
"string"
,
required
=
false
,
value
=
"appid"
),
...
@@ -279,7 +279,7 @@ public class LanguageController {
...
@@ -279,7 +279,7 @@ public class LanguageController {
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sLink"
,
dataType
=
"string"
,
required
=
true
,
value
=
"sLink"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sLink"
,
dataType
=
"string"
,
required
=
true
,
value
=
"sLink"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sDocuments"
,
dataType
=
"string"
,
value
=
"翻译文档数组"
,
allowMultiple
=
true
)
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sDocuments"
,
dataType
=
"string"
,
value
=
"翻译文档数组"
,
allowMultiple
=
true
)
})
})
public
Object
translate
(
String
sLink
,
String
[]
sDocuments
,
String
sCaption
)
{
public
Object
translate
ByArray
(
String
sLink
,
String
[]
sDocuments
,
String
sCaption
)
{
List
<
Map
<
String
,
String
>>
tmp
=
new
ArrayList
<
Map
<
String
,
String
>>();
List
<
Map
<
String
,
String
>>
tmp
=
new
ArrayList
<
Map
<
String
,
String
>>();
if
(
sDocuments
!=
null
)
{
if
(
sDocuments
!=
null
)
{
for
(
String
doc
:
sDocuments
)
{
for
(
String
doc
:
sDocuments
)
{
...
@@ -340,7 +340,53 @@ public class LanguageController {
...
@@ -340,7 +340,53 @@ public class LanguageController {
@ApiImplicitParam
(
paramType
=
"header"
,
name
=
"sig"
,
dataType
=
"string"
,
required
=
false
,
value
=
"sig"
)
@ApiImplicitParam
(
paramType
=
"header"
,
name
=
"sig"
,
dataType
=
"string"
,
required
=
false
,
value
=
"sig"
)
})
})
public
Object
translateByJson
(
@RequestBody
ContentArgs
content
)
{
public
Object
translateByJson
(
@RequestBody
ContentArgs
content
)
{
return
this
.
translate
(
content
.
getsLink
(),
content
.
getsDocuments
(),
content
.
getsCaption
());
return
this
.
translateByArray
(
content
.
getsLink
(),
content
.
getsDocuments
(),
content
.
getsCaption
());
}
@ResponseBody
@PostMapping
(
"translate"
)
@ApiOperation
(
"翻译文档"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"header"
,
name
=
"appid"
,
dataType
=
"string"
,
required
=
false
,
value
=
"appid"
),
@ApiImplicitParam
(
paramType
=
"header"
,
name
=
"sig"
,
dataType
=
"string"
,
required
=
false
,
value
=
"sig"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sLink"
,
dataType
=
"string"
,
required
=
false
,
value
=
"sLink"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sDocument"
,
dataType
=
"string"
,
required
=
false
,
value
=
"sDocument"
)
})
public
Object
translate
(
String
sLink
,
String
sDocument
)
{
String
sNodeID
=
service
.
getNodeIDByLink
(
sLink
,
true
);
Map
<
String
,
Object
>
nodeMap
=
service
.
getNodeMapByID
(
sNodeID
);
String
sContentText
=
(
String
)
nodeMap
.
get
(
"sContentText"
);
Map
<
String
,
Object
>
textMap
=
GsonUtil
.
toMap
(
sContentText
);
String
sCaption
=
(
String
)
textMap
.
get
(
"sCaption"
);
List
<?>
objList
=
(
List
<?>)
textMap
.
get
(
"sDocuments"
);
List
<
Object
>
list
=
objList
==
null
?
new
ArrayList
<
Object
>()
:
new
ArrayList
<
Object
>(
objList
);
String
dst
=
null
;
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
for
(
Object
obj
:
list
)
{
Map
<?,
?>
objMap
=
(
Map
<?,
?>)
obj
;
String
sText
=
(
String
)
objMap
.
get
(
"sText"
);
String
sTarget
=
(
String
)
objMap
.
get
(
"sTarget"
);
if
(
sDocument
.
equals
(
sText
)
&&
StringUtil
.
isNotBlank
(
sTarget
))
{
dst
=
sTarget
;
}
}
}
boolean
isUpdate
=
false
;
if
(
dst
==
null
)
{
dst
=
translate
.
st
(
sDocument
,
"auto"
,
"en"
);
isUpdate
=
true
;
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"sText"
,
sDocument
);
map
.
put
(
"sTarget"
,
dst
);
list
.
add
(
map
);
}
if
(
isUpdate
)
{
Map
<
String
,
Object
>
tmp
=
new
HashMap
<
String
,
Object
>();
tmp
.
put
(
"sCaption"
,
sCaption
);
tmp
.
put
(
"sDocuments"
,
list
);
service
.
update
(
sNodeID
,
JSON
.
toJSONString
(
tmp
,
true
));
}
return
Rjx
.
jsonOk
().
setData
(
dst
);
}
}
public
LanguageService
getService
()
{
public
LanguageService
getService
()
{
...
...
src/main/java/com/egolm/lang/config/SwaggerConfig.java
View file @
56e6ff0a
...
@@ -27,7 +27,7 @@ public class SwaggerConfig {
...
@@ -27,7 +27,7 @@ public class SwaggerConfig {
private
ApiInfo
apiInfo
()
{
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
return
new
ApiInfoBuilder
()
.
title
(
"翻译树在线文档"
)
.
title
(
"翻译树在线文档"
)
.
description
(
"翻译树在线文档,提供文档翻译缓存,在线实时翻译等服务"
)
.
description
(
"翻译树在线文档,提供文档翻译缓存,在线实时翻译等服务
,签名规则:将全部参数按参数名的字典顺序排序,然后拼接成查询字符串,然后在字符串后面拼接SECRET的值,最后求MD5值,例如:sig=MD5(\"appid={appid}&sDocument=xxx&sLink=xxx{secret}\"), {}中的值使用实际值进行替换或填充,APPID=44EB5B79174D45F48BF32C09E6F0C4AA,SECRET=4117B10F6D48494595EE5D567333BB32
"
)
.
termsOfServiceUrl
(
"NO terms of service"
)
.
termsOfServiceUrl
(
"NO terms of service"
)
.
version
(
"1.0"
)
.
version
(
"1.0"
)
.
build
();
.
build
();
...
...
src/main/java/com/egolm/lang/config/interceptor/OpenInterceptor.java
View file @
56e6ff0a
package
com
.
egolm
.
lang
.
config
.
interceptor
;
package
com
.
egolm
.
lang
.
config
.
interceptor
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
...
@@ -11,7 +8,6 @@ import org.springframework.beans.factory.annotation.Value;
...
@@ -11,7 +8,6 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
com.egolm.common.HttpUtil
;
import
com.egolm.common.StringUtil
;
import
com.egolm.common.StringUtil
;
import
com.egolm.lang.bean.LoginToken
;
import
com.egolm.lang.bean.LoginToken
;
import
com.egolm.lang.config.Constant
;
import
com.egolm.lang.config.Constant
;
...
@@ -44,10 +40,7 @@ public class OpenInterceptor extends HandlerInterceptorAdapter {
...
@@ -44,10 +40,7 @@ public class OpenInterceptor extends HandlerInterceptorAdapter {
}
else
if
(
StringUtil
.
isBlank
(
sig
))
{
}
else
if
(
StringUtil
.
isBlank
(
sig
))
{
throw
new
XException
(
"参数[sig]不能为空"
);
throw
new
XException
(
"参数[sig]不能为空"
);
}
}
Map
<
String
,
String
[]>
parameters
=
new
TreeMap
<
String
,
String
[]>(
req
.
getParameterMap
());
String
vsig
=
SigUtil
.
sig
(
req
.
getParameterMap
(),
secret
);
parameters
.
remove
(
"sig"
);
String
queryString
=
HttpUtil
.
formatToQueryString
(
parameters
);
String
vsig
=
StringUtil
.
toSHA1String
(
queryString
+
secret
);
if
(
vsig
.
toUpperCase
().
equals
(
sig
.
toUpperCase
()))
{
if
(
vsig
.
toUpperCase
().
equals
(
sig
.
toUpperCase
()))
{
return
super
.
preHandle
(
req
,
resp
,
handler
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
else
{
}
else
{
...
...
src/main/java/com/egolm/lang/config/interceptor/SigUtil.java
View file @
56e6ff0a
...
@@ -8,11 +8,11 @@ import com.egolm.common.StringUtil;
...
@@ -8,11 +8,11 @@ import com.egolm.common.StringUtil;
public
class
SigUtil
{
public
class
SigUtil
{
public
static
String
sig
(
Map
<
String
,
Object
>
parameters
,
String
secret
)
{
public
static
String
sig
(
Map
<
?,
?
>
parameters
,
String
secret
)
{
Map
<
String
,
Object
>
parameterMap
=
new
TreeMap
<
String
,
Object
>(
parameters
);
Map
<
Object
,
Object
>
parameterMap
=
new
TreeMap
<
Object
,
Object
>(
parameters
);
parameterMap
.
remove
(
"sig"
);
parameterMap
.
remove
(
"sig"
);
String
queryString
=
HttpUtil
.
formatToQueryString
(
parameterMap
);
String
queryString
=
HttpUtil
.
formatToQueryString
(
parameterMap
);
String
vsig
=
StringUtil
.
to
SHA1String
(
queryString
+
secret
);
String
vsig
=
StringUtil
.
to
MD5HexString
(
queryString
);
return
vsig
;
return
vsig
;
}
}
...
...
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