Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
聂康
local-rnr-fp
Commits
015d4257
Commit
015d4257
authored
Jun 17, 2025
by
kang.nie@inzymeits.com
Browse files
初始化代码
parent
bd38ff8b
Pipeline
#3108
failed with stages
in 0 seconds
Changes
404
Pipelines
1
Show whitespace changes
Inline
Side-by-side
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/RnrOrderServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cusc.nirvana.common.result.PageResult
;
import
com.cusc.nirvana.user.eiam.client.OrganizationClient
;
import
com.cusc.nirvana.user.eiam.client.UserClient
;
import
com.cusc.nirvana.user.eiam.dto.OrganizationDTO
;
import
com.cusc.nirvana.user.eiam.dto.UserDTO
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.fp.common.util.DateUtil
;
import
com.cusc.nirvana.user.rnr.fp.dto.RnrOrderDetailDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.RnrOrderListQueryDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.RnrOrderListResponseDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardDTO
;
import
com.cusc.nirvana.user.rnr.fp.service.IRnrOrderService
;
import
com.cusc.nirvana.user.rnr.mg.client.*
;
import
com.cusc.nirvana.user.rnr.mg.constants.*
;
import
com.cusc.nirvana.user.rnr.mg.dto.*
;
import
com.cusc.nirvana.user.util.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* @author stayAnd
* @date 2022/7/28
*/
@Service
@Slf4j
public
class
RnrOrderServiceImpl
implements
IRnrOrderService
{
@Resource
private
RnrOrderClient
orderClient
;
@Resource
private
MgRnrInfoClient
rnrInfoClient
;
@Resource
private
MgRnrCardInfoClient
cardInfoClient
;
@Resource
private
MgRnrLiaisonInfoClient
liaisonInfoClient
;
@Resource
private
MgRnrFileClient
fileClient
;
@Resource
private
MgRnrCompanyInfoClient
companyInfoClient
;
@Resource
private
MgRnrAuthenticationResultClient
authenticationResultClient
;
@Resource
private
UserClient
userClient
;
@Value
(
"${user.eiam.applicationId:4}"
)
private
String
applicationId
;
@Resource
private
OrganizationClient
organizationClient
;
/**
* 自然人关联文件类型集合
*/
private
static
Set
<
Integer
>
NPFileTypeSet
=
new
HashSet
<>();
/**
* 企业关联文件类型
*/
private
static
Set
<
Integer
>
EntFileTypeSet
=
new
HashSet
<>();
static
{
NPFileTypeSet
.
add
(
RnrFileType
.
IDENTITY_CARD_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
IDENTITY_CARD_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
POLICE_CARD_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
POLICE_CARD_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
HK_MACAO_PASSPORT_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
HK_MACAO_PASSPORT_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
TAIWAN_CARD_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
TAIWAN_CARD_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
FOREIGN_NATIONAL_PASSPORT_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
FOREIGN_NATIONAL_PASSPORT_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
HK_MACAO_RESIDENCE_PERMIT_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
HK_MACAO_RESIDENCE_PERMIT_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
TAIWAN_RESIDENCE_PERMIT_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
TAIWAN_RESIDENCE_PERMIT_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
RESIDENCE_BOOKLET_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
RESIDENCE_BOOKLET_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
OFFICIAL_CARD_FRONT
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
OFFICIAL_CARD_BACK
.
getCode
());
NPFileTypeSet
.
add
(
RnrFileType
.
OTHER
.
getCode
());
EntFileTypeSet
.
add
(
RnrFileType
.
ENTERPRISE_PIC
.
getCode
());
}
@Override
public
PageResult
<
RnrOrderListResponseDTO
>
pageListQuery
(
RnrOrderListQueryDTO
dto
)
{
PageResult
<
RnrOrderListResponseDTO
>
result
=
new
PageResult
<>();
PageResult
<
RnrOrderDTO
>
pageInfo
=
queryOrderPageOnCondition
(
dto
,
null
,
null
);
if
(
pageInfo
.
getTotalCount
()
==
0
)
{
return
new
PageResult
<>(
Collections
.
emptyList
(),
0
,
dto
.
getCurrPage
(),
dto
.
getPageSize
());
}
List
<
RnrOrderDTO
>
orderList
=
pageInfo
.
getList
();
result
.
setTotalCount
(
pageInfo
.
getTotalCount
());
List
<
RnrOrderListResponseDTO
>
listResponseDTOList
=
buildListResponseDTO
(
orderList
);
result
.
setList
(
listResponseDTOList
);
return
result
;
}
private
PageResult
<
RnrOrderDTO
>
queryOrderPageOnCondition
(
RnrOrderListQueryDTO
dto
,
List
<
Integer
>
orderStatusList
,
List
<
Integer
>
orderTypeList
){
List
<
String
>
orderIdList
=
null
;
if
(
StringUtils
.
isNotBlank
(
dto
.
getVin
())
||
StringUtils
.
isNotBlank
(
dto
.
getIccid
()))
{
MgRnrCardInfoDTO
cardQuery
=
new
MgRnrCardInfoDTO
();
cardQuery
.
setIotId
(
dto
.
getVin
());
cardQuery
.
setIccid
(
dto
.
getIccid
());
List
<
MgRnrCardInfoDTO
>
cardList
=
cardInfoClient
.
queryByList
(
cardQuery
).
getData
();
if
(
CollectionUtils
.
isEmpty
(
cardList
))
{
return
new
PageResult
<>(
Collections
.
emptyList
(),
0
,
dto
.
getCurrPage
(),
dto
.
getPageSize
());
}
orderIdList
=
cardList
.
stream
().
map
(
MgRnrCardInfoDTO:
:
getOrderId
).
distinct
().
collect
(
Collectors
.
toList
());
}
List
<
String
>
rnrIdList
=
new
ArrayList
<>();
if
(
StringUtils
.
isNotBlank
(
dto
.
getCompanyName
()))
{
MgRnrCompanyInfoDTO
companyQuery
=
new
MgRnrCompanyInfoDTO
();
companyQuery
.
setCompanyName
(
dto
.
getCompanyName
());
List
<
MgRnrCompanyInfoDTO
>
companyList
=
companyInfoClient
.
queryByList
(
companyQuery
).
getData
();
if
(
CollectionUtils
.
isEmpty
(
companyList
))
{
return
new
PageResult
<>(
Collections
.
emptyList
(),
0
,
dto
.
getCurrPage
(),
dto
.
getPageSize
());
}
List
<
String
>
companyRnrIdList
=
companyList
.
stream
().
map
(
MgRnrCompanyInfoDTO:
:
getRnrId
).
distinct
().
collect
(
Collectors
.
toList
());
rnrIdList
.
addAll
(
companyRnrIdList
);
}
if
(
StringUtils
.
isNotBlank
(
dto
.
getFullName
())
||
StringUtils
.
isNotBlank
(
dto
.
getPhone
())
||
StringUtils
.
isNotBlank
(
dto
.
getCertNumber
())){
MgRnrInfoDTO
infoQuery
=
new
MgRnrInfoDTO
();
infoQuery
.
setFullName
(
dto
.
getFullName
());
infoQuery
.
setPhone
(
dto
.
getPhone
());
infoQuery
.
setCertNumber
(
dto
.
getCertNumber
());
List
<
MgRnrInfoDTO
>
infoList
=
rnrInfoClient
.
queryByList
(
infoQuery
).
getData
();
if
(
CollectionUtils
.
isEmpty
(
infoList
))
{
return
new
PageResult
<>(
Collections
.
emptyList
(),
0
,
dto
.
getCurrPage
(),
dto
.
getPageSize
());
}
List
<
String
>
infoRnrIdList
=
infoList
.
stream
().
map
(
MgRnrInfoDTO:
:
getUuid
).
distinct
().
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
rnrIdList
))
{
rnrIdList
.
addAll
(
infoRnrIdList
);
}
else
{
rnrIdList
.
retainAll
(
infoRnrIdList
);
}
}
List
<
String
>
orgIdList
=
null
;
if
(
StringUtils
.
isNotBlank
(
dto
.
getOrganizationName
()))
{
OrganizationDTO
orgQury
=
new
OrganizationDTO
();
orgQury
.
setOrganName
(
dto
.
getOrganizationName
());
orgIdList
=
organizationClient
.
queryByList
(
orgQury
).
getData
().
stream
().
map
(
OrganizationDTO:
:
getUuid
).
collect
(
Collectors
.
toList
());
}
RnrOrderDTO
orderQuery
=
new
RnrOrderDTO
();
BeanUtils
.
copyProperties
(
dto
,
orderQuery
);
if
(!
CollectionUtils
.
isEmpty
(
orderIdList
))
{
orderQuery
.
setUuidList
(
orderIdList
);
}
if
(!
CollectionUtils
.
isEmpty
(
rnrIdList
))
{
orderQuery
.
setRnrIdList
(
rnrIdList
);
}
if
(!
CollectionUtils
.
isEmpty
(
orgIdList
))
{
orderQuery
.
setOrgIdList
(
orgIdList
);
}
if
(!
CollectionUtils
.
isEmpty
(
orderStatusList
))
{
orderQuery
.
setOrderStatusList
(
orderStatusList
);
}
if
(!
CollectionUtils
.
isEmpty
(
orderTypeList
)){
orderQuery
.
setOrderTypeList
(
orderTypeList
);
}
return
orderClient
.
queryByPage
(
orderQuery
).
getData
();
}
private
List
<
RnrOrderListResponseDTO
>
buildListResponseDTO
(
List
<
RnrOrderDTO
>
orderList
)
{
if
(
CollectionUtils
.
isEmpty
(
orderList
))
{
return
Collections
.
emptyList
();
}
List
<
String
>
orderIdList
=
orderList
.
stream
().
map
(
RnrOrderDTO:
:
getUuid
).
collect
(
Collectors
.
toList
());
List
<
String
>
rnrIdList
=
orderList
.
stream
().
map
(
RnrOrderDTO:
:
getRnrId
).
distinct
().
collect
(
Collectors
.
toList
());
//查询cardInfo
MgRnrCardInfoDTO
cardQuery
=
new
MgRnrCardInfoDTO
();
cardQuery
.
setOrderIdList
(
orderIdList
);
List
<
MgRnrCardInfoDTO
>
cardList
=
cardInfoClient
.
queryByList
(
cardQuery
).
getData
();
Map
<
String
,
MgRnrCardInfoDTO
>
cardMap
=
cardList
.
stream
().
collect
(
Collectors
.
toMap
(
MgRnrCardInfoDTO:
:
getOrderId
,
Function
.
identity
(),
(
o1
,
o2
)
->
o2
));
//查询rnrInfo
MgRnrInfoDTO
infoQuery
=
new
MgRnrInfoDTO
();
infoQuery
.
setUuidList
(
rnrIdList
);
List
<
MgRnrInfoDTO
>
infoList
=
rnrInfoClient
.
queryByList
(
infoQuery
).
getData
();
Map
<
String
,
MgRnrInfoDTO
>
infoMap
=
infoList
.
stream
().
collect
(
Collectors
.
toMap
(
MgRnrInfoDTO:
:
getUuid
,
Function
.
identity
(),
(
o1
,
o2
)
->
o2
));
//查询公司信息
MgRnrCompanyInfoDTO
companyQuery
=
new
MgRnrCompanyInfoDTO
();
companyQuery
.
setRnrIdList
(
rnrIdList
);
List
<
MgRnrCompanyInfoDTO
>
companyList
=
companyInfoClient
.
queryByList
(
companyQuery
).
getData
();
Map
<
String
,
MgRnrCompanyInfoDTO
>
companyMap
=
companyList
.
stream
().
collect
(
Collectors
.
toMap
(
MgRnrCompanyInfoDTO:
:
getRnrId
,
Function
.
identity
(),
(
o1
,
o2
)
->
o2
));
return
orderList
.
parallelStream
().
map
(
order
->{
RnrOrderListResponseDTO
responseDTO
=
new
RnrOrderListResponseDTO
();
BeanUtils
.
copyProperties
(
order
,
responseDTO
);
responseDTO
.
setOrderId
(
order
.
getUuid
());
Optional
.
ofNullable
(
cardMap
.
get
(
order
.
getUuid
())).
ifPresent
(
cardInfoDTO
->{
responseDTO
.
setVin
(
cardInfoDTO
.
getIotId
());
responseDTO
.
setIccid
(
cardInfoDTO
.
getIccid
());
});
Optional
.
ofNullable
(
companyMap
.
get
(
order
.
getRnrId
()))
.
ifPresent
(
companyInfoDTO
->
responseDTO
.
setCompanyName
(
companyInfoDTO
.
getCompanyName
()));
Optional
.
ofNullable
(
infoMap
.
get
(
order
.
getRnrId
())).
ifPresent
(
infoDTO
->
{
responseDTO
.
setFullName
(
infoDTO
.
getFullName
());
responseDTO
.
setCertNumber
(
infoDTO
.
getCertNumber
());
responseDTO
.
setPhone
(
infoDTO
.
getPhone
());
});
if
(
StringUtils
.
isNotBlank
(
order
.
getReviewUserId
()))
{
responseDTO
.
setOperatorName
(
getAuditorFormWorkOrderSystem
(
order
.
getReviewUserId
(),
order
.
getTenantNo
()));
}
return
responseDTO
;
}).
collect
(
Collectors
.
toList
());
}
private
String
getAuditorFormWorkOrderSystem
(
String
reviewUserId
,
String
tenantNo
)
{
UserDTO
userQuery
=
new
UserDTO
();
userQuery
.
setUuid
(
reviewUserId
);
userQuery
.
setTenantNo
(
tenantNo
);
userQuery
.
setApplicationId
(
applicationId
);
UserDTO
data
=
userClient
.
getByUuid
(
userQuery
).
getData
();
return
null
!=
data
?
data
.
getFullName
()
:
""
;
}
@Override
public
PageResult
<
VinCardDTO
>
queryCardPageByOrderId
(
MgRnrCardInfoDTO
dto
)
{
MgRnrCardInfoDTO
cardQuery
=
new
MgRnrCardInfoDTO
();
cardQuery
.
setCurrPage
(
dto
.
getCurrPage
());
cardQuery
.
setPageSize
(
dto
.
getPageSize
());
cardQuery
.
setOrderId
(
dto
.
getOrderId
());
PageResult
<
MgRnrCardInfoDTO
>
pageInfo
=
cardInfoClient
.
queryByPage
(
cardQuery
).
getData
();
PageResult
<
VinCardDTO
>
result
=
new
PageResult
<>();
result
.
setTotalCount
(
pageInfo
.
getTotalCount
());
result
.
setList
(
pageInfo
.
getList
().
stream
().
map
(
cardInfoDto
->{
VinCardDTO
vinCardDTO
=
new
VinCardDTO
();
vinCardDTO
.
setVin
(
cardInfoDto
.
getIotId
());
vinCardDTO
.
setIccid
(
cardInfoDto
.
getIccid
());
return
vinCardDTO
;
}).
collect
(
Collectors
.
toList
()));
return
result
;
}
@Override
public
RnrOrderDetailDTO
queryOrderDetail
(
String
orderId
)
{
RnrOrderDTO
orderQuery
=
new
RnrOrderDTO
();
orderQuery
.
setUuid
(
orderId
);
RnrOrderDTO
order
=
orderClient
.
getByUuid
(
orderQuery
).
getData
();
if
(
null
==
order
)
{
throw
new
CuscUserException
(
""
,
"未查询到订单信息"
);
}
MgRnrInfoDTO
infoQuery
=
new
MgRnrInfoDTO
();
infoQuery
.
setUuid
(
order
.
getRnrId
());
MgRnrInfoDTO
rnrInfo
=
rnrInfoClient
.
getByUuid
(
infoQuery
).
getData
();
if
(
null
==
rnrInfo
)
{
throw
new
CuscUserException
(
""
,
"未查询到实名信息"
);
}
MgRnrLiaisonInfoDTO
liaisonQuery
=
new
MgRnrLiaisonInfoDTO
();
liaisonQuery
.
setRnrId
(
order
.
getRnrId
());
MgRnrLiaisonInfoDTO
liaisonInfo
=
liaisonInfoClient
.
getByRnrid
(
liaisonQuery
).
getData
();
MgRnrCompanyInfoDTO
companyQuery
=
new
MgRnrCompanyInfoDTO
();
companyQuery
.
setRnrId
(
order
.
getRnrId
());
MgRnrCompanyInfoDTO
companyInfo
=
companyInfoClient
.
getByRnrid
(
companyQuery
).
getData
();
MgRnrAuthenticationResultDTO
authQuery
=
new
MgRnrAuthenticationResultDTO
();
authQuery
.
setOrderId
(
orderId
);
List
<
MgRnrAuthenticationResultDTO
>
authenticationList
=
authenticationResultClient
.
queryByList
(
authQuery
).
getData
();
MgRnrFileDTO
fileQuery
=
new
MgRnrFileDTO
();
fileQuery
.
setRnrId
(
rnrInfo
.
getUuid
());
fileQuery
.
setTenantNo
(
order
.
getTenantNo
());
List
<
MgRnrFileDTO
>
fileList
=
fileClient
.
getByRnrid
(
fileQuery
).
getData
();
return
buildRnrOrderDetailDTO
(
order
,
rnrInfo
,
liaisonInfo
,
companyInfo
,
authenticationList
,
fileList
);
}
@Override
public
PageResult
<
LocalVerifyListDTO
>
localverifyList
(
RnrOrderListQueryDTO
dto
)
{
log
.
info
(
"localverifyList start ,dto = {}"
,
JSONObject
.
toJSONString
(
dto
));
PageResult
<
LocalVerifyListDTO
>
result
=
new
PageResult
<>();
List
<
Integer
>
orderStatusList
=
Arrays
.
asList
(
RnrOrderStatusEnum
.
ASSIGNMENT
.
getCode
(),
RnrOrderStatusEnum
.
ASSIGNMENT
.
getCode
());
List
<
Integer
>
orderTypeList
=
Arrays
.
asList
(
RnrOrderType
.
NEW_VEHICLE
.
getCode
(),
RnrOrderType
.
SEC_VEHICLE
.
getCode
(),
RnrOrderType
.
COMPANY_NEW_VEHICLE
.
getCode
(),
RnrOrderType
.
CARMAKER_NEW_VEHICLE
.
getCode
(),
RnrOrderType
.
COMPANY_CORPORATION_CHANGE
.
getCode
(),
RnrOrderType
.
SEC_UNBIND
.
getCode
());
PageResult
<
RnrOrderDTO
>
pageInfo
=
queryOrderPageOnCondition
(
dto
,
orderStatusList
,
orderTypeList
);
if
(
pageInfo
.
getTotalCount
()
==
0
)
{
return
new
PageResult
<>(
Collections
.
emptyList
(),
0
,
dto
.
getCurrPage
(),
dto
.
getPageSize
());
}
List
<
RnrOrderDTO
>
orderList
=
pageInfo
.
getList
();
result
.
setTotalCount
(
pageInfo
.
getTotalCount
());
List
<
LocalVerifyListDTO
>
list
=
buildVerifyListDTO
(
orderList
);
result
.
setList
(
list
);
return
result
;
}
/**
* 构建待审核列表
* @param orderList
* @return
*/
private
List
<
LocalVerifyListDTO
>
buildVerifyListDTO
(
List
<
RnrOrderDTO
>
orderList
)
{
if
(
CollectionUtils
.
isEmpty
(
orderList
))
{
return
Collections
.
emptyList
();
}
List
<
String
>
orderIdList
=
orderList
.
stream
().
map
(
RnrOrderDTO:
:
getUuid
).
collect
(
Collectors
.
toList
());
List
<
String
>
rnrIdList
=
orderList
.
stream
().
map
(
RnrOrderDTO:
:
getRnrId
).
distinct
().
collect
(
Collectors
.
toList
());
List
<
String
>
orgIdList
=
orderList
.
stream
().
map
(
RnrOrderDTO:
:
getOrgId
).
distinct
().
collect
(
Collectors
.
toList
());
//查询cardInfo
MgRnrCardInfoDTO
cardQuery
=
new
MgRnrCardInfoDTO
();
cardQuery
.
setOrderIdList
(
orderIdList
);
List
<
MgRnrCardInfoDTO
>
cardList
=
cardInfoClient
.
queryByList
(
cardQuery
).
getData
();
Map
<
String
,
List
<
MgRnrCardInfoDTO
>>
cardMap
=
cardList
.
stream
().
collect
(
Collectors
.
groupingBy
(
MgRnrCardInfoDTO:
:
getOrderId
));
//查询rnrInfo
MgRnrInfoDTO
infoQuery
=
new
MgRnrInfoDTO
();
infoQuery
.
setUuidList
(
rnrIdList
);
List
<
MgRnrInfoDTO
>
infoList
=
rnrInfoClient
.
queryByList
(
infoQuery
).
getData
();
Map
<
String
,
MgRnrInfoDTO
>
infoMap
=
infoList
.
stream
().
collect
(
Collectors
.
toMap
(
MgRnrInfoDTO:
:
getUuid
,
Function
.
identity
(),
(
o1
,
o2
)
->
o2
));
//查询公司信息
MgRnrCompanyInfoDTO
companyQuery
=
new
MgRnrCompanyInfoDTO
();
companyQuery
.
setRnrIdList
(
rnrIdList
);
List
<
MgRnrCompanyInfoDTO
>
companyList
=
companyInfoClient
.
queryByList
(
companyQuery
).
getData
();
Map
<
String
,
MgRnrCompanyInfoDTO
>
companyMap
=
companyList
.
stream
().
collect
(
Collectors
.
toMap
(
MgRnrCompanyInfoDTO:
:
getRnrId
,
Function
.
identity
(),
(
o1
,
o2
)
->
o2
));
//组织信息
Map
<
String
,
String
>
orgNameMap
;
if
(!
CollectionUtils
.
isEmpty
(
orderIdList
))
{
OrganizationDTO
orgQuery
=
new
OrganizationDTO
();
orgQuery
.
setUuidList
(
orgIdList
);
orgNameMap
=
organizationClient
.
queryByList
(
orgQuery
).
getData
().
stream
().
collect
(
Collectors
.
toMap
(
OrganizationDTO:
:
getUuid
,
OrganizationDTO:
:
getOrganName
,(
o1
,
o2
)->
o2
));
}
else
{
orgNameMap
=
Collections
.
EMPTY_MAP
;
}
return
orderList
.
stream
().
map
(
order
->{
LocalVerifyListDTO
verifyDto
=
new
LocalVerifyListDTO
();
verifyDto
.
setRnrOrderInfoId
(
order
.
getUuid
());
List
<
MgRnrCardInfoDTO
>
cardInfoDTOList
=
cardMap
.
get
(
order
.
getUuid
());
if
(!
CollectionUtils
.
isEmpty
(
cardInfoDTOList
)){
List
<
String
>
iccidList
=
cardInfoDTOList
.
stream
().
map
(
MgRnrCardInfoDTO:
:
getIccid
).
distinct
().
collect
(
Collectors
.
toList
());
List
<
String
>
vinList
=
cardInfoDTOList
.
stream
().
map
(
MgRnrCardInfoDTO:
:
getIotId
).
distinct
().
collect
(
Collectors
.
toList
());
String
iccidStr
=
StringUtils
.
join
(
iccidList
,
","
);
verifyDto
.
setIccid
(
iccidStr
.
length
()
<
100
?
iccidStr
:
iccidStr
.
substring
(
0
,
100
));
String
vinStr
=
StringUtils
.
join
(
vinList
,
","
);
verifyDto
.
setVin
(
vinStr
.
length
()
<
100
?
vinStr
:
vinStr
.
substring
(
0
,
100
));
}
verifyDto
.
setOrderStatus
(
order
.
getOrderStatus
());
verifyDto
.
setOrderType
(
String
.
valueOf
(
order
.
getOrderType
()));
verifyDto
.
setOrderTypeName
(
RnrOrderType
.
getTypeByCode
(
order
.
getOrderType
()).
getComment
());
verifyDto
.
setOrgName
(
orgNameMap
.
get
(
order
.
getOrgId
()));
verifyDto
.
setRnrDate
(
DateUtil
.
formate
(
order
.
getCreateTime
(),
DateUtil
.
FORMAT_YYYYMMDDHHMMSS
));
Optional
.
ofNullable
(
companyMap
.
get
(
order
.
getRnrId
()))
.
ifPresent
(
companyInfoDTO
->
verifyDto
.
setVinCompanyName
(
companyInfoDTO
.
getCompanyName
()));
Optional
.
ofNullable
(
infoMap
.
get
(
order
.
getRnrId
())).
ifPresent
(
infoDTO
->
{
verifyDto
.
setVinOwnerName
(
infoDTO
.
getFullName
());
verifyDto
.
setVinOwnerPhone
(
infoDTO
.
getPhone
());
});
return
verifyDto
;
}).
collect
(
Collectors
.
toList
());
}
private
RnrOrderDetailDTO
buildRnrOrderDetailDTO
(
RnrOrderDTO
order
,
MgRnrInfoDTO
rnrInfo
,
MgRnrLiaisonInfoDTO
liaisonInfo
,
MgRnrCompanyInfoDTO
companyInfo
,
List
<
MgRnrAuthenticationResultDTO
>
authenticationList
,
List
<
MgRnrFileDTO
>
fileList
)
{
RnrOrderDetailDTO
result
=
new
RnrOrderDetailDTO
();
RnrOrderDetailDTO
.
BizDetailDTO
bizDetailDTO
=
new
RnrOrderDetailDTO
.
BizDetailDTO
();
BeanUtils
.
copyProperties
(
order
,
bizDetailDTO
);
result
.
setBizDetail
(
bizDetailDTO
);
RnrOrderDetailDTO
.
PersonDetailDTO
rnrDetail
=
new
RnrOrderDetailDTO
.
PersonDetailDTO
();
BeanUtils
.
copyProperties
(
rnrInfo
,
rnrDetail
);
Optional
.
ofNullable
(
CertTypeEnum
.
getEnumByCode
(
rnrDetail
.
getCertType
())).
ifPresent
(
certTypeEnum
->
rnrDetail
.
setCertTypeName
(
certTypeEnum
.
getName
()));
result
.
setRnrDetail
(
rnrDetail
);
if
(
null
!=
liaisonInfo
)
{
RnrOrderDetailDTO
.
PersonDetailDTO
liaisonDetail
=
new
RnrOrderDetailDTO
.
PersonDetailDTO
();
liaisonDetail
.
setFullName
(
liaisonInfo
.
getLiaisonName
());
liaisonDetail
.
setGender
(
liaisonInfo
.
getLiaisonGender
());
liaisonDetail
.
setCertType
(
liaisonInfo
.
getLiaisonCertType
());
liaisonDetail
.
setCertNumber
(
liaisonInfo
.
getLiaisonCertNumber
());
liaisonDetail
.
setPhone
(
liaisonInfo
.
getLiaisonPhone
());
liaisonDetail
.
setExpiredDate
(
liaisonInfo
.
getLiaisonExpiredDate
());
Optional
.
ofNullable
(
CertTypeEnum
.
getEnumByCode
(
liaisonDetail
.
getCertType
())).
ifPresent
(
certTypeEnum
->
liaisonDetail
.
setCertTypeName
(
certTypeEnum
.
getName
()));
result
.
setLiaisonDetail
(
liaisonDetail
);
}
if
(
null
!=
companyInfo
)
{
RnrOrderDetailDTO
.
CompanyDetailDTO
companyDetail
=
new
RnrOrderDetailDTO
.
CompanyDetailDTO
();
BeanUtils
.
copyProperties
(
companyInfo
,
companyDetail
);
Optional
.
ofNullable
(
IndustryTypeEnum
.
getEnumByCode
(
companyDetail
.
getIndustryType
())).
ifPresent
(
industryTypeEnum
->
companyDetail
.
setIndustryTypeName
(
industryTypeEnum
.
getValue
()));
Optional
.
ofNullable
(
CompanyTypeEnum
.
getEnumByCode
(
companyDetail
.
getCompanyType
())).
ifPresent
(
companyTypeEnum
->
companyDetail
.
setCompanyTypeName
(
companyTypeEnum
.
getValue
()));
Optional
.
ofNullable
(
CertTypeEnum
.
getEnumByCode
(
companyDetail
.
getCompanyCertType
())).
ifPresent
(
certTypeEnum
->
companyDetail
.
setCompanyCertTypeName
(
certTypeEnum
.
getName
()));
result
.
setCompanyDetail
(
companyDetail
);
}
if
(!
CollectionUtils
.
isEmpty
(
authenticationList
))
{
List
<
RnrOrderDetailDTO
.
AuthenticationDetailDTO
>
authDetailList
=
authenticationList
.
stream
().
map
(
auth
->
{
RnrOrderDetailDTO
.
AuthenticationDetailDTO
authDetailDTO
=
new
RnrOrderDetailDTO
.
AuthenticationDetailDTO
();
BeanUtils
.
copyProperties
(
auth
,
authDetailDTO
);
return
authDetailDTO
;
}).
collect
(
Collectors
.
toList
());
result
.
setAuthenticationList
(
authDetailList
);
}
RnrOrderDetailDTO
.
AuditDetailDTO
auditDetailDTO
=
new
RnrOrderDetailDTO
.
AuditDetailDTO
();
BeanUtils
.
copyProperties
(
order
,
auditDetailDTO
);
if
(
StringUtils
.
isNotBlank
(
order
.
getComment
()))
{
auditDetailDTO
.
setContent
(
order
.
getComment
());
}
else
if
(
StringUtils
.
isNotBlank
(
order
.
getVerifyComments
()))
{
auditDetailDTO
.
setContent
(
order
.
getVerifyComments
());
}
if
(
StringUtils
.
isNotBlank
(
order
.
getReviewUserId
()))
{
auditDetailDTO
.
setOperatorName
(
getAuditorFormWorkOrderSystem
(
order
.
getReviewUserId
(),
order
.
getTenantNo
()));
}
result
.
setAuditDetail
(
auditDetailDTO
);
List
<
RnrOrderDetailDTO
.
FileDTO
>
rnrFileList
=
new
ArrayList
<>();
List
<
RnrOrderDetailDTO
.
FileDTO
>
liaisonRnrFileList
=
new
ArrayList
<>();
List
<
RnrOrderDetailDTO
.
FileDTO
>
companyFileList
=
new
ArrayList
<>();
List
<
RnrOrderDetailDTO
.
FileDTO
>
ortherFileList
=
new
ArrayList
<>();
if
(!
CollectionUtils
.
isEmpty
(
fileList
))
{
for
(
MgRnrFileDTO
file
:
fileList
)
{
RnrOrderDetailDTO
.
FileDTO
fileDTO
=
new
RnrOrderDetailDTO
.
FileDTO
();
fileDTO
.
setFileType
(
file
.
getFileType
());
fileDTO
.
setFileId
(
file
.
getFileSystemId
());
if
(
NPFileTypeSet
.
contains
(
file
.
getFileType
()))
{
if
(
"0"
.
equals
(
file
.
getLiaisonId
()))
{
rnrFileList
.
add
(
fileDTO
);
}
else
{
liaisonRnrFileList
.
add
(
fileDTO
);
}
}
else
if
(
EntFileTypeSet
.
contains
(
file
.
getFileType
()))
{
companyFileList
.
add
(
fileDTO
);
}
else
{
ortherFileList
.
add
(
fileDTO
);
}
}
}
rnrDetail
.
setRnrInfoFile
(
rnrFileList
);
if
(
null
!=
result
.
getCompanyDetail
())
{
result
.
getCompanyDetail
().
setCompanyFile
(
companyFileList
);
}
if
(
null
!=
result
.
getLiaisonDetail
())
{
result
.
getLiaisonDetail
().
setRnrInfoFile
(
liaisonRnrFileList
);
}
result
.
setFileList
(
ortherFileList
);
return
result
;
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/RnrServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cache.CacheFactory
;
import
com.cache.exception.CacheException
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.ciam.client.CiamUserClient
;
import
com.cusc.nirvana.user.ciam.dto.CiamUserDTO
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.fp.common.CmccCertTypeEnum
;
import
com.cusc.nirvana.user.rnr.fp.common.MbCodeEnum
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.common.RnrResultEnum
;
import
com.cusc.nirvana.user.rnr.fp.common.cloud.CloudMethod
;
import
com.cusc.nirvana.user.rnr.fp.common.cloud.CloudService
;
import
com.cusc.nirvana.user.rnr.fp.common.config.EncryptionConfig
;
import
com.cusc.nirvana.user.rnr.fp.common.config.RnrFpConfig
;
import
com.cusc.nirvana.user.rnr.fp.constants.AuthWayTypeEnum
;
import
com.cusc.nirvana.user.rnr.fp.constants.LivenessTypeEnum
;
import
com.cusc.nirvana.user.rnr.fp.constants.RedisConstant
;
import
com.cusc.nirvana.user.rnr.fp.constants.ResultCodeEnum
;
import
com.cusc.nirvana.user.rnr.fp.dto.AttachmentDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.AttachmentRespDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.CardNumReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.CardNumberCmccCheckDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.CertCheckReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.CustomerInfoDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.EncryptionKeyDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.FaceCompareReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.FaceCompareRespDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.H5ValidationOCRReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.IdCompareReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.IdCompareRespDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.IovCardNumRespDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.LiveLoginReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.LiveLoginRespDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.LivenessCodeReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.LivenessCodeRequestDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.LivenessCodeResponseDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.LivenessReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.LivenessRespDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.LivenessResultDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.OcrNpReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.OcrNpRespDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.PersonH5CallBackRequestDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.RnrRequestDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.RnrResponseDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.RnrReturnDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.T1CommonResponseDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.UploadResultDto
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardDTO
;
import
com.cusc.nirvana.user.rnr.fp.service.*
;
import
com.cusc.nirvana.user.rnr.fp.util.SnowflakeIdWorker
;
import
com.cusc.nirvana.user.rnr.mg.client.ChangeOrUnbindIccidsClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrAuthenticationResultClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCardInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrFileClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrLiaisonInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrRelationClient
;
import
com.cusc.nirvana.user.rnr.mg.client.OrgSimRelClient
;
import
com.cusc.nirvana.user.rnr.mg.client.RnrOrderClient
;
import
com.cusc.nirvana.user.rnr.mg.constants.*
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrAuthenticationResultDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrFileDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrLiaisonInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrOrderDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrRelationDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
com.cusc.nirvana.user.util.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* @author stayAnd
* @date 2022/4/18
*/
@Service
@Slf4j
public
class
RnrServiceImpl
implements
IRnrService
{
@Resource
private
CloudService
cloudService
;
@Resource
private
CacheFactory
cacheFactory
;
@Resource
private
ExecutorService
rnrExecutorService
;
@Resource
private
MgRnrCardInfoClient
mgRnrCardInfoClient
;
@Resource
private
MgRnrInfoClient
rnrInfoClient
;
@Resource
private
RnrOrderClient
orderClient
;
@Resource
private
IFileService
fileService
;
@Resource
private
MgRnrRelationClient
mgRnrRelationClient
;
@Resource
private
MgRnrFileClient
rnrFileClient
;
@Resource
private
CiamUserClient
ciamUserClient
;
@Resource
private
MgRnrAuthenticationResultClient
authenticationResultClient
;
@Autowired
private
RnrFpConfig
rnrFpConfig
;
@Resource
private
MgRnrCardInfoClient
rnrCardInfoClient
;
@Resource
private
MgRnrLiaisonInfoClient
liaisonInfoClient
;
@Resource
private
ChangeOrUnbindIccidsClient
changeOrUnbindIccidsClient
;
@Value
(
"${T1.power:true}"
)
private
Boolean
power
;
@Value
(
"${T1.cmccUrl:}"
)
private
String
cmccUrl
;
@Value
(
"${T1.ctccUrl:}"
)
private
String
ctccUrl
;
@Autowired
private
OrgSimRelClient
orgSimRelClient
;
@Resource
private
OperatorService
operatorService
;
@Autowired
private
EncryptionConfig
encryptionConfig
;
@Resource
private
IT1UploadService
it1UploadService
;
@Autowired
@Qualifier
(
"noBalanceRestTemplateRnrFpT1"
)
RestTemplate
noBalanceRestTemplateRnrFpT1
;
@Resource
private
INewVinCardService
newVinCardService
;
/**
* 进行云端人脸和人证对比
*
* @param dto
* @param livenessPic
* @return
*/
@Override
public
RnrResponseDTO
doIdAndFaceCompare
(
RnrRequestDTO
dto
,
String
[]
livenessPic
,
Integer
subjectType
)
{
RnrResponseDTO
rnrResponseDTO
=
new
RnrResponseDTO
();
String
[]
bestFrameList
=
null
;
if
(
null
==
livenessPic
)
{
// 未做过活体
// 活体检测检测 如果失败的话 不需要进行下面 ocr 人证比对 人脸比对
bestFrameList
=
doLiveness
(
dto
,
rnrResponseDTO
);
if
(!
Boolean
.
TRUE
.
equals
(
rnrResponseDTO
.
getLivenessResult
()))
{
// 活体失败直接返回
throw
new
CuscUserException
(
""
,
rnrResponseDTO
.
getLivenessFailMsg
());
}
}
else
{
// 已经做过活体信息
bestFrameList
=
livenessPic
;
rnrResponseDTO
.
setLivenessResult
(
true
);
}
String
bestFrame
=
bestFrameList
[
0
];
// 人证比对
Future
<
Response
<
IdCompareRespDTO
>>
idCompareFuture
=
doIdCompare
(
dto
,
bestFrame
,
dto
.
getMatchVideoPerosinInfo
().
getCertNumber
(),
dto
.
getMatchVideoPerosinInfo
().
getFullName
());
// 人脸比对
Future
<
Response
<
FaceCompareRespDTO
>>
faceCompareFuture
=
doFaceCompare
(
bestFrame
,
dto
.
getMatchVideoPerosinInfo
().
getFacePicBase64
(),
dto
);
try
{
Response
<
IdCompareRespDTO
>
response
=
idCompareFuture
.
get
(
5
,
TimeUnit
.
SECONDS
);
if
(!
response
.
isSuccess
())
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
ID_COMPARE
,
"2"
,
"人证比对失败,:"
+
response
.
getMsg
(),
subjectType
);
rnrResponseDTO
.
setIdCompareFailMsg
(
"人证比对失败,:"
+
response
.
getMsg
());
}
else
{
String
similarity
=
response
.
getData
().
getSimilarity
();
if
(
Integer
.
parseInt
(
similarity
)
>
Integer
.
parseInt
(
rnrFpConfig
.
getIdCompareSimilarity
()))
{
rnrResponseDTO
.
setIdCompareResult
(
true
);
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
ID_COMPARE
,
"1"
,
"人证比对成功,相似度:"
+
similarity
,
subjectType
);
}
else
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
ID_COMPARE
,
"2"
,
"人证比对失败,相似度:"
+
similarity
,
subjectType
);
rnrResponseDTO
.
setIdCompareFailMsg
(
"人证比对失败,相似度:"
+
similarity
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"videoPersonInfoProcess idCompare Future has error,fullName = {},certNumber = {}"
,
dto
.
getMatchVideoPerosinInfo
().
getFullName
(),
dto
.
getMatchVideoPerosinInfo
().
getCertNumber
(),
e
);
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
ID_COMPARE
,
"2"
,
"人证比对异常:请求异常"
,
subjectType
);
rnrResponseDTO
.
setIdCompareFailMsg
(
"人证比对异常:请求异常"
);
}
try
{
Response
<
FaceCompareRespDTO
>
response
=
faceCompareFuture
.
get
(
5
,
TimeUnit
.
SECONDS
);
if
(!
response
.
isSuccess
())
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
FACE_COMPARE
,
"2"
,
"人脸比对失败:"
+
response
.
getMsg
(),
subjectType
);
rnrResponseDTO
.
setFaceCompareFailMsg
(
"人脸比对失败:"
+
response
.
getMsg
());
}
else
{
String
similarity
=
response
.
getData
().
getSimilarity
();
if
(
Integer
.
parseInt
(
similarity
)
>
Integer
.
parseInt
(
rnrFpConfig
.
getFaceCompareSimilarity
()))
{
rnrResponseDTO
.
setFaceCompareResult
(
true
);
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
FACE_COMPARE
,
"1"
,
"人脸比对成功,相似度:"
+
similarity
,
subjectType
);
}
else
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
FACE_COMPARE
,
"2"
,
"人脸比对失败,相似度:"
+
similarity
,
subjectType
);
rnrResponseDTO
.
setFaceCompareFailMsg
(
"人脸比对失败,相似度:"
+
similarity
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"doRnr ,videoPersonInfoProcess faceCompare Future has error,fullName = {},certNumber = {}"
,
dto
.
getMatchVideoPerosinInfo
().
getFullName
(),
dto
.
getMatchVideoPerosinInfo
().
getCertNumber
(),
e
);
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
FACE_COMPARE
,
"2"
,
"人脸比对异常:请求异常"
,
subjectType
);
rnrResponseDTO
.
setFaceCompareFailMsg
(
"人脸比对异常:请求异常"
);
}
return
rnrResponseDTO
;
}
/**
* 请求云端获取活体验证码
*
* @param dto 请求参数
* @return
*/
@Override
public
LivenessCodeResponseDTO
getLivenessCode
(
LivenessCodeRequestDTO
dto
)
{
log
.
info
(
"云端获取活体验证码,{}"
,
dto
);
//生成唯一的id
String
requestId
=
UUID
.
randomUUID
().
toString
();
String
livenessCode
=
null
;
LivenessCodeReqDTO
codeDto
=
new
LivenessCodeReqDTO
();
codeDto
.
setSerialNumber
(
dto
.
getSerialNumber
());
codeDto
.
setBizUuid
(
dto
.
getBizUuid
());
if
(
LivenessTypeEnum
.
LIP
.
getCode
().
equalsIgnoreCase
(
rnrFpConfig
.
getLivenessType
()))
{
//唇语验证,数字
Response
<
LivenessCodeResponseDTO
>
livenessCodeResponse
=
cloudService
.
postForResponse
(
CloudMethod
.
LIVENESS_CODE_TIP
,
codeDto
,
LivenessCodeResponseDTO
.
class
);
if
(
null
==
livenessCodeResponse
||
!
livenessCodeResponse
.
isSuccess
()
||
livenessCodeResponse
.
getData
()
==
null
)
{
throw
new
CuscUserException
(
""
,
"获取活体数字验证码失败"
);
}
livenessCode
=
livenessCodeResponse
.
getData
().
getLivenessCode
();
}
else
if
(
LivenessTypeEnum
.
ACTION
.
getCode
().
equalsIgnoreCase
(
rnrFpConfig
.
getLivenessType
()))
{
//动作验证,左右摇头
Response
<
LivenessCodeResponseDTO
>
resp
=
cloudService
.
postForResponse
(
CloudMethod
.
LIVENESS_CODE_ACTION
,
codeDto
,
LivenessCodeResponseDTO
.
class
);
if
(
null
==
resp
||
!
resp
.
isSuccess
()
||
resp
.
getData
()
==
null
)
{
throw
new
CuscUserException
(
""
,
"获取活体动作序列失败"
);
}
livenessCode
=
resp
.
getData
().
getActionSeq
();
}
// redis存储requestId 和 livenessCode 的关系
try
{
cacheFactory
.
ExpireString
()
.
setExpireValue
(
RedisConstant
.
USER_RNR_LIVENESSCODE_PREFIX
+
requestId
,
livenessCode
,
7200
);
}
catch
(
Exception
e
)
{
log
.
error
(
"getLivenessCode has error , dto = {}"
,
JSONObject
.
toJSONString
(
dto
),
e
);
}
LivenessCodeResponseDTO
result
=
new
LivenessCodeResponseDTO
().
setLivenessCode
(
livenessCode
).
setRequestId
(
requestId
);
result
.
setLivenessType
(
rnrFpConfig
.
getLivenessType
());
return
result
;
}
@Override
public
Integer
personRnr
(
String
serialNumber
,
String
requestId
,
RnrRelationDTO
dto
)
{
log
.
info
(
"personRnr serialNumber = {},requestId = {},dto = {}"
,
serialNumber
,
requestId
,
JSONObject
.
toJSONString
(
dto
));
boolean
sendWorkOrder
=
checkPersonData
(
serialNumber
,
requestId
,
dto
);
Response
response
=
mgRnrRelationClient
.
saveRnrRelation
(
dto
);
if
(!
response
.
isSuccess
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
// 如果不需要发送工单,则立即发送云端系统
if
(!
sendWorkOrder
&&
response
.
isSuccess
())
{
this
.
notifyResult
(
dto
.
getCardList
(),
RnrBizzTypeEnum
.
Bind
.
getCode
().
toString
(),
serialNumber
,
null
,
ResultCodeEnum
.
PASS
.
getCode
());
}
return
sendWorkOrder
?
RnrResultEnum
.
REVIEW
.
getCode
()
:
RnrResultEnum
.
PASS
.
getCode
();
}
/**
* 校验个人信息
*
* @param serialNumber
* @param requestId
* @param dto
* @return 是否需要发送工单
*/
@Override
public
boolean
checkPersonData
(
String
serialNumber
,
String
requestId
,
RnrRelationDTO
dto
)
{
// 卡实名状态校验
if
(
dto
.
getIsSecondHandCar
()
==
0
)
{
iccidListCheck
(
dto
);
}
// 一证十卡校验
cardNumberCheck
(
dto
);
RnrRequestDTO
rnrRequest
=
rnrPersonRelationDto2RnrRequestDTO
(
dto
);
rnrRequest
.
setBizUuid
(
dto
.
getInfo
().
getUuid
());
rnrRequest
.
setSerialNumber
(
dto
.
getOrder
().
getUuid
());
rnrRequest
.
setRequestId
(
requestId
);
RnrResponseDTO
rnrResponseDTO
=
doPersonRnr
(
rnrRequest
,
null
);
// 添加活体图片1
MgRnrFileDTO
livenessPic1
=
new
MgRnrFileDTO
();
livenessPic1
.
setUuid
(
CuscStringUtils
.
generateUuid
());
livenessPic1
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
livenessPic1
.
setRnrId
(
dto
.
getInfo
().
getUuid
());
livenessPic1
.
setLiaisonId
(
rnrRequest
.
getMatchVideoPerosinInfo
().
getPersonId
());
livenessPic1
.
setFileSystemId
(
rnrResponseDTO
.
getLivenessPic1
());
livenessPic1
.
setFileType
(
RnrFileType
.
LIVENESS_SCREEN_FIRST
.
getCode
());
livenessPic1
.
setTenantNo
(
dto
.
getTenantNo
());
livenessPic1
.
setRoutingKey
(
dto
.
getInfo
().
getRoutingKey
());
livenessPic1
.
setCreator
(
dto
.
getInfo
().
getCreator
());
livenessPic1
.
setFileName
(
"活体视频1.png"
);
dto
.
getRnrFileList
().
add
(
livenessPic1
);
// 添加活体图片1
MgRnrFileDTO
livenessPic2
=
new
MgRnrFileDTO
();
livenessPic2
.
setUuid
(
CuscStringUtils
.
generateUuid
());
livenessPic2
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
livenessPic2
.
setRnrId
(
dto
.
getInfo
().
getUuid
());
livenessPic2
.
setLiaisonId
(
rnrRequest
.
getMatchVideoPerosinInfo
().
getPersonId
());
livenessPic2
.
setFileSystemId
(
rnrResponseDTO
.
getLivenessPic2
());
livenessPic2
.
setFileType
(
RnrFileType
.
LIVENESS_SCREEN_TWO
.
getCode
());
livenessPic2
.
setTenantNo
(
dto
.
getTenantNo
());
livenessPic2
.
setRoutingKey
(
dto
.
getInfo
().
getRoutingKey
());
livenessPic2
.
setCreator
(
dto
.
getInfo
().
getCreator
());
livenessPic2
.
setFileName
(
"活体视频2.png"
);
dto
.
getRnrFileList
().
add
(
livenessPic2
);
// 实名整体结果
Boolean
rnrResult
=
rnrResponseDTO
.
getRnrResult
();
// 新车实名通过 && 非委托人模式 && 新车实名 ====> 自动审核
boolean
success
=
rnrResult
&&
dto
.
getIsTrust
()
==
0
&&
dto
.
getIsSecondHandCar
()
==
0
;
// 二手车实名,委托人模式,新车车主非身份证模式都需要发送工单
if
(!
dto
.
getOrder
().
getSendWorkOrder
())
{
// 不需要发送工单系统,
dto
.
getOrder
().
setSendWorkOrder
(!
success
);
}
// 如果新车实名通过并且是本人办理的新车实名则审核类型为自动1,
dto
.
getOrder
()
.
setAuditType
(
success
?
RnrOrderAuditTypeEnum
.
AUTO
.
getCode
()
:
RnrOrderAuditTypeEnum
.
MANUAL
.
getCode
());
// 同时设置工单状态为审核通过3
dto
.
getOrder
()
.
setOrderStatus
(
success
?
RnrOrderStatusEnum
.
PASS
.
getCode
()
:
RnrOrderStatusEnum
.
ASSIGNMENT
.
getCode
());
// 同时设置实名状态为已实名1
dto
.
getInfo
().
setRnrStatus
(
success
?
RnrStatus
.
RNR
.
getCode
()
:
RnrStatus
.
INIT
.
getCode
());
dto
.
getCardList
()
.
forEach
(
card
->
card
.
setRnrStatus
(
success
?
RnrStatus
.
RNR
.
getCode
()
:
RnrStatus
.
INIT
.
getCode
()));
return
dto
.
getOrder
().
getSendWorkOrder
();
}
/**
* 二手车实名
*
* @param serialNumber serialNumber
* @param requestId requestId
* @param dto dto
* @return
*/
@Override
public
Integer
personSecondHandRnr
(
String
serialNumber
,
String
requestId
,
RnrRelationDTO
dto
)
{
//解绑操作
// Response response = unboundCards(dto);
// if(!response.isSuccess()) {
// throw new CuscUserException("","解绑卡失败,"+response.getMsg());
// }
personRnr
(
serialNumber
,
requestId
,
dto
);
return
RnrResultEnum
.
REVIEW
.
getCode
();
}
/**
* 下载&检查 文件
*
* @param dto
* @return key-->人的id value.key-->文件类型 value.value-->文件base64
*/
private
Map
<
String
,
Map
<
Integer
,
String
>>
downLoadFileBase64FromRnrRelationDTO
(
RnrRelationDTO
dto
)
{
if
(
CollectionUtils
.
isEmpty
(
dto
.
getRnrFileList
()))
{
return
Collections
.
emptyMap
();
}
//按照人的信息分组
Map
<
String
,
List
<
MgRnrFileDTO
>>
personFileMap
=
dto
.
getRnrFileList
().
stream
().
collect
(
Collectors
.
groupingBy
(
MgRnrFileDTO:
:
getLiaisonId
));
Map
<
String
,
Map
<
Integer
,
String
>>
fileMap
=
new
HashMap
<>(
personFileMap
.
size
());
personFileMap
.
forEach
((
key
,
fileDTOS
)
->
{
//只有身份证和视频需要下载
List
<
MgRnrFileDTO
>
downLoadFileList
=
fileDTOS
.
stream
()
.
filter
(
fileDTO
->
RnrFileType
.
IDENTITY_CARD_BACK
.
getCode
().
equals
(
fileDTO
.
getFileType
())
||
RnrFileType
.
IDENTITY_CARD_FRONT
.
getCode
().
equals
(
fileDTO
.
getFileType
())
||
RnrFileType
.
LIVENESS_VIDEO
.
getCode
().
equals
(
fileDTO
.
getFileType
()))
.
collect
(
Collectors
.
toList
());
Map
<
Integer
,
String
>
fileInfo
=
downLoadFileList
.
parallelStream
().
collect
(
Collectors
.
toMap
(
MgRnrFileDTO:
:
getFileType
,
fileDto
->
fileService
.
downLoadBase64
(
fileDto
.
getFileSystemId
()),
(
k
,
v
)
->
v
));
fileMap
.
put
(
key
,
fileInfo
);
});
return
fileMap
;
}
@Override
public
void
cardNumberCheck
(
RnrRelationDTO
dto
)
{
List
<
MgRnrCardInfoDTO
>
cardList
=
dto
.
getCardList
();
//如果是移动得卡,调用移动一证十卡验证
//todo 移动一证十卡暂未提供,此功能先屏蔽待后续联调
// if(power&& com.cusc.nirvana.user.rnr.fp.constants.MbCodeEnum.CMCC.getCode().equals(operatorService.get(cardList.get(0).getIccid()))){
// cardNumberCmccCheck(dto);
// }
// mock模式直接返回
if
(
rnrFpConfig
.
isMock
())
{
return
;
}
Boolean
check
=
false
;
// 只校验联通的一证十卡
for
(
MgRnrCardInfoDTO
mgRnrCardInfoDTO
:
dto
.
getCardList
())
{
MbCodeEnum
mbCodeEnum
=
MbCodeEnum
.
get
(
mgRnrCardInfoDTO
.
getIccid
());
if
(
MbCodeEnum
.
CUCC
.
getCode
().
equals
(
mbCodeEnum
.
getCode
()))
{
check
=
true
;
log
.
info
(
"只有联通的卡进行一证十卡验证,{}"
,
mbCodeEnum
.
getName
());
}
}
if
(
check
)
{
CardNumReqDTO
query
=
new
CardNumReqDTO
();
query
.
setCardNo
(
dto
.
getInfo
().
getCertNumber
());
query
.
setSerialNumber
(
dto
.
getInfo
().
getUuid
());
query
.
setTenantNo
(
dto
.
getTenantNo
());
//todo 调用云端接口
Response
<
IovCardNumRespDTO
>
rnrResponse
=
cloudService
.
postForResponse
(
CloudMethod
.
IOVCARD_NUM
,
query
,
IovCardNumRespDTO
.
class
);
log
.
info
(
"认证流程,一证十卡 query = {},response = {}"
,
query
.
getSerialNumber
(),
JSONObject
.
toJSONString
(
rnrResponse
));
if
(
null
==
rnrResponse
||
!
rnrResponse
.
isSuccess
()
||
null
==
rnrResponse
.
getData
())
{
throw
new
CuscUserException
(
""
,
"一证十卡查询失败"
);
}
IovCardNumRespDTO
data
=
rnrResponse
.
getData
();
Integer
nowVehicleNum
=
data
.
getNowVehicleNum
();
log
.
info
(
"认证流程,一证十卡云端数量,{}"
,
nowVehicleNum
);
// 还需要查询本地未进行上报的
MgRnrInfoDTO
bean
=
new
MgRnrInfoDTO
();
bean
.
setCertNumber
(
dto
.
getInfo
().
getCertNumber
());
Response
<
Integer
>
numWithUnload
=
mgRnrCardInfoClient
.
getNumWithUnload
(
bean
);
if
(
numWithUnload
.
isSuccess
())
{
log
.
info
(
"认证流程,一证十卡本地未上报数量,{}"
,
numWithUnload
.
getData
());
nowVehicleNum
+=
numWithUnload
.
getData
();
}
log
.
info
(
"认证流程,一证十卡最终数量,{}"
,
nowVehicleNum
);
if
(
nowVehicleNum
>=
rnrFpConfig
.
getCardNumLimit
())
{
throw
new
CuscUserException
(
""
,
"超过一证十卡验证"
);
}
}
}
/**
* @author: jk
* @description: 移动一证十卡校验
* @date: 2022/8/4 13:41
* @version: 1.0
*/
public
void
cardNumberCmccCheck
(
RnrRelationDTO
dto
)
{
String
url
=
cmccUrl
+
"/realname/interface/v1/iotIdCheck"
;
EncryptionKeyDTO
t1VehicleCompanyDTO
=
encryptionConfig
.
getKey
(
dto
.
getOrder
().
getOrgId
());
if
(
t1VehicleCompanyDTO
==
null
)
{
throw
new
CuscUserException
(
""
,
"查询车企密钥配置失败,查询参数: 租户编号:"
+
dto
.
getTenantNo
()+
"组织id:"
+
dto
.
getOrder
().
getOrgId
());
}
String
companyCode
=
t1VehicleCompanyDTO
.
getCompanyCode
();
CardNumberCmccCheckDTO
cardNumberCmccCheckDTO
=
new
CardNumberCmccCheckDTO
();
cardNumberCmccCheckDTO
.
setAuth
(
it1UploadService
.
getAuth
(
t1VehicleCompanyDTO
));
cardNumberCmccCheckDTO
.
setCode
(
companyCode
);
String
requestIdCmss
=
(
null
!=
t1VehicleCompanyDTO
.
getPlatFormId
()&&
t1VehicleCompanyDTO
.
getPlatFormId
().
length
()>
5
)?
t1VehicleCompanyDTO
.
getPlatFormId
().
substring
(
0
,
5
)+
String
.
valueOf
(
SnowflakeIdWorker
.
nextId
()):
t1VehicleCompanyDTO
.
getPlatFormId
()+
String
.
valueOf
(
SnowflakeIdWorker
.
nextId
());
cardNumberCmccCheckDTO
.
setRequestID
(
requestIdCmss
);
CustomerInfoDTO
customerInfoDTO
=
new
CustomerInfoDTO
();
customerInfoDTO
.
setCustomerCertNumber
(
dto
.
getInfo
().
getCertNumber
());
customerInfoDTO
.
setCustomerCertType
(
CmccCertTypeEnum
.
getCmccCode
(
dto
.
getInfo
().
getCertType
()));
cardNumberCmccCheckDTO
.
setCustomerInfo
(
customerInfoDTO
);
String
requestStr
=
JSON
.
toJSONString
(
cardNumberCmccCheckDTO
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
requestHeaders
.
setContentType
(
MediaType
.
APPLICATION_JSON_UTF8
);
log
.
info
(
"查询移动一证十卡接口入参{}"
,
requestStr
);
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFpT1
.
exchange
(
url
,
HttpMethod
.
POST
,
new
HttpEntity
<>(
requestStr
,
requestHeaders
),
String
.
class
);
T1CommonResponseDTO
result
=
JSON
.
parseObject
(
entity
.
getBody
(),
T1CommonResponseDTO
.
class
);
if
(
null
==
result
||
!
"1"
.
equals
(
result
.
getOprRst
())){
throw
new
CuscUserException
(
""
,
"移动一证十卡查询失败"
);
}
if
(!
"2"
.
equals
(
result
.
getCustomerCheck
())){
throw
new
CuscUserException
(
""
,
"超过移动一证十卡验证"
);
}
}
@Override
public
void
iccidListCheck
(
RnrRelationDTO
dto
)
{
if
(
CollectionUtils
.
isEmpty
(
dto
.
getCardList
()))
{
throw
new
CuscUserException
(
""
,
"卡信息为空"
);
}
List
<
String
>
iccidList
=
dto
.
getCardList
().
stream
().
map
(
MgRnrCardInfoDTO:
:
getIccid
).
collect
(
Collectors
.
toList
());
MgRnrCardInfoDTO
query
=
new
MgRnrCardInfoDTO
();
query
.
setIccidList
(
iccidList
);
Response
<
List
<
MgRnrCardInfoDTO
>>
response
=
mgRnrCardInfoClient
.
queryByList
(
query
);
if
(
null
==
response
||
!
response
.
getSuccess
())
{
throw
new
CuscUserException
(
""
,
"查询卡信息失败"
);
}
List
<
MgRnrCardInfoDTO
>
cardInfoDTOList
=
response
.
getData
();
if
(!
CollectionUtils
.
isEmpty
(
cardInfoDTOList
))
{
List
<
MgRnrCardInfoDTO
>
alreadyRnrIccidList
=
cardInfoDTOList
.
stream
().
filter
(
cardDto
->
cardDto
.
getRnrStatus
()
==
1
).
collect
(
Collectors
.
toList
());
//非车企实名 需要过滤掉车企实名的卡 允许覆盖
if
(!
RnrOrderType
.
CARMAKER_NEW_VEHICLE
.
getCode
().
equals
(
dto
.
getOrder
().
getOrderType
()))
{
alreadyRnrIccidList
=
newVinCardService
.
filterManufacturerRnr
(
alreadyRnrIccidList
);
}
if
(!
CollectionUtils
.
isEmpty
(
alreadyRnrIccidList
))
{
throw
new
CuscUserException
(
""
,
"存在已经实名的卡【"
+
StringUtils
.
join
(
alreadyRnrIccidList
,
","
)
+
"】"
);
}
}
}
@Override
public
String
getRnrLivenessType
(
String
tenantNo
)
{
//TODO 后期可以基于tenantNo扩展
return
rnrFpConfig
.
getLivenessType
();
}
@Override
public
Response
notifyResult
(
List
<
MgRnrCardInfoDTO
>
dtoList
,
String
rnrBizzType
,
String
serialNumber
,
String
orgId
,
String
resultCode
)
{
Response
response
=
null
;
try
{
//将实名结果回传给智网(新增)
List
<
VinCardDTO
>
vinCardList
=
new
ArrayList
<>();
dtoList
.
forEach
(
mgRnrCardInfoDTO
->
{
VinCardDTO
cardDto
=
new
VinCardDTO
();
cardDto
.
setIccid
(
mgRnrCardInfoDTO
.
getIccid
());
cardDto
.
setVin
(
mgRnrCardInfoDTO
.
getIotId
());
cardDto
.
setOldIccid
(
mgRnrCardInfoDTO
.
getOldCardId
());
cardDto
.
setResultCode
(
resultCode
);
vinCardList
.
add
(
cardDto
);
});
UploadResultDto
resultDto
=
new
UploadResultDto
();
resultDto
.
setSerialNumber
(
serialNumber
);
resultDto
.
setRnrBizzType
(
rnrBizzType
);
resultDto
.
setVinCardList
(
vinCardList
);
resultDto
.
setOrgId
(
orgId
);
log
.
info
(
"通知云端,实名请求是 = {}"
,
resultDto
);
response
=
cloudService
.
postForResponse
(
CloudMethod
.
NOTIFY_RESULT
,
resultDto
,
String
.
class
);
log
.
info
(
"通知云端,返回结果是 = {}"
,
response
);
if
(!
response
.
isSuccess
())
{
log
.
error
(
"通知云端失败,serialNumber = {}"
,
serialNumber
);
}
else
{
// todo 保存记录,可以添加重试机制
}
}
catch
(
Exception
e
)
{
log
.
error
(
"实名结果通知云端出现异常 = {}"
,
e
.
getMessage
());
}
return
response
;
}
@Override
public
Response
<
LiveLoginRespDTO
>
h5LiveLoginUrl
(
LiveLoginReqDTO
dto
)
{
return
cloudService
.
postForResponse
(
CloudMethod
.
H5LIVELOGIN_URL
,
dto
,
LiveLoginRespDTO
.
class
);
}
@Override
public
RnrResponseDTO
doPersonRnr
(
RnrRequestDTO
dto
,
String
[]
livenessPic
)
{
RnrResponseDTO
rnrResponseDTO
=
new
RnrResponseDTO
();
String
[]
bestFrameList
=
null
;
if
(
null
==
livenessPic
)
{
// 未做过活体
// 活体检测检测 如果失败的话 不需要进行下面 ocr 人证比对 人脸比对
bestFrameList
=
doLiveness
(
dto
,
rnrResponseDTO
);
if
(!
Boolean
.
TRUE
.
equals
(
rnrResponseDTO
.
getLivenessResult
()))
{
//活体失败直接返回
throw
new
CuscUserException
(
""
,
rnrResponseDTO
.
getLivenessFailMsg
());
}
}
else
{
//已经做过活体信息
bestFrameList
=
livenessPic
;
rnrResponseDTO
.
setLivenessResult
(
true
);
Integer
subjectType
=
CollectionUtils
.
isEmpty
(
dto
.
getPeorsonList
())
?
SubjectTypeEnum
.
ONESELF
.
getCode
()
:
SubjectTypeEnum
.
CONSIGNOR
.
getCode
();
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
LIVENESS
,
"1"
,
"活体成功"
,
subjectType
);
}
//活体视频 对应人的信息需要做的处理 (ocr & 认证对比 & 人脸对比)
videoPersonInfoProcess
(
dto
,
rnrResponseDTO
,
bestFrameList
[
0
]);
//其他人信息的核查(ocr & 人份信息核查)
personListInfoProcess
(
dto
,
rnrResponseDTO
);
//活体认证成功 && ocr认证成功 && 认证对比成功 && 人脸对边成功 ==> 实名认证成功
Boolean
rnrStatus
=
Boolean
.
TRUE
.
equals
(
rnrResponseDTO
.
getLivenessResult
())
&&
(
null
!=
rnrResponseDTO
.
getVideoPerosonOcResult
()
&&
Boolean
.
TRUE
.
equals
(
rnrResponseDTO
.
getVideoPerosonOcResult
().
getOcrResult
()))
&&
Boolean
.
TRUE
.
equals
(
rnrResponseDTO
.
getIdCompareResult
())
&&
Boolean
.
TRUE
.
equals
(
rnrResponseDTO
.
getFaceCompareResult
());
if
(!
CollectionUtils
.
isEmpty
(
rnrResponseDTO
.
getPersonListOcrResult
()))
{
//如果有其他人的信息 则需要 ocr成功 && 身份核查成功
rnrStatus
=
rnrStatus
&&
rnrResponseDTO
.
getPersonListOcrResult
().
stream
()
.
allMatch
(
ocrResultInfo
->
null
!=
ocrResultInfo
.
getOcrResult
()
&&
ocrResultInfo
.
getOcrResult
()
&&
null
!=
ocrResultInfo
.
getCertCheckResult
()
&&
ocrResultInfo
.
getCertCheckResult
());
}
rnrResponseDTO
.
setRnrResult
(
rnrStatus
);
return
rnrResponseDTO
;
}
private
void
personListInfoProcess
(
RnrRequestDTO
dto
,
RnrResponseDTO
rnrResponseDTO
)
{
if
(
CollectionUtils
.
isEmpty
(
dto
.
getPeorsonList
()))
{
return
;
}
//如果是代理人模式 这里校验的是本人的信息
Integer
subjectType
=
SubjectTypeEnum
.
ONESELF
.
getCode
();
List
<
RnrResponseDTO
.
OcrResultInfo
>
ocrResultInfoList
=
new
ArrayList
<>();
for
(
RnrRequestDTO
.
RnrPersonInfo
personInfo
:
dto
.
getPeorsonList
())
{
//人脸ocr
Future
<
Response
<
OcrNpRespDTO
>>
faceOcrResult
=
doOcr
(
dto
,
personInfo
.
getFacePicBase64
());
//国徽ocr
Future
<
Response
<
OcrNpRespDTO
>>
nationOcrResult
=
doOcr
(
dto
,
personInfo
.
getNationalEmblemPicBase64
());
//身份信息核查
Future
<
Boolean
>
certCheckResult
=
doCertCheck
(
dto
,
personInfo
.
getFullName
(),
personInfo
.
getCertNumber
());
try
{
RnrResponseDTO
.
OcrResultInfo
personOcrResult
=
processOcrResult
(
dto
,
personInfo
,
faceOcrResult
.
get
(
5
,
TimeUnit
.
SECONDS
),
nationOcrResult
.
get
(
5
,
TimeUnit
.
SECONDS
),
subjectType
);
Boolean
certCheck
=
certCheckResult
.
get
(
5
,
TimeUnit
.
SECONDS
);
if
(
certCheck
)
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
CERT_CHECK
,
"1"
,
"身份信息核查成功"
,
subjectType
);
}
else
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
CERT_CHECK
,
"2"
,
"身份信息核查失败"
,
subjectType
);
}
personOcrResult
.
setCertCheckResult
(
certCheck
);
ocrResultInfoList
.
add
(
personOcrResult
);
}
catch
(
Exception
e
)
{
log
.
error
(
"personListInfoProcess has error,fullName = {},certNumber = {}"
,
personInfo
.
getFullName
(),
personInfo
.
getCertNumber
(),
e
);
}
}
rnrResponseDTO
.
setPersonListOcrResult
(
ocrResultInfoList
);
}
private
void
videoPersonInfoProcess
(
RnrRequestDTO
dto
,
RnrResponseDTO
rnrResponseDTO
,
String
bestFrame
)
{
RnrRequestDTO
.
RnrPersonInfo
videoPersonInfo
=
dto
.
getMatchVideoPerosinInfo
();
if
(!
videoPersonInfo
.
getIsIdentityCard
())
{
//非身份证不需要做 ocr 人证比对 人脸比对
return
;
}
//ocr 做活体视频 人脸照
Future
<
Response
<
OcrNpRespDTO
>>
facePicOcrFuture
=
doOcr
(
dto
,
videoPersonInfo
.
getFacePicBase64
());
//ocr 做活体视频 国徽照
Future
<
Response
<
OcrNpRespDTO
>>
nationPicOcrFuture
=
doOcr
(
dto
,
videoPersonInfo
.
getNationalEmblemPicBase64
());
//人证比对
Future
<
Response
<
IdCompareRespDTO
>>
idCompareFuture
=
doIdCompare
(
dto
,
bestFrame
,
videoPersonInfo
.
getCertNumber
(),
videoPersonInfo
.
getFullName
());
//人脸比对
Future
<
Response
<
FaceCompareRespDTO
>>
faceCompareFuture
=
doFaceCompare
(
bestFrame
,
videoPersonInfo
.
getFacePicBase64
(),
dto
);
//判断是不是本人
Integer
subjectType
=
CollectionUtils
.
isEmpty
(
dto
.
getPeorsonList
())
?
SubjectTypeEnum
.
ONESELF
.
getCode
()
:
SubjectTypeEnum
.
CONSIGNOR
.
getCode
();
try
{
RnrResponseDTO
.
OcrResultInfo
videoPersonOcrResult
=
processOcrResult
(
dto
,
videoPersonInfo
,
facePicOcrFuture
.
get
(
5
,
TimeUnit
.
SECONDS
),
nationPicOcrFuture
.
get
(
5
,
TimeUnit
.
SECONDS
),
subjectType
);
rnrResponseDTO
.
setVideoPerosonOcResult
(
videoPersonOcrResult
);
}
catch
(
Exception
e
)
{
log
.
error
(
"videoPersonInfoProcess ocr Future has error ,fullName = {},certNumber = {}"
,
videoPersonInfo
.
getFullName
(),
videoPersonInfo
.
getCertNumber
(),
e
);
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"2"
,
"OCR异常"
,
subjectType
);
RnrResponseDTO
.
OcrResultInfo
videoPersonOcrResult
=
new
RnrResponseDTO
.
OcrResultInfo
();
videoPersonOcrResult
.
setOcrFailMsg
(
Collections
.
singletonList
(
"OCR异常:请求异常"
));
rnrResponseDTO
.
setVideoPerosonOcResult
(
videoPersonOcrResult
);
}
try
{
Response
<
IdCompareRespDTO
>
response
=
idCompareFuture
.
get
(
5
,
TimeUnit
.
SECONDS
);
if
(!
response
.
isSuccess
())
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
ID_COMPARE
,
"2"
,
"人证比对失败,:"
+
response
.
getMsg
(),
subjectType
);
rnrResponseDTO
.
setIdCompareFailMsg
(
"人证比对失败,:"
+
response
.
getMsg
());
}
else
{
String
similarity
=
response
.
getData
().
getSimilarity
();
if
(
Integer
.
parseInt
(
similarity
)
>
Integer
.
parseInt
(
rnrFpConfig
.
getIdCompareSimilarity
()))
{
rnrResponseDTO
.
setIdCompareResult
(
true
);
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
ID_COMPARE
,
"1"
,
"人证比对成功,相似度:"
+
similarity
,
subjectType
);
}
else
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
ID_COMPARE
,
"2"
,
"人证比对失败,相似度:"
+
similarity
,
subjectType
);
rnrResponseDTO
.
setIdCompareFailMsg
(
"人证比对失败,相似度:"
+
similarity
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"videoPersonInfoProcess idCompare Future has error,fullName = {},certNumber = {}"
,
videoPersonInfo
.
getFullName
(),
videoPersonInfo
.
getCertNumber
(),
e
);
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
ID_COMPARE
,
"2"
,
"人证比对异常:请求异常"
,
subjectType
);
rnrResponseDTO
.
setIdCompareFailMsg
(
"人证比对异常:请求异常"
);
}
try
{
Response
<
FaceCompareRespDTO
>
response
=
faceCompareFuture
.
get
(
5
,
TimeUnit
.
SECONDS
);
if
(!
response
.
isSuccess
())
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
FACE_COMPARE
,
"2"
,
"人脸比对失败:"
+
response
.
getMsg
(),
subjectType
);
rnrResponseDTO
.
setFaceCompareFailMsg
(
"人脸比对失败:"
+
response
.
getMsg
());
}
else
{
String
similarity
=
response
.
getData
().
getSimilarity
();
if
(
Integer
.
parseInt
(
similarity
)
>
Integer
.
parseInt
(
rnrFpConfig
.
getFaceCompareSimilarity
()))
{
rnrResponseDTO
.
setFaceCompareResult
(
true
);
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
FACE_COMPARE
,
"1"
,
"人脸比对成功,相似度:"
+
similarity
,
subjectType
);
}
else
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
FACE_COMPARE
,
"2"
,
"人脸比对失败,相似度:"
+
similarity
,
subjectType
);
rnrResponseDTO
.
setFaceCompareFailMsg
(
"人脸比对失败,相似度:"
+
similarity
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"doRnr ,videoPersonInfoProcess faceCompare Future has error,fullName = {},certNumber = {}"
,
videoPersonInfo
.
getFullName
(),
videoPersonInfo
.
getCertNumber
(),
e
);
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
FACE_COMPARE
,
"2"
,
"人脸比对异常:请求异常"
,
subjectType
);
rnrResponseDTO
.
setFaceCompareFailMsg
(
"人脸比对异常:请求异常"
);
}
}
private
RnrResponseDTO
.
OcrResultInfo
processOcrResult
(
RnrRequestDTO
dto
,
RnrRequestDTO
.
RnrPersonInfo
personInfo
,
Response
<
OcrNpRespDTO
>
faceOcrResponse
,
Response
<
OcrNpRespDTO
>
nationResponse
,
Integer
subjectType
)
{
RnrResponseDTO
.
OcrResultInfo
ocrResultInfo
=
new
RnrResponseDTO
.
OcrResultInfo
();
List
<
String
>
failMsg
=
new
ArrayList
<>();
if
(!
faceOcrResponse
.
isSuccess
()
||
!
nationResponse
.
isSuccess
()
||
null
==
faceOcrResponse
.
getData
()
||
null
==
nationResponse
.
getData
())
{
if
(!
faceOcrResponse
.
isSuccess
())
{
failMsg
.
add
(
faceOcrResponse
.
getMsg
());
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"2"
,
faceOcrResponse
.
getMsg
(),
subjectType
);
}
if
(!
nationResponse
.
isSuccess
())
{
failMsg
.
add
(
nationResponse
.
getMsg
());
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"2"
,
faceOcrResponse
.
getMsg
(),
subjectType
);
}
return
ocrResultInfo
;
}
OcrNpRespDTO
faceData
=
faceOcrResponse
.
getData
();
OcrNpRespDTO
nationData
=
nationResponse
.
getData
();
ocrResultInfo
.
setOrgianFullName
(
personInfo
.
getFullName
());
//填充ocr读取的信息
ocrResultInfo
.
setOcrFullName
(
faceData
.
getFullName
());
ocrResultInfo
.
setOcrCertNumber
(
faceData
.
getCertNumber
());
ocrResultInfo
.
setOcrGender
(
faceData
.
getGender
());
ocrResultInfo
.
setOcrAddress
(
faceData
.
getAddress
());
ocrResultInfo
.
setOcrBirthday
(
faceData
.
getBirthday
());
ocrResultInfo
.
setOcrRace
(
faceData
.
getRace
());
ocrResultInfo
.
setOcrIssued
(
nationData
.
getIssued
());
ocrResultInfo
.
setOcrValidDate
(
nationData
.
getValidDate
());
boolean
compareFullName
=
personInfo
.
getFullName
().
equals
(
faceData
.
getFullName
());
if
(!
compareFullName
)
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"2"
,
"ocr扫描结果身份证姓名与输入身份证信息不一致"
,
subjectType
);
failMsg
.
add
(
"ocr扫描结果身份证姓名与输入身份证信息不一致"
);
}
boolean
certNumberCompare
=
personInfo
.
getCertNumber
().
equals
(
faceData
.
getCertNumber
());
if
(!
certNumberCompare
)
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"2"
,
"ocr扫描结果身份证号码与输入身份证信息不一致"
,
subjectType
);
failMsg
.
add
(
"ocr扫描结果身份证号码与输入身份证信息不一致"
);
}
boolean
genderCompare
=
null
!=
personInfo
.
getGender
()
&&
GenderEnum
.
findByCode
(
personInfo
.
getGender
()).
getName
()
.
equals
(
faceData
.
getGender
());
if
(!
genderCompare
)
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"2"
,
"ocr扫描结果性别与输入身份证信息不一致"
,
subjectType
);
failMsg
.
add
(
"ocr扫描结果性别与输入身份证信息不一致"
);
}
if
(
StringUtils
.
isNotBlank
(
nationData
.
getValidDate
()))
{
//读取出来的有效期格式为2021.11.11-2022.12.12
String
validDate
=
nationData
.
getValidDate
().
split
(
"-"
)[
1
];
// Date validDate = DateUtil.parseDate(validDateStr, DateUtil.YYYYMMDDDOT);
boolean
validDateCheck
=
true
;
if
(
StringUtils
.
isBlank
(
validDate
))
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"2"
,
"ocr扫描结果身份证有效期非法"
,
subjectType
);
failMsg
.
add
(
"ocr扫描结果身份证有效期非法"
);
validDateCheck
=
false
;
}
if
(
StringUtils
.
isNotBlank
(
validDate
))
{
//将截止时间统一改为-
validDate
=
validDate
.
replaceAll
(
"\\."
,
"-"
);
if
(!
validDate
.
equals
(
personInfo
.
getExpiredDate
()))
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"2"
,
"ocr扫描结果身份证有效期与输入身份证有效期不一致"
,
subjectType
);
log
.
info
(
"processOcrResult validDate :{}"
,
validDate
);
failMsg
.
add
(
"ocr扫描结果身份证有效期与输入身份证有效期不一致"
);
validDateCheck
=
false
;
}
if
(!
"长期"
.
equals
(
validDate
))
{
Date
date
=
DateUtils
.
parseDate
(
validDate
,
"yyyy-MM-dd"
);
if
(
StringUtils
.
isNotBlank
(
validDate
)
&&
null
!=
date
&&
date
.
getTime
()
<
System
.
currentTimeMillis
())
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"2"
,
"ocr扫描结果身份证有效期失效"
,
subjectType
);
failMsg
.
add
(
"ocr扫描结果身份证有效期失效"
);
validDateCheck
=
false
;
}
}
}
ocrResultInfo
.
setOcrResult
(
compareFullName
&&
certNumberCompare
&&
genderCompare
&&
validDateCheck
);
if
(
Boolean
.
TRUE
.
equals
(
ocrResultInfo
.
getOcrResult
()))
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"1"
,
"ocr成功"
,
subjectType
);
}
}
else
{
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
OCR
,
"2"
,
"ocr扫描结果身份证有效期为空"
,
subjectType
);
failMsg
.
add
(
"ocr扫描结果身份证有效期为空"
);
}
if
(!
CollectionUtils
.
isEmpty
(
failMsg
))
{
ocrResultInfo
.
setOcrFailMsg
(
failMsg
);
}
return
ocrResultInfo
;
}
private
Future
<
Response
<
FaceCompareRespDTO
>>
doFaceCompare
(
String
bestFrame
,
String
faceImg
,
RnrRequestDTO
dto
)
{
return
rnrExecutorService
.
submit
(()
->
{
FaceCompareReqDTO
faceDto
=
new
FaceCompareReqDTO
();
faceDto
.
setSerialNumber
(
dto
.
getSerialNumber
());
faceDto
.
setBizUuid
(
dto
.
getBizUuid
());
faceDto
.
setTenantNo
(
dto
.
getTenantNo
());
faceDto
.
setBaseImg
(
bestFrame
);
faceDto
.
setFaceImg
(
faceImg
);
Response
<
FaceCompareRespDTO
>
response
=
cloudService
.
postForResponse
(
CloudMethod
.
FACE_COMPARE
,
faceDto
,
FaceCompareRespDTO
.
class
);
log
.
info
(
"认证流程 , 人脸比对 rnrId = {},response = {}"
,
dto
.
getBizUuid
(),
JSONObject
.
toJSONString
(
response
));
return
response
;
});
}
private
Future
<
Response
<
IdCompareRespDTO
>>
doIdCompare
(
RnrRequestDTO
dto
,
String
bestFrame
,
String
certNumber
,
String
fullName
)
{
return
rnrExecutorService
.
submit
(()
->
{
IdCompareReqDTO
idDto
=
new
IdCompareReqDTO
();
idDto
.
setSerialNumber
(
dto
.
getSerialNumber
());
idDto
.
setBizUuid
(
dto
.
getBizUuid
());
idDto
.
setTenantNo
(
dto
.
getTenantNo
());
idDto
.
setFaceImg
(
bestFrame
);
idDto
.
setCertNumber
(
certNumber
);
idDto
.
setFullName
(
fullName
);
Response
<
IdCompareRespDTO
>
response
=
cloudService
.
postForResponse
(
CloudMethod
.
ID_COMPARE
,
idDto
,
IdCompareRespDTO
.
class
);
log
.
info
(
"认证流程 , 人证比对 rnrId = {},response = {}"
,
dto
.
getBizUuid
(),
JSONObject
.
toJSONString
(
response
));
return
response
;
});
}
private
Future
<
Response
<
OcrNpRespDTO
>>
doOcr
(
RnrRequestDTO
dto
,
String
picBase64
)
{
return
rnrExecutorService
.
submit
(()
->
{
OcrNpReqDTO
ocrDto
=
new
OcrNpReqDTO
();
ocrDto
.
setSerialNumber
(
dto
.
getSerialNumber
());
ocrDto
.
setBizUuid
(
dto
.
getBizUuid
());
ocrDto
.
setTenantNo
(
dto
.
getTenantNo
());
ocrDto
.
setOcrPic
(
picBase64
);
Response
<
OcrNpRespDTO
>
ocr
=
cloudService
.
postForResponse
(
CloudMethod
.
OCR_NP
,
ocrDto
,
OcrNpRespDTO
.
class
);
System
.
out
.
println
(
"认证流程 , 身份证ocr,response = {}"
+
JSONObject
.
toJSONString
(
ocr
));
log
.
info
(
"认证流程 , 身份证ocr rnrId = {},response = {}"
,
dto
.
getBizUuid
(),
JSONObject
.
toJSONString
(
ocr
));
return
ocr
;
});
}
private
Future
<
Boolean
>
doCertCheck
(
RnrRequestDTO
dto
,
String
fullName
,
String
certNumber
)
{
return
rnrExecutorService
.
submit
(()
->
{
CertCheckReqDTO
certCheckDto
=
new
CertCheckReqDTO
();
certCheckDto
.
setSerialNumber
(
dto
.
getSerialNumber
());
certCheckDto
.
setFullName
(
fullName
);
certCheckDto
.
setBizUuid
(
dto
.
getBizUuid
());
certCheckDto
.
setCertNumber
(
certNumber
);
Response
rnrResponse
=
cloudService
.
postForResponse
(
CloudMethod
.
CERT_CHECK
,
certCheckDto
,
LivenessCodeResponseDTO
.
class
);
log
.
info
(
"认证流程, 身份信息核查,response = {}"
+
JSONObject
.
toJSONString
(
rnrResponse
));
log
.
info
(
"认证流程, 身份信息核查 rnrId = {},response = {}"
,
dto
.
getBizUuid
(),
JSONObject
.
toJSONString
(
rnrResponse
));
return
rnrResponse
.
isSuccess
();
});
}
private
String
[]
doLiveness
(
RnrRequestDTO
dto
,
RnrResponseDTO
rnrResponseDTO
)
{
String
livenessCode
=
null
;
try
{
livenessCode
=
cacheFactory
.
getStringService
()
.
getValue
(
RedisConstant
.
USER_RNR_LIVENESSCODE_PREFIX
+
dto
.
getRequestId
(),
String
.
class
);
}
catch
(
Exception
e
)
{
log
.
error
(
"getLivenessCode from redis has error , dto = {}"
,
JSONObject
.
toJSONString
(
dto
),
e
);
}
if
(
StringUtils
.
isBlank
(
livenessCode
))
{
rnrResponseDTO
.
setLivenessFailMsg
(
"活体失败:未查询到活体数字验证码/动作序列"
);
return
null
;
}
LivenessReqDTO
livenessDto
=
new
LivenessReqDTO
();
livenessDto
.
setSerialNumber
(
dto
.
getSerialNumber
());
livenessDto
.
setVideoBase64
(
dto
.
getVideoBase64
());
livenessDto
.
setLivenessType
(
rnrFpConfig
.
getLivenessType
());
livenessDto
.
setValidateData
(
livenessCode
);
Response
<
LivenessRespDTO
>
livenessResponse
;
try
{
//todo 调用云端接口
livenessResponse
=
cloudService
.
postForResponse
(
CloudMethod
.
LIVENESS
,
livenessDto
,
LivenessRespDTO
.
class
);
log
.
info
(
"认证流程 , 活体检测 rnrId = {},response = {}"
,
dto
.
getBizUuid
(),
livenessResponse
.
getCode
());
if
(!
livenessResponse
.
isSuccess
()
||
null
==
livenessResponse
.
getData
())
{
rnrResponseDTO
.
setLivenessFailMsg
(
"活体失败:"
+
livenessResponse
.
getMsg
());
return
null
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"doLiveness has error"
,
e
);
rnrResponseDTO
.
setLivenessFailMsg
(
"活体失败:请求失败"
);
return
null
;
}
LivenessRespDTO
data
=
livenessResponse
.
getData
();
if
(
null
==
data
.
getBestFrameList
()
||
data
.
getBestFrameList
().
length
!=
2
)
{
rnrResponseDTO
.
setLivenessFailMsg
(
"活体失败:活体认证返回的图片少于两张"
);
return
null
;
}
rnrResponseDTO
.
setLivenessResult
(
true
);
rnrResponseDTO
.
setLivenessPic1
(
fileService
.
upLoadImgBase64
(
data
.
getBestFrameList
()[
0
],
"png"
));
rnrResponseDTO
.
setLivenessPic2
(
fileService
.
upLoadImgBase64
(
data
.
getBestFrameList
()[
1
],
"png"
));
Integer
subjectType
=
CollectionUtils
.
isEmpty
(
dto
.
getPeorsonList
())
?
SubjectTypeEnum
.
ONESELF
.
getCode
()
:
SubjectTypeEnum
.
CONSIGNOR
.
getCode
();
recordRnrResultLog
(
dto
,
AuthWayTypeEnum
.
LIVENESS
,
"1"
,
"活体成功"
,
subjectType
);
return
data
.
getBestFrameList
();
}
/**
* 审核页面重试接口
*
* @param dto
* @return
*/
@Override
public
RnrRequestDTO
rnrPersonRelationDto2RnrRequestDTO
(
RnrRelationDTO
dto
)
{
RnrRequestDTO
rnrRequestDTO
=
new
RnrRequestDTO
();
rnrRequestDTO
.
setTenantNo
(
dto
.
getTenantNo
());
rnrRequestDTO
.
setBizUuid
(
dto
.
getInfo
().
getUuid
());
Map
<
String
,
Map
<
Integer
,
String
>>
fileMap
=
downLoadFileBase64FromRnrRelationDTO
(
dto
);
//是否是委托人实名
boolean
trust
=
dto
.
getIsTrust
()
==
1
;
MgRnrLiaisonInfoDTO
consigneePersonInfo
=
null
;
if
(
trust
)
{
//委托实名 被委托人做活体视频
consigneePersonInfo
=
dto
.
getRnrLiaisonList
().
stream
()
.
filter
(
mgRnrLiaisonInfoDTO
->
RnrLiaisonType
.
CONSIGNEE
.
getCode
()
.
equals
(
mgRnrLiaisonInfoDTO
.
getLiaisonType
()))
.
findFirst
().
orElseThrow
(()
->
new
CuscUserException
(
""
,
"未查询到代办人信息"
));
}
Map
<
Integer
,
String
>
videoPersonFileInfo
=
fileMap
.
get
(
trust
?
consigneePersonInfo
.
getUuid
()
:
"0"
);
if
(
null
==
videoPersonFileInfo
)
{
throw
new
CuscUserException
(
""
,
"未查询到"
+
(
trust
?
"代办人"
:
"本人"
)
+
"文件信息"
);
}
//获取活体视频 活体视频人的id为0
String
videoBase64
=
videoPersonFileInfo
.
get
(
RnrFileType
.
LIVENESS_VIDEO
.
getCode
());
if
(
StringUtils
.
isBlank
(
videoBase64
))
{
throw
new
CuscUserException
(
""
,
"未查询到"
+
(
trust
?
"代办人"
:
"本人"
)
+
"活体视频"
);
}
rnrRequestDTO
.
setVideoBase64
(
videoBase64
);
rnrRequestDTO
.
setRequestId
(
dto
.
getRequestId
());
//构建 活体视频对应的人的信息
RnrRequestDTO
.
RnrPersonInfo
videoPersonInfo
=
new
RnrRequestDTO
.
RnrPersonInfo
();
if
(
trust
)
{
//被委托人的信息
videoPersonInfo
.
setPersonId
(
consigneePersonInfo
.
getUuid
());
videoPersonInfo
.
setCertNumber
(
consigneePersonInfo
.
getLiaisonCertNumber
());
videoPersonInfo
.
setFullName
(
consigneePersonInfo
.
getLiaisonName
());
videoPersonInfo
.
setGender
(
consigneePersonInfo
.
getLiaisonGender
());
videoPersonInfo
.
setExpiredDate
(
consigneePersonInfo
.
getLiaisonExpiredDate
());
}
else
{
videoPersonInfo
.
setPersonId
(
"0"
);
videoPersonInfo
.
setCertNumber
(
dto
.
getInfo
().
getCertNumber
());
videoPersonInfo
.
setFullName
(
dto
.
getInfo
().
getFullName
());
videoPersonInfo
.
setExpiredDate
(
dto
.
getInfo
().
getExpiredDate
());
videoPersonInfo
.
setGender
(
dto
.
getInfo
().
getGender
());
}
String
idFaceBase64
=
videoPersonFileInfo
.
get
(
RnrFileType
.
IDENTITY_CARD_BACK
.
getCode
());
if
(
StringUtils
.
isNotBlank
(
idFaceBase64
))
{
videoPersonInfo
.
setFacePicBase64
(
idFaceBase64
);
}
String
nationFaceBase64
=
videoPersonFileInfo
.
get
(
RnrFileType
.
IDENTITY_CARD_FRONT
.
getCode
());
if
(
StringUtils
.
isNotBlank
(
idFaceBase64
))
{
videoPersonInfo
.
setNationalEmblemPicBase64
(
nationFaceBase64
);
}
videoPersonInfo
.
setIsIdentityCard
(
StringUtils
.
isNotBlank
(
idFaceBase64
)
&&
StringUtils
.
isNotBlank
(
idFaceBase64
));
rnrRequestDTO
.
setMatchVideoPerosinInfo
(
videoPersonInfo
);
//构建其他人的信息
List
<
RnrRequestDTO
.
RnrPersonInfo
>
personList
=
new
ArrayList
<>();
if
(
trust
)
{
//将委托人的信息 放在PeorsonList中
RnrRequestDTO
.
RnrPersonInfo
selfPerson
=
new
RnrRequestDTO
.
RnrPersonInfo
();
selfPerson
.
setPersonId
(
""
);
selfPerson
.
setFullName
(
dto
.
getInfo
().
getFullName
());
selfPerson
.
setCertNumber
(
dto
.
getInfo
().
getCertNumber
());
selfPerson
.
setExpiredDate
(
dto
.
getInfo
().
getExpiredDate
());
selfPerson
.
setGender
(
dto
.
getInfo
().
getGender
());
Map
<
Integer
,
String
>
selfFileMap
=
fileMap
.
get
(
"0"
);
String
personIdFaceBase64
=
selfFileMap
.
get
(
RnrFileType
.
IDENTITY_CARD_BACK
.
getCode
());
if
(
StringUtils
.
isNotBlank
(
personIdFaceBase64
))
{
selfPerson
.
setFacePicBase64
(
personIdFaceBase64
);
}
String
personNationFaceBase64
=
selfFileMap
.
get
(
RnrFileType
.
IDENTITY_CARD_FRONT
.
getCode
());
if
(
StringUtils
.
isNotBlank
(
personNationFaceBase64
))
{
selfPerson
.
setNationalEmblemPicBase64
(
personNationFaceBase64
);
}
selfPerson
.
setIsIdentityCard
(
StringUtils
.
isNotBlank
(
personIdFaceBase64
)
&&
StringUtils
.
isNotBlank
(
personNationFaceBase64
));
personList
.
add
(
selfPerson
);
}
rnrRequestDTO
.
setPeorsonList
(
personList
);
return
rnrRequestDTO
;
}
@Override
public
void
personRnrH5
(
String
serialNumber
,
RnrRelationDTO
dto
)
{
//卡实名状态校验
if
(
dto
.
getIsSecondHandCar
()
==
0
)
{
iccidListCheck
(
dto
);
}
//一证十卡校验
cardNumberCheck
(
dto
);
dto
.
getInfo
().
setRnrStatus
(
RnrStatus
.
INIT
.
getCode
());
dto
.
getInfo
().
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
dto
.
getOrder
().
setOrderStatus
(
RnrOrderStatusEnum
.
COMMIT
.
getCode
());
dto
.
getOrder
().
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
dto
.
getOrder
().
setSendWorkOrder
(
false
);
dto
.
getCardList
().
forEach
(
card
->
card
.
setRnrStatus
(
RnrStatus
.
INIT
.
getCode
()));
Response
response
=
mgRnrRelationClient
.
saveRnrRelation
(
dto
);
if
(
response
.
isSuccess
())
{
RnrOrderDTO
message
=
new
RnrOrderDTO
();
message
.
setUuid
(
dto
.
getOrder
().
getUuid
());
changeOrUnbindIccidsClient
.
sendMSMToMQ
(
message
);
}
}
@Override
public
Integer
personH5CallBack
(
PersonH5CallBackRequestDTO
dto
)
{
if
(
null
==
dto
.
getLivenessPicFileId
()
||
dto
.
getLivenessPicFileId
().
length
!=
2
)
{
throw
new
CuscUserException
(
""
,
"活体照片不是2张"
);
}
//订单号
String
orderNo
=
dto
.
getOrderNo
();
//根据订单号加锁
try
{
boolean
lockStatus
=
cacheFactory
.
getLockService
().
lock
(
RedisConstant
.
RNR_H5_CALLBACK_LOCK
+
orderNo
,
RedisConstant
.
RNR_H5_CALLBACK_LOCK_EXPIRE
);
if
(!
lockStatus
){
throw
new
CuscUserException
(
""
,
"当前有正在处理的实名请求,请勿重复提交"
);
}
}
catch
(
CacheException
e
)
{
log
.
error
(
"personH5CallBack 加锁失败 "
,
e
);
}
RnrOrderDTO
orderQuery
=
new
RnrOrderDTO
();
orderQuery
.
setUuid
(
orderNo
);
Response
<
RnrOrderDTO
>
orderResponse
=
orderClient
.
getByUuid
(
orderQuery
);
if
(!
orderResponse
.
isSuccess
()
||
null
==
orderResponse
.
getData
())
{
throw
new
CuscUserException
(
""
,
"未查询到订单信息"
);
}
RnrOrderDTO
orderDTO
=
orderResponse
.
getData
();
//判断工单状态,如果是审核通过则不继续
if
(
orderDTO
.
getOrderStatus
()
!=
null
&&
RnrOrderStatusEnum
.
PASS
.
getCode
().
intValue
()
==
orderDTO
.
getOrderStatus
().
intValue
())
{
return
RnrResultEnum
.
PASS
.
getCode
();
}
//判断工单是否作废
if
(
orderDTO
.
getOrderStatus
()
!=
null
&&
RnrOrderStatusEnum
.
CANCEL
.
getCode
().
intValue
()
==
orderDTO
.
getOrderStatus
().
intValue
()){
throw
new
CuscUserException
(
""
,
"实名工单已超时作废,请重新实名"
);
}
if
(
orderDTO
.
getOrderStatus
()
!=
null
&&
RnrOrderStatusEnum
.
NOT_PASS
.
getCode
().
intValue
()
==
orderDTO
.
getOrderStatus
().
intValue
()){
throw
new
CuscUserException
(
""
,
"实名工单审核不通过,请重新实名"
);
}
//判断工单状态,如果是审核通过则不继续
if
(
orderDTO
.
getOrderStatus
()
!=
null
&&
RnrOrderStatusEnum
.
PASS
.
getCode
().
intValue
()
==
orderDTO
.
getOrderStatus
().
intValue
())
{
return
RnrResultEnum
.
PASS
.
getCode
();
}
String
rnrId
=
orderDTO
.
getRnrId
();
MgRnrInfoDTO
rnrInfoQuery
=
new
MgRnrInfoDTO
();
rnrInfoQuery
.
setUuid
(
rnrId
);
Response
<
MgRnrInfoDTO
>
rnrInfoResponse
=
rnrInfoClient
.
getByUuid
(
rnrInfoQuery
);
if
(!
rnrInfoResponse
.
isSuccess
()
||
null
==
rnrInfoResponse
.
getData
())
{
throw
new
CuscUserException
(
""
,
"未查询到实名信息"
);
}
MgRnrInfoDTO
rnrInfo
=
rnrInfoResponse
.
getData
();
if
(
orderDTO
.
getOrderStatus
()
!=
null
&&
RnrOrderStatusEnum
.
ASSIGNMENT
.
getCode
().
intValue
()
==
orderDTO
.
getOrderStatus
().
intValue
())
{
throw
new
CuscUserException
(
""
,
"已有工单在审核中,请等待"
);
}
//H5认证的信息 构建 认证流程请求
RnrResponseDTO
rnrResponse
;
String
[]
bestBaseLiveness64
=
new
String
[
2
];
String
[]
bestBaseLiveness64ForFile
=
new
String
[
2
];
AttachmentDTO
attachmentDTO
=
new
AttachmentDTO
();
attachmentDTO
.
setSerialNumber
(
CuscStringUtils
.
generateUuid
());
attachmentDTO
.
setFileId
(
dto
.
getLivenessPicFileId
()[
0
]);
Response
<
AttachmentRespDTO
>
response1
=
cloudService
.
postForResponse
(
CloudMethod
.
ATTACHMENT_DOWNLOAD
,
attachmentDTO
,
AttachmentRespDTO
.
class
);
if
(
response1
.
isSuccess
())
{
AttachmentRespDTO
attachmentRespDTO
=
response1
.
getData
();
bestBaseLiveness64
[
0
]
=
attachmentRespDTO
.
getBase64
();
bestBaseLiveness64
[
1
]
=
attachmentRespDTO
.
getBase64
();
bestBaseLiveness64ForFile
[
0
]
=
attachmentRespDTO
.
getBase64
();
}
else
{
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
"下载活体截图失败"
);
}
AttachmentDTO
attachmentDTOForVideo
=
new
AttachmentDTO
();
attachmentDTOForVideo
.
setSerialNumber
(
CuscStringUtils
.
generateUuid
());
attachmentDTOForVideo
.
setFileId
(
dto
.
getVideFileId
());
Response
<
AttachmentRespDTO
>
response3
=
cloudService
.
postForResponse
(
CloudMethod
.
ATTACHMENT_DOWNLOAD
,
attachmentDTOForVideo
,
AttachmentRespDTO
.
class
);
if
(
response3
.
isSuccess
())
{
AttachmentRespDTO
attachmentRespDTO
=
response3
.
getData
();
bestBaseLiveness64ForFile
[
1
]
=
attachmentRespDTO
.
getBase64
();
}
else
{
log
.
info
(
"活体视频下载失败,orderNo = {}"
,
dto
.
getOrderNo
());
}
//是否是代办人模式
boolean
trust
=
rnrInfo
.
getIsTrust
()
==
1
;
RnrRequestDTO
rnrRequestDTO
=
h5InfoToRnrRequest
(
trust
,
orderDTO
,
rnrId
,
rnrInfo
);
rnrResponse
=
doPersonRnr
(
rnrRequestDTO
,
bestBaseLiveness64
);
//非二手车且只是身份证时,自然人实名失败则自动返回
RnrReturnDTO
personRnrMsg
=
personRnrResult
(
rnrInfo
,
rnrResponse
);
if
(
null
!=
personRnrMsg
)
{
//通过实名id查询vin
MgRnrCardInfoDTO
cardInfoDTO
=
new
MgRnrCardInfoDTO
();
cardInfoDTO
.
setRnrId
(
rnrInfo
.
getUuid
());
cardInfoDTO
.
setTenantNo
(
rnrInfo
.
getTenantNo
());
Response
<
List
<
MgRnrCardInfoDTO
>>
cardResp
=
rnrCardInfoClient
.
queryByList
(
cardInfoDTO
);
if
(!
cardResp
.
isSuccess
())
{
throw
new
CuscUserException
(
cardResp
.
getCode
(),
cardResp
.
getMsg
());
}
if
(
CollectionUtils
.
isEmpty
(
cardResp
.
getData
()))
{
throw
new
CuscUserException
(
""
,
"未查询到实名卡信息"
);
}
String
errorCountKey
=
rnrInfo
.
getCertNumber
()
+
"_"
+
cardResp
.
getData
().
get
(
0
).
getIotId
();
//检查实名错误次数是否超过配置次数
if
(!
toArtificialOrder
(
errorCountKey
))
{
//设置错误次数
setPersonRnrErrorCount
(
errorCountKey
);
updateInValid
(
rnrId
,
orderNo
,
StringUtils
.
isNotBlank
(
personRnrMsg
.
getPersonRnrResultMsg
())?
personRnrMsg
.
getPersonRnrResultMsg
():
personRnrMsg
.
getPersonH5CallBackMsg
());
throw
new
CuscUserException
(
""
,
personRnrMsg
.
getPersonRnrResultMsg
());
}
}
if
(
rnrResponse
.
getRnrResult
()
&&
rnrInfo
.
getIsSecondHandCar
()
==
0
&&
rnrInfo
.
getIsTrust
()
==
0
)
{
String
userId
=
null
;
try
{
if
(
CuscStringUtils
.
isEmpty
(
dto
.
getCiamUserId
())
&&
!
RnrOrderSourceEnum
.
H5_CUSTOMER
.
getCode
().
equals
(
orderDTO
.
getOrderSource
()))
{
CiamUserDTO
ciamUserDto
=
new
CiamUserDTO
();
ciamUserDto
.
setTenantNo
(
rnrInfo
.
getTenantNo
());
ciamUserDto
.
setPhoneNum
(
rnrInfo
.
getPhone
());
Response
<
CiamUserDTO
>
user
=
ciamUserClient
.
createUser
(
ciamUserDto
);
if
(
null
!=
user
&&
user
.
isSuccess
()
&&
null
!=
user
.
getData
())
{
userId
=
user
.
getData
().
getUuid
();
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"H5实名成功 创建C端用户 错误 dto = {}"
,
JSONObject
.
toJSONString
(
dto
),
e
);
}
processRnrResult
(
orderDTO
,
true
,
RnrOrderStatusEnum
.
PASS
,
userId
,
StringUtils
.
isNotEmpty
(
personRnrMsg
.
getPersonRnrResultMsg
())?
personRnrMsg
.
getPersonRnrResultMsg
():
personRnrMsg
.
getPersonH5CallBackMsg
());
}
else
{
processRnrResult
(
orderDTO
,
false
,
RnrOrderStatusEnum
.
ASSIGNMENT
,
null
,
StringUtils
.
isNotEmpty
(
personRnrMsg
.
getPersonRnrResultMsg
())?
personRnrMsg
.
getPersonRnrResultMsg
():
personRnrMsg
.
getPersonH5CallBackMsg
());
try
{
//发起一个工单
RnrOrderDTO
workOrder
=
new
RnrOrderDTO
();
workOrder
.
setUuid
(
orderDTO
.
getUuid
());
orderClient
.
startWorkOrder
(
workOrder
);
}
catch
(
Exception
e
)
{
log
.
error
(
"H5回调发起工单流程失败:info = {}"
,
JSONObject
.
toJSONString
(
dto
),
e
);
}
}
//文件上传
String
best64Img
=
bestBaseLiveness64ForFile
[
0
];
String
best64ImgFileKey
=
""
;
if
(
StringUtils
.
isNotBlank
(
best64Img
))
{
best64ImgFileKey
=
fileService
.
upLoadImgBase64
(
best64Img
,
"png"
);
}
String
video
=
bestBaseLiveness64ForFile
[
1
];
String
videoFileKey
=
""
;
if
(
StringUtils
.
isNotBlank
(
video
))
{
videoFileKey
=
fileService
.
upLoadFileBase64
(
video
,
"mp4"
);
}
String
liaisonId
=
rnrRequestDTO
.
getMatchVideoPerosinInfo
().
getPersonId
();
//视屏文件存储
MgRnrFileDTO
videoFile
=
new
MgRnrFileDTO
();
videoFile
.
setUuid
(
CuscStringUtils
.
generateUuid
());
videoFile
.
setLiaisonId
(
liaisonId
);
videoFile
.
setRnrId
(
rnrId
);
videoFile
.
setFileType
(
RnrFileType
.
LIVENESS_VIDEO
.
getCode
());
videoFile
.
setFileSystemId
(
videoFileKey
);
videoFile
.
setTenantNo
(
orderDTO
.
getTenantNo
());
videoFile
.
setRoutingKey
(
orderDTO
.
getRoutingKey
());
videoFile
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
rnrFileClient
.
add
(
videoFile
);
//活体截图1
MgRnrFileDTO
faceFile
=
new
MgRnrFileDTO
();
faceFile
.
setUuid
(
CuscStringUtils
.
generateUuid
());
faceFile
.
setLiaisonId
(
liaisonId
);
faceFile
.
setRnrId
(
rnrId
);
faceFile
.
setFileType
(
RnrFileType
.
LIVENESS_SCREEN_FIRST
.
getCode
());
faceFile
.
setFileSystemId
(
best64ImgFileKey
);
faceFile
.
setTenantNo
(
orderDTO
.
getTenantNo
());
faceFile
.
setRoutingKey
(
orderDTO
.
getRoutingKey
());
faceFile
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
rnrFileClient
.
add
(
faceFile
);
//活体截图1
MgRnrFileDTO
nationFile
=
new
MgRnrFileDTO
();
nationFile
.
setUuid
(
CuscStringUtils
.
generateUuid
());
nationFile
.
setLiaisonId
(
liaisonId
);
nationFile
.
setRnrId
(
rnrId
);
nationFile
.
setFileType
(
RnrFileType
.
LIVENESS_SCREEN_TWO
.
getCode
());
nationFile
.
setFileSystemId
(
best64ImgFileKey
);
nationFile
.
setTenantNo
(
orderDTO
.
getTenantNo
());
nationFile
.
setRoutingKey
(
orderDTO
.
getRoutingKey
());
nationFile
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
rnrFileClient
.
add
(
nationFile
);
try
{
//解锁
cacheFactory
.
getLockService
().
unLock
(
RedisConstant
.
RNR_H5_CALLBACK_LOCK
+
orderNo
);
}
catch
(
CacheException
e
)
{
log
.
error
(
"personH5CallBack 解锁失败 "
,
e
);
}
return
rnrResponse
.
getRnrResult
()
&&
rnrInfo
.
getIsTrust
()
==
0
&&
rnrInfo
.
getIsSecondHandCar
()
==
0
?
RnrResultEnum
.
PASS
.
getCode
()
:
RnrResultEnum
.
REVIEW
.
getCode
();
}
@Override
public
RnrRequestDTO
h5InfoToRnrRequest
(
boolean
isTrust
,
RnrOrderDTO
orderDTO
,
String
rnrId
,
MgRnrInfoDTO
rnrInfo
)
{
//认证请求
RnrRequestDTO
rnrRequestDTO
=
new
RnrRequestDTO
();
rnrRequestDTO
.
setBizUuid
(
rnrId
);
rnrRequestDTO
.
setSerialNumber
(
orderDTO
.
getUuid
());
rnrRequestDTO
.
setTenantNo
(
rnrInfo
.
getTenantNo
());
//查询委托人信息
MgRnrLiaisonInfoDTO
liaisonInfoDTO
=
null
;
if
(
isTrust
)
{
MgRnrLiaisonInfoDTO
liaisonQuery
=
new
MgRnrLiaisonInfoDTO
();
liaisonQuery
.
setRnrId
(
rnrId
);
liaisonInfoDTO
=
liaisonInfoClient
.
getByRnrid
(
liaisonQuery
).
getData
();
if
(
null
==
liaisonInfoDTO
)
{
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
"未查询到责任人信息"
);
}
}
//查询出文件
MgRnrFileDTO
rnrFileQuery
=
new
MgRnrFileDTO
();
rnrFileQuery
.
setTenantNo
(
orderDTO
.
getTenantNo
());
rnrFileQuery
.
setRnrId
(
rnrId
);
Response
<
List
<
MgRnrFileDTO
>>
fileResponse
=
rnrFileClient
.
queryByList
(
rnrFileQuery
);
if
(!
fileResponse
.
isSuccess
()
&&
CollectionUtils
.
isEmpty
(
fileResponse
.
getData
()))
{
throw
new
CuscUserException
(
""
,
"未查询到文件信息"
);
}
List
<
MgRnrFileDTO
>
fileDTOList
=
fileResponse
.
getData
();
//实名本人的文件信息
List
<
MgRnrFileDTO
>
rnrInfoFileList
=
fileDTOList
.
stream
().
filter
(
file
->
file
.
getLiaisonId
().
equals
(
"0"
)).
collect
(
Collectors
.
toList
());
Map
<
Integer
,
MgRnrFileDTO
>
rnrFileMap
=
rnrInfoFileList
.
stream
()
.
collect
(
Collectors
.
toMap
(
MgRnrFileDTO:
:
getFileType
,
Function
.
identity
(),
(
k
,
v
)
->
v
));
//委托人文件信息
List
<
MgRnrFileDTO
>
trustInfoFileList
=
fileDTOList
.
stream
().
filter
(
file
->
!
file
.
getLiaisonId
().
equals
(
"0"
)).
collect
(
Collectors
.
toList
());
Map
<
Integer
,
MgRnrFileDTO
>
trustInfoFileMap
=
trustInfoFileList
.
stream
()
.
collect
(
Collectors
.
toMap
(
MgRnrFileDTO:
:
getFileType
,
Function
.
identity
(),
(
k
,
v
)
->
v
));
//本人信息
RnrRequestDTO
.
RnrPersonInfo
selfPersonInfo
=
new
RnrRequestDTO
.
RnrPersonInfo
();
selfPersonInfo
.
setPersonId
(
"0"
);
selfPersonInfo
.
setIsIdentityCard
(
CertTypeEnum
.
IDCARD
.
getCode
().
equals
(
rnrInfo
.
getCertType
()));
//身份证人像面
MgRnrFileDTO
faceFileDTO
=
rnrFileMap
.
get
(
RnrFileType
.
IDENTITY_CARD_BACK
.
getCode
());
//身份证国徽面
MgRnrFileDTO
nationFileDTO
=
rnrFileMap
.
get
(
RnrFileType
.
IDENTITY_CARD_FRONT
.
getCode
());
if
(
null
!=
faceFileDTO
)
{
String
faceBase64
=
fileService
.
downLoadBase64
(
faceFileDTO
.
getFileSystemId
());
selfPersonInfo
.
setFacePicBase64
(
faceBase64
);
}
if
(
null
!=
nationFileDTO
)
{
String
nationBase64
=
fileService
.
downLoadBase64
(
nationFileDTO
.
getFileSystemId
());
selfPersonInfo
.
setNationalEmblemPicBase64
(
nationBase64
);
}
selfPersonInfo
.
setCertNumber
(
rnrInfo
.
getCertNumber
());
selfPersonInfo
.
setFullName
(
rnrInfo
.
getFullName
());
selfPersonInfo
.
setExpiredDate
(
rnrInfo
.
getExpiredDate
());
selfPersonInfo
.
setGender
(
rnrInfo
.
getGender
());
//委托人信息
RnrRequestDTO
.
RnrPersonInfo
trustInfo
=
null
;
if
(
isTrust
)
{
trustInfo
=
new
RnrRequestDTO
.
RnrPersonInfo
();
trustInfo
.
setPersonId
(
liaisonInfoDTO
.
getUuid
());
trustInfo
.
setIsIdentityCard
(
CertTypeEnum
.
IDCARD
.
getCode
().
equals
(
liaisonInfoDTO
.
getLiaisonCertType
()));
//委托人身份证人像面
MgRnrFileDTO
trustFaceFileDTO
=
trustInfoFileMap
.
get
(
RnrFileType
.
IDENTITY_CARD_BACK
.
getCode
());
//委托人身份证国徽面
MgRnrFileDTO
trustNationFileDTO
=
trustInfoFileMap
.
get
(
RnrFileType
.
IDENTITY_CARD_FRONT
.
getCode
());
if
(
null
!=
trustFaceFileDTO
)
{
String
faceBase64
=
fileService
.
downLoadBase64
(
trustFaceFileDTO
.
getFileSystemId
());
trustInfo
.
setFacePicBase64
(
faceBase64
);
}
if
(
null
!=
trustNationFileDTO
)
{
String
nationBase64
=
fileService
.
downLoadBase64
(
trustNationFileDTO
.
getFileSystemId
());
trustInfo
.
setNationalEmblemPicBase64
(
nationBase64
);
}
trustInfo
.
setCertNumber
(
liaisonInfoDTO
.
getLiaisonCertNumber
());
trustInfo
.
setFullName
(
liaisonInfoDTO
.
getLiaisonName
());
trustInfo
.
setExpiredDate
(
liaisonInfoDTO
.
getLiaisonExpiredDate
());
trustInfo
.
setGender
(
liaisonInfoDTO
.
getLiaisonGender
());
}
if
(!
isTrust
)
{
rnrRequestDTO
.
setMatchVideoPerosinInfo
(
selfPersonInfo
);
}
else
{
rnrRequestDTO
.
setMatchVideoPerosinInfo
(
trustInfo
);
rnrRequestDTO
.
setPeorsonList
(
Collections
.
singletonList
(
selfPersonInfo
));
}
return
rnrRequestDTO
;
}
private
void
processRnrResult
(
RnrOrderDTO
rnrOrderDTO
,
Boolean
success
,
RnrOrderStatusEnum
orderStatusEnum
,
String
userId
,
String
msg
)
{
String
rnrId
=
rnrOrderDTO
.
getRnrId
();
//更新工单信息
RnrOrderDTO
orderUpdate
=
new
RnrOrderDTO
();
orderUpdate
.
setUuid
(
rnrOrderDTO
.
getUuid
());
orderUpdate
.
setOrderStatus
(
orderStatusEnum
.
getCode
());
if
(
StringUtils
.
isNotEmpty
(
msg
)){
orderUpdate
.
setComment
(
msg
);
}
orderUpdate
.
setComment
(
msg
);
orderClient
.
update
(
orderUpdate
);
//更新实名信息
if
(
success
)
{
MgRnrInfoDTO
rnrInfoUpdate
=
new
MgRnrInfoDTO
();
rnrInfoUpdate
.
setUuid
(
rnrId
);
rnrInfoUpdate
.
setRnrStatus
(
RnrStatus
.
RNR
.
getCode
());
if
(
StringUtils
.
isNotBlank
(
userId
))
{
rnrInfoUpdate
.
setUserId
(
userId
);
}
rnrInfoClient
.
update
(
rnrInfoUpdate
);
//更新卡信息
MgRnrCardInfoDTO
cardUpdate
=
new
MgRnrCardInfoDTO
();
cardUpdate
.
setRnrId
(
rnrId
);
cardUpdate
.
setRnrStatus
(
RnrStatus
.
RNR
.
getCode
());
mgRnrCardInfoClient
.
updateCardStatusByRnrId
(
cardUpdate
);
try
{
MgRnrCardInfoDTO
noticeDto
=
new
MgRnrCardInfoDTO
();
noticeDto
.
setOrderId
(
rnrOrderDTO
.
getUuid
());
Response
response
=
mgRnrCardInfoClient
.
sendCardNotice
(
noticeDto
);
log
.
info
(
"H5实名成功 发送卡通知 dto = {} response = {}"
,
JSONObject
.
toJSONString
(
rnrOrderDTO
),
JSONObject
.
toJSONString
(
response
));
}
catch
(
Exception
e
)
{
log
.
error
(
"H5实名成功 发送卡通知 错误 dto = {}"
,
JSONObject
.
toJSONString
(
rnrOrderDTO
),
e
);
}
}
}
private
void
recordRnrResultLog
(
RnrRequestDTO
rnrRequestDTO
,
AuthWayTypeEnum
authWayTypeEnum
,
String
authResult
,
String
authResultMsg
,
Integer
subjectType
)
{
try
{
MgRnrAuthenticationResultDTO
dto
=
new
MgRnrAuthenticationResultDTO
();
dto
.
setRnrId
(
rnrRequestDTO
.
getBizUuid
());
dto
.
setOrderId
(
rnrRequestDTO
.
getSerialNumber
());
dto
.
setAuthWayType
(
authWayTypeEnum
.
getCode
());
dto
.
setTenantNo
(
rnrRequestDTO
.
getTenantNo
());
dto
.
setAuthResult
(
authResult
);
dto
.
setAuthResultMsg
(
authResultMsg
);
dto
.
setSubjectType
(
subjectType
);
Response
response
=
authenticationResultClient
.
add
(
dto
);
log
.
info
(
"recordRnrResultLog | request = {},response = {}"
,
JSONObject
.
toJSONString
(
dto
),
JSONObject
.
toJSONString
(
response
));
}
catch
(
Exception
e
)
{
log
.
error
(
"recordRnrResultLog has error,rnrId = {},orderId = {},authWayTypeEnum = {},authResult = {},"
+
"authResultMsg = {}"
,
rnrRequestDTO
.
getBizUuid
(),
rnrRequestDTO
.
getSerialNumber
(),
authWayTypeEnum
.
getName
(),
authResult
,
authResultMsg
);
}
}
/**
* h5验证身份证信息
*
* @param dto
* @return
*/
@Override
public
Response
<
RnrResponseDTO
>
h5ValidationOCR
(
H5ValidationOCRReqDTO
dto
)
{
RnrResponseDTO
returnBean
=
new
RnrResponseDTO
();
List
<
RnrResponseDTO
.
OcrResultInfo
>
ocrResultInfoList
=
new
ArrayList
<>();
Integer
subjectType
=
1
;
RnrRequestDTO
rnrRequestDTO
=
new
RnrRequestDTO
();
rnrRequestDTO
.
setTenantNo
(
dto
.
getTenantNo
());
rnrRequestDTO
.
setBizUuid
(
dto
.
getBizUuid
());
rnrRequestDTO
.
setSerialNumber
(
dto
.
getSerialNumber
());
String
facePicBase64
=
fileService
.
downLoadBase64
(
dto
.
getFacePicBase64
());
String
nationalEmblemPicBase64
=
fileService
.
downLoadBase64
(
dto
.
getNationalEmblemPicBase64
());
RnrRequestDTO
.
RnrPersonInfo
personInfo
=
new
RnrRequestDTO
.
RnrPersonInfo
();
personInfo
.
setPersonId
(
dto
.
getPersonId
());
personInfo
.
setIsIdentityCard
(
dto
.
getIsIdentityCard
());
personInfo
.
setFacePicBase64
(
facePicBase64
);
personInfo
.
setNationalEmblemPicBase64
(
nationalEmblemPicBase64
);
personInfo
.
setCertNumber
(
dto
.
getCertNumber
());
personInfo
.
setFullName
(
dto
.
getFullName
());
personInfo
.
setExpiredDate
(
dto
.
getExpiredDateStr
());
personInfo
.
setGender
(
dto
.
getGender
());
List
<
RnrRequestDTO
.
RnrPersonInfo
>
peorsonList
=
new
ArrayList
<>();
peorsonList
.
add
(
personInfo
);
rnrRequestDTO
.
setPeorsonList
(
peorsonList
);
//人脸ocr
Future
<
Response
<
OcrNpRespDTO
>>
faceOcrResult
=
doOcr
(
rnrRequestDTO
,
personInfo
.
getFacePicBase64
());
//国徽ocr
Future
<
Response
<
OcrNpRespDTO
>>
nationOcrResult
=
doOcr
(
rnrRequestDTO
,
personInfo
.
getNationalEmblemPicBase64
());
//身份信息核查
Future
<
Boolean
>
certCheckResult
=
doCertCheck
(
rnrRequestDTO
,
personInfo
.
getFullName
(),
personInfo
.
getCertNumber
());
try
{
RnrResponseDTO
.
OcrResultInfo
personOcrResult
=
processOcrResult
(
rnrRequestDTO
,
personInfo
,
faceOcrResult
.
get
(
5
,
TimeUnit
.
SECONDS
),
nationOcrResult
.
get
(
5
,
TimeUnit
.
SECONDS
),
subjectType
);
Boolean
certCheck
=
certCheckResult
.
get
(
5
,
TimeUnit
.
SECONDS
);
if
(
certCheck
)
{
recordRnrResultLog
(
rnrRequestDTO
,
AuthWayTypeEnum
.
CERT_CHECK
,
"1"
,
"身份信息核查成功"
,
subjectType
);
}
else
{
recordRnrResultLog
(
rnrRequestDTO
,
AuthWayTypeEnum
.
CERT_CHECK
,
"2"
,
"身份信息核查失败"
,
subjectType
);
}
personOcrResult
.
setCertCheckResult
(
certCheck
);
ocrResultInfoList
.
add
(
personOcrResult
);
}
catch
(
Exception
e
)
{
log
.
error
(
"h5ValidationOCR has error,fullName = {},certNumber = {}"
,
personInfo
.
getFullName
(),
personInfo
.
getCertNumber
(),
e
);
}
returnBean
.
setPersonListOcrResult
(
ocrResultInfoList
);
return
Response
.
createSuccess
(
returnBean
);
}
@Override
public
Response
updateRnrInValid
(
RnrOrderDTO
bean
)
{
if
(
CuscStringUtils
.
isEmpty
(
bean
.
getUuid
()))
{
return
Response
.
createError
(
"工单id不能为空"
);
}
Response
<
RnrOrderDTO
>
orderResp
=
orderClient
.
getByUuid
(
bean
);
if
(!
orderResp
.
isSuccess
())
{
return
Response
.
createError
(
orderResp
.
getMsg
(),
orderResp
.
getCode
());
}
if
(
orderResp
.
getData
()
==
null
)
{
return
Response
.
createError
(
"未查询到实名工单信息"
);
}
updateInValid
(
orderResp
.
getData
().
getRnrId
(),
orderResp
.
getData
().
getUuid
(),
""
);
return
Response
.
createSuccess
();
}
/**
* 获取H5活体检测URL
*
* @param dto
* @return
*/
@Override
public
Response
<
LivenessResultDTO
>
h5LivenessResult
(
LiveLoginReqDTO
dto
)
{
return
cloudService
.
postForResponse
(
CloudMethod
.
GET_LIVENESSRESULT
,
dto
,
LivenessResultDTO
.
class
);
}
//--------------------私有方法区域--------------
/**
* Description: 自然人实名结果
* <br />
* CreateDate 2022-06-23 20:03:01
**/
private
RnrReturnDTO
personRnrResult
(
MgRnrInfoDTO
rnrInfo
,
RnrResponseDTO
rnrResponse
)
{
RnrReturnDTO
rnrReturnDTO
=
new
RnrReturnDTO
();
log
.
info
(
"personH5CallBack personRnrToArtificial : {}"
,
JSONObject
.
toJSONString
(
rnrResponse
));
if
(
rnrInfo
.
getIsSecondHandCar
()
==
0
&&
CertTypeEnum
.
IDCARD
.
getCode
().
equals
(
rnrInfo
.
getCertType
()))
{
if
(
rnrResponse
.
getVideoPerosonOcResult
()
!=
null
&&
!
Boolean
.
TRUE
.
equals
(
rnrResponse
.
getVideoPerosonOcResult
().
getOcrResult
()))
{
rnrReturnDTO
.
setPersonRnrResultMsg
(
"ocr比对失败,请核验姓名、证件号、有效期、性别是否正确"
);
return
rnrReturnDTO
;
}
if
(!
CollectionUtils
.
isEmpty
(
rnrResponse
.
getPersonListOcrResult
()))
{
log
.
info
(
"personH5CallBack ocr : {}"
,
JSONObject
.
toJSONString
(
rnrResponse
.
getPersonListOcrResult
()));
for
(
RnrResponseDTO
.
OcrResultInfo
ori
:
rnrResponse
.
getPersonListOcrResult
())
{
if
(
ori
.
getOcrResult
()
==
null
||
!
ori
.
getOcrResult
())
{
List
<
String
>
ocrFailMsg
=
ori
.
getOcrFailMsg
();
if
(
CollectionUtils
.
isEmpty
(
ocrFailMsg
)){
rnrReturnDTO
.
setPersonRnrResultMsg
(
"ocr比对失败,请核验姓名、证件号、有效期、性别是否正确"
);
}
else
{
rnrReturnDTO
.
setPersonRnrResultMsg
(
String
.
join
(
","
,
ocrFailMsg
));
}
return
rnrReturnDTO
;
}
}
}
if
(
rnrResponse
.
getIdCompareResult
()
==
null
||
!
rnrResponse
.
getIdCompareResult
())
{
rnrReturnDTO
.
setPersonH5CallBackMsg
(
rnrResponse
.
getIdCompareFailMsg
());
return
rnrReturnDTO
;
}
if
(
rnrResponse
.
getFaceCompareResult
()
==
null
||
!
rnrResponse
.
getFaceCompareResult
())
{
rnrReturnDTO
.
setPersonH5CallBackMsg
(
rnrResponse
.
getFaceCompareFailMsg
());
return
rnrReturnDTO
;
}
}
return
null
;
}
/**
* Description: 是否转人工 true 转人工 false 不转人工
* <br />
* CreateDate 2022-06-23 20:03:01
**/
private
boolean
toArtificialOrder
(
String
key
)
{
try
{
Integer
rnrErrorCount
=
cacheFactory
.
ExpireString
()
.
getValue
(
RedisConstant
.
PERSON_RNR_ERROR_COUNT_THRESHOLD
+
key
,
Integer
.
class
);
if
(
rnrErrorCount
==
null
)
{
rnrErrorCount
=
0
;
}
if
(
rnrFpConfig
.
getPersonErrorCount
().
intValue
()
>
rnrErrorCount
.
intValue
())
{
return
false
;
}
}
catch
(
CacheException
e
)
{
log
.
error
(
"toArtificialOrder error "
,
e
);
}
return
true
;
}
/**
* Description: 设置自然人实名错误次数
* <br />
* CreateDate 2022-06-23 20:03:01
**/
private
void
setPersonRnrErrorCount
(
String
key
)
{
try
{
Integer
rnrErrorCount
=
cacheFactory
.
ExpireString
()
.
getValue
(
RedisConstant
.
PERSON_RNR_ERROR_COUNT_THRESHOLD
+
key
,
Integer
.
class
);
if
(
rnrErrorCount
==
null
)
{
rnrErrorCount
=
0
;
}
rnrErrorCount
=
rnrErrorCount
+
1
;
cacheFactory
.
ExpireString
()
.
setExpireValue
(
RedisConstant
.
PERSON_RNR_ERROR_COUNT_THRESHOLD
+
key
,
rnrErrorCount
,
RedisConstant
.
PERSON_RNR_ERROR_COUNT_THRESHOLD_EXPIRE
);
}
catch
(
CacheException
e
)
{
log
.
error
(
"setPersonRnrErrorCount error "
,
e
);
}
}
/**
* Description: 修改实名信息未无效
* <br />
* CreateDate 2022-06-25 15:07:53
**/
private
void
updateInValid
(
String
rnrId
,
String
orderUuid
,
String
msg
)
{
MgRnrInfoDTO
rnrInfoUpdate
=
new
MgRnrInfoDTO
();
rnrInfoUpdate
.
setUuid
(
rnrId
);
rnrInfoUpdate
.
setRnrStatus
(
RnrStatus
.
RNR_FAIL
.
getCode
());
rnrInfoClient
.
update
(
rnrInfoUpdate
);
RnrOrderDTO
orderUpdate
=
new
RnrOrderDTO
();
orderUpdate
.
setUuid
(
orderUuid
);
orderUpdate
.
setOrderStatus
(
RnrOrderStatusEnum
.
CANCEL
.
getCode
());
if
(
StringUtils
.
isNotEmpty
(
msg
))
{
orderUpdate
.
setComment
(
msg
);
}
orderClient
.
update
(
orderUpdate
);
MgRnrCardInfoDTO
cardUpdate
=
new
MgRnrCardInfoDTO
();
cardUpdate
.
setRnrId
(
rnrId
);
cardUpdate
.
setRnrStatus
(
RnrStatus
.
RNR_FAIL
.
getCode
());
mgRnrCardInfoClient
.
updateCardStatusByRnrId
(
cardUpdate
);
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/RnrUnbindServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.fp.common.RnrResultEnum
;
import
com.cusc.nirvana.user.rnr.fp.common.util.DateUtil
;
import
com.cusc.nirvana.user.rnr.fp.dto.RnrRequestDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.RnrResponseDTO
;
import
com.cusc.nirvana.user.rnr.fp.service.IRnrService
;
import
com.cusc.nirvana.user.rnr.fp.service.IRnrUnbindService
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCardInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrUnboundClient
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrFileType
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderAuditTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderStatusEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrStatus
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrFileDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrRelationDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.UUID
;
/**
* 实名解绑实现类
*
* @author yubo
* @since 2022-04-25 09:45
*/
@Service
public
class
RnrUnbindServiceImpl
implements
IRnrUnbindService
{
@Autowired
IRnrService
rnrService
;
@Autowired
MgRnrUnboundClient
mgRnrUnboundClient
;
@Autowired
MgRnrCardInfoClient
cardInfoClient
;
@Value
(
"${rnr.mock:false}"
)
private
boolean
mock
;
/**
* 二手车现车主解绑-自然人
*/
@Override
public
Integer
secondHandPersonalUnbind
(
String
serialNumber
,
String
requestId
,
RnrRelationDTO
dto
)
{
// boolean result = rnrService.checkPersonData(serialNumber, requestId, dto);
//判断卡是否已经实名
iccidListCheck
(
dto
);
RnrRequestDTO
rnrRequest
=
rnrService
.
rnrPersonRelationDto2RnrRequestDTO
(
dto
);
rnrRequest
.
setBizUuid
(
dto
.
getInfo
().
getUuid
());
rnrRequest
.
setSerialNumber
(
dto
.
getOrder
().
getUuid
());
rnrRequest
.
setRequestId
(
requestId
);
RnrResponseDTO
rnrResponseDTO
=
rnrService
.
doPersonRnr
(
rnrRequest
,
null
);
//添加活体图片1
MgRnrFileDTO
livenessPic1
=
new
MgRnrFileDTO
();
livenessPic1
.
setUuid
(
CuscStringUtils
.
generateUuid
());
livenessPic1
.
setRnrId
(
dto
.
getInfo
().
getUuid
());
livenessPic1
.
setLiaisonId
(
rnrRequest
.
getMatchVideoPerosinInfo
().
getPersonId
());
livenessPic1
.
setFileSystemId
(
rnrResponseDTO
.
getLivenessPic1
());
livenessPic1
.
setFileType
(
RnrFileType
.
LIVENESS_SCREEN_FIRST
.
getCode
());
livenessPic1
.
setCreator
(
dto
.
getInfo
().
getCreator
());
dto
.
getRnrFileList
().
add
(
livenessPic1
);
//添加活体图片1
MgRnrFileDTO
livenessPic2
=
new
MgRnrFileDTO
();
livenessPic2
.
setUuid
(
CuscStringUtils
.
generateUuid
());
livenessPic2
.
setRnrId
(
dto
.
getInfo
().
getUuid
());
livenessPic2
.
setLiaisonId
(
rnrRequest
.
getMatchVideoPerosinInfo
().
getPersonId
());
livenessPic2
.
setFileSystemId
(
rnrResponseDTO
.
getLivenessPic2
());
livenessPic2
.
setFileType
(
RnrFileType
.
LIVENESS_SCREEN_TWO
.
getCode
());
livenessPic2
.
setCreator
(
dto
.
getInfo
().
getCreator
());
dto
.
getRnrFileList
().
add
(
livenessPic2
);
//二手车解绑,直接走人工审核
dto
.
getOrder
().
setAuditType
(
RnrOrderAuditTypeEnum
.
MANUAL
.
getCode
());
dto
.
getOrder
().
setOrderStatus
(
RnrOrderStatusEnum
.
ASSIGNMENT
.
getCode
());
dto
.
getInfo
().
setRnrStatus
(
RnrStatus
.
INIT
.
getCode
());
dto
.
getCardList
().
forEach
(
card
->
card
.
setRnrStatus
(
RnrStatus
.
INIT
.
getCode
()));
Response
response
=
mgRnrUnboundClient
.
secondHandUnBound
(
dto
);
if
(!
response
.
isSuccess
())
{
throw
new
CuscUserException
(
response
.
getCode
(),
response
.
getMsg
());
}
return
RnrResultEnum
.
REVIEW
.
getCode
();
}
private
void
iccidListCheck
(
RnrRelationDTO
dto
)
{
List
<
MgRnrCardInfoDTO
>
cardList
=
dto
.
getCardList
();
//检查车和卡是否已经实名了
for
(
MgRnrCardInfoDTO
mgRnrCardInfoDTO
:
cardList
)
{
Response
<
MgRnrCardInfoDTO
>
oneByIccid
=
cardInfoClient
.
getOneByIccid
(
mgRnrCardInfoDTO
);
if
(!
oneByIccid
.
isSuccess
()
||
oneByIccid
.
getData
()
==
null
)
{
throw
new
CuscUserException
(
""
,
"车【"
+
mgRnrCardInfoDTO
.
getIotId
()
+
"】和卡【"
+
mgRnrCardInfoDTO
.
getIccid
()
+
"】未绑定"
);
}
}
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/ShortMessageCheckServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.cache.CacheFactory
;
import
com.cache.exception.CacheException
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.common.config.SmsPropertyConfig
;
import
com.cusc.nirvana.user.rnr.fp.common.config.SmsTemplateConfig
;
import
com.cusc.nirvana.user.rnr.fp.constants.RedisConstant
;
import
com.cusc.nirvana.user.rnr.fp.dto.SmsRequestDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.SmsResponseDTO
;
import
com.cusc.nirvana.user.rnr.fp.service.ISmsService
;
import
com.cusc.nirvana.user.rnr.fp.service.ShortMessageCheckService
;
import
com.cusc.nirvana.user.util.CuscRandomUtils
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
@Service
@Slf4j
@RefreshScope
public
class
ShortMessageCheckServiceImpl
implements
ShortMessageCheckService
{
@Value
(
"${fp.sms.captcha.expire:1800}"
)
private
int
captchaExpire
;
@Value
(
"${fp.sms.captcha.interval:60}"
)
private
int
captchaIntervalExpire
;
@Resource
private
CacheFactory
cacheFactory
;
@Autowired
private
ISmsService
smsService
;
@Autowired
private
SmsTemplateConfig
templateConfig
;
@Autowired
private
SmsPropertyConfig
smsPropertyConfig
;
@Override
public
Response
<
SmsResponseDTO
>
sendSmsCaptcha
(
SmsRequestDTO
bean
)
{
String
smsCaptcha
;
//String intervalKey = getIntervalKey(bean);
try
{
//判断当前验证码是否达到发送间隔 60s
/*if (cacheFactory.getExpireStringService().containsKey(intervalKey)) {
return Response.createError(ResponseCode.SMS_CAPTCHA_INTERVAL_FAIL.getMsg(),
ResponseCode.SMS_CAPTCHA_INTERVAL_FAIL.getCode());
}*/
//创建随机验证
smsCaptcha
=
CuscRandomUtils
.
randomNumeric
(
6
);
//获取短信模板
String
template
=
templateConfig
.
getSmsTemplates
().
get
(
bean
.
getBizType
());
if
(
StringUtils
.
isBlank
(
template
))
{
return
Response
.
createError
(
ResponseCode
.
SMS_TEMPLATE_NULL
.
getMsg
(),
ResponseCode
.
SMS_TEMPLATE_NULL
.
getCode
());
}
// smsConfig.setIntervalLimitKey(RedisConstant.SMS_CAPTCHA_SEND_INTERVAL_KEY);
//发送短信
Response
<
SmsResponseDTO
>
response
=
smsService
.
sendSms
(
bean
.
getPhone
(),
smsCaptcha
,
template
);
if
(
response
.
isSuccess
()
&&
response
.
getData
()
!=
null
)
{
//放到redis
//cacheFactory.getExpireStringService().setExpireValue(intervalKey, smsCaptcha, captchaIntervalExpire);
String
smsKey
=
getSmsKey
(
bean
);
cacheFactory
.
getExpireStringService
().
setExpireValue
(
smsKey
,
smsCaptcha
,
captchaExpire
);
}
return
response
;
}
catch
(
CacheException
e
)
{
log
.
error
(
"sendSmsCaptcha 存放reids失败:"
,
e
);
return
Response
.
createError
(
ResponseCode
.
SMS_CREATE_CAPTCHA_FAIL
.
getMsg
(),
ResponseCode
.
SMS_CREATE_CAPTCHA_FAIL
.
getCode
());
}
}
//发送短信
@Override
public
Response
<
SmsResponseDTO
>
sendUnbindSms
(
SmsRequestDTO
bean
,
String
rnrId
,
String
iccids
)
{
log
.
info
(
"换卡/解绑短信发送入参:{}"
,
JSON
.
toJSONString
(
bean
));
Response
<
SmsResponseDTO
>
response
=
sendSms
(
bean
);
log
.
info
(
"换卡/解绑短信发送出参:{}"
,
JSON
.
toJSONString
(
response
));
return
response
;
}
@Override
public
Response
<
SmsResponseDTO
>
sendSms
(
SmsRequestDTO
bean
)
{
//获取短信模板
String
template
=
templateConfig
.
getSmsTemplates
().
get
(
bean
.
getBizType
());
if
(
StringUtils
.
isBlank
(
template
))
{
return
Response
.
createError
(
ResponseCode
.
SMS_TEMPLATE_NULL
.
getMsg
(),
ResponseCode
.
SMS_TEMPLATE_NULL
.
getCode
());
}
return
smsService
.
sendSms
(
bean
.
getPhone
(),
bean
.
getParams
(),
template
);
}
@Override
public
Response
checkSmsCaptcha
(
SmsRequestDTO
bean
)
{
String
smsCaptcha
;
try
{
String
key
=
getSmsKey
(
bean
);
smsCaptcha
=
cacheFactory
.
getExpireStringService
().
getValue
(
key
,
String
.
class
);
if
(
CuscStringUtils
.
isEmpty
(
smsCaptcha
)
||
!
smsCaptcha
.
equals
(
bean
.
getCaptcha
()))
{
checkSmsCaptchaErrorCount
(
bean
);
return
Response
.
createError
(
ResponseCode
.
SMS_CAPTCHA_INVALID
.
getMsg
(),
ResponseCode
.
SMS_CAPTCHA_INVALID
.
getCode
()
+
""
);
}
//验证成功之后清理验证码
cacheFactory
.
getExpireStringService
().
delete
(
key
);
cacheFactory
.
getExpireStringService
().
delete
(
RedisConstant
.
SMS_CAPTCHA_ERROR_COUNT_KEY
+
bean
.
getPhone
()
+
"_"
+
bean
.
getTenantNo
()
+
"_"
+
bean
.
getBizType
());
}
catch
(
CacheException
e
)
{
log
.
error
(
"checkSmsCaptcha 获取reids失败 :"
,
e
);
return
Response
.
createError
(
ResponseCode
.
SMS_GET_CAPTCHA_FAIL
.
getMsg
(),
ResponseCode
.
SMS_GET_CAPTCHA_FAIL
.
getCode
());
}
return
Response
.
createSuccess
(
true
);
}
//----------------------私有方法区---------
/**
* 短信间隔key
*
* @param bean
* @return
*/
private
String
getIntervalKey
(
SmsRequestDTO
bean
)
{
return
RedisConstant
.
SMS_RNR_CAPTCHA_SEND_INTERVAL_KEY
+
bean
.
getPhone
()
+
"_"
+
bean
.
getTenantNo
()
+
"_"
+
bean
.
getBizType
();
}
/**
* 短信间隔key
*
* @param bean
* @return
*/
private
String
getSmsKey
(
SmsRequestDTO
bean
)
{
return
RedisConstant
.
SMS_CAPTCHA_KEY
+
bean
.
getPhone
()
+
"_"
+
bean
.
getTenantNo
()
+
"_"
+
bean
.
getBizType
();
}
/**
* Description: 检查短信验证码验证错误次数
* <br />
* CreateDate 2022-07-08 19:41:51
*
* @author yuyi
**/
private
void
checkSmsCaptchaErrorCount
(
SmsRequestDTO
bean
)
{
Integer
errorCount
;
try
{
String
redisKey
=
RedisConstant
.
SMS_CAPTCHA_ERROR_COUNT_KEY
+
bean
.
getPhone
()
+
"_"
+
bean
.
getTenantNo
()
+
"_"
+
bean
.
getBizType
();
errorCount
=
cacheFactory
.
getExpireStringService
().
getValue
(
redisKey
,
Integer
.
class
);
if
(
errorCount
==
null
)
{
errorCount
=
0
;
}
errorCount
++;
if
(
errorCount
.
intValue
()
>
smsPropertyConfig
.
errorCount
.
intValue
())
{
//超过错误次数之后清理验证码
cacheFactory
.
getExpireStringService
().
delete
(
getSmsKey
(
bean
));
cacheFactory
.
getExpireStringService
().
delete
(
redisKey
);
return
;
}
cacheFactory
.
getExpireStringService
()
.
setExpireValue
(
redisKey
,
errorCount
,
RedisConstant
.
SMS_CAPTCHA_ERROR_COUNT_EXPIRE
);
}
catch
(
CacheException
e
)
{
log
.
error
(
"checkSmsCaptchaErrorCount 检查短信验证码验证错误次数 访问redis异常:"
,
e
);
}
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/SimVehicleRelServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.cusc.nirvana.common.result.PageResult
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.fp.dto.SimVehicleBindingDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.SimVehicleBindingResult
;
import
com.cusc.nirvana.user.rnr.fp.dto.SimVehicleDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.*
;
import
com.cusc.nirvana.user.rnr.fp.service.ISimVehicleRelService
;
import
com.cusc.nirvana.user.rnr.mg.client.OrgSimRelClient
;
import
com.cusc.nirvana.user.rnr.mg.constants.BindingStatus
;
import
com.cusc.nirvana.user.rnr.mg.dto.*
;
import
lombok.extern.slf4j.Slf4j
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.servlet.support.BindStatus
;
import
java.util.ArrayList
;
import
java.util.List
;
@Service
@Slf4j
public
class
SimVehicleRelServiceImpl
implements
ISimVehicleRelService
{
private
final
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SimVehicleRelServiceImpl
.
class
);
@Autowired
private
OrgSimRelClient
orgSimRelClient
;
@Override
public
Response
<
SimVehicleBindingResult
>
importSimVehicle
(
SimVehicleBindingDTO
bindingDTO
)
{
String
tagUuid
=
bindingDTO
.
getTagUuid
();
// SIM卡列表信息
List
<
OrgSimRelDTO
>
list
=
new
ArrayList
<>();
bindingDTO
.
getBindingList
().
forEach
(
simVehicleDTO
->
{
OrgSimRelDTO
orgSimRelDTO
=
simVehicleDTOToOrgSimRelDto
(
simVehicleDTO
);
orgSimRelDTO
.
setOrgUuid
(
bindingDTO
.
getOrganizationId
());
orgSimRelDTO
.
setBindStatus
(
0
);
orgSimRelDTO
.
setTagUuid
(
tagUuid
);
orgSimRelDTO
.
setCompanyCode
(
bindingDTO
.
getCompanyCode
());
list
.
add
(
orgSimRelDTO
);
});
OrgSimRelBatchDTO
batchDTO
=
new
OrgSimRelBatchDTO
();
batchDTO
.
setOrgSimRels
(
list
);
Response
response
=
orgSimRelClient
.
addBatch
(
batchDTO
);
if
(
response
.
isSuccess
())
{
SimVehicleBindingResult
simVehicleBindingResult
=
new
SimVehicleBindingResult
();
simVehicleBindingResult
.
setFailCount
(
0
);
simVehicleBindingResult
.
setSuccessCount
(
bindingDTO
.
getBindingList
().
size
());
simVehicleBindingResult
.
setFailData
(
new
ArrayList
<>());
return
Response
.
createSuccess
(
simVehicleBindingResult
);
}
else
{
SimVehicleBindingResult
simVehicleBindingResult
=
new
SimVehicleBindingResult
();
int
size
=
bindingDTO
.
getBindingList
().
size
();
simVehicleBindingResult
.
setFailCount
(
size
);
simVehicleBindingResult
.
setSuccessCount
(
size
);
simVehicleBindingResult
.
setFailData
(
bindingDTO
.
getBindingList
());
return
Response
.
createError
(
"导入车卡关系失败"
);
}
}
@Override
public
Response
<
SimVehicleDTO
>
unbind
(
BindRequestDTO
requestDTO
)
{
return
updateBindStatus
(
requestDTO
,
1
);
}
@Override
public
Response
<
SimVehicleDTO
>
bind
(
BindRequestDTO
requestDTO
)
{
return
updateBindStatus
(
requestDTO
,
0
);
}
private
Response
<
SimVehicleDTO
>
updateBindStatus
(
BindRequestDTO
requestDTO
,
Integer
bindStatus
)
{
OrgSimRelBindStatusDTO
bindStatusDTO
=
new
OrgSimRelBindStatusDTO
();
bindStatusDTO
.
setIccid
(
requestDTO
.
getIccid
());
bindStatusDTO
.
setVin
(
requestDTO
.
getVin
());
bindStatusDTO
.
setBindStatus
(
bindStatus
);
Response
response
=
orgSimRelClient
.
updateBindStatus
(
bindStatusDTO
);
if
(
response
.
isSuccess
())
{
Response
<
OrgSimRelDTO
>
orgSimRelDTOResponse
=
orgSimRelClient
.
getByIccid
(
requestDTO
.
getIccid
());
SimVehicleDTO
simVehicleDTO
=
null
;
if
(
orgSimRelDTOResponse
.
isSuccess
())
{
simVehicleDTO
=
orgSimRelDtoToSimVehicleDto
(
orgSimRelDTOResponse
.
getData
());
return
Response
.
createSuccess
(
simVehicleDTO
);
}
else
{
return
Response
.
createSuccess
(
simVehicleDTO
);
}
}
return
Response
.
createError
(
"更新车卡绑定状态失败"
);
}
@Override
public
Response
<
List
<
VinIccidDTO
>>
getIccidByVin
(
String
vin
)
{
OrgSimRelVinQueryDTO
queryDTO
=
new
OrgSimRelVinQueryDTO
();
queryDTO
.
setVin
(
vin
);
Response
<
List
<
OrgSimRelDTO
>>
response
=
orgSimRelClient
.
queryByVin
(
queryDTO
);
List
<
VinIccidDTO
>
vinIccidDTOS
=
new
ArrayList
<>();
if
(
response
.
isSuccess
()
&&
!
CollectionUtils
.
isEmpty
(
response
.
getData
()))
{
response
.
getData
().
forEach
(
orgSimRelDTO
->
{
VinIccidDTO
vinIccidDTO
=
new
VinIccidDTO
();
BeanUtils
.
copyProperties
(
orgSimRelDTO
,
vinIccidDTO
);
vinIccidDTOS
.
add
(
vinIccidDTO
);
});
}
return
Response
.
createSuccess
(
vinIccidDTOS
);
}
@Override
public
Response
<
VinIccidDTO
>
getVinByIccid
(
String
iccid
)
{
Response
<
OrgSimRelDTO
>
response
=
orgSimRelClient
.
getByIccid
(
iccid
);
if
(
response
.
isSuccess
())
{
if
(
response
.
getData
()
!=
null
)
{
VinIccidDTO
vinIccidDTO
=
new
VinIccidDTO
();
BeanUtils
.
copyProperties
(
response
.
getData
(),
vinIccidDTO
);
return
Response
.
createSuccess
(
vinIccidDTO
);
}
else
{
return
Response
.
createSuccess
();
}
}
else
{
return
Response
.
createError
(
response
.
getMsg
());
}
}
@Override
public
Response
<
VinIccidDTO
>
getBindingInfo
(
String
iccid
,
String
vin
)
{
Response
<
OrgSimRelDTO
>
response
=
orgSimRelClient
.
getByIccid
(
iccid
);
if
(
response
.
isSuccess
())
{
if
(
response
.
getData
()
!=
null
&&
response
.
getData
().
getBindStatus
()
==
0
)
{
VinIccidDTO
vinIccidDTO
=
new
VinIccidDTO
();
BeanUtils
.
copyProperties
(
response
.
getData
(),
vinIccidDTO
);
return
Response
.
createSuccess
(
vinIccidDTO
);
}
return
Response
.
createSuccess
();
}
else
{
return
Response
.
createError
(
response
.
getMsg
());
}
}
@Override
public
Response
<
List
<
IccidDetailDTO
>>
queryByIccids
(
IccidListDTO
listDTO
)
{
IccIdListRequestDTO
requestDTO
=
new
IccIdListRequestDTO
();
requestDTO
.
setIccids
(
listDTO
.
getIccidList
());
Response
<
List
<
OrgSimRelDTO
>>
response
=
orgSimRelClient
.
queryByList
(
requestDTO
);
if
(
response
.
isSuccess
())
{
List
<
IccidDetailDTO
>
iccidDetailDTOS
=
new
ArrayList
<>();
response
.
getData
().
forEach
(
orgSimRelDTO
->
{
IccidDetailDTO
iccidDetailDTO
=
new
IccidDetailDTO
();
BeanUtils
.
copyProperties
(
orgSimRelDTO
,
iccidDetailDTO
);
iccidDetailDTOS
.
add
(
iccidDetailDTO
);
});
return
Response
.
createSuccess
(
iccidDetailDTOS
);
}
else
{
return
Response
.
createError
(
response
.
getMsg
());
}
}
@Override
public
Response
<
IccidDetailDTO
>
getDetailByIccid
(
String
iccid
)
{
List
<
String
>
iccids
=
new
ArrayList
<>();
iccids
.
add
(
iccid
);
IccidListDTO
listDTO
=
new
IccidListDTO
();
listDTO
.
setIccidList
(
iccids
);
Response
<
List
<
IccidDetailDTO
>>
response
=
queryByIccids
(
listDTO
);
if
(
response
.
isSuccess
()
&&
!
CollectionUtils
.
isEmpty
(
response
.
getData
()))
{
return
Response
.
createSuccess
(
response
.
getData
().
get
(
0
));
}
return
Response
.
createError
(
"没有查询到该iccid详情"
);
}
@Override
public
Response
<
PageResult
<
SimVehicleResultDTO
>>
queryBindingPage
(
SimVehicleQueryDTO
queryDTO
)
{
OrgSimRelQueryDTO
orgSimRelQueryDTO
=
new
OrgSimRelQueryDTO
();
BeanUtils
.
copyProperties
(
queryDTO
,
orgSimRelQueryDTO
);
orgSimRelQueryDTO
.
setOrgUuid
(
queryDTO
.
getOrganizationId
());
Response
<
PageResult
<
OrgSimRelDTO
>>
resultResponse
=
orgSimRelClient
.
queryByPage
(
orgSimRelQueryDTO
);
PageResult
<
SimVehicleResultDTO
>
pageResult
=
new
PageResult
<>();
if
(
resultResponse
.
isSuccess
()
&&
resultResponse
.
getData
()
!=
null
)
{
pageResult
.
setCurrPage
(
resultResponse
.
getData
().
getCurrPage
());
pageResult
.
setPageSize
(
resultResponse
.
getData
().
getPageSize
());
pageResult
.
setTotalCount
(
resultResponse
.
getData
().
getTotalCount
());
pageResult
.
setHasMore
(
resultResponse
.
getData
().
isHasMore
());
List
<
SimVehicleResultDTO
>
resultDTOS
=
new
ArrayList
<>();
resultResponse
.
getData
().
getList
().
forEach
(
orgSimRelDTO
->
{
SimVehicleResultDTO
simVehicleResultDTO
=
new
SimVehicleResultDTO
();
BeanUtils
.
copyProperties
(
orgSimRelDTO
,
simVehicleResultDTO
);
resultDTOS
.
add
(
simVehicleResultDTO
);
});
pageResult
.
setList
(
resultDTOS
);
return
Response
.
createSuccess
(
pageResult
);
}
return
Response
.
createError
(
resultResponse
.
getMsg
());
}
private
OrgSimRelDTO
simVehicleDTOToOrgSimRelDto
(
SimVehicleDTO
simVehicleDTO
)
{
LOGGER
.
info
(
JSON
.
toJSONString
(
simVehicleDTO
));
OrgSimRelDTO
orgSimRelDTO
=
new
OrgSimRelDTO
();
BeanUtils
.
copyProperties
(
simVehicleDTO
,
orgSimRelDTO
);
LOGGER
.
info
(
JSON
.
toJSONString
(
orgSimRelDTO
));
return
orgSimRelDTO
;
}
private
SimVehicleDTO
orgSimRelDtoToSimVehicleDto
(
OrgSimRelDTO
orgSimRelDTO
)
{
SimVehicleDTO
simVehicleDTO
=
new
SimVehicleDTO
();
BeanUtils
.
copyProperties
(
orgSimRelDTO
,
simVehicleDTO
);
return
simVehicleDTO
;
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/SmsServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.TypeReference
;
import
com.cache.CacheFactory
;
import
com.cusc.nirvana.common.encrypt.sign.HMAC
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.common.cloud.SignConstants
;
import
com.cusc.nirvana.user.rnr.fp.common.config.SmsPropertyConfig
;
import
com.cusc.nirvana.user.rnr.fp.common.util.DateUtil
;
import
com.cusc.nirvana.user.rnr.fp.constants.RedisConstant
;
import
com.cusc.nirvana.user.rnr.fp.dto.SmsResponseDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.SmsSendDTO
;
import
com.cusc.nirvana.user.rnr.fp.service.ISmsService
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
com.cusc.nirvana.user.util.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Description: 短信service
* <br />
* CreateDate 2021-11-02 20:25:49
*
* @author yuyi
**/
@Service
@Slf4j
public
class
SmsServiceImpl
implements
ISmsService
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SmsServiceImpl
.
class
);
@Autowired
private
RestTemplate
noBalanceRestTemplateRnrFp
;
@Autowired
private
SmsPropertyConfig
smsPropertyConfig
;
@Value
(
"${sms.cusc.strategyCode:}"
)
private
String
strategyCode
;
@Value
(
"${sms.cusc.interval:60000}"
)
private
Integer
intervalTime
;
@Value
(
"${sms.cusc.limit:20}"
)
private
Integer
maxLimit
;
private
static
final
Integer
ONE_DAY_SEC
=
24
*
60
*
60
;
@Resource
private
CacheFactory
cacheFactory
;
@Override
public
Response
<
SmsResponseDTO
>
sendSms
(
String
phone
,
List
<
String
>
paramterList
,
String
smsTemplate
)
{
try
{
//判断当前验证码是否达到发送间隔 60s
String
intervalKey
=
RedisConstant
.
SMS_RNR_CAPTCHA_SEND_INTERVAL_KEY
+
phone
;
log
.
info
(
"sendSms intervalKey = {}"
,
intervalKey
);
if
(!
cacheFactory
.
getLockService
().
lock
(
intervalKey
,
intervalTime
))
{
throw
new
CuscUserException
(
ResponseCode
.
SMS_CAPTCHA_INTERVAL_FAIL
.
getCode
(),
ResponseCode
.
SMS_CAPTCHA_INTERVAL_FAIL
.
getMsg
());
}
//判断短信是否发到最大次数
String
maxTimesKey
=
RedisConstant
.
SMS_RNR_CAPTCHA_LIMIT_TIMES
+
DateUtils
.
formatDate
(
LocalDate
.
now
(),
DateUtil
.
YYMM_DD_MM
)+
phone
;
log
.
info
(
"sendSms maxTimesKey = {},maxLimit = {}"
,
intervalKey
,
maxLimit
);
if
(
cacheFactory
.
getExpireStringService
().
setExpireValueIncr
(
maxTimesKey
,
1L
,
ONE_DAY_SEC
)
>
maxLimit
)
{
throw
new
CuscUserException
(
ResponseCode
.
SMS_OVER_MAX_LIMIT
.
getCode
(),
ResponseCode
.
SMS_OVER_MAX_LIMIT
.
getMsg
());
}
}
catch
(
CuscUserException
e
)
{
throw
e
;
}
catch
(
Exception
e
)
{
throw
new
CuscUserException
(
ResponseCode
.
SYSTEM_ERROR
.
getCode
(),
ResponseCode
.
SYSTEM_ERROR
.
getMsg
());
}
SmsSendDTO
send
=
new
SmsSendDTO
();
List
<
String
>
phoneList
=
new
ArrayList
<>();
phoneList
.
add
(
phone
);
send
.
setPhoneNumbers
(
phoneList
);
send
.
setTemplateParams
(
paramterList
);
send
.
setSignatureCode
(
smsPropertyConfig
.
getSignatureCode
());
send
.
setAccesskey
(
smsPropertyConfig
.
getAccessKey
());
send
.
setStrategyCode
(
strategyCode
);
send
.
setTemplateCode
(
smsTemplate
);
Response
<
SmsResponseDTO
>
retResp
;
try
{
/* retResp = RestTemplateUtils.postForResponse(noBalanceRestTemplateRnrFp,
smsPropertyConfig.getSmsUrl() + smsPropertyConfig.getSendUrl(),
send,
SmsResponseDTO.class);*/
HttpEntity
httpEntity
=
new
HttpEntity
(
JSON
.
toJSONString
(
send
),
headers
());
String
sendSmdUrl
=
smsPropertyConfig
.
getSmsUrl
()
+
smsPropertyConfig
.
getSendUrl
();
log
.
info
(
"SmsServiceImpl sendSms request url : {}"
,
sendSmdUrl
);
long
startTime
=
System
.
currentTimeMillis
();
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFp
.
exchange
(
sendSmdUrl
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
retResp
=
JSON
.
parseObject
(
entity
.
getBody
(),
new
TypeReference
<
Response
<
SmsResponseDTO
>>(
SmsResponseDTO
.
class
)
{
}.
getType
());
if
(
null
!=
retResp
&&
null
!=
retResp
.
getData
())
{
//置空短信为空
retResp
.
getData
().
setCaptcha
(
""
);
}
log
.
info
(
"SmsServiceImpl sendSms response url : {} , result : {}, cost: {} ms "
,
sendSmdUrl
,
JSON
.
toJSONString
(
retResp
),
System
.
currentTimeMillis
()
-
startTime
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"短信发送失败: "
,
e
);
retResp
=
Response
.
createError
(
ResponseCode
.
SMS_CAPTCHA_SEND_FAIL
.
getMsg
(),
ResponseCode
.
SMS_CAPTCHA_SEND_FAIL
.
getCode
());
}
return
retResp
;
}
@Override
public
Response
<
SmsResponseDTO
>
sendSms
(
String
phone
,
String
parameter
,
String
smsTemplate
)
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
parameter
);
return
sendSms
(
phone
,
list
,
smsTemplate
);
}
/**
* 生成请求头
*
* @return
*/
public
HttpHeaders
headers
()
{
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
httpHeaders
.
add
(
SignConstants
.
APP_ID
,
smsPropertyConfig
.
getAPPID
());
httpHeaders
.
add
(
SignConstants
.
NONCE_STR
,
CuscStringUtils
.
generateUuid
());
httpHeaders
.
add
(
SignConstants
.
TIMESTAMP
,
String
.
valueOf
(
System
.
currentTimeMillis
()));
httpHeaders
.
add
(
SignConstants
.
VERSION
,
smsPropertyConfig
.
getVERSION
());
httpHeaders
.
setContentType
(
MediaType
.
parseMediaType
(
"application/json; charset=UTF-8"
));
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
SignConstants
.
APP_ID
+
smsPropertyConfig
.
getAPPID
());
sb
.
append
(
SignConstants
.
NONCE_STR
+
httpHeaders
.
get
(
SignConstants
.
NONCE_STR
).
get
(
0
));
sb
.
append
(
SignConstants
.
TIMESTAMP
+
httpHeaders
.
get
(
SignConstants
.
TIMESTAMP
).
get
(
0
));
sb
.
append
(
SignConstants
.
VERSION
+
httpHeaders
.
get
(
SignConstants
.
VERSION
).
get
(
0
));
log
.
info
(
"SmsServiceImpl headers param : {}, appScret:{}"
,
sb
,
smsPropertyConfig
.
getAPPSCRET
());
String
scret
=
HMAC
.
sign
(
sb
.
toString
(),
smsPropertyConfig
.
getAPPSCRET
(),
HMAC
.
Type
.
HmacSHA256
);
httpHeaders
.
add
(
SignConstants
.
SIGN
,
scret
);
return
httpHeaders
;
}
// @Override
// public boolean checkSmsConfigNotNull(SmsSendConfig bean) {
// return bean != null && CuscStringUtils.isNotEmpty(bean.getSmsTemplateCode());
// }
//
// @Override
// public void convertToSmsConfig(ApplicationDTO fromBean, SmsSendConfig toBean) {
// //短信配置为空,从应用配置中取
// if (!checkSmsConfigNotNull(toBean)) {
// throw new CuscUserException(ResponseCode.SMS_SEND_CONFIG_NOT_NULL.getCode() + "",
// ResponseCode.SMS_SEND_CONFIG_NOT_NULL.getMsg());
// }
//
// if (toBean.getSmsTotalLimit() == null) {
// if (fromBean.getSmsTotalLimit() == null) {
// log.warn("sms config smsTotalLimit is null");
// throw new CuscUserException(ResponseCode.SMS_SEND_CONFIG_NOT_NULL.getCode() + "",
// ResponseCode.SMS_SEND_CONFIG_NOT_NULL.getMsg());
// }
// toBean.setSmsTotalLimit(fromBean.getSmsTotalLimit());
// }
//
// if (toBean.getSmsIntervalLimit() == null) {
// if (fromBean.getSmsIntervalLimit() == null) {
// log.warn("sms config smsIntervalLimit is null");
// throw new CuscUserException(ResponseCode.SMS_SEND_CONFIG_NOT_NULL.getCode() + "",
// ResponseCode.SMS_SEND_CONFIG_NOT_NULL.getMsg());
// }
// toBean.setSmsIntervalLimit(fromBean.getSmsIntervalLimit());
// }
//
// if (toBean.getSmsPlatformKey() == null) {
// if (fromBean.getSmsPlatformKey() == null) {
// log.warn("sms config smsPlatformKey is null");
// throw new CuscUserException(ResponseCode.SMS_SEND_CONFIG_NOT_NULL.getCode() + "",
// ResponseCode.SMS_SEND_CONFIG_NOT_NULL.getMsg());
// }
// toBean.setSmsPlatformKey(fromBean.getSmsPlatformKey());
// }
//
// if (toBean.getSmsSignatureCode() == null) {
// if (fromBean.getSmsSignatureCode() == null) {
// log.warn("sms config smsSignatureCode is null");
// throw new CuscUserException(ResponseCode.SMS_SEND_CONFIG_NOT_NULL.getCode() + "",
// ResponseCode.SMS_SEND_CONFIG_NOT_NULL.getMsg());
// }
// toBean.setSmsSignatureCode(fromBean.getSmsSignatureCode());
// }
// }
// /**
// * Description: 短信发送限制检查
// * <br />
// * CreateDate 2022-01-27 14:43:41
// *
// * @author yuyi
// **/
// @Override
// public void checkSmsSendLimit(String phone, SmsSendConfig bean) {
// try {
// if (bean.getSmsTotalLimit() != null && bean.getSmsTotalLimit() > 0 && CuscStringUtils.isNotEmpty(
// bean.getTotalLimitKey())) {
// //记录发送总次数限制
// Integer smsTotal = cacheFactory.getExpireStringService()
// .getValue(bean.getTotalLimitKey() + phone + "_" + bean.getTenantNo() + "_" + bean.getAppId(),
// Integer.class);
// if (smsTotal != null && smsTotal >= bean.getSmsTotalLimit()) {
// throw new CuscUserException(ResponseCode.SMS_TOTAL_LIMIT_OVERRUN.getCode(),
// ResponseCode.SMS_TOTAL_LIMIT_OVERRUN.getMsg());
// }
// }
//
// if (bean.getSmsIntervalLimit() != null && bean.getSmsIntervalLimit() > 0 && CuscStringUtils.isNotEmpty(
// bean.getIntervalLimitKey())) {
// //记录发送间隔限制
// boolean isExists =
// cacheFactory.getExpireStringService()
// .containsKey(bean.getIntervalLimitKey() + phone + "_" + bean.getTenantNo() + "_" +
// bean.getAppId());
// if (isExists) {
// throw new CuscUserException(ResponseCode.SMS_INTERVAL_LIMIT_OVERRUN.getCode(),
// ResponseCode.SMS_INTERVAL_LIMIT_OVERRUN.getMsg());
// }
// }
// } catch (Exception e) {
// //只记录,不抛出异常,屏蔽对业务的影响
// log.error("检查短信发送限制信息时访问redis 异常:", e);
// }
// }
// //----------------私有方法区域--------------------------
//
// /**
// * Description: 保存短信发送限制信息到redis
// * <br />
// * CreateDate 2022-02-16 09:50:25
// *
// * @author yuyi
// **/
// private void saveSmsSendLimitToRedis(String phone, SmsSendConfig bean) {
// try {
// if (bean.getSmsTotalLimit() != null && bean.getSmsTotalLimit() > 0 && CuscStringUtils.isNotEmpty(
// bean.getTotalLimitKey())) {
// //记录发送总次数限制
// Integer smsTotal =
// cacheFactory.getExpireStringService().getValue(
// bean.getTotalLimitKey() + phone + "_" + bean.getTenantNo() + "_" + bean.getAppId(),
// Integer.class);
// Long expireTime;
// if (smsTotal == null) {
// smsTotal = 1;
// LocalDateTime begin = LocalDateTime.now();
// expireTime = DateUtils.secondBetween(begin, DateUtils.getDayEnd(begin));
// } else {
// smsTotal++;
// expireTime =
// cacheFactory.getExpireStringService().getKeyExpireTime(bean.getTotalLimitKey() + phone
// + "_" + bean.getTenantNo() + "_" + bean.getAppId());
// }
// cacheFactory.getExpireStringService().setExpireValue(bean.getTotalLimitKey() + phone + "_" + bean
// .getTenantNo() + "_" + bean.getAppId(), smsTotal,
// expireTime.intValue());
// }
//
// if (bean.getSmsIntervalLimit() != null && bean.getSmsIntervalLimit() > 0 && CuscStringUtils.isNotEmpty(
// bean.getIntervalLimitKey())) {
// //记录发送间隔限制
// cacheFactory.getExpireStringService()
// .setExpireValue(bean.getIntervalLimitKey() + phone + "_" + bean.getTenantNo() + "_" + bean
// .getAppId(), 1, bean.getSmsIntervalLimit());
// }
// } catch (CacheException e) {
// //只记录,不抛出异常,屏蔽对业务的影响
// log.error("保存短信发送限制信息到redis 异常:", e);
// }
// }
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/T1ReportCompletionServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.fp.dto.BulkBackDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.FpT1UploadStatusDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.T1CompletionReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.service.T1ReportCompletionService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
/**
* @className: T1ReportCompletionServiceImpl
* @description:
* @author: jk
* @date: 2022/8/23 11:03
* @version: 1.0
**/
@Service
public
class
T1ReportCompletionServiceImpl
implements
T1ReportCompletionService
{
@Resource
private
FpT1UploadStatusServiceImpl
fpT1UploadStatusService
;
@Override
public
Response
T1ReportCompletionCmcc
(
T1CompletionReqDTO
t1CompletionReqDTO
)
{
BulkBackDTO
bulkBackDTO
=
(
BulkBackDTO
)
t1CompletionReqDTO
.
getCallbackData
();
FpT1UploadStatusDTO
fpT1UploadStatusDTO
=
new
FpT1UploadStatusDTO
();
fpT1UploadStatusDTO
.
setRequestId
(
t1CompletionReqDTO
.
getRequestID
());
if
(
"1"
.
equals
(
bulkBackDTO
.
getOprRst
())){
fpT1UploadStatusDTO
.
setReportCompletion
(
1
);
}
else
{
fpT1UploadStatusDTO
.
setReportCompletion
(
2
);
}
fpT1UploadStatusDTO
.
setReportCompletionResp
(
JSON
.
toJSONString
(
bulkBackDTO
));
fpT1UploadStatusService
.
update
(
fpT1UploadStatusDTO
);
return
Response
.
createSuccess
();
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/T1UploadServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
cn.hutool.crypto.SecureUtil
;
import
cn.hutool.crypto.symmetric.AES
;
import
com.alibaba.fastjson.JSON
;
import
com.cusc.nirvana.common.encrypt.sign.HMAC
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.exception.CuscUserException
;
import
com.cusc.nirvana.user.rnr.fp.common.CmccCertTypeEnum
;
import
com.cusc.nirvana.user.rnr.fp.common.MbCodeEnum
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.common.cloud.SignConstants
;
import
com.cusc.nirvana.user.rnr.fp.common.config.EncryptionConfig
;
import
com.cusc.nirvana.user.rnr.fp.common.config.SmsPropertyConfig
;
import
com.cusc.nirvana.user.rnr.fp.common.util.WatermarkUtil
;
import
com.cusc.nirvana.user.rnr.fp.config.T1Config
;
import
com.cusc.nirvana.user.rnr.fp.dto.*
;
import
com.cusc.nirvana.user.rnr.fp.service.*
;
import
com.cusc.nirvana.user.rnr.fp.util.*
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCardInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrRelationClient
;
import
com.cusc.nirvana.user.rnr.mg.client.RnrOrderClient
;
import
com.cusc.nirvana.user.rnr.mg.constants.CertTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrBizzTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrFileType
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderType
;
import
com.cusc.nirvana.user.rnr.mg.dto.*
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
com.cusc.nirvana.user.util.DateUtils
;
import
com.cusc.nirvana.user.util.crypt.DataCryptService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.http.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
java.io.*
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* Description: T1上报服务
* <br />
* CreateDate 2022-06-07 20:13:25
*
* @author yuyi
**/
@Service
@Slf4j
@RefreshScope
public
class
T1UploadServiceImpl
implements
IT1UploadService
{
public
static
final
String
SM4_KEY
=
"7faf0abf9e6c4aa0aa04eeccf3110e37"
;
@Resource
private
T1Config
t1Config
;
@Autowired
private
MgRnrRelationClient
rnrRelationClient
;
@Autowired
private
MgRnrCardInfoClient
rnrCardInfoClient
;
@Autowired
private
ISimVehicleRelService
simVehicleRelService
;
@Autowired
private
EncryptionConfig
encryptionConfig
;
@Autowired
private
IFileService
fileService
;
@Autowired
@Qualifier
(
"noBalanceRestTemplateRnrFpT1"
)
RestTemplate
noBalanceRestTemplateRnrFpT1
;
@Resource
private
IFpCarInfoService
iFpCarInfoService
;
@Resource
private
FpT1UploadStatusServiceImpl
fpT1UploadStatusService
;
@Autowired
private
DataCryptService
dataCryptService
;
// @Autowired
// private SmsPropertyConfig smsPropertyConfig;
@Autowired
private
RnrOrderClient
orderClient
;
@Autowired
private
MgRnrInfoClient
mgRnrInfoClient
;
@Value
(
"${t1.chinaMobile.platformID:}"
)
//由OneLink车联卡实名平台为各个车 企分配的标识
private
String
platformID
;
@Value
(
"${t1.chinaMobile.t1UserInfoKey:}"
)
//开户信息的加密密钥由 OneLink 平台生成后,自动发送到指定邮箱。
private
String
t1UserInfoKey
=
"7faf0abf9e6c4aa0aa04eeccf3110e37"
;
@Autowired
private
CtccT1UploadService
ctccSftpUtil
;
@Autowired
private
CmccT1UploadService
cmccSftpUtil
;
@Autowired
private
OperatorService
operatorService
;
@Value
(
"${T1.power:true}"
)
private
Boolean
power
;
private
static
EncryptionKeyDTO
encryptionKeyDTO
;
private
static
String
requestIdCmss
;
private
static
String
companyCode
;
@Override
public
Response
uploadUserInfoAndFile
(
MgCardNoticeDTO
cardNoticeDTO
)
{
if
(
cardNoticeDTO
.
getResultCode
()!=
3
){
return
Response
.
createSuccess
(
"不用上报T1"
);
}
//初始化上报状态
FpT1UploadStatusDTO
t1UploadStatus
=
new
FpT1UploadStatusDTO
();
t1UploadStatus
.
setIccid
(
cardNoticeDTO
.
getIccid
());
t1UploadStatus
.
setOrderId
(
cardNoticeDTO
.
getOrderId
());
t1UploadStatus
.
setTenantNo
(
cardNoticeDTO
.
getTenantNo
());
t1UploadStatus
.
setT1Request
(
JSON
.
toJSONString
(
cardNoticeDTO
));
t1UploadStatus
=
fpT1UploadStatusService
.
insertOrReset
(
t1UploadStatus
);
log
.
info
(
"uploadUserInfoAndFile t1UploadStatus : {}"
,
JSON
.
toJSONString
(
t1UploadStatus
));
MgRnrCardInfoDTO
card
=
new
MgRnrCardInfoDTO
();
card
.
setTenantNo
(
cardNoticeDTO
.
getTenantNo
());
card
.
setIotId
(
cardNoticeDTO
.
getVin
());
card
.
setOrderId
(
cardNoticeDTO
.
getOrderId
());
boolean
isSuccess
=
false
;
//实名
if
(
RnrBizzTypeEnum
.
Bind
.
getCode
().
equals
(
cardNoticeDTO
.
getRnrBizzType
()))
{
card
.
setIccid
(
cardNoticeDTO
.
getIccid
());
isSuccess
=
userInfoUpload
(
card
,
true
,
"4"
,
cardNoticeDTO
.
getManufacturerOrgId
(),
"A"
,
cardNoticeDTO
);
}
//更换责任人
if
(
RnrBizzTypeEnum
.
INFO_CHANGE
.
getCode
().
equals
(
cardNoticeDTO
.
getRnrBizzType
()))
{
card
.
setIccid
(
cardNoticeDTO
.
getIccid
());
isSuccess
=
userInfoUpload
(
card
,
true
,
"4"
,
cardNoticeDTO
.
getManufacturerOrgId
(),
"M"
,
cardNoticeDTO
);
}
//解绑
if
(
RnrBizzTypeEnum
.
Unbound
.
getCode
().
equals
(
cardNoticeDTO
.
getRnrBizzType
()))
{
card
.
setIccid
(
cardNoticeDTO
.
getIccid
());
RnrOrderDTO
rnrOrderDTO
=
new
RnrOrderDTO
();
rnrOrderDTO
.
setUuid
(
cardNoticeDTO
.
getOrderId
());
Response
<
RnrOrderDTO
>
response
=
orderClient
.
getByUuid
(
rnrOrderDTO
);
if
(!
response
.
isSuccess
()
||
null
==
response
.
getData
()){
return
Response
.
createSuccess
(
"没有查到订单信息"
);
}
String
vehicleStatus
=
""
;
if
(
RnrOrderType
.
COMPANY_CORPORATION_UNBIND
.
getCode
().
equals
(
response
.
getData
().
getOrderType
())){
vehicleStatus
=
"2"
;
}
else
{
vehicleStatus
=
"4"
;
}
isSuccess
=
userInfoUpload
(
card
,
false
,
vehicleStatus
,
cardNoticeDTO
.
getManufacturerOrgId
(),
"M"
,
cardNoticeDTO
);
}
//换件
if
(
RnrBizzTypeEnum
.
ChangeBinding
.
getCode
().
equals
(
cardNoticeDTO
.
getRnrBizzType
()))
{
FpT1UploadStatusDTO
t1UploadStatusOld
=
new
FpT1UploadStatusDTO
();
t1UploadStatusOld
.
setIccid
(
cardNoticeDTO
.
getOldIccid
());
t1UploadStatusOld
.
setOrderId
(
cardNoticeDTO
.
getOrderId
());
t1UploadStatusOld
.
setTenantNo
(
cardNoticeDTO
.
getTenantNo
());
t1UploadStatus
=
fpT1UploadStatusService
.
insertOrReset
(
t1UploadStatusOld
);
//老卡
card
.
setIccid
(
cardNoticeDTO
.
getOldIccid
());
isSuccess
=
userInfoUpload
(
card
,
false
,
"7"
,
cardNoticeDTO
.
getManufacturerOrgId
(),
"M"
,
cardNoticeDTO
);
//新卡
card
.
setIccid
(
cardNoticeDTO
.
getIccid
());
isSuccess
=
userInfoUpload
(
card
,
true
,
"4"
,
cardNoticeDTO
.
getManufacturerOrgId
(),
"M"
,
cardNoticeDTO
);
}
if
(
isSuccess
)
{
return
Response
.
createSuccess
();
}
return
Response
.
createError
(
"开户信息和上传文件至少有一个失败"
);
}
/**
* 用户信息上报
* isUploadUser : 是否上报用户信息。解绑和换件的老卡不需要,其他需要
* vehicleStatus 1表示生产期,2表示测试期,3表示待售,4表示已售 5表示过户 6表示报废,7 表示其他
* operType : 实名时为A,其他为M
*
* @return
*/
private
boolean
userInfoUpload
(
MgRnrCardInfoDTO
card
,
boolean
isUploadUser
,
String
vehicleStatus
,
String
orgId
,
String
operType
,
MgCardNoticeDTO
cardNoticeDTO
)
{
log
.
warn
(
"userInfoUpload方法入参===MgRnrCardInfoDTO{},isUploadUser{},vehicleStatus{},orgId{},operType{}"
,
JSON
.
toJSON
(
card
),
isUploadUser
,
vehicleStatus
,
orgId
,
operType
);
T1UserInfoDTO
ret
=
new
T1UserInfoDTO
();
//查询上报状态
FpT1UploadStatusDTO
t1Us
=
fpT1UploadStatusService
.
getByIccidAndOrderId
(
card
.
getIccid
(),
card
.
getOrderId
());
String
t1UploadStatusUuid
=
""
;
if
(
t1Us
!=
null
){
t1UploadStatusUuid
=
t1Us
.
getUuid
();
}
//运营商
String
serviceProvider
=
operatorService
.
get
(
cardNoticeDTO
.
getIccid
());
//通过iccid查询msisdn
//Response<VinIccidDTO> iccidResp = simVehicleRelService.getVinByIccid(card.getIccid());
//log.warn("iccidResp回参{}",JSON.toJSON(iccidResp));
//if (!iccidResp.isSuccess() || iccidResp.getData() == null) {
// log.warn("userInfoUpload 通过卡获取msisdn失败,失败原因:{}", JSON.toJSONString(iccidResp));
// return false;
//}
String
orderId
=
card
.
getOrderId
();
//VinIccidDTO iccidInfo = iccidResp.getData();
//ret.setMSISDN(iccidInfo.getMsisdn());
ret
.
setICCID
(
card
.
getIccid
());
if
(
vehicleStatus
.
equals
(
"7"
))
{
ret
.
setVIN
(
""
);
}
else
{
ret
.
setVIN
(
card
.
getIotId
());
}
ret
.
setVehicleStatus
(
vehicleStatus
);
ret
.
setStatusUpdateTime
(
DateUtils
.
formatDate
(
LocalDateTime
.
now
(),
"yyyyMMddHHmmss"
));
ret
.
setAcceptTime
(
ret
.
getStatusUpdateTime
());
ret
.
setServiceProvider
(
operatorService
.
get
(
cardNoticeDTO
.
getIccid
()));
//通过卡查询到用户信息
T1UserInfoReqDTO
t1UserInfoReq
=
new
T1UserInfoReqDTO
();
//通过租户查询
FpT1VehicleCompanyDTO
t1VehicleCompanyDTO
=
new
FpT1VehicleCompanyDTO
();
t1VehicleCompanyDTO
.
setTenantNo
(
card
.
getTenantNo
());
t1VehicleCompanyDTO
.
setOrgId
(
orgId
);
encryptionKeyDTO
=
encryptionConfig
.
getKey
(
orgId
);
log
.
info
(
"encryptionKeyDATO-----{}"
,
JSON
.
toJSON
(
encryptionKeyDTO
));
if
(
null
==
encryptionKeyDTO
){
log
.
warn
(
"查询车企密钥配置失败,查询参数: 租户编号:{},组织id:{}"
,
card
.
getTenantNo
(),
orgId
);
return
false
;
}
RnrOrderDTO
rnrOrderDTO
=
new
RnrOrderDTO
();
rnrOrderDTO
.
setUuid
(
orderId
);
Response
<
RnrOrderDTO
>
responseOrder
=
orderClient
.
getByUuid
(
rnrOrderDTO
);
if
(!
responseOrder
.
isSuccess
()
||
null
==
responseOrder
.
getData
())
{
log
.
info
(
"查询订单信息失败,查询参数: 订单id:{}"
,
orderId
);
return
false
;
}
MgRnrInfoDTO
mgRnrInfoDTO
=
new
MgRnrInfoDTO
();
mgRnrInfoDTO
.
setUuid
(
responseOrder
.
getData
().
getRnrId
());
Response
<
MgRnrInfoDTO
>
mgRnrInfoDTOResponse
=
mgRnrInfoClient
.
getByUuid
(
mgRnrInfoDTO
);
if
(!
mgRnrInfoDTOResponse
.
isSuccess
()
||
null
==
mgRnrInfoDTOResponse
.
getData
())
{
log
.
info
(
"查询用户信息失败,查询参数: 订单id:{}"
,
orderId
);
return
false
;
}
Integer
CustomerType
=
mgRnrInfoDTOResponse
.
getData
().
getIsCompany
();
//移动用雪花算法
if
(
power
&&
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
constants
.
MbCodeEnum
.
CMCC
.
getCode
().
equals
(
serviceProvider
)){
requestIdCmss
=
(
null
!=
encryptionKeyDTO
.
getPlatFormId
()&&
encryptionKeyDTO
.
getPlatFormId
().
length
()>
5
)?
encryptionKeyDTO
.
getPlatFormId
().
substring
(
0
,
5
)+
String
.
valueOf
(
SnowflakeIdWorker
.
nextId
()):
encryptionKeyDTO
.
getPlatFormId
()+
String
.
valueOf
(
SnowflakeIdWorker
.
nextId
());
t1UserInfoReq
.
setRequestID
(
requestIdCmss
);
}
else
if
(
power
&&
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
constants
.
MbCodeEnum
.
CTCC
.
getCode
().
equals
(
serviceProvider
)){
t1UserInfoReq
.
setRequestID
(
encryptionKeyDTO
.
getPlatFormId
()+
String
.
valueOf
(
SnowflakeIdWorker
.
nextId
()));
}
else
{
t1UserInfoReq
.
setRequestID
(
CuscStringUtils
.
generateUuid
());
}
t1VehicleCompanyDTO
.
setT1UserInfoKey
(
encryptionKeyDTO
.
getT1UserInfoKey
());
t1VehicleCompanyDTO
.
setT1InstructionKey
(
encryptionKeyDTO
.
getT1InstructionKey
());
t1VehicleCompanyDTO
.
setCompanyCode
(
encryptionKeyDTO
.
getCompanyCode
());
companyCode
=
t1VehicleCompanyDTO
.
getCompanyCode
();
t1UserInfoReq
.
setCode
(
companyCode
);
t1UserInfoReq
.
setOperType
(
operType
);
if
(!
isUploadUser
)
{
ret
.
setCustomerType
(
CustomerType
==
0
?
"1"
:
"2"
);
String
encryptUserInfo
=
RnrDataSm4Util
.
encryptEcbPadding
(
t1VehicleCompanyDTO
.
getT1UserInfoKey
(),
JSON
.
toJSONString
(
ret
),
true
,
null
);
t1UserInfoReq
.
setEncryptUserInfo
(
encryptUserInfo
);
log
.
warn
(
"上报开户信息{}"
,
JSON
.
toJSON
(
t1UserInfoReq
));
T1CommonResponseDTO
t1UserResult
=
null
;
if
(
MbCodeEnum
.
CMCC
.
getCode
().
equals
(
serviceProvider
)){
t1UserResult
=
this
.
t1UploadUserInfoCMCC
(
card
,
ret
,
t1VehicleCompanyDTO
,
t1UserInfoReq
);
}
else
if
(
MbCodeEnum
.
CTCC
.
getCode
().
equals
(
serviceProvider
)){
t1UserResult
=
this
.
t1UploadUserInfoCTCC
(
card
,
ret
,
t1VehicleCompanyDTO
,
t1UserInfoReq
);
}
else
{
t1UserResult
=
uploadT1UserInfo
(
t1UserInfoReq
);
}
log
.
warn
(
"开户信息回参{}"
,
JSON
.
toJSON
(
t1UserResult
));
Response
responses
=
null
;
// //换件 老卡
// if(RnrBizzTypeEnum.ChangeBinding.getCode().equals(cardNoticeDTO.getRnrBizzType())){
// response = this.T1CarInfo(cardNoticeDTO.getVin(),cardNoticeDTO.getManufacturerOrgId(),cardNoticeDTO.getTenantNo(),cardNoticeDTO.getIccid(),uuid);
// }
return
this
.
getIsUploadUser
(
t1UserResult
,
card
,
t1UploadStatusUuid
,
cardNoticeDTO
,
responses
);
}
Response
<
RnrRelationDTO
>
rnrRelationResp
=
rnrRelationClient
.
getRnrRelation
(
card
);
if
(!
rnrRelationResp
.
isSuccess
()
||
rnrRelationResp
.
getData
()
==
null
)
{
log
.
warn
(
"userInfoUpload 通过卡获取实名信息失败,失败原因:{}"
,
JSON
.
toJSONString
(
rnrRelationResp
));
return
false
;
}
RnrRelationDTO
rnrRelation
=
rnrRelationResp
.
getData
();
MgRnrInfoDTO
info
=
rnrRelation
.
getInfo
();
if
(
info
==
null
)
{
log
.
warn
(
"userInfoUpload 通过卡获取Info信息失败,失败原因:实名信息为空。 {}"
,
JSON
.
toJSONString
(
rnrRelation
));
return
false
;
}
if
(
info
.
getIsCompany
()
==
0
)
{
// 个人
ret
.
setCustomerType
(
"1"
);
ret
.
setCustomerName
(
info
.
getFullName
());
ret
.
setCustomerCertType
(
certTypeTransform
(
info
.
getCertType
()));
ret
.
setCustomerCertNumber
(
info
.
getCertNumber
());
ret
.
setCustomerCertAddress
(
info
.
getCertAddress
());
String
endTimeStr
=
info
.
getExpiredDate
();
SimpleDateFormat
simp
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
if
(!
StringUtils
.
isEmpty
(
endTimeStr
)&&
"长期"
.
equals
(
endTimeStr
)){
log
.
info
(
"时间长期====="
);
endTimeStr
=
"30000101"
;
}
endTimeStr
=
endTimeStr
.
replaceAll
(
"-"
,
""
);
String
startTimeStr
=
""
;
if
(
null
!=
info
.
getEffectiveDate
()){
startTimeStr
=
simp
.
format
(
info
.
getEffectiveDate
());
}
ret
.
setCustomerCertDate
(
startTimeStr
+
"-"
+
endTimeStr
);
log
.
info
(
"身份证有效期{}"
,
ret
.
getCustomerCertDate
());
// ret.setCustomerCertDate(endTimeStr);
ret
.
setCustomerPosterAddress
(
info
.
getContactAddress
());
ret
.
setCustomerPosterTelephone
(
info
.
getPhone
());
//是否有委托人
if
(!
CollectionUtils
.
isEmpty
(
rnrRelation
.
getRnrLiaisonList
()))
{
MgRnrLiaisonInfoDTO
rnrLiaison
=
rnrRelation
.
getRnrLiaisonList
().
get
(
0
);
ret
.
setOperatorName
(
rnrLiaison
.
getLiaisonName
());
ret
.
setOperatorCertType
(
certTypeTransform
(
rnrLiaison
.
getLiaisonCertType
()));
ret
.
setOperatorCertNumber
(
rnrLiaison
.
getLiaisonCertNumber
());
ret
.
setOperatorCertAddress
(
rnrLiaison
.
getLiaisonCertAddress
());
ret
.
setOperatorPosterAddress
(
rnrLiaison
.
getLiaisonContactAddress
());
ret
.
setOperatorTelephone
(
rnrLiaison
.
getLiaisonPhone
());
}
}
else
{
//企业
ret
.
setCustomerType
(
"2"
);
MgRnrCompanyInfoDTO
companyInfo
=
rnrRelation
.
getCompanyInfo
();
if
(
companyInfo
==
null
)
{
log
.
warn
(
"userInfoUpload 企业实名获取企业信息失败,失败原因:企业信息为空。 {}"
,
JSON
.
toJSONString
(
rnrRelation
));
return
false
;
}
if
(
companyInfo
.
getIsVehicleCompany
().
intValue
()
==
1
)
{
//车企实名,修改车辆状态
ret
.
setVehicleStatus
(
"2"
);
}
ret
.
setCompanyName
(
companyInfo
.
getCompanyName
());
ret
.
setCompanyCertType
(
certTypeTransform
(
companyInfo
.
getCompanyCertType
()));
ret
.
setCompanyCertNumber
(
companyInfo
.
getCompanyCertNumber
());
ret
.
setCompanyCertAddress
(
companyInfo
.
getCompanyCertAddress
());
ret
.
setCompanyPosterAddress
(
companyInfo
.
getCompanyContactAddress
());
//公司责任人
ret
.
setCorporationName
(
info
.
getFullName
());
ret
.
setCorporationCertType
(
certTypeTransform
(
info
.
getCertType
()));
ret
.
setCorporationCertNumber
(
info
.
getCertNumber
());
ret
.
setCorporationCertAddress
(
info
.
getCertAddress
());
ret
.
setCorporationPosterAddress
(
info
.
getContactAddress
());
ret
.
setCorporationTelephone
(
info
.
getPhone
());
}
ret
.
setPhoName
(
"KH_"
+
t1UserInfoReq
.
getRequestID
()
+
"_"
+
t1UserInfoReq
.
getCode
()
+
".zip"
);
ret
.
setServiceProvider
(
operatorService
.
get
(
cardNoticeDTO
.
getIccid
()));
boolean
fileResult
=
true
;
if
(!
CollectionUtils
.
isEmpty
(
rnrRelation
.
getRnrFileList
()))
{
//根据文件id,下载,压缩,上传
T1FileReqDTO
t1FileReqDTO
=
new
T1FileReqDTO
();
t1FileReqDTO
.
setCode
(
t1VehicleCompanyDTO
.
getCompanyCode
());
t1FileReqDTO
.
setRequestID
(
t1UserInfoReq
.
getRequestID
());
t1FileReqDTO
.
setPlatformID
(
encryptionKeyDTO
.
getPlatFormId
());
fileResult
=
fileUpload
(
rnrRelation
.
getRnrFileList
(),
t1FileReqDTO
,
t1VehicleCompanyDTO
.
getT1UserInfoKey
(),
t1UploadStatusUuid
,
cardNoticeDTO
.
getIccid
());
}
//上报开户信息
String
encryptUserInfo
=
RnrDataSm4Util
.
encryptEcbPadding
(
t1VehicleCompanyDTO
.
getT1UserInfoKey
(),
JSON
.
toJSONString
(
ret
),
true
,
null
);
t1UserInfoReq
.
setEncryptUserInfo
(
encryptUserInfo
);
Response
response
=
null
;
//换件 老卡
if
(
RnrBizzTypeEnum
.
ChangeBinding
.
getCode
().
equals
(
cardNoticeDTO
.
getRnrBizzType
())||
RnrBizzTypeEnum
.
Bind
.
getCode
().
equals
(
cardNoticeDTO
.
getRnrBizzType
())){
response
=
this
.
T1CarInfo
(
cardNoticeDTO
.
getVin
(),
cardNoticeDTO
.
getManufacturerOrgId
(),
cardNoticeDTO
.
getTenantNo
(),
cardNoticeDTO
.
getIccid
(),
t1UploadStatusUuid
);
}
T1CommonResponseDTO
t1UserResult
=
null
;
if
(
MbCodeEnum
.
CMCC
.
getCode
().
equals
(
serviceProvider
)){
t1UserResult
=
this
.
t1UploadUserInfoCMCC
(
card
,
ret
,
t1VehicleCompanyDTO
,
t1UserInfoReq
);
}
else
if
(
MbCodeEnum
.
CTCC
.
getCode
().
equals
(
serviceProvider
)){
t1UserResult
=
this
.
t1UploadUserInfoCTCC
(
card
,
ret
,
t1VehicleCompanyDTO
,
t1UserInfoReq
);
}
else
{
t1UserResult
=
uploadT1UserInfo
(
t1UserInfoReq
);
}
//防止别的平台已经实名过了
if
(
null
!=
t1UserResult
&&
"2"
.
equals
(
t1UserResult
.
getOprRst
())
&&
"该iccid未被解绑"
.
equals
(
t1UserResult
.
getFailureCause
())){
t1UserInfoReq
.
setOperType
(
"M"
);
if
(
MbCodeEnum
.
CMCC
.
getCode
().
equals
(
serviceProvider
)){
t1UserResult
=
this
.
t1UploadUserInfoCMCC
(
card
,
ret
,
t1VehicleCompanyDTO
,
t1UserInfoReq
);
}
else
if
(
MbCodeEnum
.
CTCC
.
getCode
().
equals
(
serviceProvider
)){
t1UserResult
=
this
.
t1UploadUserInfoCTCC
(
card
,
ret
,
t1VehicleCompanyDTO
,
t1UserInfoReq
);
}
else
{
t1UserResult
=
uploadT1UserInfo
(
t1UserInfoReq
);
}
}
if
(
t1UserResult
!=
null
&&
t1UserResult
.
getOprRst
().
equals
(
"1"
)){
this
.
fpT1UpdateUsertatus
(
t1UploadStatusUuid
,
1
,
t1UserResult
);
}
else
{
this
.
fpT1UpdateUsertatus
(
t1UploadStatusUuid
,
2
,
t1UserResult
);
}
//更新数据库
return
this
.
getIsUploadFile
(
t1UserResult
,
card
,
cardNoticeDTO
,
response
,
fileResult
);
}
/**
* @author: jk
* @description: 移动开户信息加密 AES
* @date: 2022/8/9 10:38
* @version: 1.0
*/
public
String
encryptUserInfo
(
String
t1UserInfoKey
,
String
data
)
{
byte
[]
key
=
AESUtil
.
MD5
(
t1UserInfoKey
);
//构建
AES
aes
=
SecureUtil
.
aes
(
key
);
//加密
return
aes
.
encryptHex
(
data
);
}
/**
* 如果换件和解绑需要三个状态都成功
* @param t1UserResult
* @param card
* @param cardNoticeDTO
* @param response
* @param fileResult
* @return
*/
private
Boolean
getIsUploadFile
(
T1CommonResponseDTO
t1UserResult
,
MgRnrCardInfoDTO
card
,
MgCardNoticeDTO
cardNoticeDTO
,
Response
response
,
boolean
fileResult
)
{
//如果换件和解绑需要三个状态都成功
if
(
RnrBizzTypeEnum
.
ChangeBinding
.
getCode
().
equals
(
cardNoticeDTO
.
getRnrBizzType
())
||
RnrBizzTypeEnum
.
Bind
.
getCode
().
equals
(
cardNoticeDTO
.
getRnrBizzType
()))
{
if
(
t1UserResult
!=
null
&&
t1UserResult
.
getOprRst
().
equals
(
"1"
)
&&
fileResult
&&
response
.
isSuccess
())
{
this
.
updateCardStatus
(
card
);
return
true
;
}
}
else
{
if
(
t1UserResult
!=
null
&&
t1UserResult
.
getOprRst
().
equals
(
"1"
)
&&
fileResult
)
{
this
.
updateCardStatus
(
card
);
return
true
;
}
}
return
false
;
}
/**
* 如果需要发送车辆信息,用户信息和车辆信息都需要上传成功才可以更新数据库
* @param t1UserResult
* @param card
* @param uuid
* @param cardNoticeDTO
* @param response
* @return
*/
private
Boolean
getIsUploadUser
(
T1CommonResponseDTO
t1UserResult
,
MgRnrCardInfoDTO
card
,
String
uuid
,
MgCardNoticeDTO
cardNoticeDTO
,
Response
response
){
//如果需要发送车辆信息,用户信息和车辆信息都需要上传成功才可以更新数据库
// if(RnrBizzTypeEnum.ChangeBinding.getCode().equals(cardNoticeDTO.getRnrBizzType())){
// if (t1UserResult != null && t1UserResult.getOprRst().equals("1") && !response.isSuccess()) {
// //修改卡card的T1状态
// this.updateCardStatus(card);
// //记录入库
// this.fpT1UpdateUsertatus(uuid,1,t1UserResult);
// return true;
// }
// this.fpT1UpdateUsertatus(uuid,2,t1UserResult);
// return false;
// }else {
if
(
t1UserResult
!=
null
&&
t1UserResult
.
getOprRst
().
equals
(
"1"
))
{
//修改卡card的T1状态
this
.
updateCardStatus
(
card
);
//记录入库
this
.
fpT1UpdateUsertatus
(
uuid
,
1
,
t1UserResult
);
return
true
;
}
this
.
fpT1UpdateUsertatus
(
uuid
,
2
,
t1UserResult
);
return
false
;
// }
}
/**
* 更新卡状态
* @param card
*/
private
void
updateCardStatus
(
MgRnrCardInfoDTO
card
){
MgRnrCardInfoDTO
cardT1
=
new
MgRnrCardInfoDTO
();
cardT1
.
setTenantNo
(
card
.
getTenantNo
());
cardT1
.
setIccid
(
card
.
getIccid
());
cardT1
.
setIotId
(
card
.
getIotId
());
if
(!
StringUtils
.
isEmpty
(
card
.
getOrderId
())){
cardT1
.
setOrderId
(
card
.
getOrderId
());
}
Response
<
List
<
MgRnrCardInfoDTO
>>
cardListResp
=
rnrCardInfoClient
.
queryByList
(
cardT1
);
if
(
cardListResp
!=
null
&&
!
CollectionUtils
.
isEmpty
(
cardListResp
.
getData
()))
{
for
(
MgRnrCardInfoDTO
tmpCard
:
cardListResp
.
getData
())
{
cardT1
=
new
MgRnrCardInfoDTO
();
cardT1
.
setUuid
(
tmpCard
.
getUuid
());
cardT1
.
setT1UploadStatus
(
1
);
rnrCardInfoClient
.
update
(
cardT1
);
}
}
}
/**
* 更新用户上报状态
* @param uuid
* @param status
* @param t1UserResult
*/
private
void
fpT1UpdateUsertatus
(
String
uuid
,
Integer
status
,
T1CommonResponseDTO
t1UserResult
){
FpT1UploadStatusDTO
fpT1UploadStatusDTO
=
new
FpT1UploadStatusDTO
();
fpT1UploadStatusDTO
.
setUuid
(
uuid
);
fpT1UploadStatusDTO
.
setUserStatus
(
status
);
fpT1UploadStatusDTO
.
setUserStatusResp
(
JSON
.
toJSONString
(
t1UserResult
));
fpT1UploadStatusService
.
update
(
fpT1UploadStatusDTO
);
}
/**
* 更新文件上传状态
* @param uuid
* @param status
* @param t1UserResult
*/
private
void
fpT1UpdateFiletatus
(
String
uuid
,
Integer
status
,
T1CommonResponseDTO
t1UserResult
){
FpT1UploadStatusDTO
fpT1UploadStatusDTO
=
new
FpT1UploadStatusDTO
();
fpT1UploadStatusDTO
.
setUuid
(
uuid
);
fpT1UploadStatusDTO
.
setFileStatus
(
status
);
fpT1UploadStatusDTO
.
setFileStatusResp
(
JSON
.
toJSONString
(
t1UserResult
));
fpT1UploadStatusService
.
update
(
fpT1UploadStatusDTO
);
}
/**
* 车辆上报状态
* @param uuid
* @param status
* @param t1UserResult
*/
private
void
fpT1UpdateCartatus
(
String
uuid
,
Integer
status
,
T1CommonResponseDTO
t1UserResult
){
FpT1UploadStatusDTO
fpT1UploadStatusDTO
=
new
FpT1UploadStatusDTO
();
fpT1UploadStatusDTO
.
setUuid
(
uuid
);
fpT1UploadStatusDTO
.
setCarStatus
(
status
);
fpT1UploadStatusDTO
.
setCarStatusResp
(
JSON
.
toJSONString
(
t1UserResult
));
fpT1UploadStatusService
.
update
(
fpT1UploadStatusDTO
);
}
/**
* @author: jk
* @description: 车辆信息上报
* @date: 2022/6/30 17:11
* @version: 1.0
*/
private
Response
T1CarInfo
(
String
vin
,
String
orgId
,
String
tenantNo
,
String
iccid
,
String
uuid
){
log
.
info
(
"车辆信息上报入参vin{},orgId{},tenantNo{},iccid{},uuid{}"
,
vin
,
orgId
,
tenantNo
,
iccid
,
uuid
);
T1CarInfoDTO
t1CarInfoDTO
=
new
T1CarInfoDTO
();
t1CarInfoDTO
.
setRequestId
(
CuscStringUtils
.
generateUuid
());
t1CarInfoDTO
.
setCode
(
encryptionKeyDTO
.
getCompanyCode
());
FpCarInfoDTO
fpCarInfoDTO
=
new
FpCarInfoDTO
();
fpCarInfoDTO
.
setVin
(
dataCryptService
.
encryptData
(
vin
));
log
.
info
(
"查询车辆信息入参{}"
,
JSON
.
toJSON
(
fpCarInfoDTO
));
List
<
FpCarInfoDTO
>
fpCarInfoDTOList
=
iFpCarInfoService
.
queryByList
(
fpCarInfoDTO
);
log
.
info
(
"查询车辆信息回参{}"
,
JSON
.
toJSON
(
fpCarInfoDTOList
));
if
(
CollectionUtils
.
isEmpty
(
fpCarInfoDTOList
)){
return
Response
.
createError
(
ResponseCode
.
DATA_IS_NULL
.
getMsg
(),
ResponseCode
.
DATA_IS_NULL
.
getCode
());
}
FpCarInfoDTO
fpCarInfo
=
fpCarInfoDTOList
.
get
(
0
);
String
encryptCarInfo
=
null
;
try
{
if
(
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
constants
.
MbCodeEnum
.
CMCC
.
getCode
().
equals
(
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
constants
.
MbCodeEnum
.
get
(
iccid
).
getCode
()))
{
Response
<
VinIccidDTO
>
iccidResp
=
simVehicleRelService
.
getVinByIccid
(
iccid
);
log
.
warn
(
"t1UploadUserInfoCMCC方法iccidResp回参{}"
,
JSON
.
toJSON
(
iccidResp
));
if
(!
iccidResp
.
isSuccess
()
||
iccidResp
.
getData
()
==
null
)
{
log
.
warn
(
"t1UploadUserInfoCMCC 通过卡获取msisdn失败,失败原因:{}"
,
JSON
.
toJSONString
(
iccidResp
));
}
VinIccidDTO
iccidInfo
=
iccidResp
.
getData
();
fpCarInfo
.
setMSISDN
(
iccidInfo
.
getMsisdn
());
encryptCarInfo
=
AESUtil
.
encryptStr
(
JSON
.
toJSONString
(
fpCarInfo
),
encryptionKeyDTO
.
getCmccTextOrPictureKey
());
}
else
{
encryptCarInfo
=
RnrDataAesUtil
.
encodeByECB
(
Md5CaculateUtil
.
MD5
(
encryptionKeyDTO
.
getCarInfoKey
()),
JSON
.
toJSONString
(
fpCarInfoDTOList
.
get
(
0
)));
t1CarInfoDTO
.
setServiceProvider
(
operatorService
.
get
(
iccid
));
}
}
catch
(
Exception
e
)
{
log
.
error
(
"加密失败"
,
e
.
getMessage
());
FpT1UploadStatusDTO
fpT1UploadStatusDTO
=
new
FpT1UploadStatusDTO
();
fpT1UploadStatusDTO
.
setUuid
(
uuid
);
fpT1UploadStatusDTO
.
setCarStatus
(
2
);
fpT1UploadStatusDTO
.
setCarStatusResp
(
"加密失败"
);
fpT1UploadStatusService
.
update
(
fpT1UploadStatusDTO
);
return
Response
.
createSuccess
(
"加密失败"
);
}
t1CarInfoDTO
.
setEncryptCarInfo
(
encryptCarInfo
);
log
.
info
(
"车辆信息上报入参{}"
,
JSON
.
toJSON
(
t1CarInfoDTO
));
T1CommonResponseDTO
t1CommonResponseDTO
=
null
;
if
(
power
&&
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
constants
.
MbCodeEnum
.
CMCC
.
getCode
().
equals
(
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
constants
.
MbCodeEnum
.
get
(
iccid
).
getCode
()))
{
t1CommonResponseDTO
=
this
.
t1UploadCarInfoCMCC
(
t1CarInfoDTO
);
}
else
if
(
power
&&
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
constants
.
MbCodeEnum
.
CTCC
.
getCode
().
equals
(
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
constants
.
MbCodeEnum
.
get
(
iccid
).
getCode
()))
{
t1CommonResponseDTO
=
this
.
t1UploadCarInfoCTCC
(
t1CarInfoDTO
);
}
else
{
//执行文件上传
t1CommonResponseDTO
=
uploadT1CarInfo
(
t1CarInfoDTO
);
}
log
.
info
(
"车辆信息上报回参{}"
,
JSON
.
toJSON
(
t1CommonResponseDTO
));
if
(
t1CommonResponseDTO
==
null
||
!
t1CommonResponseDTO
.
getOprRst
().
equals
(
"1"
)
)
{
FpT1UploadStatusDTO
fpT1UploadStatusDTO
=
new
FpT1UploadStatusDTO
();
fpT1UploadStatusDTO
.
setUuid
(
uuid
);
fpT1UploadStatusDTO
.
setCarStatus
(
2
);
fpT1UploadStatusDTO
.
setCarStatusResp
(
JSON
.
toJSONString
(
t1CommonResponseDTO
));
fpT1UploadStatusService
.
update
(
fpT1UploadStatusDTO
);
throw
new
CuscUserException
(
t1CommonResponseDTO
.
getRequestID
(),
t1CommonResponseDTO
.
getFailureCause
());
}
FpT1UploadStatusDTO
fpT1UploadStatusDTO
=
new
FpT1UploadStatusDTO
();
fpT1UploadStatusDTO
.
setUuid
(
uuid
);
fpT1UploadStatusDTO
.
setCarStatus
(
1
);
fpT1UploadStatusDTO
.
setCarStatusResp
(
JSON
.
toJSONString
(
t1CommonResponseDTO
));
fpT1UploadStatusService
.
update
(
fpT1UploadStatusDTO
);
return
Response
.
createSuccess
();
}
/**
* Description: 车辆信息上报
* <br />
* CreateDate 2022-05-16 10:22:07
*
* @author yuyi
**/
private
T1CommonResponseDTO
uploadT1CarInfo
(
T1CarInfoDTO
carInfo
)
{
long
startTime
=
System
.
currentTimeMillis
();
String
url
=
t1Config
.
getDateUrl
()
+
"/user-rnr-data/data/vehicleInfo"
;
log
.
info
(
"uploadT1CarInfo url: {},request: {}"
,
url
,
JSON
.
toJSONString
(
carInfo
));
String
requestStr
=
JSON
.
toJSONString
(
carInfo
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
requestHeaders
.
setContentType
(
MediaType
.
APPLICATION_JSON_UTF8
);
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFpT1
.
exchange
(
url
,
HttpMethod
.
POST
,
new
HttpEntity
<>(
requestStr
,
headers
()),
String
.
class
);
log
.
info
(
"uploadT1CarInfo url: {},response: {},cost: {} ms"
,
url
,
entity
.
getBody
(),
System
.
currentTimeMillis
()
-
startTime
);
T1CommonResponseDTO
result
=
JSON
.
parseObject
(
entity
.
getBody
(),
T1CommonResponseDTO
.
class
);
return
result
;
}
/**
* Description: 文件信息上报
* <br />
* CreateDate 2022-06-08 09:50:30
*
* @author yuyi
**/
private
boolean
fileUpload
(
List
<
MgRnrFileDTO
>
list
,
T1FileReqDTO
t1FileReqDTO
,
String
userInfoT1Key
,
String
uuid
,
String
iccid
)
{
//从文件系统下载文件到本地目录
String
folderName
=
""
;
if
(
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
constants
.
MbCodeEnum
.
CMCC
.
getCode
().
equals
(
operatorService
.
get
(
iccid
)))
{
folderName
=
"KH_"
+
t1FileReqDTO
.
getRequestID
()
+
"_"
+
encryptionKeyDTO
.
getPlatFormId
();
}
else
{
folderName
=
"KH_"
+
t1FileReqDTO
.
getRequestID
()
+
"_"
+
t1FileReqDTO
.
getCode
();
}
String
folderPath
=
System
.
getProperty
(
"java.io.tmpdir"
)
+
File
.
separator
+
folderName
;
File
rootFile
=
new
File
(
folderPath
);
if
(!
rootFile
.
exists
())
{
rootFile
.
mkdirs
();
}
FileDownloadDTO
fileDownload
;
String
fileName
;
boolean
isDecryptFile
;
for
(
MgRnrFileDTO
file
:
list
)
{
isDecryptFile
=
true
;
fileName
=
fileTypeConvertName
(
file
);
if
(
CuscStringUtils
.
isEmpty
(
fileName
))
{
continue
;
}
//判断文件是否需要加密
if
(
fileName
.
equals
(
"027"
)
||
fileName
.
equals
(
"047"
))
{
isDecryptFile
=
false
;
}
// //通过文件id查询文件格式
// FileRecordDTO fileRecord = fileService.fileMetainfo(file.getFileSystemId());
// if (fileRecord == null) {
// log.error("文件【{}】未查询到文件信息", file.getFileSystemId());
// continue;
// }
//增加文件类型后缀
fileName
=
fileName
+
file
.
getFileSystemId
().
substring
(
file
.
getFileSystemId
().
lastIndexOf
(
"."
));
fileDownload
=
new
FileDownloadDTO
();
fileDownload
.
setFilePath
(
folderPath
);
fileDownload
.
setUuid
(
file
.
getFileSystemId
());
fileDownload
.
setFileName
(
folderName
+
"_"
+
fileName
);
// //根据类型判断是否需要解密
// if (isDecryptFile) {
// Response<ImageBytesDTO> bytesResp = cuscImageService.getBytes(file.getFileSystemId());
// if (bytesResp.isSuccess()) {
// try {
// FileUtils.writeByteArrayToFile(
// new File(fileDownload.getFilePath() + File.separator + fileDownload.getFileName()),
// bytesResp.getData().getBytes());
// } catch (IOException e) {
// log.error("FileUtils.writeByteArrayToFile error ", e);
// }
// }
// } else {
String
targetPath
=
fileDownload
.
getFilePath
()
+
File
.
separator
+
fileDownload
.
getFileName
();
byte
[]
bytes
=
fileService
.
downLoadBytes
(
file
.
getFileSystemId
());
InputStream
sbs
=
new
ByteArrayInputStream
(
bytes
);
String
font
=
"中国移动车联网卡实名登记,"
+
file
.
getCreateTime
()+
","
+
encryptionKeyDTO
.
getPlatFormId
()+
t1FileReqDTO
.
getRequestID
();
try
{
//移动需要增加水印
if
(
MbCodeEnum
.
CMCC
.
getCode
().
equals
(
operatorService
.
get
(
iccid
)))
{
WatermarkUtil
.
waterPress
(
sbs
,
new
FileOutputStream
(
targetPath
),
14
,
0.9f
,
30
,
30
,
font
.
split
(
","
));
}
else
{
Files
.
copy
(
sbs
,
Paths
.
get
(
targetPath
));
}
new
File
(
targetPath
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// fileService.downloadToLocal(fileDownload);
}
// }
//压缩目录并加密,将压缩文件读取到EncryptFile中
String
zipFileName
=
folderPath
+
".zip"
;
try
{
if
(
com
.
cusc
.
nirvana
.
user
.
rnr
.
fp
.
constants
.
MbCodeEnum
.
CMCC
.
getCode
().
equals
(
operatorService
.
get
(
iccid
)))
{
ZipUtils
.
toZip
(
folderPath
,
new
FileOutputStream
(
zipFileName
),
false
);
File
file
=
encryptZipFile
(
new
File
(
zipFileName
),
encryptionKeyDTO
);
t1FileReqDTO
.
setEncryptFile
(
file
);
log
.
info
(
"file.getPath(){},"
,
file
.
getPath
());
// AESUtil.decryptFile(fpT1VehicleCompanyDTO.getCmccTextOrPictureKey(),file.getPath(),"D:\\测试文件夹\\"+file.getName());
}
else
{
ZipUtils
.
toZip
(
folderPath
,
new
FileOutputStream
(
zipFileName
),
false
);
log
.
info
(
"zipFileName----------{}"
,
JSON
.
toJSON
(
zipFileName
));
byte
[]
byteArr
=
ZipUtils
.
readByteFromFile
(
zipFileName
);
log
.
info
(
"userInfoT1Key============={}"
,
JSON
.
toJSON
(
encryptionKeyDTO
.
getT1UserInfoKey
()));
byte
[]
encodeByteArr
=
RnrDataSm4Util
.
encryptEcbPaddingBytes
(
encryptionKeyDTO
.
getT1UserInfoKey
(),
byteArr
,
true
);
t1FileReqDTO
.
setEncryptFile
(
CuscFileUtils
.
byte2File
(
encodeByteArr
,
folderPath
+
".bin"
));
}
t1FileReqDTO
.
setServiceProvider
(
iccid
);
if
(
MbCodeEnum
.
CMCC
.
getCode
().
equals
(
MbCodeEnum
.
get
(
iccid
).
getCode
())){
this
.
t1UploadFileInfoCMCC
(
t1FileReqDTO
,
uuid
);
}
else
if
(
MbCodeEnum
.
CTCC
.
getCode
().
equals
(
MbCodeEnum
.
get
(
iccid
).
getCode
())){
this
.
t1UploadFileInfoCTCC
(
t1FileReqDTO
,
uuid
);
}
else
{
//执行文件上传
uploadT1File
(
t1FileReqDTO
,
uuid
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"ZipUtils toZip error "
,
e
);
return
false
;
}
finally
{
//删除文件夹
CuscFileUtils
.
delFolder
(
folderPath
);
//删除zip文件
File
zipFile
=
new
File
(
zipFileName
);
if
(
zipFile
.
exists
())
{
zipFile
.
delete
();
}
//删除bin文件
File
binFile
=
new
File
(
folderPath
+
".bin"
);
if
(
binFile
.
exists
())
{
binFile
.
delete
();
}
}
return
true
;
}
@Override
public
File
encryptZipFile
(
File
zip
,
EncryptionKeyDTO
encryptionKeyDTO
)
throws
Exception
{
String
sourceFile
=
zip
.
getAbsolutePath
();
return
AESUtil
.
encryptFile
(
encryptionKeyDTO
.
getCmccTextOrPictureKey
(),
sourceFile
,
-
1
!=
sourceFile
.
indexOf
(
".zip"
)
?
sourceFile
.
replace
(
".zip"
,
".bin"
)
:
sourceFile
);
}
@Override
public
T1CommonResponseDTO
t1CallbackResult
(
T1CallbackResultDTO
t1CallbackResultDTO
)
{
T1CommonResponseDTO
t1CommonResponseDTO
=
new
T1CommonResponseDTO
();
t1CommonResponseDTO
.
setRequestID
(
t1CallbackResultDTO
.
getRequestID
());
//查询上报信息
FpT1UploadStatusDTO
fpT1UploadStatusDTO
=
fpT1UploadStatusService
.
getByRequestId
(
t1CallbackResultDTO
.
getRequestID
());
if
(
null
==
fpT1UploadStatusDTO
){
t1CommonResponseDTO
.
setOprRst
(
"2"
);
t1CommonResponseDTO
.
setFailureCause
(
"根据requestId没有查询到上报信息"
);
log
.
info
(
"没有查询到T1上报信息requestId{}"
,
t1CallbackResultDTO
.
getRequestID
());
return
t1CommonResponseDTO
;
}
FpT1UploadStatusDTO
fpT1UploadStatus
=
new
FpT1UploadStatusDTO
();
fpT1UploadStatus
.
setUuid
(
fpT1UploadStatusDTO
.
getUuid
());
fpT1UploadStatus
.
setReportCompletion
(
Integer
.
valueOf
(
t1CallbackResultDTO
.
getOprRst
()));
fpT1UploadStatus
.
setReportCompletionResp
(
JSON
.
toJSONString
(
t1CallbackResultDTO
));
fpT1UploadStatusService
.
update
(
fpT1UploadStatus
);
t1CommonResponseDTO
.
setOprRst
(
"1"
);
return
t1CommonResponseDTO
;
}
@Override
public
Response
againUploadUserInfoAndFile
(
AgainUploadDTO
againUploadDTO
)
{
List
<
String
>
requestIdList
=
againUploadDTO
.
getRequestIdList
();
if
(
CollectionUtils
.
isEmpty
(
requestIdList
)){
return
Response
.
createError
(
"入参不可以为空"
);
}
List
<
FpT1UploadStatusDTO
>
list
=
fpT1UploadStatusService
.
queryByRequestIdList
(
requestIdList
);
if
(
CollectionUtils
.
isEmpty
(
list
)){
return
Response
.
createError
(
"没有查询到上报信息"
);
}
for
(
FpT1UploadStatusDTO
fpT1UploadStatusDTO
:
list
){
MgCardNoticeDTO
mgCardNoticeDTO
=
JSON
.
parseObject
(
fpT1UploadStatusDTO
.
getT1Request
(),
MgCardNoticeDTO
.
class
);
Response
response
=
uploadUserInfoAndFile
(
mgCardNoticeDTO
);
if
(!
response
.
isSuccess
()){
log
.
warn
(
"重试失败requestId{}"
,
fpT1UploadStatusDTO
.
getRequestId
());
}
}
return
Response
.
createSuccess
();
}
public
static
void
main
(
String
[]
args
)
{
// HttpHeaders httpHeaders = new HttpHeaders();
// httpHeaders.add(SignConstants.APP_ID, "78F985EE0C6F4418B73013D2B5C48AB2");
// httpHeaders.add(SignConstants.NONCE_STR, CuscStringUtils.generateUuid());
// httpHeaders.add(SignConstants.TIMESTAMP, String.valueOf(System.currentTimeMillis()));
// httpHeaders.add(SignConstants.VERSION, "1.0.0");
// httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
// StringBuilder sb = new StringBuilder();
// sb.append(SignConstants.APP_ID + "78F985EE0C6F4418B73013D2B5C48AB2");
// sb.append(SignConstants.NONCE_STR + httpHeaders.get(SignConstants.NONCE_STR).get(0));
// sb.append(SignConstants.TIMESTAMP + httpHeaders.get(SignConstants.TIMESTAMP).get(0));
// sb.append(SignConstants.VERSION + httpHeaders.get(SignConstants.VERSION).get(0));
// log.info("SmsServiceImpl headers param : {}, appScret:{}", sb, "6C0768AA4CE64AC3893A0F0F280571A6");
// String scret = HMAC.sign(sb.toString(), "6C0768AA4CE64AC3893A0F0F280571A6", HMAC.Type.HmacSHA256);
// httpHeaders.add(SignConstants.SIGN, scret);
//
// RestTemplate restTemplate = new RestTemplate();
// long startTime = System.currentTimeMillis();
//
// String url = "https://pre-fileservice.cu-sc.com:19098/open-api/unified-storage/file/api/upload";
//
// File file = new File("C:\\Users\\PC\\Desktop\\T1上报.txt");
//
// FileSystemResource fileSystemResource = new FileSystemResource(file);
//
// // body体参数
// MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>();
// // headers参数
// HttpHeaders requestHeaders = new HttpHeaders();
// requestBody.add("RequestID", "dsajsahsadfsdfsfahksa");
//// requestBody.add("Path", file.getEncryptFile().getPath());
// try {
// requestBody.add("Md5", DigestUtils.md5Hex(new FileInputStream(file)));
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// requestBody.add("File", fileSystemResource);
//
//// ByteArrayResource resource = null;
//// //存储
//// resource = new ByteArrayResource(File2byte(file.getEncryptFile())) ;
//// requestBody.add("File", resource);
//
//// try {
//// InputStream inputStream = new FileInputStream(file.getEncryptFile());
//// MultipartFile multipartFile = new MockMultipartFile(file.getEncryptFile().getName(), inputStream);
//// requestBody.add("File", multipartFile.getResource());
//// } catch (IOException e) {
//// e.printStackTrace();
//// }
//
// // 封装所有参数
// HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(requestBody, httpHeaders);
// ResponseEntity<String> entity =
// restTemplate.exchange(url,HttpMethod.POST, requestEntity, String.class);
// log.info("uploadT1File url: {},response: {},cost: {} ms", url, entity.getBody(),
// System.currentTimeMillis() - startTime);
// T1CommonResponseDTO result = JSON.parseObject(entity.getBody(), T1CommonResponseDTO.class);
//
RestTemplate
restTemplateT1
=
new
RestTemplate
();
long
startTimeT1
=
System
.
currentTimeMillis
();
HttpHeaders
httpHeaderT1
=
new
HttpHeaders
();
httpHeaderT1
.
add
(
SignConstants
.
APP_ID
,
"78F985EE0C6F4418B73013D2B5C48AB2"
);
httpHeaderT1
.
add
(
SignConstants
.
NONCE_STR
,
CuscStringUtils
.
generateUuid
());
httpHeaderT1
.
add
(
SignConstants
.
TIMESTAMP
,
String
.
valueOf
(
System
.
currentTimeMillis
()));
httpHeaderT1
.
add
(
SignConstants
.
VERSION
,
"1.0.0"
);
httpHeaderT1
.
setContentType
(
MediaType
.
parseMediaType
(
"application/json; charset=UTF-8"
));
StringBuilder
sbs
=
new
StringBuilder
();
sbs
.
append
(
SignConstants
.
APP_ID
+
"78F985EE0C6F4418B73013D2B5C48AB2"
);
sbs
.
append
(
SignConstants
.
NONCE_STR
+
httpHeaderT1
.
get
(
SignConstants
.
NONCE_STR
).
get
(
0
));
sbs
.
append
(
SignConstants
.
TIMESTAMP
+
httpHeaderT1
.
get
(
SignConstants
.
TIMESTAMP
).
get
(
0
));
sbs
.
append
(
SignConstants
.
VERSION
+
httpHeaderT1
.
get
(
SignConstants
.
VERSION
).
get
(
0
));
log
.
info
(
"SmsServiceImpl headers param : {}, appScret:{}"
,
sbs
,
"6C0768AA4CE64AC3893A0F0F280571A6"
);
String
screts
=
HMAC
.
sign
(
sbs
.
toString
(),
"6C0768AA4CE64AC3893A0F0F280571A6"
,
HMAC
.
Type
.
HmacSHA256
);
httpHeaderT1
.
add
(
SignConstants
.
SIGN
,
screts
);
// body体参数
Map
<
String
,
String
>
requestBodyT1
=
new
HashMap
<>();
// 设置header是文件上传
// 参数设置文件
requestBodyT1
.
put
(
"RequestID"
,
"dsajsahsadfsdfsfahksa"
);
requestBodyT1
.
put
(
"Code"
,
"cuscplus"
);
// requestBody.add("EncryptFile", fileSystemResource);
requestBodyT1
.
put
(
"EncryptFileId"
,
"261a1000000000000285235"
);
String
urls
=
"https://pre-rnr-open-api.cu-sc.com:19098/open-api/user-rnr-data/file/rnr"
;
// try {
// requestBody.add("FileMd5",DigestUtils.md5Hex(new FileInputStream(file.getEncryptFile())));
// } catch (IOException e) {
// e.printStackTrace();
// }
requestBodyT1
.
put
(
"ServiceProvider"
,
"89860098000000000036"
);
// 封装所有参数
HttpEntity
<
Map
<
String
,
String
>>
requestEntitys
=
new
HttpEntity
<>(
requestBodyT1
,
httpHeaderT1
);
log
.
info
(
"开户文件上报{}"
,
JSON
.
toJSON
(
requestEntitys
));
ResponseEntity
<
String
>
entitys
=
restTemplateT1
.
exchange
(
urls
,
HttpMethod
.
POST
,
requestEntitys
,
String
.
class
);
log
.
info
(
"开户文件上报回参 url: {},response: {},cost: {} ms"
,
urls
,
entitys
.
getBody
(),
System
.
currentTimeMillis
()
-
startTimeT1
);
T1CommonResponseDTO
results
=
JSON
.
parseObject
(
entitys
.
getBody
(),
T1CommonResponseDTO
.
class
);
System
.
out
.
println
(
JSON
.
toJSON
(
results
));
}
/**
* Description: 根据文件类型转文件名称
* <br />
* CreateDate 2022-06-08 21:32:02
*
* @author yuyi
**/
private
String
fileTypeConvertName
(
MgRnrFileDTO
file
)
{
StringBuffer
fileName
=
new
StringBuffer
();
fileName
.
append
(
"0"
);
//第3 位指示照片类型,“1”表示“视频截图1”,“2”表示“视频截图2”,“4”表示“证件正面照片”,“5”表示“证件反面照片”,“6”表示“现场正面照片”,“7”表示“授权书”
//判断个人还是企业
if
(
file
.
getIsCompany
()
==
0
)
{
//“1”表示个人用户照片,,“4”表示代/经办人照片
//个人
if
(
CuscStringUtils
.
isEmpty
(
file
.
getLiaisonId
())
||
file
.
getLiaisonId
().
equals
(
"0"
))
{
//本人
//“1”表示“视频截图1”
if
(
RnrFileType
.
LIVENESS_SCREEN_FIRST
.
getCode
().
equals
(
file
.
getFileType
()))
{
fileName
.
append
(
"11"
);
return
fileName
.
toString
();
}
//“2”表示“视频截图2”
if
(
RnrFileType
.
LIVENESS_SCREEN_TWO
.
getCode
().
equals
(
file
.
getFileType
()))
{
fileName
.
append
(
"12"
);
return
fileName
.
toString
();
}
//“4”表示“证件正面照片”
if
(
isCertPicFront
(
file
.
getFileType
()))
{
fileName
.
append
(
"14"
);
return
fileName
.
toString
();
}
//“5”表示“证件反面照片”
if
(
isCertPicBack
(
file
.
getFileType
()))
{
fileName
.
append
(
"15"
);
return
fileName
.
toString
();
}
}
else
{
//委托人
//“1”表示“视频截图1”
if
(
RnrFileType
.
LIVENESS_SCREEN_FIRST
.
getCode
().
equals
(
file
.
getFileType
()))
{
fileName
.
append
(
"41"
);
return
fileName
.
toString
();
}
//“2”表示“视频截图2”
if
(
RnrFileType
.
LIVENESS_SCREEN_TWO
.
getCode
().
equals
(
file
.
getFileType
()))
{
fileName
.
append
(
"42"
);
return
fileName
.
toString
();
}
//“4”表示“证件正面照片”
if
(
isCertPicFront
(
file
.
getFileType
()))
{
fileName
.
append
(
"44"
);
return
fileName
.
toString
();
}
//“5”表示“证件反面照片”
if
(
isCertPicBack
(
file
.
getFileType
()))
{
fileName
.
append
(
"45"
);
return
fileName
.
toString
();
}
//个人 “7”表示“授权书”
if
(
RnrFileType
.
LETTER_ATTORNEY
.
getCode
().
equals
(
file
.
getFileType
()))
{
fileName
.
append
(
"47"
);
return
fileName
.
toString
();
}
}
}
else
{
//企业 “2”表示责任人照片,“3”表示单位照片
//“1”表示“视频截图1”
if
(
RnrFileType
.
LIVENESS_SCREEN_FIRST
.
getCode
().
equals
(
file
.
getFileType
()))
{
fileName
.
append
(
"21"
);
return
fileName
.
toString
();
}
//“2”表示“视频截图2”
if
(
RnrFileType
.
LIVENESS_SCREEN_TWO
.
getCode
().
equals
(
file
.
getFileType
()))
{
fileName
.
append
(
"22"
);
return
fileName
.
toString
();
}
//“4”表示“证件正面照片”
if
(
isCertPicFront
(
file
.
getFileType
()))
{
fileName
.
append
(
"24"
);
return
fileName
.
toString
();
}
//“5”表示“证件反面照片”
if
(
isCertPicBack
(
file
.
getFileType
()))
{
fileName
.
append
(
"25"
);
return
fileName
.
toString
();
}
//企业 “7”表示“授权书”
if
(
RnrFileType
.
ENTERPRISE_AUTH_FILE
.
getCode
().
equals
(
file
.
getFileType
()))
{
fileName
.
append
(
"27"
);
return
fileName
.
toString
();
}
//企业 “4”表示“证件正面照片”
if
(
RnrFileType
.
ENTERPRISE_PIC
.
getCode
().
equals
(
file
.
getFileType
()))
{
fileName
.
append
(
"34"
);
return
fileName
.
toString
();
}
}
return
null
;
}
/**
* Description: 验证文件类型是否是证件正面
* <br />
* CreateDate 2022-06-09 10:12:56
*
* @author yuyi
**/
private
boolean
isCertPicFront
(
Integer
fileType
)
{
if
(
RnrFileType
.
IDENTITY_CARD_BACK
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
OFFICIAL_CARD_FRONT
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
POLICE_CARD_FRONT
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
HK_MACAO_PASSPORT_FRONT
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
TAIWAN_CARD_FRONT
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
FOREIGN_NATIONAL_PASSPORT_FRONT
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
HK_MACAO_RESIDENCE_PERMIT_FRONT
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
TAIWAN_RESIDENCE_PERMIT_FRONT
.
getCode
().
equals
(
fileType
))
{
return
true
;
}
return
false
;
}
/**
* Description: 验证文件类型是否是证件反面
* <br />
* CreateDate 2022-06-09 10:12:56
*
* @author yuyi
**/
private
boolean
isCertPicBack
(
Integer
fileType
)
{
if
(
RnrFileType
.
IDENTITY_CARD_FRONT
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
OFFICIAL_CARD_BACK
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
POLICE_CARD_BACK
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
HK_MACAO_PASSPORT_BACK
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
TAIWAN_CARD_BACK
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
FOREIGN_NATIONAL_PASSPORT_BACK
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
HK_MACAO_RESIDENCE_PERMIT_BACK
.
getCode
().
equals
(
fileType
)
||
RnrFileType
.
TAIWAN_RESIDENCE_PERMIT_BACK
.
getCode
().
equals
(
fileType
))
{
return
true
;
}
return
false
;
}
/**
* Description: 上传开户信息
* <br />
* CreateDate 2022-05-16 10:22:07
*
* @author yuyi
**/
private
T1CommonResponseDTO
uploadT1UserInfo
(
T1UserInfoReqDTO
userInfo
)
{
long
startTime
=
System
.
currentTimeMillis
();
String
url
=
t1Config
.
getDateUrl
()
+
"/user-rnr-data/data/userInfo"
;
log
.
info
(
"uploadUserInfo url: {},request: {}"
,
url
,
JSON
.
toJSONString
(
userInfo
));
String
requestStr
=
JSON
.
toJSONString
(
userInfo
);
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFpT1
.
exchange
(
url
,
HttpMethod
.
POST
,
new
HttpEntity
<>(
requestStr
,
headers
()),
String
.
class
);
log
.
info
(
"uploadUserInfo url: {},response: {},cost: {} ms"
,
url
,
entity
.
getBody
(),
System
.
currentTimeMillis
()
-
startTime
);
T1CommonResponseDTO
result
=
JSON
.
parseObject
(
entity
.
getBody
(),
T1CommonResponseDTO
.
class
);
return
result
;
}
public
HttpHeaders
headers
()
{
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
httpHeaders
.
add
(
SignConstants
.
APP_ID
,
t1Config
.
getAPPID
());
httpHeaders
.
add
(
SignConstants
.
NONCE_STR
,
CuscStringUtils
.
generateUuid
());
httpHeaders
.
add
(
SignConstants
.
TIMESTAMP
,
String
.
valueOf
(
System
.
currentTimeMillis
()));
httpHeaders
.
add
(
SignConstants
.
VERSION
,
t1Config
.
getVERSION
());
httpHeaders
.
setContentType
(
MediaType
.
parseMediaType
(
"application/json; charset=UTF-8"
));
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
SignConstants
.
APP_ID
+
t1Config
.
getAPPID
());
sb
.
append
(
SignConstants
.
NONCE_STR
+
httpHeaders
.
get
(
SignConstants
.
NONCE_STR
).
get
(
0
));
sb
.
append
(
SignConstants
.
TIMESTAMP
+
httpHeaders
.
get
(
SignConstants
.
TIMESTAMP
).
get
(
0
));
sb
.
append
(
SignConstants
.
VERSION
+
httpHeaders
.
get
(
SignConstants
.
VERSION
).
get
(
0
));
log
.
info
(
"SmsServiceImpl headers param : {}, appScret:{}"
,
sb
,
t1Config
.
getAPPSCRET
());
String
scret
=
HMAC
.
sign
(
sb
.
toString
(),
t1Config
.
getAPPSCRET
(),
HMAC
.
Type
.
HmacSHA256
);
httpHeaders
.
add
(
SignConstants
.
SIGN
,
scret
);
log
.
info
(
"httpHeaders============{}"
,
JSON
.
toJSON
(
httpHeaders
));
return
httpHeaders
;
}
public
HttpHeaders
fileHeader
()
{
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
httpHeaders
.
add
(
SignConstants
.
APP_ID
,
t1Config
.
getAPPID
());
httpHeaders
.
add
(
SignConstants
.
NONCE_STR
,
CuscStringUtils
.
generateUuid
());
httpHeaders
.
add
(
SignConstants
.
TIMESTAMP
,
String
.
valueOf
(
System
.
currentTimeMillis
()));
httpHeaders
.
add
(
SignConstants
.
VERSION
,
t1Config
.
getVERSION
());
httpHeaders
.
setContentType
(
MediaType
.
MULTIPART_FORM_DATA
);
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
SignConstants
.
APP_ID
+
t1Config
.
getAPPID
());
sb
.
append
(
SignConstants
.
NONCE_STR
+
httpHeaders
.
get
(
SignConstants
.
NONCE_STR
).
get
(
0
));
sb
.
append
(
SignConstants
.
TIMESTAMP
+
httpHeaders
.
get
(
SignConstants
.
TIMESTAMP
).
get
(
0
));
sb
.
append
(
SignConstants
.
VERSION
+
httpHeaders
.
get
(
SignConstants
.
VERSION
).
get
(
0
));
log
.
info
(
"SmsServiceImpl headers param : {}, appScret:{}"
,
sb
,
t1Config
.
getAPPSCRET
());
String
scret
=
HMAC
.
sign
(
sb
.
toString
(),
t1Config
.
getAPPSCRET
(),
HMAC
.
Type
.
HmacSHA256
);
httpHeaders
.
add
(
SignConstants
.
SIGN
,
scret
);
log
.
info
(
"httpHeaders============{}"
,
JSON
.
toJSON
(
httpHeaders
));
return
httpHeaders
;
}
/**
* Description: 上传开户信息
* <br />
* CreateDate 2022-05-16 10:22:07
*
* @author yuyi
**/
private
T1CommonResponseDTO
uploadT1File
(
T1FileReqDTO
file
,
String
uuid
)
{
T1CommonResponseDTO
t1
=
uploadFile
(
file
);
if
(
null
!=
t1
.
getOprRst
()
&&
!
"1"
.
equals
(
t1
.
getOprRst
())){
this
.
fpT1UpdateFiletatus
(
uuid
,
2
,
t1
);
return
t1
;
}
long
startTime
=
System
.
currentTimeMillis
();
String
url
=
t1Config
.
getDateUrl
()
+
"/user-rnr-data/file/rnr"
;
log
.
info
(
"uploadT1File url: {},request: {}"
,
url
,
JSON
.
toJSONString
(
file
));
FileSystemResource
fileSystemResource
=
new
FileSystemResource
(
file
.
getEncryptFile
());
// headers参数
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
// body体参数
Map
<
String
,
String
>
requestBody
=
new
HashMap
<>();
// 设置header是文件上传
requestHeaders
.
setContentType
(
MediaType
.
MULTIPART_FORM_DATA
);
// 参数设置文件
requestBody
.
put
(
"RequestID"
,
file
.
getRequestID
());
requestBody
.
put
(
"Code"
,
file
.
getCode
());
// requestBody.add("EncryptFile", fileSystemResource);
requestBody
.
put
(
"EncryptFileId"
,
t1
.
getFileId
());
// try {
// requestBody.add("FileMd5",DigestUtils.md5Hex(new FileInputStream(file.getEncryptFile())));
// } catch (IOException e) {
// e.printStackTrace();
// }
requestBody
.
put
(
"ServiceProvider"
,
file
.
getServiceProvider
());
// 封装所有参数
HttpEntity
<
Map
<
String
,
String
>>
requestEntity
=
new
HttpEntity
<>(
requestBody
,
headers
());
log
.
info
(
"开户文件上报{}"
,
JSON
.
toJSON
(
requestEntity
));
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFpT1
.
exchange
(
url
,
HttpMethod
.
POST
,
requestEntity
,
String
.
class
);
log
.
info
(
"uploadT1File url: {},response: {},cost: {} ms"
,
url
,
entity
.
getBody
(),
System
.
currentTimeMillis
()
-
startTime
);
T1CommonResponseDTO
result
=
JSON
.
parseObject
(
entity
.
getBody
(),
T1CommonResponseDTO
.
class
);
if
(
result
.
getOprRst
().
equals
(
"1"
)){
this
.
fpT1UpdateFiletatus
(
uuid
,
1
,
result
);
}
else
{
this
.
fpT1UpdateFiletatus
(
uuid
,
2
,
result
);
}
return
result
;
}
/**
* 中国移动上传开户信息
*/
private
T1CommonResponseDTO
t1UploadUserInfoCMCC
(
MgRnrCardInfoDTO
card
,
T1UserInfoDTO
ret
,
FpT1VehicleCompanyDTO
t1VehicleCompanyDTO
,
T1UserInfoReqDTO
t1UserInfoReq
){
//通过iccid查询msisdn
T1CommonResponseDTO
result
=
null
;
Response
<
VinIccidDTO
>
iccidResp
=
simVehicleRelService
.
getVinByIccid
(
card
.
getIccid
());
log
.
warn
(
"t1UploadUserInfoCMCC方法iccidResp回参{}"
,
JSON
.
toJSON
(
iccidResp
));
if
(!
iccidResp
.
isSuccess
()
||
iccidResp
.
getData
()
==
null
)
{
log
.
warn
(
"t1UploadUserInfoCMCC 通过卡获取msisdn失败,失败原因:{}"
,
JSON
.
toJSONString
(
iccidResp
));
}
VinIccidDTO
iccidInfo
=
iccidResp
.
getData
();
ret
.
setMSISDN
(
iccidInfo
.
getMsisdn
());
//移动的开户信息用AES加密
String
encryptUserInfo
=
null
;
try
{
encryptUserInfo
=
AESUtil
.
encryptStr
(
JSON
.
toJSONString
(
ret
),
encryptionKeyDTO
.
getCmccTextOrPictureKey
());
}
catch
(
Exception
e
)
{
result
=
new
T1CommonResponseDTO
();
result
.
setOprRst
(
"2"
);
result
.
setFailureCause
(
"加密失败"
);
return
result
;
}
t1UserInfoReq
.
setEncryptUserInfo
(
encryptUserInfo
);
t1UserInfoReq
.
setAuth
(
getAuth
(
encryptionKeyDTO
));
t1UserInfoReq
.
setServiceProvider
(
null
);
long
startTime
=
System
.
currentTimeMillis
();
String
url
=
t1Config
.
getCmccUrl
()
+
"/realname/interface/v1/account-info/sync"
;
log
.
info
(
"uploadUserInfo url: {},request: {}"
,
url
,
JSON
.
toJSONString
(
t1UserInfoReq
));
String
requestStr
=
JSON
.
toJSONString
(
t1UserInfoReq
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
requestHeaders
.
setContentType
(
MediaType
.
APPLICATION_JSON_UTF8
);
try
{
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFpT1
.
exchange
(
url
,
HttpMethod
.
POST
,
new
HttpEntity
<>(
requestStr
,
requestHeaders
),
String
.
class
);
log
.
info
(
"uploadUserInfo url: {},response: {},cost: {} ms"
,
url
,
entity
.
getBody
(),
System
.
currentTimeMillis
()
-
startTime
);
result
=
JSON
.
parseObject
(
entity
.
getBody
(),
T1CommonResponseDTO
.
class
);
}
catch
(
RestClientException
e
)
{
result
=
new
T1CommonResponseDTO
();
result
.
setOprRst
(
"2"
);
result
.
setFailureCause
(
"调用报错"
);
}
return
result
;
}
/**
* 中国移动上传车辆信息
*/
private
T1CommonResponseDTO
t1UploadCarInfoCMCC
(
T1CarInfoDTO
t1CarInfoDTO
){
T1CarInfoCMCCDTO
t1CarInfoCMCCDTO
=
new
T1CarInfoCMCCDTO
();
BeanUtils
.
copyProperties
(
t1CarInfoDTO
,
t1CarInfoCMCCDTO
);
t1CarInfoCMCCDTO
.
setAuth
(
getAuth
(
encryptionKeyDTO
));
t1CarInfoCMCCDTO
.
setRequestId
(
requestIdCmss
);
long
startTime
=
System
.
currentTimeMillis
();
String
url
=
t1Config
.
getCmccUrl
()
+
"/realname/interface/v1/car-info/sync"
;
log
.
info
(
"uploadUserInfo url: {},request: {}"
,
url
,
JSON
.
toJSONString
(
t1CarInfoCMCCDTO
));
String
requestStr
=
JSON
.
toJSONString
(
t1CarInfoCMCCDTO
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
requestHeaders
.
setContentType
(
MediaType
.
APPLICATION_JSON_UTF8
);
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFpT1
.
exchange
(
url
,
HttpMethod
.
POST
,
new
HttpEntity
<>(
requestStr
,
requestHeaders
),
String
.
class
);
log
.
info
(
"uploadUserInfo url: {},response: {},cost: {} ms"
,
url
,
entity
.
getBody
(),
System
.
currentTimeMillis
()
-
startTime
);
T1CommonResponseDTO
result
=
JSON
.
parseObject
(
entity
.
getBody
(),
T1CommonResponseDTO
.
class
);
return
result
;
}
/**
* 中国移动上传图片信息
*/
private
Boolean
t1UploadFileInfoCMCC
(
T1FileReqDTO
t1FileReqDTO
,
String
uuid
)
{
Response
response
=
cmccSftpUtil
.
upload
(
t1FileReqDTO
);
T1CommonResponseDTO
t1CommonResponseDTO
=
new
T1CommonResponseDTO
();
t1CommonResponseDTO
.
setFailureCause
(
"上传移动文件服务器失败"
);
t1CommonResponseDTO
.
setRequestID
(
response
.
getException
());
t1CommonResponseDTO
.
setFailureCause
(
response
.
getMsg
());
if
(
response
.
isSuccess
()){
t1CommonResponseDTO
.
setOprRst
(
"1"
);
this
.
fpT1UpdateFiletatus
(
uuid
,
1
,
t1CommonResponseDTO
);
return
true
;
}
else
{
t1CommonResponseDTO
.
setOprRst
(
"2"
);
this
.
fpT1UpdateFiletatus
(
uuid
,
2
,
t1CommonResponseDTO
);
return
false
;
}
}
/**
* 中国电信上传开户信息
*/
private
T1CommonResponseDTO
t1UploadUserInfoCTCC
(
MgRnrCardInfoDTO
card
,
T1UserInfoDTO
ret
,
FpT1VehicleCompanyDTO
t1VehicleCompanyDTO
,
T1UserInfoReqDTO
t1UserInfoReq
){
//通过iccid查询msisdn
Response
<
VinIccidDTO
>
iccidResp
=
simVehicleRelService
.
getVinByIccid
(
card
.
getIccid
());
log
.
warn
(
"t1UploadUserInfoCMCC方法iccidResp回参{}"
,
JSON
.
toJSON
(
iccidResp
));
if
(!
iccidResp
.
isSuccess
()
||
iccidResp
.
getData
()
==
null
)
{
log
.
warn
(
"t1UploadUserInfoCMCC 通过卡获取msisdn失败,失败原因:{}"
,
JSON
.
toJSONString
(
iccidResp
));
}
VinIccidDTO
iccidInfo
=
iccidResp
.
getData
();
ret
.
setMSISDN
(
iccidInfo
.
getMsisdn
());
String
encryptUserInfo
=
RnrDataSm4Util
.
encryptEcbPadding
(
t1VehicleCompanyDTO
.
getT1UserInfoKey
(),
JSON
.
toJSONString
(
ret
),
true
,
null
);
t1UserInfoReq
.
setEncryptUserInfo
(
encryptUserInfo
);
t1UserInfoReq
.
setAuth
(
getAuth
(
encryptionKeyDTO
));
long
startTime
=
System
.
currentTimeMillis
();
String
url
=
t1Config
.
getCtccUrl
()
+
"/api/createAccount"
;
log
.
info
(
"uploadUserInfo url: {},request: {}"
,
url
,
JSON
.
toJSONString
(
t1UserInfoReq
));
String
requestStr
=
JSON
.
toJSONString
(
t1UserInfoReq
);
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFpT1
.
exchange
(
url
,
HttpMethod
.
POST
,
new
HttpEntity
<>(
requestStr
),
String
.
class
);
log
.
info
(
"uploadUserInfo url: {},response: {},cost: {} ms"
,
url
,
entity
.
getBody
(),
System
.
currentTimeMillis
()
-
startTime
);
T1CommonResponseDTO
result
=
JSON
.
parseObject
(
entity
.
getBody
(),
T1CommonResponseDTO
.
class
);
return
result
;
}
/**
* 中国电信上传车辆信息
*/
private
T1CommonResponseDTO
t1UploadCarInfoCTCC
(
T1CarInfoDTO
t1CarInfoDTO
){
//通过iccid查询msisdn
// Response<VinIccidDTO> iccidResp = simVehicleRelService.getVinByIccid(card.getIccid());
// log.warn("t1UploadCarInfoCUCC方法iccidResp回参{}",JSON.toJSON(iccidResp));
// if (!iccidResp.isSuccess() || iccidResp.getData() == null) {
// log.warn("t1UploadCarInfoCUCC 通过卡获取msisdn失败,失败原因:{}", JSON.toJSONString(iccidResp));
// }
// VinIccidDTO iccidInfo = iccidResp.getData();
// ret.setMSISDN(iccidInfo.getMsisdn());
T1CarInfoCMCCDTO
t1CarInfoCMCCDTO
=
new
T1CarInfoCMCCDTO
();
BeanUtils
.
copyProperties
(
t1CarInfoDTO
,
t1CarInfoCMCCDTO
);
t1CarInfoCMCCDTO
.
setAuth
(
getAuth
(
encryptionKeyDTO
));
long
startTime
=
System
.
currentTimeMillis
();
String
url
=
t1Config
.
getCtccUrl
()
+
"/api/vehicleInfo"
;
log
.
info
(
"uploadUserInfo url: {},request: {}"
,
url
,
JSON
.
toJSONString
(
t1CarInfoCMCCDTO
));
String
requestStr
=
JSON
.
toJSONString
(
t1CarInfoCMCCDTO
);
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFpT1
.
exchange
(
url
,
HttpMethod
.
POST
,
new
HttpEntity
<>(
requestStr
),
String
.
class
);
log
.
info
(
"uploadUserInfo url: {},response: {},cost: {} ms"
,
url
,
entity
.
getBody
(),
System
.
currentTimeMillis
()
-
startTime
);
T1CommonResponseDTO
result
=
JSON
.
parseObject
(
entity
.
getBody
(),
T1CommonResponseDTO
.
class
);
return
result
;
}
/**
* 中国电信上传图片信息
*/
private
Boolean
t1UploadFileInfoCTCC
(
T1FileReqDTO
t1FileReqDTO
,
String
uuid
){
Response
response
=
ctccSftpUtil
.
upload
(
t1FileReqDTO
);
T1CommonResponseDTO
t1CommonResponseDTO
=
new
T1CommonResponseDTO
();
t1CommonResponseDTO
.
setFailureCause
(
"上传移动文件服务器失败"
);
t1CommonResponseDTO
.
setRequestID
(
response
.
getException
());
t1CommonResponseDTO
.
setFailureCause
(
response
.
getMsg
());
if
(
response
.
isSuccess
())
{
t1CommonResponseDTO
.
setOprRst
(
"1"
);
this
.
fpT1UpdateFiletatus
(
uuid
,
1
,
t1CommonResponseDTO
);
return
true
;
}
else
{
t1CommonResponseDTO
.
setOprRst
(
"2"
);
this
.
fpT1UpdateFiletatus
(
uuid
,
2
,
t1CommonResponseDTO
);
log
.
warn
(
"t1UploadFileInfoCTCC---{}"
,
response
.
getMsg
());
return
false
;
}
}
/**
* 上传文件信息
* @param file
* @return
*/
private
T1CommonResponseDTO
uploadFile
(
T1FileReqDTO
file
)
{
long
startTime
=
System
.
currentTimeMillis
();
String
url
=
t1Config
.
getFileUrl
()
+
"/unified-storage/file/api/upload"
;
log
.
info
(
"uploadFile url: {},request: {}"
,
url
,
JSON
.
toJSONString
(
file
));
File
f
=
file
.
getEncryptFile
();
FileSystemResource
fileSystemResource
=
new
FileSystemResource
(
f
);
// body体参数
MultiValueMap
<
String
,
Object
>
requestBody
=
new
LinkedMultiValueMap
<>();
// headers参数
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
requestBody
.
add
(
"RequestID"
,
file
.
getRequestID
());
// requestBody.add("Path", file.getEncryptFile().getPath());
try
{
requestBody
.
add
(
"Md5"
,
DigestUtils
.
md5Hex
(
new
FileInputStream
(
f
)));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
requestBody
.
add
(
"File"
,
fileSystemResource
);
// ByteArrayResource resource = null;
// //存储
// resource = new ByteArrayResource(File2byte(file.getEncryptFile())) ;
// requestBody.add("File", resource);
// try {
// InputStream inputStream = new FileInputStream(file.getEncryptFile());
// MultipartFile multipartFile = new MockMultipartFile(file.getEncryptFile().getName(), inputStream);
// requestBody.add("File", multipartFile.getResource());
// } catch (IOException e) {
// e.printStackTrace();
// }
// 封装所有参数
HttpEntity
<
MultiValueMap
<
String
,
Object
>>
requestEntity
=
new
HttpEntity
<>(
requestBody
,
fileHeader
());
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFpT1
.
exchange
(
url
,
HttpMethod
.
POST
,
requestEntity
,
String
.
class
);
log
.
info
(
"uploadT1File url: {},response: {},cost: {} ms"
,
url
,
entity
.
getBody
(),
System
.
currentTimeMillis
()
-
startTime
);
T1CommonResponseDTO
result
=
JSON
.
parseObject
(
entity
.
getBody
(),
T1CommonResponseDTO
.
class
);
return
result
;
}
public
static
byte
[]
File2byte
(
File
tradeFile
){
byte
[]
buffer
=
null
;
try
{
FileInputStream
fis
=
new
FileInputStream
(
tradeFile
);
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
byte
[]
b
=
new
byte
[
1024
];
int
n
;
while
((
n
=
fis
.
read
(
b
))
!=
-
1
)
{
bos
.
write
(
b
,
0
,
n
);
}
fis
.
close
();
bos
.
close
();
buffer
=
bos
.
toByteArray
();
}
catch
(
FileNotFoundException
e
){
e
.
printStackTrace
();
}
catch
(
IOException
e
){
e
.
printStackTrace
();
}
return
buffer
;
}
/**
* Description: 证件类型转换
* <br />
* CreateDate 2022-06-08 17:20:28
*
* @author yuyi
**/
private
String
certTypeTransform
(
String
certType
)
{
//居民身份证
if
(
CertTypeEnum
.
IDCARD
.
getCode
().
equals
(
certType
))
{
return
"A"
;
}
//户口簿
if
(
CertTypeEnum
.
RESIDENCE
.
getCode
().
equals
(
certType
))
{
return
"B"
;
}
//军官证 -中国人民解放军军人身份证件
if
(
CertTypeEnum
.
PLA
.
getCode
().
equals
(
certType
))
{
return
"C"
;
}
//警官证
if
(
CertTypeEnum
.
POLICEPAPER
.
getCode
().
equals
(
certType
))
{
return
"D"
;
}
//港澳居民来往内地通行证
if
(
CertTypeEnum
.
HKIDCARD
.
getCode
().
equals
(
certType
))
{
return
"E"
;
}
//台湾居民来往大陆通行证
if
(
CertTypeEnum
.
TAIBAOZHENG
.
getCode
().
equals
(
certType
))
{
return
"F"
;
}
//外国公民护照
if
(
CertTypeEnum
.
PASSPORT
.
getCode
().
equals
(
certType
))
{
return
"G"
;
}
//营业执照
if
(
CertTypeEnum
.
BUSINESS_LICENSE_NO
.
getCode
().
equals
(
certType
))
{
return
"I"
;
}
//统一社会信用代码
if
(
CertTypeEnum
.
UNITCREDITCODE
.
getCode
().
equals
(
certType
))
{
return
"K"
;
}
//港澳居民居住证
if
(
CertTypeEnum
.
HKRESIDENCECARD
.
getCode
().
equals
(
certType
))
{
return
"S"
;
}
//港澳居民居住证
if
(
CertTypeEnum
.
TWRESIDENCECARD
.
getCode
().
equals
(
certType
))
{
return
"T"
;
}
if
(
CertTypeEnum
.
OTHER
.
getCode
().
equals
(
certType
))
{
return
"O"
;
}
return
"N"
;
}
@Override
public
T1AuthDTO
getAuth
(
EncryptionKeyDTO
encryptionKeyDTO
)
{
final
T1AuthDTO
t1AuthDTO
=
new
T1AuthDTO
();
t1AuthDTO
.
setPlatformID
(
encryptionKeyDTO
.
getPlatFormId
());
//平台标识+密码的SM3值,密码由 OneLink车联卡实名平台分配
String
signNature
=
RnrDataSM3Utils
.
encode
(
encryptionKeyDTO
.
getPlatFormId
()
+
encryptionKeyDTO
.
getCmccApiKey
());
t1AuthDTO
.
setSignNature
(
signNature
);
return
t1AuthDTO
;
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/VehicleRnrUnBoundServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.fp.common.ResponseCode
;
import
com.cusc.nirvana.user.rnr.fp.dto.VehicleUnboundVerifyRequestDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VerifyVinCardResponseDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardVerityResult
;
import
com.cusc.nirvana.user.rnr.fp.service.IVehicleRnrUnBoundService
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCardInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrCompanyInfoClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgRnrUnboundClient
;
import
com.cusc.nirvana.user.rnr.mg.client.MgVehicleCompanyClient
;
import
com.cusc.nirvana.user.rnr.mg.constants.NoticeStatusEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrBizzTypeEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrOrderStatusEnum
;
import
com.cusc.nirvana.user.rnr.mg.constants.RnrStatus
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgRnrCompanyInfoDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.MgVehicleCompanyDTO
;
import
com.cusc.nirvana.user.rnr.mg.dto.VehicleUnbindDTO
;
import
com.google.common.collect.Maps
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* @author yubo
* @since 2022-04-24 17:13
*/
@Service
public
class
VehicleRnrUnBoundServiceImpl
implements
IVehicleRnrUnBoundService
{
@Resource
private
MgRnrCardInfoClient
cardInfoClient
;
@Resource
private
MgRnrCompanyInfoClient
companyInfoClient
;
@Resource
private
MgRnrUnboundClient
mgRnrUnboundClient
;
@Resource
private
MgVehicleCompanyClient
vehicleCompanyClient
;
@Override
public
Response
<
VerifyVinCardResponseDTO
>
verifyUnboundVinCardBatch
(
VehicleUnboundVerifyRequestDTO
responseDTO
)
{
return
verifyUnboundVinCardBatch
(
responseDTO
.
getCardDTOS
(),
responseDTO
.
getTenantNo
(),
null
,
null
);
}
@Override
public
Response
batchUnbound
(
VehicleUnbindDTO
requestDTO
)
{
List
<
String
>
cardIds
=
new
ArrayList
<>();
List
<
String
>
rnrIds
=
new
ArrayList
<>();
List
<
VinCardDTO
>
cardDTOs
=
requestDTO
.
getCardList
().
stream
()
.
map
(
card
->
new
VinCardDTO
(
card
.
getIotId
(),
card
.
getIccid
(),
null
,
null
))
.
collect
(
Collectors
.
toList
());
//获取校验结果
Response
<
VerifyVinCardResponseDTO
>
response
=
verifyUnboundVinCardBatch
(
cardDTOs
,
requestDTO
.
getInfo
().
getTenantNo
(),
cardIds
,
rnrIds
);
if
(!
response
.
isSuccess
())
{
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
//校验结果处理,计算失败次数
List
<
VinCardVerityResult
>
iccidVerifyResults
=
response
.
getData
().
getIccidVerifyResults
();
int
failCount
=
(
int
)
iccidVerifyResults
.
stream
().
filter
(
r
->
!
r
.
isExist
()).
count
();
if
(
iccidVerifyResults
.
isEmpty
())
{
return
Response
.
createError
(
"没有需要解绑的记录"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
if
(
failCount
>
0
)
{
return
Response
.
createError
(
"存在未绑定的记录"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
requestDTO
.
getOrder
().
setOrderStatus
(
RnrOrderStatusEnum
.
PASS
.
getCode
());
requestDTO
.
getInfo
().
setRnrStatus
(
RnrStatus
.
UNBOUND
.
getCode
());
requestDTO
.
setRnrIds
(
rnrIds
);
requestDTO
.
setCardIds
(
cardIds
);
requestDTO
.
getCardList
().
stream
().
forEach
(
c
->
{
c
.
setRnrStatus
(
RnrStatus
.
UNBOUND
.
getCode
());
c
.
setNoticeStatus
(
NoticeStatusEnum
.
NONEED
.
getCode
());
});
return
mgRnrUnboundClient
.
batchUnbound
(
requestDTO
);
}
//--------------- 私有方法区
/**
* 验证车卡信息
*/
private
Response
<
VerifyVinCardResponseDTO
>
verifyUnboundVinCardBatch
(
List
<
VinCardDTO
>
cardDTOS
,
String
tenantNo
,
List
<
String
>
cardIds
,
List
<
String
>
rnrIds
)
{
Map
<
String
,
Map
<
String
,
MgRnrCardInfoDTO
>>
vinCardMap
=
Maps
.
newHashMap
();
List
<
VinCardVerityResult
>
iccidVerifyResults
=
new
ArrayList
<>();
VinCardVerityResult
verityResult
;
if
(
StringUtils
.
isBlank
(
tenantNo
))
{
return
Response
.
createError
(
"租户编号不能为空"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
//查询公司名下所有实名业务
MgVehicleCompanyDTO
vehicleCompanyDTO
=
new
MgVehicleCompanyDTO
();
vehicleCompanyDTO
.
setTenantNo
(
tenantNo
);
Response
<
MgVehicleCompanyDTO
>
vcResp
=
vehicleCompanyClient
.
getVehicleCompany
(
vehicleCompanyDTO
);
if
(
vcResp
==
null
||
!
vcResp
.
isSuccess
()
||
vcResp
.
getData
()
==
null
)
{
return
Response
.
createError
(
"未查询到对应的车企信息"
,
ResponseCode
.
INVALID_DATA
.
getCode
());
}
vehicleCompanyDTO
=
vcResp
.
getData
();
//查询公司的业务信息
MgRnrCompanyInfoDTO
mgRnrCompanyInfoDTO
=
new
MgRnrCompanyInfoDTO
();
mgRnrCompanyInfoDTO
.
setCompanyName
(
vehicleCompanyDTO
.
getCompanyName
());
Response
<
List
<
String
>>
response
=
companyInfoClient
.
findRnrIdsByCompanyName
(
mgRnrCompanyInfoDTO
);
if
(!
response
.
isSuccess
())
{
return
Response
.
createError
(
response
.
getMsg
(),
response
.
getCode
());
}
Set
<
String
>
rnrIdSet
=
new
HashSet
<>(
response
.
getData
());
for
(
VinCardDTO
verifyDTO
:
cardDTOS
)
{
String
vin
=
verifyDTO
.
getVin
();
String
iccid
=
verifyDTO
.
getIccid
();
//根据vin获取已绑定的iccid map
Map
<
String
,
MgRnrCardInfoDTO
>
map
=
vinCardMap
.
get
(
vin
);
if
(
map
==
null
)
{
MgRnrCardInfoDTO
mgRnrCardInfoDTO
=
new
MgRnrCardInfoDTO
();
mgRnrCardInfoDTO
.
setIotId
(
vin
);
mgRnrCardInfoDTO
.
setRnrBizzType
(
RnrBizzTypeEnum
.
Bind
.
getCode
());
Response
<
List
<
MgRnrCardInfoDTO
>>
listResponse
=
cardInfoClient
.
queryBindListByVinAndBizType
(
mgRnrCardInfoDTO
);
if
(!
listResponse
.
isSuccess
())
{
return
Response
.
createError
(
listResponse
.
getMsg
(),
listResponse
.
getCode
());
}
map
=
listResponse
.
getData
().
stream
().
collect
(
Collectors
.
toMap
(
MgRnrCardInfoDTO:
:
getIccid
,
dto
->
dto
));
vinCardMap
.
put
(
vin
,
map
);
}
//校验
verityResult
=
new
VinCardVerityResult
();
verityResult
.
setVin
(
vin
);
verityResult
.
setIccid
(
iccid
);
String
msg
=
""
;
boolean
bind
=
true
;
if
(!
map
.
containsKey
(
iccid
))
{
msg
=
"车辆["
+
vin
+
"]和卡["
+
iccid
+
"]未绑定"
;
bind
=
false
;
}
else
if
(!
rnrIdSet
.
contains
(
map
.
get
(
iccid
).
getRnrId
()))
{
//只能解绑自己公司的卡
msg
=
"没有权限解绑"
;
bind
=
false
;
}
verityResult
.
setExist
(
bind
);
verityResult
.
setMsg
(
msg
);
iccidVerifyResults
.
add
(
verityResult
);
if
(
cardIds
!=
null
&&
bind
)
{
cardIds
.
add
(
map
.
get
(
iccid
).
getUuid
());
}
if
(
rnrIds
!=
null
&&
bind
)
{
rnrIds
.
add
(
map
.
get
(
iccid
).
getRnrId
());
}
}
return
Response
.
createSuccess
(
new
VerifyVinCardResponseDTO
(
iccidVerifyResults
));
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/VehicleT1UploadServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
cn.hutool.crypto.SecureUtil
;
import
cn.hutool.crypto.symmetric.AES
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cusc.nirvana.user.rnr.fp.dto.T1CommonResponseDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.T1UserInfoReqDTO
;
import
com.cusc.nirvana.user.rnr.fp.util.AESUtil
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
java.nio.charset.StandardCharsets
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
@Service
@Slf4j
public
class
VehicleT1UploadServiceImpl
{
@Value
(
"${t1.vehicle.url:}"
)
private
String
url
;
@Value
(
"${t1.vehicle.appId:}"
)
private
String
appId
;
@Value
(
"${t1.vehicle.secret:}"
)
private
String
secret
;
@Value
(
"${t1.vehicle.t1InstructionKey:}"
)
//此接口上传的车辆信息加密密钥由工信部下发
private
String
t1InstructionKey
;
@Autowired
@Qualifier
(
"noBalanceRestTemplateRnrFp"
)
RestTemplate
noBalanceRestTemplateRnrFp
;
final
String
encryptCarInfo
(
String
carInfoStr
)
{
byte
[]
key
=
AESUtil
.
MD5
(
t1InstructionKey
);
//构建
AES
aes
=
SecureUtil
.
aes
(
key
);
//加密
return
aes
.
encryptHex
(
carInfoStr
);
}
final
String
getVehicleInfo
(
String
vin
)
{
try
{
long
startTime
=
System
.
currentTimeMillis
();
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"vin"
,
vin
);
String
bodyStr
=
new
ObjectMapper
().
writeValueAsString
(
param
);
//转成json格式, 要用于签名
String
ts
=
String
.
valueOf
(
System
.
currentTimeMillis
());
//生成签名
Map
<
String
,
String
>
signMap
=
new
HashMap
<>();
signMap
.
put
(
"timestamp"
,
ts
);
signMap
.
put
(
"param"
,
bodyStr
);
signMap
.
put
(
"appId"
,
appId
);
String
sign
=
md5Sign
(
signMap
,
secret
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
requestHeaders
.
setContentType
(
MediaType
.
APPLICATION_JSON_UTF8
);
requestHeaders
.
set
(
"sign"
,
sign
);
requestHeaders
.
set
(
"timestamp"
,
ts
);
requestHeaders
.
set
(
"appId"
,
appId
);
ResponseEntity
<
String
>
entity
=
noBalanceRestTemplateRnrFp
.
exchange
(
url
,
HttpMethod
.
POST
,
new
HttpEntity
<>(
bodyStr
,
requestHeaders
),
String
.
class
);
log
.
info
(
"getVehicleInfo url: {},response: {},cost: {} ms"
,
url
,
entity
.
getBody
(),
System
.
currentTimeMillis
()
-
startTime
);
return
entity
.
getBody
();
}
catch
(
JsonProcessingException
|
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
log
.
error
(
"get vehicle info failed:"
+
vin
,
e
);
}
return
null
;
}
public
static
String
md5Sign
(
Map
<
String
,
String
>
signMap
,
String
secret
)
throws
NoSuchAlgorithmException
{
StringBuilder
signStr
=
new
StringBuilder
();
signMap
.
keySet
().
stream
().
sorted
().
forEach
(
key
->
{
if
(
key
.
equalsIgnoreCase
(
"sign"
))
return
;
signStr
.
append
(
key
);
Object
value
=
signMap
.
get
(
key
);
if
(
value
!=
null
)
{
signStr
.
append
(
value
.
toString
());
}
});
signStr
.
append
(
secret
);
byte
[]
digest
=
MessageDigest
.
getInstance
(
"MD5"
).
digest
(
signStr
.
toString
().
getBytes
(
StandardCharsets
.
UTF_8
));
return
encodeAsHexString
(
digest
).
toUpperCase
(
Locale
.
ROOT
);
}
public
static
String
encodeAsHexString
(
byte
[]
bytes
)
{
StringBuilder
buf
=
new
StringBuilder
();
int
i
;
for
(
byte
aByte
:
bytes
)
{
i
=
aByte
;
if
(
i
<
0
)
i
=
i
&
255
|
256
;
//反码不变,复原符号位,byte转int时第8位符号位会丢失
if
(
i
<
16
)
buf
.
append
(
'0'
);
//padding with zero
buf
.
append
(
Integer
.
toHexString
(
i
));
}
return
buf
.
toString
();
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/service/impl/VinCardServiceImpl.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.service.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.fp.dto.*
;
import
com.cusc.nirvana.user.rnr.fp.service.ISimVehicleRelService
;
import
com.cusc.nirvana.user.rnr.fp.service.IVinCardService
;
import
com.cusc.nirvana.user.rnr.project.context.VinCardContext
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author stayAnd
* @date 2022/4/11
*/
@Slf4j
@Service
public
class
VinCardServiceImpl
implements
IVinCardService
{
@Resource
private
VinCardContext
vinCardContext
;
@Autowired
private
ISimVehicleRelService
simVehicleRelService
;
@Override
public
VinCardInfoDTO
queryVinCard
(
String
vin
)
{
return
vinCardContext
.
getVinCardHandler
().
queryCardByVin
(
vin
);
}
@Override
public
List
<
VinCardInfoDTO
>
queryVinCardList
(
List
<
String
>
vinList
)
{
return
vinCardContext
.
getVinCardHandler
().
queryCardByVinList
(
vinList
);
}
/**
* 车卡关系和卡校验
*
* @param verifyDTOs
* @return
*/
@Override
public
Response
verifyVinCard
(
List
<
VinCardDTO
>
verifyDTOs
)
{
List
<
VinCardVerityResult
>
iccidVerifyResults
=
new
ArrayList
<>();
verifyDTOs
.
forEach
(
verifyDTO
->
{
VinCardVerityResult
vinCardVerityResult
=
new
VinCardVerityResult
();
vinCardVerityResult
.
setVin
(
verifyDTO
.
getVin
());
vinCardVerityResult
.
setIccid
(
verifyDTO
.
getIccid
());
vinCardVerityResult
.
setExist
(
false
);
VinIccidDTO
data
=
simVehicleRelService
.
getVinByIccid
(
verifyDTO
.
getIccid
()).
getData
();
if
(
null
!=
data
&&
data
.
getBindStatus
()
==
0
)
{
vinCardVerityResult
.
setExist
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isBlank
(
data
.
getVin
())
||
verifyDTO
.
getVin
().
equals
(
data
.
getVin
()));
}
iccidVerifyResults
.
add
(
vinCardVerityResult
);
});
VerifyVinCardResponseDTO
verifyVinCardResponseDTO
=
new
VerifyVinCardResponseDTO
();
verifyVinCardResponseDTO
.
setIccidVerifyResults
(
iccidVerifyResults
);
return
Response
.
createSuccess
(
verifyVinCardResponseDTO
);
}
//------------------------------ 私有方法去
private
String
toKey
(
String
vin
,
String
iccid
)
{
return
vin
+
"-"
+
iccid
;
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/AESUtil.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
cn.hutool.core.util.CharsetUtil
;
import
cn.hutool.crypto.SecureUtil
;
import
cn.hutool.crypto.symmetric.AES
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.crypto.Cipher
;
import
javax.crypto.CipherInputStream
;
import
javax.crypto.CipherOutputStream
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.io.*
;
import
java.security.Key
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
/**
* Description AESUtil function
*
* @author zx
* @version 1.0
* @date 2022-06-16 10:29
*/
public
class
AESUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
AESUtil
.
class
);
private
static
final
String
ALGORITHM
=
"AES"
;
private
static
final
String
PATTERN
=
"AES/ECB/PKCS5Padding"
;
private
static
final
int
CACHE_SIZE
=
1024
;
public
AESUtil
()
{
}
public
static
byte
[]
encrypt
(
byte
[]
data
,
String
key
)
throws
Exception
{
Key
k
=
toKey
(
MD5
(
key
));
byte
[]
raw
=
k
.
getEncoded
();
SecretKeySpec
secretKeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES"
);
cipher
.
init
(
1
,
secretKeySpec
);
return
cipher
.
doFinal
(
data
);
}
public
static
byte
[]
decrypt
(
byte
[]
data
,
String
key
)
throws
Exception
{
Key
k
=
toKey
(
MD5
(
key
));
byte
[]
raw
=
k
.
getEncoded
();
SecretKeySpec
secretKeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES"
);
cipher
.
init
(
2
,
secretKeySpec
);
return
cipher
.
doFinal
(
data
);
}
public
static
File
encryptFile
(
String
key
,
String
sourceFilePath
,
String
destFilePath
)
throws
Exception
{
File
sourceFile
=
new
File
(
sourceFilePath
);
File
destFile
=
new
File
(
destFilePath
);
if
(
sourceFile
.
exists
()
&&
sourceFile
.
isFile
())
{
if
(!
destFile
.
getParentFile
().
exists
())
{
destFile
.
getParentFile
().
mkdirs
();
}
destFile
.
createNewFile
();
InputStream
in
=
new
FileInputStream
(
sourceFile
);
OutputStream
out
=
new
FileOutputStream
(
destFile
);
Key
k
=
toKey
(
MD5
(
key
));
byte
[]
raw
=
k
.
getEncoded
();
SecretKeySpec
secretKeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/ECB/PKCS5Padding"
);
cipher
.
init
(
1
,
secretKeySpec
);
CipherInputStream
cin
=
new
CipherInputStream
(
in
,
cipher
);
byte
[]
cache
=
new
byte
[
1024
];
boolean
var13
=
false
;
int
nRead
;
while
((
nRead
=
cin
.
read
(
cache
))
!=
-
1
)
{
out
.
write
(
cache
,
0
,
nRead
);
out
.
flush
();
}
out
.
close
();
cin
.
close
();
in
.
close
();
return
destFile
;
}
else
{
log
.
error
(
"文件[{}]不存在!"
,
sourceFilePath
);
return
null
;
}
}
public
static
void
decryptFile
(
String
key
,
String
sourceFilePath
,
String
destFilePath
)
throws
Exception
{
File
sourceFile
=
new
File
(
sourceFilePath
);
File
destFile
=
new
File
(
destFilePath
);
if
(
sourceFile
.
exists
()
&&
sourceFile
.
isFile
())
{
if
(!
destFile
.
getParentFile
().
exists
())
{
destFile
.
getParentFile
().
mkdirs
();
}
destFile
.
createNewFile
();
FileInputStream
in
=
new
FileInputStream
(
sourceFile
);
FileOutputStream
out
=
new
FileOutputStream
(
destFile
);
Key
k
=
toKey
(
MD5
(
key
));
byte
[]
raw
=
k
.
getEncoded
();
SecretKeySpec
secretKeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/ECB/PKCS5Padding"
);
cipher
.
init
(
2
,
secretKeySpec
);
CipherOutputStream
cout
=
new
CipherOutputStream
(
out
,
cipher
);
byte
[]
cache
=
new
byte
[
1024
];
boolean
var13
=
false
;
int
nRead
;
while
((
nRead
=
in
.
read
(
cache
))
!=
-
1
)
{
cout
.
write
(
cache
,
0
,
nRead
);
cout
.
flush
();
}
cout
.
close
();
out
.
close
();
in
.
close
();
}
}
private
static
Key
toKey
(
byte
[]
key
)
throws
Exception
{
SecretKey
secretKey
=
new
SecretKeySpec
(
key
,
"AES"
);
return
secretKey
;
}
public
static
byte
[]
MD5
(
String
plainText
)
{
try
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
md
.
update
(
plainText
.
getBytes
());
return
md
.
digest
();
}
catch
(
NoSuchAlgorithmException
var2
)
{
log
.
error
(
"MD5加密失败,异常信息:"
,
var2
);
return
null
;
}
}
public
static
String
encryptStr
(
String
str
,
String
key
)
{
if
(
StringUtils
.
isEmpty
(
str
)){
return
str
;
}
AES
aes
=
SecureUtil
.
aes
(
AESUtil
.
MD5
(
key
));
String
decryptStr
=
aes
.
encryptHex
(
str
,
CharsetUtil
.
CHARSET_UTF_8
);
log
.
info
(
"decode content: {}"
,
decryptStr
);
return
decryptStr
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
type
=
args
[
0
];
System
.
out
.
println
(
"操作类型:"
+
type
);
String
key
=
args
[
1
];
System
.
out
.
println
(
"密钥字符串:"
+
key
);
String
sourcePath
=
args
[
2
];
System
.
out
.
println
(
"源文件路径:"
+
sourcePath
);
String
destPath
=
args
[
3
];
System
.
out
.
println
(
"目标文件路径:"
+
destPath
);
if
(
args
.
length
!=
4
)
{
System
.
out
.
println
(
"参数错误,参数格式:操作类型 密钥字符串 源文件路径 目标文件路径"
);
}
if
(
type
.
equals
(
"e"
))
{
System
.
out
.
println
(
"开始加密..."
);
encryptFile
(
key
,
sourcePath
,
destPath
);
System
.
out
.
println
(
"加密完成,目标文件路径:"
+
destPath
);
}
else
if
(
type
.
equals
(
"d"
))
{
System
.
out
.
println
(
"开始解密..."
);
decryptFile
(
key
,
sourcePath
,
destPath
);
System
.
out
.
println
(
"解密完成,目标文件路径:"
+
destPath
);
}
else
{
System
.
out
.
println
(
"参数错误,参数格式:操作类型 密钥字符串 源文件路径 目标文件路径"
);
}
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/AESUtils.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.crypto.*
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.io.*
;
import
java.security.Key
;
import
java.security.SecureRandom
;
/**
* Description AESUtils function
*
* @author zx
* @version 1.0
* @date 2022-06-16 10:42
*/
public
class
AESUtils
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
AESUtils
.
class
);
private
static
final
String
ALGORITHM
=
"AES"
;
private
static
final
int
KEY_SIZE
=
128
;
private
static
final
int
CACHE_SIZE
=
1024
;
public
AESUtils
()
{
}
public
static
String
getSecretKey
()
throws
Exception
{
return
getSecretKey
((
String
)
null
);
}
public
static
String
getSecretKey
(
String
seed
)
throws
Exception
{
KeyGenerator
keyGenerator
=
KeyGenerator
.
getInstance
(
"AES"
);
SecureRandom
secureRandom
;
if
(
seed
!=
null
&&
!
""
.
equals
(
seed
))
{
secureRandom
=
new
SecureRandom
(
seed
.
getBytes
());
}
else
{
secureRandom
=
new
SecureRandom
();
}
keyGenerator
.
init
(
128
,
secureRandom
);
SecretKey
secretKey
=
keyGenerator
.
generateKey
();
return
Base64Utils
.
encode
(
secretKey
.
getEncoded
());
}
public
static
byte
[]
encrypt
(
byte
[]
data
,
String
key
)
throws
Exception
{
Key
k
=
toKey
(
Base64Utils
.
decode
(
key
));
byte
[]
raw
=
k
.
getEncoded
();
SecretKeySpec
secretKeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES"
);
cipher
.
init
(
1
,
secretKeySpec
);
return
cipher
.
doFinal
(
data
);
}
public
static
File
encryptFile
(
String
key
,
String
sourceFilePath
,
String
destFilePath
)
throws
Exception
{
File
sourceFile
=
new
File
(
sourceFilePath
);
File
destFile
=
new
File
(
destFilePath
);
if
(
sourceFile
.
exists
()
&&
sourceFile
.
isFile
())
{
if
(!
destFile
.
getParentFile
().
exists
())
{
destFile
.
getParentFile
().
mkdirs
();
}
destFile
.
createNewFile
();
InputStream
in
=
new
FileInputStream
(
sourceFile
);
OutputStream
out
=
new
FileOutputStream
(
destFile
);
Key
k
=
toKey
(
Base64Utils
.
decode
(
key
));
byte
[]
raw
=
k
.
getEncoded
();
SecretKeySpec
secretKeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES"
);
cipher
.
init
(
1
,
secretKeySpec
);
CipherInputStream
cin
=
new
CipherInputStream
(
in
,
cipher
);
byte
[]
cache
=
new
byte
[
1024
];
boolean
var13
=
false
;
int
nRead
;
while
((
nRead
=
cin
.
read
(
cache
))
!=
-
1
)
{
out
.
write
(
cache
,
0
,
nRead
);
out
.
flush
();
}
out
.
close
();
cin
.
close
();
in
.
close
();
return
destFile
;
}
else
{
log
.
error
(
"文件[{}]不存在!"
,
sourceFilePath
);
return
null
;
}
}
public
static
byte
[]
decrypt
(
byte
[]
data
,
String
key
)
throws
Exception
{
Key
k
=
toKey
(
Base64Utils
.
decode
(
key
));
byte
[]
raw
=
k
.
getEncoded
();
SecretKeySpec
secretKeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES"
);
cipher
.
init
(
2
,
secretKeySpec
);
return
cipher
.
doFinal
(
data
);
}
public
static
void
decryptFile
(
String
key
,
String
sourceFilePath
,
String
destFilePath
)
throws
Exception
{
File
sourceFile
=
new
File
(
sourceFilePath
);
File
destFile
=
new
File
(
destFilePath
);
if
(
sourceFile
.
exists
()
&&
sourceFile
.
isFile
())
{
if
(!
destFile
.
getParentFile
().
exists
())
{
destFile
.
getParentFile
().
mkdirs
();
}
destFile
.
createNewFile
();
FileInputStream
in
=
new
FileInputStream
(
sourceFile
);
FileOutputStream
out
=
new
FileOutputStream
(
destFile
);
Key
k
=
toKey
(
Base64Utils
.
decode
(
key
));
byte
[]
raw
=
k
.
getEncoded
();
SecretKeySpec
secretKeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES"
);
cipher
.
init
(
2
,
secretKeySpec
);
CipherOutputStream
cout
=
new
CipherOutputStream
(
out
,
cipher
);
byte
[]
cache
=
new
byte
[
1024
];
boolean
var13
=
false
;
int
nRead
;
while
((
nRead
=
in
.
read
(
cache
))
!=
-
1
)
{
cout
.
write
(
cache
,
0
,
nRead
);
cout
.
flush
();
}
cout
.
close
();
out
.
close
();
in
.
close
();
}
}
private
static
Key
toKey
(
byte
[]
key
)
throws
Exception
{
SecretKey
secretKey
=
new
SecretKeySpec
(
key
,
"AES"
);
return
secretKey
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
type
=
args
[
0
];
System
.
out
.
println
(
"操作类型:"
+
type
);
String
key
=
args
[
1
];
System
.
out
.
println
(
"Base64秘钥:"
+
key
);
String
sourcePath
=
args
[
2
];
System
.
out
.
println
(
"源文件路径:"
+
sourcePath
);
String
destPath
=
args
[
3
];
System
.
out
.
println
(
"目标文件路径:"
+
destPath
);
if
(
args
.
length
!=
4
)
{
System
.
out
.
println
(
"参数错误,参数格式:操作类型 Base64秘钥 源文件路径 目标文件路径"
);
}
if
(
type
.
equals
(
"e"
))
{
System
.
out
.
println
(
"开始加密..."
);
encryptFile
(
key
,
sourcePath
,
destPath
);
System
.
out
.
println
(
"加密完成,目标文件路径:"
+
destPath
);
}
else
if
(
type
.
equals
(
"d"
))
{
System
.
out
.
println
(
"开始解密..."
);
decryptFile
(
key
,
sourcePath
,
destPath
);
System
.
out
.
println
(
"解密完成,目标文件路径:"
+
destPath
);
}
else
{
System
.
out
.
println
(
"参数错误,参数格式:操作类型 Base64秘钥 源文件路径 目标文件路径"
);
}
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/Base64Utils.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
org.apache.tomcat.util.codec.binary.Base64
;
/**
* Description Base64Utils function
*
* @author zx
* @version 1.0
* @date 2022-06-16 10:43
*/
public
class
Base64Utils
{
private
static
final
int
CACHE_SIZE
=
1024
;
public
Base64Utils
()
{
}
public
static
byte
[]
decode
(
String
base64
)
throws
Exception
{
return
Base64
.
decodeBase64
(
base64
);
}
public
static
String
encode
(
byte
[]
bytes
)
throws
Exception
{
return
Base64
.
encodeBase64String
(
bytes
);
}
public
static
String
encodeFile
(
String
filePath
)
throws
Exception
{
byte
[]
bytes
=
fileToByte
(
filePath
);
return
encode
(
bytes
);
}
public
static
void
decodeToFile
(
String
filePath
,
String
base64
)
throws
Exception
{
byte
[]
bytes
=
decode
(
base64
);
byteArrayToFile
(
bytes
,
filePath
);
}
public
static
byte
[]
fileToByte
(
String
filePath
)
throws
Exception
{
byte
[]
data
=
new
byte
[
0
];
File
file
=
new
File
(
filePath
);
if
(
file
.
exists
())
{
FileInputStream
in
=
new
FileInputStream
(
file
);
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
(
2048
);
byte
[]
cache
=
new
byte
[
1024
];
boolean
var6
=
false
;
int
nRead
;
while
((
nRead
=
in
.
read
(
cache
))
!=
-
1
)
{
out
.
write
(
cache
,
0
,
nRead
);
out
.
flush
();
}
out
.
close
();
in
.
close
();
data
=
out
.
toByteArray
();
}
return
data
;
}
public
static
void
byteArrayToFile
(
byte
[]
bytes
,
String
filePath
)
throws
Exception
{
InputStream
in
=
new
ByteArrayInputStream
(
bytes
);
File
destFile
=
new
File
(
filePath
);
if
(!
destFile
.
getParentFile
().
exists
())
{
destFile
.
getParentFile
().
mkdirs
();
}
destFile
.
createNewFile
();
OutputStream
out
=
new
FileOutputStream
(
destFile
);
byte
[]
cache
=
new
byte
[
1024
];
boolean
var6
=
false
;
int
nRead
;
while
((
nRead
=
in
.
read
(
cache
))
!=
-
1
)
{
out
.
write
(
cache
,
0
,
nRead
);
out
.
flush
();
}
out
.
close
();
in
.
close
();
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
before
=
"openplatform123"
;
String
after
=
encode
(
before
.
getBytes
());
System
.
out
.
println
(
"(加密后)"
);
System
.
out
.
println
(
after
);
String
before1
=
"b3BlbnBsYXRmb3Jt"
;
String
after1
=
new
String
(
decode
(
before1
));
System
.
out
.
println
(
"(解密后)"
);
System
.
out
.
println
(
after1
);
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/CuscFileUtils.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.*
;
/**
* Description: 文件工具类
* <br />
* CreateDate 2022-06-09 11:23:19
*
* @author yuyi
**/
public
class
CuscFileUtils
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
CuscFileUtils
.
class
);
/**
* Description: byte to file
* <br />
* CreateDate 2022-06-09 11:23:50
*
* @author yuyi
**/
public
static
File
byte2File
(
byte
[]
bfile
,
String
fileName
)
{
BufferedOutputStream
bos
=
null
;
FileOutputStream
fos
=
null
;
File
file
;
try
{
file
=
new
File
(
fileName
);
fos
=
new
FileOutputStream
(
file
);
bos
=
new
BufferedOutputStream
(
fos
);
bos
.
write
(
bfile
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"FileUtils.byte2File error "
,
e
);
return
null
;
}
finally
{
if
(
bos
!=
null
)
{
try
{
bos
.
close
();
}
catch
(
IOException
e1
)
{
LOGGER
.
error
(
"FileUtils.byte2File close BufferedOutputStream error"
,
e1
);
}
}
if
(
fos
!=
null
)
{
try
{
fos
.
close
();
}
catch
(
IOException
e1
)
{
LOGGER
.
error
(
"FileUtils.byte2File close FileOutputStream error"
,
e1
);
}
}
}
return
file
;
}
/**
* Description: folderPath 文件夹完整绝对路径
* <br />
* CreateDate 2022-06-10 17:09:53
*
* @author yuyi
**/
public
static
void
delFolder
(
String
folderPath
)
{
try
{
//删除完里面所有内容
delAllFile
(
folderPath
);
java
.
io
.
File
myFilePath
=
new
java
.
io
.
File
(
folderPath
);
//删除空文件夹
myFilePath
.
delete
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"FileUtils.delFolder error"
,
e
);
}
}
/**
* Description: 删除指定文件夹下所有文件
* <br />
* CreateDate 2022-06-10 17:11:56
*
* @author yuyi
**/
public
static
boolean
delAllFile
(
String
path
)
{
boolean
flag
=
false
;
File
file
=
new
File
(
path
);
if
(!
file
.
exists
())
{
return
flag
;
}
if
(!
file
.
isDirectory
())
{
return
flag
;
}
String
[]
tempList
=
file
.
list
();
File
temp
;
for
(
int
i
=
0
;
i
<
tempList
.
length
;
i
++)
{
if
(
path
.
endsWith
(
File
.
separator
))
{
temp
=
new
File
(
path
+
tempList
[
i
]);
}
else
{
temp
=
new
File
(
path
+
File
.
separator
+
tempList
[
i
]);
}
if
(
temp
.
isFile
())
{
temp
.
delete
();
}
if
(
temp
.
isDirectory
())
{
//先删除文件夹里面的文件
delAllFile
(
path
+
"/"
+
tempList
[
i
]);
//再删除空文件夹
delFolder
(
path
+
"/"
+
tempList
[
i
]);
flag
=
true
;
}
}
return
flag
;
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/ImgUtil.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
javax.imageio.ImageIO
;
import
javax.imageio.stream.ImageOutputStream
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.List
;
/**
* @author stayAnd
* @date 2022/6/22
*/
public
class
ImgUtil
{
/**
* 水印文字颜色
*/
private
static
Color
color
=
new
Color
(
255
,
255
,
255
);
/**
*
* @param imgStream 图片流
* @param logoText 文字水印内容
* @param suffix 图片后缀名
* @return
* @throws IOException
*/
public
static
InputStream
addWorkMarkUpperLeftToInputStreamFile
(
InputStream
imgStream
,
List
<
String
>
logoText
,
String
suffix
)
throws
IOException
{
BufferedImage
img
=
ImageIO
.
read
(
imgStream
);
// 创建画笔
Graphics2D
pen
=
img
.
createGraphics
();
// 设置画笔颜色为白色
pen
.
setColor
(
Color
.
WHITE
);
//pen.setColor(new Color(179, 250, 233, 200));
// 设置画笔字体样式为微软雅黑,斜体,文字大小为20px
pen
.
setFont
(
new
Font
(
"微软雅黑"
,
Font
.
ITALIC
,
20
));
// 写上水印文字和坐标
pen
.
drawString
(
"我是图片水印"
,
30
,
550
);
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
ImageIO
.
write
(
img
,
"png"
,
os
);
InputStream
input
=
new
ByteArrayInputStream
(
os
.
toByteArray
());
return
input
;
}
private
static
int
getCharLen
(
char
c
,
Graphics2D
g
)
{
return
g
.
getFontMetrics
(
g
.
getFont
()).
charWidth
(
c
);
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/Md5CaculateUtil.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
org.apache.commons.codec.binary.Hex
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.*
;
import
java.math.BigInteger
;
import
java.security.MessageDigest
;
/**
* Description: MD5计算工具类
* <br />
* CreateDate 2022-03-11 15:58
*
* @author yuy336
**/
public
class
Md5CaculateUtil
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Md5CaculateUtil
.
class
);
/**
* 获取一个文件的md5值(可处理大文件)
*
* @return md5 value
*/
public
static
String
getFileMD5
(
File
file
)
{
FileInputStream
fileInputStream
=
null
;
try
{
MessageDigest
MD5
=
MessageDigest
.
getInstance
(
"MD5"
);
fileInputStream
=
new
FileInputStream
(
file
);
byte
[]
buffer
=
new
byte
[
8192
];
int
length
;
while
((
length
=
fileInputStream
.
read
(
buffer
))
!=
-
1
)
{
MD5
.
update
(
buffer
,
0
,
length
);
}
return
new
String
(
Hex
.
encodeHex
(
MD5
.
digest
()));
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"getFileMD5 error : "
,
e
);
return
null
;
}
finally
{
try
{
if
(
fileInputStream
!=
null
)
{
fileInputStream
.
close
();
}
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"getFileMD5 FileInputStream close error : "
,
e
);
}
}
}
/**
* 获取上传文件的md5
*
* @param file
* @return
* @throws IOException
*/
public
static
String
getMd5
(
MultipartFile
file
)
{
try
{
//获取文件的byte信息
byte
[]
uploadBytes
=
file
.
getBytes
();
// 拿到一个MD5转换器
MessageDigest
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
byte
[]
digest
=
md5
.
digest
(
uploadBytes
);
//转换为16进制
return
new
BigInteger
(
1
,
digest
).
toString
(
16
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"getMd5 error :"
,
e
);
}
return
null
;
}
/**
* 求一个字符串的md5值
*
* @param target 字符串
* @return md5 value
*/
public
static
String
MD5
(
String
target
)
{
return
DigestUtils
.
md5Hex
(
target
);
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/RnrDataAesUtil.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
org.bouncycastle.pqc.math.linearalgebra.ByteUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.crypto.Cipher
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.nio.charset.StandardCharsets
;
/**
* Description: AES加密算法
* <br />
* CreateDate 2021-11-04 09:14:32
*
* @author yuyi
**/
public
class
RnrDataAesUtil
{
private
final
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
RnrDataAesUtil
.
class
);
private
static
final
String
ALGORITHM
=
"AES"
;
//private static final String AES_CBC_PADDING = "AES/CBC/PKCS5Padding";
private
static
final
String
AES_ECB_PADDING
=
"AES/ECB/PKCS5Padding"
;
/**
* Aes加密(ECB工作模式),不要IV
*
* @param key 密钥,key长度必须大于等于 3*8 = 24,并且是8的倍数
* @param data 明文
* @return 密文
* @throws Exception
*/
public
static
byte
[]
encodeByECB
(
byte
[]
key
,
byte
[]
data
)
throws
Exception
{
//获取SecretKey对象,也可以使用getSecretKey()方法
SecretKey
secretKey
=
new
SecretKeySpec
(
key
,
ALGORITHM
);
//获取指定转换的密码对象Cipher(参数:算法/工作模式/填充模式)
Cipher
cipher
=
Cipher
.
getInstance
(
AES_ECB_PADDING
);
//用密钥和一组算法参数规范初始化此Cipher对象(加密模式)
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
secretKey
);
//执行加密操作
return
cipher
.
doFinal
(
data
);
}
/**
* Aes加密(ECB工作模式),不要IV
*
* @param key 密钥,key长度必须大于等于 3*8 = 24,并且是8的倍数
* @param data 明文
* @return 密文
* @throws Exception
*/
public
static
byte
[]
encodeByECB
(
String
key
,
byte
[]
data
)
throws
Exception
{
return
encodeByECB
(
key
.
getBytes
(
StandardCharsets
.
UTF_8
),
data
);
}
/**
* Aes加密(ECB工作模式),不要IV
*
* @param key 密钥,key长度必须大于等于 3*8 = 24,并且是8的倍数
* @param data 明文
* @return 密文
* @throws Exception
*/
public
static
String
encodeByECB
(
String
key
,
String
data
)
throws
Exception
{
return
ByteUtils
.
toHexString
(
encodeByECB
(
key
.
getBytes
(
StandardCharsets
.
UTF_8
),
data
.
getBytes
(
StandardCharsets
.
UTF_8
)));
}
/**
* Aes解密(ECB工作模式),不要IV
*
* @param key 密钥,key长度必须大于等于 3*8 = 24,并且是8的倍数
* @param data 密文
* @return 明文
* @throws Exception
*/
public
static
byte
[]
decodeByECB
(
byte
[]
key
,
byte
[]
data
)
throws
Exception
{
//获取SecretKey对象,也可以使用getSecretKey()方法
SecretKey
secretKey
=
new
SecretKeySpec
(
key
,
ALGORITHM
);
//获取指定转换的密码对象Cipher(参数:算法/工作模式/填充模式)
Cipher
cipher
=
Cipher
.
getInstance
(
AES_ECB_PADDING
);
//用密钥和一组算法参数规范初始化此Cipher对象(加密模式)
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
secretKey
);
//执行加密操作
return
cipher
.
doFinal
(
data
);
}
/**
* Aes解密(ECB工作模式),不要IV
*
* @param key 密钥,key长度必须大于等于 3*8 = 24,并且是8的倍数
* @param data 密文
* @return 明文
* @throws Exception
*/
public
static
byte
[]
decodeByECB
(
String
key
,
byte
[]
data
)
throws
Exception
{
return
decodeByECB
(
key
.
getBytes
(
StandardCharsets
.
UTF_8
),
data
);
}
/**
* Aes解密(ECB工作模式),不要IV
*
* @param key 密钥,key长度必须大于等于 3*8 = 24,并且是8的倍数
* @param data 密文
* @return 明文
* @throws Exception
*/
public
static
String
decodeByECB
(
String
key
,
String
data
)
throws
Exception
{
return
new
String
(
decodeByECB
(
key
.
getBytes
(
StandardCharsets
.
UTF_8
),
ByteUtils
.
fromHexString
(
data
)),
StandardCharsets
.
UTF_8
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
aesKey
=
Md5CaculateUtil
.
MD5
(
"clw@LT#1079"
);
System
.
out
.
println
(
encodeByECB
(
aesKey
,
"042e18fb003a4c7dbccf60758b58e55c"
));
//ccEyCOMijZZqGOi2zYTRSb1ml8gTEZ4z8msGFYnyk+C0teZECA==
//System.out.println(decodeByECB("rnF2auSElnrgw/3Xxvb78F/91Fq7pyUzSOgPJUikWAH6gcojOw==",
// "042e18fb003a4c7dbccf60758b58e55c"));
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/RnrDataSM3Utils.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
org.bouncycastle.crypto.digests.SM3Digest
;
/**
* Description RnrDataSM3Utils function
*
* @author zx
* @version 1.0
* @date 2022-06-16 17:20
*/
public
class
RnrDataSM3Utils
{
public
static
String
encode
(
String
context
)
{
return
ZTSecurityUtil
.
toString
(
encode
(
ZTSecurityUtil
.
toBytes
(
context
)));
}
public
static
byte
[]
encode
(
byte
[]
context
)
{
SM3Digest
sm3
=
new
SM3Digest
();
sm3
.
update
(
context
,
0
,
context
.
length
);
byte
[]
hash
=
new
byte
[
sm3
.
getDigestSize
()];
sm3
.
doFinal
(
hash
,
0
);
String
hexText
=
ZTSecurityUtil
.
toHexString
(
hash
);
return
ZTSecurityUtil
.
toBytes
(
hexText
);
}
public
static
void
main
(
String
[]
args
)
{
String
text
=
"123sdfq"
;
System
.
out
.
println
(
encode
(
text
));
// 48ae4d7348bab584c92da40d89a141acdb91e648f88825cc9c2363dc24a36e8c
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/RnrDataSm4Util.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
org.bouncycastle.jce.provider.BouncyCastleProvider
;
import
org.bouncycastle.pqc.math.linearalgebra.ByteUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.crypto.BadPaddingException
;
import
javax.crypto.Cipher
;
import
javax.crypto.IllegalBlockSizeException
;
import
javax.crypto.KeyGenerator
;
import
javax.crypto.NoSuchPaddingException
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.io.*
;
import
java.nio.charset.StandardCharsets
;
import
java.security.InvalidAlgorithmParameterException
;
import
java.security.InvalidKeyException
;
import
java.security.Key
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.NoSuchProviderException
;
import
java.security.SecureRandom
;
import
java.security.Security
;
import
java.util.Base64
;
/**
* Description: 国密SM4
* <br />
* BC库从1.59版本开始已经基本实现了国密算法(SM2、SM3、SM4)
* CreateDate 2021-11-17 14:37
*
* @author yuyi
**/
public
class
RnrDataSm4Util
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
RnrDataSm4Util
.
class
);
//算法名称
public
static
final
String
ALGORITHM_NAME
=
"SM4"
;
//ECB P5填充
public
static
final
String
ALGORITHM_NAME_ECB_PADDING
=
"SM4/ECB/PKCS5Padding"
;
//CBC P5填充
public
static
final
String
ALGORITHM_NAME_CBC_PADDING
=
"SM4/CBC/PKCS5Padding"
;
//密钥长度
public
static
final
int
DEFAULT_KEY_SIZE
=
128
;
static
{
Security
.
addProvider
(
new
BouncyCastleProvider
());
}
private
RnrDataSm4Util
()
{
}
/**
* 获取密钥
*
* @return byte
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
*/
public
static
byte
[]
generateKey
()
throws
NoSuchAlgorithmException
,
NoSuchProviderException
{
return
generateKey
(
DEFAULT_KEY_SIZE
);
}
/**
* 获取指定长度密钥
*
* @param keySize 密钥的长度
* @return byte
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
*/
public
static
byte
[]
generateKey
(
int
keySize
)
throws
NoSuchAlgorithmException
,
NoSuchProviderException
{
KeyGenerator
kg
=
KeyGenerator
.
getInstance
(
ALGORITHM_NAME
,
BouncyCastleProvider
.
PROVIDER_NAME
);
kg
.
init
(
keySize
,
new
SecureRandom
());
return
kg
.
generateKey
().
getEncoded
();
}
/**
* ECB P5填充加密
*
* @param key 密钥
* @param data 明文数据
* @return byte
* @throws Exception
*/
public
static
byte
[]
encryptEcbPaddingByte
(
byte
[]
key
,
byte
[]
data
)
throws
Exception
{
Cipher
cipher
=
generateEcbCipher
(
ALGORITHM_NAME_ECB_PADDING
,
Cipher
.
ENCRYPT_MODE
,
key
);
return
cipher
.
doFinal
(
data
);
}
/**
* Description: ecb加密
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
encryptEcbPadding
(
String
key
,
String
data
)
{
return
encryptEcbPadding
(
key
,
data
,
false
,
null
);
}
/**
* Description: ecb加密,可以指定混淆
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
encryptEcbPadding
(
String
key
,
String
data
,
boolean
isHex
,
String
charset
)
{
if
(
CuscStringUtils
.
isEmpty
(
data
))
{
return
null
;
}
try
{
byte
[]
keyBytes
=
getKeyBytes
(
key
,
isHex
);
byte
[]
dataBytes
=
getDataBytes
(
data
,
charset
);
return
ByteUtils
.
toHexString
(
encryptEcbPaddingByte
(
keyBytes
,
dataBytes
));
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Sm4Util.encryptEcbPadding error ! "
,
e
);
return
null
;
}
}
/**
* Description: ecb加密,可以指定混淆
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
byte
[]
encryptEcbPaddingBytes
(
String
key
,
byte
[]
dataBytes
,
boolean
isHex
)
{
if
(
dataBytes
==
null
)
{
return
null
;
}
try
{
byte
[]
keyBytes
=
getKeyBytes
(
key
,
isHex
);
return
encryptEcbPaddingByte
(
keyBytes
,
dataBytes
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Sm4Util.encryptEcbPaddingBytes error ! "
,
e
);
return
null
;
}
}
/**
* Description: ecb加密
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
encryptEcbPaddingBase64
(
String
key
,
String
data
)
{
return
encryptEcbPaddingBase64
(
key
,
data
,
false
,
null
);
}
/**
* Description: ecb加密,可以指定混淆
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
encryptEcbPaddingBase64
(
String
key
,
String
data
,
boolean
isHex
,
String
charset
)
{
if
(
CuscStringUtils
.
isEmpty
(
data
))
{
return
null
;
}
try
{
byte
[]
keyBytes
=
getKeyBytes
(
key
,
isHex
);
byte
[]
dataBytes
=
getDataBytes
(
data
,
charset
);
return
base64Encoder
(
encryptEcbPaddingByte
(
keyBytes
,
dataBytes
));
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Sm4Util.encryptEcbPaddingBase64 error ! "
,
e
);
return
null
;
}
}
/**
* ECB P5填充解密
*
* @param key 密钥
* @param cipherText 加密后的数据
* @return byte
* @throws Exception
*/
public
static
byte
[]
decryptEcbPaddingByte
(
byte
[]
key
,
byte
[]
cipherText
)
throws
Exception
{
Cipher
cipher
=
generateEcbCipher
(
ALGORITHM_NAME_ECB_PADDING
,
Cipher
.
DECRYPT_MODE
,
key
);
return
cipher
.
doFinal
(
cipherText
);
}
/**
* Description: ecb解密
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
decryptEcbPadding
(
String
key
,
String
data
)
{
return
decryptEcbPadding
(
key
,
data
,
false
,
null
);
}
/**
* Description: ecb解密,可以指定混淆
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
decryptEcbPadding
(
String
key
,
String
data
,
boolean
isHex
,
String
charset
)
{
if
(
CuscStringUtils
.
isEmpty
(
data
))
{
return
null
;
}
try
{
byte
[]
keyBytes
=
getKeyBytes
(
key
,
isHex
);
byte
[]
decrypted
=
decryptEcbPaddingByte
(
keyBytes
,
ByteUtils
.
fromHexString
(
data
));
if
(
CuscStringUtils
.
isNotEmpty
(
charset
))
{
return
new
String
(
decrypted
,
charset
);
}
return
new
String
(
decrypted
,
StandardCharsets
.
UTF_8
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Sm4Util.decryptEcbPaddingBase64 error ! "
,
e
);
return
null
;
}
}
/**
* Description: ecb解密,可以指定混淆
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
byte
[]
decryptEcbPaddingBytes
(
String
key
,
byte
[]
dataBytes
,
boolean
isHex
)
{
if
(
dataBytes
==
null
)
{
return
null
;
}
try
{
byte
[]
keyBytes
=
getKeyBytes
(
key
,
isHex
);
return
decryptEcbPaddingByte
(
keyBytes
,
dataBytes
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Sm4Util.decryptEcbPaddingBytes error ! "
,
e
);
return
null
;
}
}
/**
* Description: ecb解密
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
decryptEcbPaddingBase64
(
String
key
,
String
data
)
{
return
decryptEcbPaddingBase64
(
key
,
data
,
false
,
null
);
}
/**
* Description: ecb解密,可以指定混淆
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
decryptEcbPaddingBase64
(
String
key
,
String
data
,
boolean
isHex
,
String
charset
)
{
if
(
CuscStringUtils
.
isEmpty
(
data
))
{
return
null
;
}
try
{
byte
[]
keyBytes
=
getKeyBytes
(
key
,
isHex
);
byte
[]
decrypted
=
decryptEcbPaddingByte
(
keyBytes
,
base64Decoder
(
data
));
if
(
CuscStringUtils
.
isNotEmpty
(
charset
))
{
return
new
String
(
decrypted
,
charset
);
}
return
new
String
(
decrypted
,
StandardCharsets
.
UTF_8
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Sm4Util.decryptEcbPaddingBase64 error ! "
,
e
);
return
null
;
}
}
/**
* CBC P5填充加密
*
* @param key 密钥
* @param iv 偏移量
* @param data 明文数据
* @return byte
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws NoSuchPaddingException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
* @throws InvalidAlgorithmParameterException
*/
public
static
byte
[]
encryptCbcPaddingByte
(
byte
[]
key
,
byte
[]
iv
,
byte
[]
data
)
throws
InvalidKeyException
,
NoSuchAlgorithmException
,
NoSuchProviderException
,
NoSuchPaddingException
,
IllegalBlockSizeException
,
BadPaddingException
,
InvalidAlgorithmParameterException
{
Cipher
cipher
=
generateCbcCipher
(
ALGORITHM_NAME_CBC_PADDING
,
Cipher
.
ENCRYPT_MODE
,
key
,
iv
);
return
cipher
.
doFinal
(
data
);
}
/**
* Description: cbc加密
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
encryptCbcPaddingBase64
(
String
key
,
String
data
,
String
iv
)
{
return
encryptCbcPaddingBase64
(
key
,
data
,
iv
,
false
,
null
);
}
/**
* Description: cbc加密,可以指定混淆
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
encryptCbcPaddingBase64
(
String
key
,
String
data
,
String
iv
,
boolean
isHex
,
String
charset
)
{
if
(
CuscStringUtils
.
isEmpty
(
data
))
{
return
null
;
}
try
{
byte
[]
keyBytes
=
getKeyBytes
(
key
,
isHex
);
byte
[]
ivBytes
=
getKeyBytes
(
iv
,
isHex
);
byte
[]
dataBytes
=
getDataBytes
(
data
,
charset
);
byte
[]
encrypted
=
encryptCbcPaddingByte
(
keyBytes
,
ivBytes
,
dataBytes
);
return
base64Encoder
(
encrypted
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Sm4Util.encryptCbcPaddingBase64 error ! "
,
e
);
return
null
;
}
}
/**
* CBC P5填充解密
*
* @param key 密钥
* @param iv 偏移量
* @param cipherText 加密数据
* @return byte
* @throws IllegalBlockSizeException
* @throws BadPaddingException
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws NoSuchPaddingException
* @throws InvalidAlgorithmParameterException
*/
public
static
byte
[]
decryptCbcPaddingByte
(
byte
[]
key
,
byte
[]
iv
,
byte
[]
cipherText
)
throws
IllegalBlockSizeException
,
BadPaddingException
,
InvalidKeyException
,
NoSuchAlgorithmException
,
NoSuchProviderException
,
NoSuchPaddingException
,
InvalidAlgorithmParameterException
{
Cipher
cipher
=
generateCbcCipher
(
ALGORITHM_NAME_CBC_PADDING
,
Cipher
.
DECRYPT_MODE
,
key
,
iv
);
return
cipher
.
doFinal
(
cipherText
);
}
/**
* Description: cbc解密
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
decryptCbcPaddingBase64
(
String
key
,
String
data
,
String
iv
)
{
return
decryptCbcPaddingBase64
(
key
,
data
,
iv
,
false
,
null
);
}
/**
* Description: cbc解密,可以指定混淆
* <br />
* CreateDate 2021-11-17 15:53:34
*
* @author yuyi
**/
public
static
String
decryptCbcPaddingBase64
(
String
key
,
String
data
,
String
iv
,
boolean
isHex
,
String
charset
)
{
if
(
CuscStringUtils
.
isEmpty
(
data
))
{
return
null
;
}
try
{
byte
[]
keyBytes
=
getKeyBytes
(
key
,
isHex
);
byte
[]
ivBytes
=
getKeyBytes
(
iv
,
isHex
);
byte
[]
decrypted
=
decryptCbcPaddingByte
(
keyBytes
,
ivBytes
,
base64Decoder
(
data
));
if
(
CuscStringUtils
.
isNotEmpty
(
charset
))
{
return
new
String
(
decrypted
,
charset
);
}
return
new
String
(
decrypted
,
StandardCharsets
.
UTF_8
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Sm4Util.decryptCbcPaddingHex error ! "
,
e
);
return
null
;
}
}
/**
* ECB P5填充加解密Cipher初始化
*
* @param algorithmName 算法名称
* @param mode 1 加密 2解密
* @param key 密钥
* @return Cipher
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws NoSuchPaddingException
* @throws InvalidKeyException
*/
private
static
Cipher
generateEcbCipher
(
String
algorithmName
,
int
mode
,
byte
[]
key
)
throws
NoSuchAlgorithmException
,
NoSuchProviderException
,
NoSuchPaddingException
,
InvalidKeyException
{
Cipher
cipher
=
Cipher
.
getInstance
(
algorithmName
,
BouncyCastleProvider
.
PROVIDER_NAME
);
Key
sm4Key
=
new
SecretKeySpec
(
key
,
ALGORITHM_NAME
);
cipher
.
init
(
mode
,
sm4Key
);
return
cipher
;
}
/**
* CBC P5填充加解密Cipher初始化
*
* @param algorithmName 算法名称
* @param mode 1 加密 2解密
* @param key 密钥
* @param iv 偏移量
* @return Cipher
* @throws InvalidKeyException
* @throws InvalidAlgorithmParameterException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws NoSuchPaddingException
*/
private
static
Cipher
generateCbcCipher
(
String
algorithmName
,
int
mode
,
byte
[]
key
,
byte
[]
iv
)
throws
InvalidKeyException
,
InvalidAlgorithmParameterException
,
NoSuchAlgorithmException
,
NoSuchProviderException
,
NoSuchPaddingException
{
Cipher
cipher
=
Cipher
.
getInstance
(
algorithmName
,
BouncyCastleProvider
.
PROVIDER_NAME
);
Key
sm4Key
=
new
SecretKeySpec
(
key
,
ALGORITHM_NAME
);
IvParameterSpec
ivParameterSpec
=
new
IvParameterSpec
(
iv
);
cipher
.
init
(
mode
,
sm4Key
,
ivParameterSpec
);
return
cipher
;
}
//-------------私有方法区----------------------
/**
* Description: base64编码
* <br />
* CreateDate 2021-11-17 15:54:52
*
* @author yuyi
**/
private
static
String
base64Encoder
(
byte
[]
encrypted
)
{
return
Base64
.
getEncoder
().
encodeToString
(
encrypted
);
}
/**
* Description: base64解码
* <br />
* CreateDate 2021-11-17 17:44:13
*
* @author yuyi
**/
private
static
byte
[]
base64Decoder
(
String
encrypted
)
{
return
Base64
.
getDecoder
().
decode
(
encrypted
);
}
/**
* Description: 获取密钥的byte数组
* <br />
* CreateDate 2021-11-17 17:44:13
*
* @author yuyi
**/
private
static
byte
[]
getKeyBytes
(
String
key
,
boolean
isHex
)
{
byte
[]
keyBytes
;
if
(
isHex
)
{
keyBytes
=
ByteUtils
.
fromHexString
(
key
);
}
else
{
keyBytes
=
key
.
getBytes
();
}
System
.
out
.
println
(
keyBytes
.
length
);
return
keyBytes
;
}
/**
* Description: 获取数据的byte数组
* <br />
* CreateDate 2021-11-17 17:44:13
*
* @author yuyi
**/
private
static
byte
[]
getDataBytes
(
String
data
,
String
charset
)
throws
UnsupportedEncodingException
{
byte
[]
dataBytes
;
if
(
CuscStringUtils
.
isNotEmpty
(
charset
))
{
dataBytes
=
data
.
getBytes
(
charset
);
}
else
{
dataBytes
=
data
.
getBytes
(
StandardCharsets
.
UTF_8
);
}
return
dataBytes
;
}
public
static
void
main
(
String
[]
args
)
{
// 自定义的32位16进制密钥
//String key = "DBBAA833E6A371D1B26820D2C763E882";
//String test="广西灌阳县文市镇会湘村湖坪丘屯011号";
String
sm4Key
=
"7faf0abf9e6c4aa0aa04eeccf3110e37"
;
//String sm4Key = "9f14c36b0af06878";
String
content
=
"广西灌阳县文市镇会湘村湖坪丘屯011号"
;
//System.out.println("base64:"+RnrDataSm4Util.encryptEcbPaddingBase64(sm4Key, content));
String
mw
=
RnrDataSm4Util
.
encryptEcbPadding
(
sm4Key
,
content
,
true
,
null
);
System
.
out
.
println
(
"hex:"
+
mw
);
System
.
out
.
println
(
"hex mw:"
+
RnrDataSm4Util
.
decryptEcbPadding
(
sm4Key
,
mw
,
true
,
null
));
System
.
out
.
println
(
"313e527d850548249f14c36b0af06878"
.
substring
(
16
));
}
}
Prev
1
…
15
16
17
18
19
20
21
Next
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