Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
civil-bigdata
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
civil
civil-bigdata
Commits
b6f14f70
Commit
b6f14f70
authored
Nov 29, 2021
by
袁伟铭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善api接口
parent
be96a3e0
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
114 additions
and
33 deletions
+114
-33
api-server/pom.xml
+0
-6
api-server/src/main/java/com/zq/api/config/FeignConfig.java
+4
-0
api-server/src/main/java/com/zq/api/controller/ApiController.java
+4
-5
api-server/src/main/java/com/zq/api/feign/SysFeign.java
+12
-12
api-server/src/main/java/com/zq/api/form/ApiForm.java
+2
-1
api-server/src/main/java/com/zq/api/form/ApiResp.java
+1
-0
api-server/src/main/java/com/zq/api/service/ApiService.java
+1
-1
api-server/src/main/java/com/zq/api/service/IApiLogic.java
+10
-0
api-server/src/main/java/com/zq/api/service/impl/ApiV100Logic.java
+6
-1
api-server/src/main/java/com/zq/api/utils/ApiUtils.java
+68
-0
pom.xml
+1
-1
sys-server/src/main/java/com/zq/system/modules/system/entity/BindUserInfo.java
+1
-1
sys-server/src/main/java/com/zq/system/modules/system/service/SingleService.java
+4
-5
No files found.
api-server/pom.xml
View file @
b6f14f70
...
...
@@ -36,12 +36,6 @@
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-eureka-client
</artifactId>
</dependency>
<!--Spring devtools 热部署-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
<scope>
runtime
</scope>
</dependency>
<!-- 远程调用cloud feign -->
<dependency>
...
...
api-server/src/main/java/com/zq/api/config/FeignConfig.java
View file @
b6f14f70
...
...
@@ -63,11 +63,15 @@ public class FeignConfig {
}
if
(
HEADERS_TO_TRY
.
contains
(
name
.
toUpperCase
()))
{
String
values
=
request
.
getHeader
(
name
);
if
(
name
.
equalsIgnoreCase
(
"AUTHORIZATION"
)
&&
!
values
.
startsWith
(
"Bearer "
))
{
template
.
header
(
"Authorization"
,
"Bearer "
+
values
);
}
else
{
template
.
header
(
name
,
values
);
}
}
}
}
}
};
}
...
...
api-server/src/main/java/com/zq/api/controller/ApiController.java
View file @
b6f14f70
...
...
@@ -42,11 +42,6 @@ public class ApiController {
return
ApiUtils
.
getSuccessResp
(
form
);
}
//解析业务参数
if
(!
form
.
parseBizContent
())
{
return
ApiUtils
.
getParamError
(
form
);
}
String
method
=
form
.
getMethod
();
if
(
StrUtil
.
isBlank
(
method
))
{
method
=
request
.
getParameter
(
"method"
);
...
...
@@ -59,6 +54,10 @@ public class ApiController {
// 身份验证
resp
=
apiService
.
auth
(
form
,
appId
,
appSecret
,
Authorization
);
if
(
resp
.
isSuccess
())
{
//解析业务参数
if
(!
form
.
parseBizContent
())
{
return
ApiUtils
.
getParamError
(
form
);
}
// 调用接口方法
resp
=
apiService
.
action
(
form
);
}
...
...
api-server/src/main/java/com/zq/api/feign/SysFeign.java
View file @
b6f14f70
...
...
@@ -3,10 +3,7 @@ package com.zq.api.feign;
import
com.zq.api.config.FeignConfig
;
import
com.zq.common.vo.ResultVo
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Map
;
...
...
@@ -14,28 +11,31 @@ import java.util.Map;
* @author wilmiam
* @since 2021-08-09 10:48
*/
@FeignClient
(
name
=
"SYS-SERVER"
,
path
=
"/sys
/api
"
,
configuration
=
FeignConfig
.
class
)
@FeignClient
(
name
=
"SYS-SERVER"
,
path
=
"/sys"
,
configuration
=
FeignConfig
.
class
)
public
interface
SysFeign
{
@GetMapping
(
"/user/sendCode"
)
@GetMapping
(
"/
api/
user/sendCode"
)
ResultVo
sendCode
(
@RequestParam
String
phone
);
@PostMapping
(
"/user/resetPassword"
)
@PostMapping
(
"/
api/
user/resetPassword"
)
ResultVo
resetPassword
(
@RequestBody
Map
<
String
,
Object
>
paramsMap
);
@PostMapping
(
"/user/phoneLogin"
)
@PostMapping
(
"/
api/
user/phoneLogin"
)
ResultVo
phoneLogin
(
@RequestBody
Map
<
String
,
Object
>
paramsMap
);
@PostMapping
(
"/user/passwdLogin"
)
@PostMapping
(
"/
api/
user/passwdLogin"
)
ResultVo
passwdLogin
(
@RequestBody
Map
<
String
,
Object
>
paramsMap
);
@PostMapping
(
"/user/modifyPasswd"
)
@PostMapping
(
"/
api/
user/modifyPasswd"
)
ResultVo
modifyPasswd
(
@RequestBody
Map
<
String
,
Object
>
paramsMap
);
@GetMapping
(
"/version/getAppVersion"
)
@GetMapping
(
"/
api/
version/getAppVersion"
)
ResultVo
getAppVersion
(
@RequestParam
String
appName
);
@GetMapping
(
value
=
"/getApiUserByAppId"
)
@GetMapping
(
value
=
"/
api/
getApiUserByAppId"
)
ResultVo
getApiUserByAppId
(
@RequestParam
String
appId
,
@RequestParam
String
appSecret
);
@GetMapping
(
value
=
"/single/getUserInfo/{appId}"
)
ResultVo
getSingleUserInfo
(
@PathVariable
String
appId
);
}
api-server/src/main/java/com/zq/api/form/ApiForm.java
View file @
b6f14f70
...
...
@@ -203,8 +203,9 @@ public class ApiForm {
public
String
getSignStr
(
String
key
)
{
TreeMap
<
String
,
String
>
treeMap
=
new
TreeMap
<>();
treeMap
.
put
(
"appId"
,
this
.
appId
);
treeMap
.
put
(
"apiNo"
,
this
.
apiNo
);
treeMap
.
put
(
"timestamp"
,
this
.
timestamp
);
// treeMap.put("nonce", this.nonce);
treeMap
.
put
(
"method"
,
this
.
method
);
treeMap
.
put
(
"version"
,
this
.
version
);
String
bizContent
=
StrUtil
.
isBlank
(
this
.
bizContent
)
?
""
:
this
.
bizContent
;
...
...
api-server/src/main/java/com/zq/api/form/ApiResp.java
View file @
b6f14f70
...
...
@@ -26,6 +26,7 @@ public class ApiResp {
}
public
ApiResp
(
ApiForm
form
,
ApiCodeEnum
apiCodeEnum
)
{
this
.
apiNo
=
form
.
getApiNo
();
this
.
code
=
apiCodeEnum
.
code
();
this
.
msg
=
apiCodeEnum
.
msg
();
}
...
...
api-server/src/main/java/com/zq/api/service/ApiService.java
View file @
b6f14f70
...
...
@@ -108,7 +108,7 @@ public class ApiService {
form
.
setApiTokenVo
(
apiTokenVo
);
// 认证签名
String
key
=
redisUtils
.
getStr
(
form
.
getToken
()
);
String
key
=
redisUtils
.
getStr
(
token
);
String
serverSign
=
ApiUtils
.
getSign
(
form
.
getSignStr
(
key
==
null
?
""
:
key
));
if
(!
serverSign
.
equals
(
form
.
getSign
()))
{
return
ApiUtils
.
getCheckSignValidError
(
form
);
...
...
api-server/src/main/java/com/zq/api/service/IApiLogic.java
View file @
b6f14f70
...
...
@@ -211,6 +211,16 @@ public interface IApiLogic extends IApiCommon {
*/
ApiResp
getCremationStatsList
(
ApiForm
form
);
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓SYS接口↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
/**
* 获取单点登录用户信息
*
* @param form
* @return
*/
ApiResp
getSingleUserInfo
(
ApiForm
form
);
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓开放接口↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
/**
...
...
api-server/src/main/java/com/zq/api/service/impl/ApiV100Logic.java
View file @
b6f14f70
...
...
@@ -97,7 +97,7 @@ public class ApiV100Logic extends BaseApiLogic implements IApiLogic {
@Override
public
ApiResp
getAreaUnderNumStats
(
ApiForm
form
)
{
return
ApiUtils
.
toApiResp
(
form
,
portalFeign
.
getAreaUnderNumStats
(
form
.
getParamsMap
()));
return
ApiUtils
.
toApiResp
(
form
,
portalFeign
.
getAreaUnderNumStats
(
form
.
getParamsMap
()));
}
@Override
...
...
@@ -151,6 +151,11 @@ public class ApiV100Logic extends BaseApiLogic implements IApiLogic {
}
@Override
public
ApiResp
getSingleUserInfo
(
ApiForm
form
)
{
return
ApiUtils
.
toApiResp
(
form
,
sysFeign
.
getSingleUserInfo
(
form
.
getAppId
()));
}
@Override
public
ApiResp
marriageSearch
(
ApiForm
form
)
{
Map
<
String
,
Object
>
paramsMap
=
form
.
getParamsMap
();
ApiTokenVo
apiTokenVo
=
form
.
getApiTokenVo
();
...
...
api-server/src/main/java/com/zq/api/utils/ApiUtils.java
View file @
b6f14f70
package
com
.
zq
.
api
.
utils
;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.URLUtil
;
import
cn.hutool.crypto.digest.MD5
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
com.zq.api.constant.ApiCodeEnum
;
import
com.zq.api.form.ApiForm
;
import
com.zq.api.form.ApiResp
;
...
...
@@ -13,8 +21,10 @@ import com.zq.common.vo.ResultVo;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Component
;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.TreeMap
;
@Component
public
class
ApiUtils
{
...
...
@@ -224,4 +234,62 @@ public class ApiUtils {
return
MD5
.
create
().
digestHex
(
content
).
toUpperCase
();
}
public
static
void
main
(
String
[]
args
)
{
String
appId
=
"d469c70c4e8b11ecaa2900163e1475c7"
;
String
apiNo
=
IdUtil
.
simpleUUID
();
String
method
=
"getSingleUserInfo"
;
String
timestamp
=
System
.
currentTimeMillis
()
+
""
;
String
version
=
"1.0.0"
;
String
bizContent
=
"{}"
;
bizContent
=
StrUtil
.
isBlank
(
bizContent
)
?
""
:
URLUtil
.
encode
(
Base64
.
encode
(
bizContent
),
StandardCharsets
.
UTF_8
);
Map
<
String
,
String
>
params
=
new
HashMap
<>();
params
.
put
(
"appId"
,
appId
);
params
.
put
(
"apiNo"
,
apiNo
);
params
.
put
(
"method"
,
method
);
params
.
put
(
"timestamp"
,
timestamp
);
params
.
put
(
"bizContent"
,
bizContent
);
params
.
put
(
"version"
,
version
);
// 签名参数排序
TreeMap
<
String
,
String
>
signTreeMap
=
new
TreeMap
<>();
signTreeMap
.
put
(
"appId"
,
appId
);
signTreeMap
.
put
(
"apiNo"
,
apiNo
);
signTreeMap
.
put
(
"timestamp"
,
timestamp
);
signTreeMap
.
put
(
"method"
,
method
);
signTreeMap
.
put
(
"version"
,
version
);
signTreeMap
.
put
(
"bizContent"
,
bizContent
);
// 拼接签名参数
StringBuilder
src
=
new
StringBuilder
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
signTreeMap
.
entrySet
())
{
src
.
append
(
entry
.
getKey
()).
append
(
"="
).
append
(
entry
.
getValue
()).
append
(
"&"
);
}
src
.
append
(
"key="
).
append
(
"ce8fcdd1ae6e42efaabe8819e3fbd8da"
);
params
.
put
(
"sign"
,
MD5
.
create
().
digestHex
(
src
.
toString
()).
toUpperCase
());
HttpRequest
request
=
HttpRequest
.
post
(
"http://127.0.0.1:9888/api/action"
)
.
header
(
"appId"
,
appId
)
.
header
(
"appSecret"
,
"e209eb5e4e8b11ecaa2900163e1475c7"
)
.
header
(
"Authorization"
,
"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJhZG1pbiIsImp0aSI6IjY4OTJlY2E2OTAwNzRjZDRhOGI0NjJlNDM5NDNhZmI1In0.AB77eTqqiBsSunVChqfAx9jB8FN58I7fph1Dw-RfYEVWvN-U2AQYYvuMlCczsiBbduL0vCNALjBzo_1jjKlAPg"
)
.
contentType
(
"application/x-www-form-urlencoded"
)
.
formStr
(
params
);
HttpResponse
execute
=
request
.
execute
();
String
body
=
execute
.
body
();
System
.
out
.
println
(
"响应 => "
+
body
);
// 失败 => {"apiNo":"09c1ad82ec0f4b2d80cae0cfb1d7059b","code":"103","msg":"调用方法异常","timestamp":1638176339560,"data":null,"success":false}
// 成功 => {"apiNo":"bc070a7c31ac4b8eb1180b2d82a2096b","code":"200","msg":"成功","timestamp":1638176552353,"data":{"userId":"123","username":"admin@gxfy.com"},"success":true}
int
status
=
execute
.
getStatus
();
if
(
status
==
200
)
{
JSONObject
obj
=
JSONUtil
.
parseObj
(
body
);
Integer
code
=
obj
.
getInt
(
"code"
);
if
(
code
==
200
)
{
JSONObject
data
=
obj
.
getJSONObject
(
"data"
);
System
.
out
.
println
(
"成功拿到数据 => "
+
data
);
}
}
}
}
pom.xml
View file @
b6f14f70
...
...
@@ -27,7 +27,7 @@
<pagehelper.version>
5.2.0
</pagehelper.version>
<jjwt.version>
0.9.1
</jjwt.version>
<fastjson.version>
1.2.76
</fastjson.version>
<hutool.version>
5.7.
7
</hutool.version>
<hutool.version>
5.7.
16
</hutool.version>
</properties>
<modules>
...
...
sys-server/src/main/java/com/zq/system/modules/system/entity/BindUserInfo.java
View file @
b6f14f70
...
...
@@ -21,7 +21,7 @@ import java.util.Date;
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName
(
value
=
"t_b
l
ind_user_info"
)
@TableName
(
value
=
"t_bind_user_info"
)
public
class
BindUserInfo
{
/**
...
...
sys-server/src/main/java/com/zq/system/modules/system/service/SingleService.java
View file @
b6f14f70
...
...
@@ -142,10 +142,10 @@ public class SingleService {
String
serviceUrl
=
request
.
getParameter
(
"service"
);
AssertUtils
.
hasText
(
serviceUrl
,
"跳转地址为空"
);
//
String passwd = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, vo.getPasswd());
String
passwd
=
RsaUtils
.
decryptByPrivateKey
(
RsaProperties
.
privateKey
,
vo
.
getPasswd
());
UsernamePasswordAuthenticationToken
authenticationToken
=
new
UsernamePasswordAuthenticationToken
(
vo
.
getUsername
(),
vo
.
getPasswd
()
);
new
UsernamePasswordAuthenticationToken
(
vo
.
getUsername
(),
passwd
);
Authentication
authentication
=
authenticationManagerBuilder
.
getObject
().
authenticate
(
authenticationToken
);
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
// 生成令牌
...
...
@@ -157,8 +157,7 @@ public class SingleService {
String
key
=
IdUtil
.
simpleUUID
();
redisUtils
.
setStr
(
token
,
key
,
properties
.
getTokenValidityInSeconds
()
/
1000
,
TimeUnit
.
SECONDS
);
response
.
setHeader
(
properties
.
getHeader
(),
properties
.
getTokenStartWith
()
+
token
);
response
.
sendRedirect
(
serviceUrl
+
"?"
+
properties
.
getHeader
()
+
"="
+
properties
.
getTokenStartWith
()
+
token
+
"&key="
+
key
);
response
.
sendRedirect
(
serviceUrl
+
"?"
+
properties
.
getHeader
()
+
"="
+
token
+
"&key="
+
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
"【{}】单点登录错误 => {}"
,
vo
.
getUsername
(),
e
.
getMessage
());
ServletUtil
.
write
(
response
,
e
.
getMessage
(),
"application/json;charset=utf-8"
);
...
...
@@ -172,7 +171,7 @@ public class SingleService {
SysInfo
sysInfo
=
sysInfoDao
.
selectOne
(
Wrappers
.
lambdaQuery
(
SysInfo
.
builder
().
appId
(
appId
).
build
()));
BindUserInfo
bindUserInfo
=
blindUserInfoDao
.
selectOne
(
Wrappers
.
lambdaQuery
(
BindUserInfo
.
builder
().
sysId
(
sysInfo
.
getId
()).
userId
(
adminContext
.
getUserId
()).
build
()));
AssertUtils
.
notNull
(
bindUserInfo
,
501
,
"用户未绑定该系统"
);
AssertUtils
.
notNull
(
bindUserInfo
,
"用户未绑定该系统"
);
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"userId"
,
bindUserInfo
.
getSystemUserId
());
...
...
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