Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lyf-beidou-cdp-api
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhoupeng
lyf-beidou-cdp-api
Commits
ce382280
Commit
ce382280
authored
Aug 28, 2023
by
zhoupeng
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
592105aa
4625ea13
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
22 deletions
+132
-22
QiDianController.java
.../java/com/rome/order/api/controller/QiDianController.java
+26
-14
QiDianService.java
...ain/java/com/rome/order/domain/service/QiDianService.java
+21
-3
QiDianServiceImpl.java
...com/rome/order/domain/service/impl/QiDianServiceImpl.java
+52
-4
HttpUtil.java
src/main/java/com/rome/order/domain/util/HttpUtil.java
+17
-0
RemoteConstant.java
.../order/infrastructure/remote/constant/RemoteConstant.java
+16
-1
No files found.
src/main/java/com/rome/order/api/controller/QiDianController.java
View file @
ce382280
...
...
@@ -10,7 +10,6 @@ import com.rome.order.domain.util.ParameterCheckUtils;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -34,35 +33,48 @@ public class QiDianController {
@Autowired
private
QiDianService
qiDianService
;
@GetMapping
(
"/toSSOCallback"
)
@GetMapping
(
"/toSSOCallback"
)
@ApiOperation
(
value
=
"跳转至企点鉴权地址"
)
public
void
toSSOCallback
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
public
void
toSSOCallback
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
String
token
=
request
.
getParameter
(
"token"
);
log
.
info
(
"-------跳转至企点鉴权地址token入参信息-------:{}"
,
token
);
log
.
info
(
"-------跳转至企点鉴权地址token入参信息-------:{}"
,
token
);
// 参数非空校验
ParameterCheckUtils
.
noNull
(
ResponseMsg
.
PARAM_ERROR_TOKEN
,
token
);
ParameterCheckUtils
.
noNull
(
ResponseMsg
.
PARAM_ERROR_TOKEN
,
token
);
response
.
sendRedirect
(
qiDianService
.
getSSOCallback
(
token
));
}
@PostMapping
(
"/getQiDianAccessToken"
)
@PostMapping
(
"/getQiDianAccessToken"
)
@ApiOperation
(
value
=
"提供获取accessToken接口"
)
public
QiDianAccessTokenResponseResDTO
getQiDianAccessToken
(
@RequestBody
QiDianAccessTokenReqDTO
qiDianAccessTokenReqDTO
)
{
log
.
info
(
"---getQiDianAccessToken企点服务器入参信息为----:{}"
,
JSON
.
toJSONString
(
qiDianAccessTokenReqDTO
));
return
qiDianService
.
getQiDianAccessToken
(
qiDianAccessTokenReqDTO
);
public
QiDianAccessTokenResponseResDTO
getQiDianAccessToken
(
@RequestBody
QiDianAccessTokenReqDTO
qiDianAccessTokenReqDTO
)
{
log
.
info
(
"---getQiDianAccessToken企点服务器入参信息为----:{}"
,
JSON
.
toJSONString
(
qiDianAccessTokenReqDTO
));
return
qiDianService
.
getQiDianAccessToken
(
qiDianAccessTokenReqDTO
);
}
@GetMapping
(
"/getAccessToken"
)
@GetMapping
(
"/getAccessToken"
)
@ApiOperation
(
value
=
"获取token"
)
public
String
getAccessToken
(){
public
String
getAccessToken
()
{
return
qiDianService
.
getCacheToken
();
}
@PostMapping
(
"/IDPRegister"
)
@PostMapping
(
"/IDPRegister"
)
@ApiOperation
(
value
=
"IDP身份注册接口"
)
public
String
putIDPRegister
(
@RequestBody
QiDianIDPRegisterReq
qiDianIDPRegisterReq
)
{
public
String
putIDPRegister
(
@RequestBody
QiDianIDPRegisterReq
qiDianIDPRegisterReq
)
{
return
qiDianService
.
putIDPRegister
(
qiDianIDPRegisterReq
);
}
@GetMapping
(
"/login"
)
@ApiOperation
(
value
=
"第三方sso登录"
)
public
String
login
(
@RequestParam
(
"code"
)
String
code
)
{
return
qiDianService
.
login
(
code
);
}
@GetMapping
(
"/logout"
)
@ApiOperation
(
value
=
"第三方sso用户退出登录"
)
public
String
logout
(
@RequestParam
(
"account"
)
String
account
)
{
return
qiDianService
.
logout
(
account
);
}
}
src/main/java/com/rome/order/domain/service/QiDianService.java
View file @
ce382280
...
...
@@ -117,24 +117,42 @@ public interface QiDianService {
* @param disableUrl 停用员工
* @return
*/
EmpMainDataResDTO
disable
(
String
employeeNumber
,
String
disableUrl
,
String
openId
);
EmpMainDataResDTO
disable
(
String
employeeNumber
,
String
disableUrl
,
String
openId
);
/**
* 企点启用员工
*
* @param employeeNumber
* @param disableUrl
* @param openId
* @param department
* @return
*/
EmpMainDataResDTO
open
(
String
employeeNumber
,
String
disableUrl
,
String
openId
,
List
<
Integer
>
department
);
EmpMainDataResDTO
open
(
String
employeeNumber
,
String
disableUrl
,
String
openId
,
List
<
Integer
>
department
);
/**
* IDP身份注册接口
*
* @param qiDianIDPRegisterReq
* @return
*/
String
putIDPRegister
(
QiDianIDPRegisterReq
qiDianIDPRegisterReq
);
String
putIDPRegister
(
QiDianIDPRegisterReq
qiDianIDPRegisterReq
);
/**
* 第三方sso登录
*
* @param code
* @return
*/
String
login
(
String
code
);
/**
* 第三方sso用户退出登录
*
* @param account
* @returns
*/
String
logout
(
String
account
);
}
src/main/java/com/rome/order/domain/service/impl/QiDianServiceImpl.java
View file @
ce382280
...
...
@@ -59,7 +59,7 @@ public class QiDianServiceImpl implements QiDianService {
private
String
redirectUrl
;
@Value
(
"${qidian.password:}"
)
private
String
password
;
private
String
password
;
@Override
public
String
getCacheToken
()
{
...
...
@@ -82,7 +82,7 @@ public class QiDianServiceImpl implements QiDianService {
//使用urlencode转义
String
redirectUrlEncode
=
ServletUtils
.
urlEncode
(
redirectUrl
);
//跳转至企点鉴权地址
String
url
=
QiDianConstant
.
SKIP_CALLBACK_URL
+
RemoteConstant
.
SKIP_SSOCALLBACK_URL
+
"?code="
+
code
+
"&appid="
+
QiDianConstant
.
APP_ID
+
"&redirect_url="
+
redirectUrlEncode
;
String
url
=
QiDianConstant
.
SKIP_CALLBACK_URL
+
RemoteConstant
.
SKIP_SSOCALLBACK_URL
+
"?code="
+
code
+
"&appid="
+
QiDianConstant
.
APP_ID
+
"&redirect_url="
+
redirectUrlEncode
;
log
.
info
(
"---getSSOCallbackUrl获取的地址为-----:{}"
,
url
);
return
url
;
}
...
...
@@ -397,13 +397,13 @@ public class QiDianServiceImpl implements QiDianService {
}
@Override
public
EmpMainDataResDTO
open
(
String
employeeNumber
,
String
openUrl
,
String
openId
,
List
<
Integer
>
department
)
{
public
EmpMainDataResDTO
open
(
String
employeeNumber
,
String
openUrl
,
String
openId
,
List
<
Integer
>
department
)
{
EmpMainDataResDTO
dataResDTO
=
new
EmpMainDataResDTO
();
try
{
dataResDTO
.
setEmployeeNumber
(
employeeNumber
);
Map
<
Object
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"openId"
,
openId
);
paramMap
.
put
(
"department"
,
department
);
paramMap
.
put
(
"department"
,
department
);
paramMap
.
put
(
"passwordMd5"
,
Md5Utils
.
string2MD5
(
password
));
log
.
info
(
"-----openUrl员工入参信息为------openUrlUrl:{},paramMap={}"
,
openUrl
,
JSONObject
.
toJSONString
(
paramMap
));
String
result
=
HttpUtil
.
httpPost
(
openUrl
,
JSONObject
.
toJSONString
(
paramMap
));
...
...
@@ -445,5 +445,53 @@ public class QiDianServiceImpl implements QiDianService {
}
}
@Override
public
String
login
(
String
code
)
{
try
{
String
url
=
String
.
format
(
RemoteConstant
.
SSO_LOGIN_API_URL
,
code
);
Map
<
String
,
String
>
headers
=
getSSOHeaderMap
();
log
.
info
(
"-----第三方sso登录------url:{},headers={}"
,
url
,
JSONObject
.
toJSONString
(
headers
));
String
result
=
HttpUtil
.
httpGet
(
url
,
headers
);
log
.
info
(
"-----第三方sso登录,result------:{}"
,
result
);
Map
map
=
JSONObject
.
parseObject
(
result
,
Map
.
class
);
if
(
RemoteConstant
.
SSO_SUCCESS
.
equals
(
Integer
.
parseInt
(
map
.
get
(
"code"
).
toString
())))
{
//todo 成功
}
return
map
.
get
(
"msg"
).
toString
();
}
catch
(
Exception
e
)
{
String
errorMsg
=
e
.
getMessage
();
log
.
error
(
"-----第三方sso登录报错了-------:{}"
,
errorMsg
);
return
errorMsg
;
}
}
@Override
public
String
logout
(
String
account
)
{
try
{
String
url
=
String
.
format
(
RemoteConstant
.
SSO_LOGOUT_API_URL
,
account
);
Map
<
String
,
String
>
headers
=
getSSOHeaderMap
();
log
.
info
(
"-----第三方sso用户退出登录------url:{},headers={}"
,
url
,
JSONObject
.
toJSONString
(
headers
));
String
result
=
HttpUtil
.
httpGet
(
url
,
headers
);
log
.
info
(
"-----第三方sso用户退出登录,result------:{}"
,
result
);
Map
map
=
JSONObject
.
parseObject
(
result
,
Map
.
class
);
if
(
RemoteConstant
.
SSO_SUCCESS
.
equals
(
Integer
.
parseInt
(
map
.
get
(
"code"
).
toString
())))
{
//todo 成功
}
return
map
.
get
(
"msg"
).
toString
();
}
catch
(
Exception
e
)
{
String
errorMsg
=
e
.
getMessage
();
log
.
error
(
"-----第三方sso登录报错了-------:{}"
,
errorMsg
);
return
errorMsg
;
}
}
private
Map
<
String
,
String
>
getSSOHeaderMap
()
{
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"corporationId"
,
"0"
);
headers
.
put
(
"timestamp"
,
""
);
headers
.
put
(
"sign"
,
""
);
return
headers
;
}
}
src/main/java/com/rome/order/domain/util/HttpUtil.java
View file @
ce382280
...
...
@@ -16,6 +16,8 @@ import org.apache.http.protocol.HTTP;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* http请求
*
...
...
@@ -99,6 +101,21 @@ public class HttpUtil {
}
}
public
static
String
httpGet
(
String
url
,
Map
<
String
,
String
>
headers
)
{
try
{
HttpClient
httpClient
=
HttpClientBuilder
.
create
().
build
();
HttpGet
httpGet
=
new
HttpGet
(
url
);
for
(
String
key
:
headers
.
keySet
())
{
httpGet
.
setHeader
(
key
,
headers
.
get
(
key
));
}
HttpResponse
response
=
httpClient
.
execute
(
httpGet
);
return
EntityUtils
.
toString
(
response
.
getEntity
());
}
catch
(
Exception
e
)
{
log
.
error
(
"http GET请求异常:"
,
e
);
throw
new
TradeException
(
RomeExceptionEnum
.
HTTP_ERROR
);
}
}
public
static
String
httpPut
(
String
token
,
String
url
,
String
jsonStr
)
{
try
{
HttpClient
httpClient
=
HttpClientBuilder
.
create
().
build
();
...
...
src/main/java/com/rome/order/infrastructure/remote/constant/RemoteConstant.java
View file @
ce382280
...
...
@@ -66,6 +66,17 @@ public class RemoteConstant {
*/
public
static
String
IDP_REGISTER_URL
=
"/cgi-bin/v1/sso/SSOService/IDPRegister"
;
/**
* 第三方sso登录 登录完成后回调业务地址
*/
public
static
String
SSO_LOGIN_API_URL
=
"/api/dataauth/authserver/login/third/sso?code=%s&redirect=%s"
;
/**
* 第三方sso登录 第三方sso用户退出登录
*/
public
static
String
SSO_LOGOUT_API_URL
=
"/api/dataauth/authserver/logout/third/sso?account=%s"
;
/**
* UTF-8 字符集
*/
...
...
@@ -78,6 +89,10 @@ public class RemoteConstant {
public
static
final
Integer
SUCCESS
=
0
;
/**
* 成功标识
*/
public
static
final
Integer
SSO_SUCCESS
=
1
;
/**
* 失败标识
*/
public
static
final
Integer
FAIL
=
500
;
...
...
@@ -133,5 +148,5 @@ public class RemoteConstant {
/**
* 为空
*/
public
static
final
String
EMP
=
""
;
public
static
final
String
EMP
=
""
;
}
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