Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
youjj
cloud-platform
Commits
12968aca
Commit
12968aca
authored
Jul 09, 2019
by
libin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
批量会员导入
parent
b7a01086
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
128 additions
and
120 deletions
+128
-120
AppPermissionService.java
...aoqi/security/admin/rpc/service/AppPermissionService.java
+128
-120
No files found.
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/rpc/service/AppPermissionService.java
View file @
12968aca
...
...
@@ -94,8 +94,6 @@ public class AppPermissionService {
private
BaseUserMemberBiz
baseUserMemberBiz
;
public
AppUserInfo
validate
(
String
username
,
String
password
)
{
AppUserInfo
info
=
new
AppUserInfo
();
AppUserLogin
user
=
appUserLoginBiz
.
checkeUserLogin
(
username
);
...
...
@@ -203,7 +201,7 @@ public class AppPermissionService {
* @param headimgurl
* @param mobilecode
*/
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRED
)
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRED
)
public
JSONObject
register
(
String
username
,
String
password
,
String
headimgurl
,
String
nickname
,
String
mobilecode
,
String
openId
,
String
unionid
,
Integer
type
)
{
// 判断参数和验证码
...
...
@@ -263,28 +261,28 @@ public class AppPermissionService {
appUserDetailBiz
.
insertSelective
(
rsUserDetail
);
log
.
error
(
"注册:新增用户详情: "
+
userid
);
//临时会员绑定
insertUserMemberByUserIdAndPhone
(
userid
,
username
);
//自动登录获取优惠卷
insertUserMemberByUserIdAndPhone
(
userid
,
username
);
//自动登录获取优惠卷
authCoupn
(
userid
);
// 登录结果要做做统一处理
JSONObject
data
=
autoLogin
(
userid
,
username
,
headimgurl
,
nickname
);
// 到im注册,获取返回结果
Map
<
String
,
Object
>
map
=
registerIm
(
username
,
appUserLogin
.
getPassword
(),
nickname
);
if
(
map
!=
null
)
{
Integer
imUserId
=
Integer
.
parseInt
(
map
.
get
(
"userId"
).
toString
());
Map
<
String
,
Object
>
map
=
registerIm
(
username
,
appUserLogin
.
getPassword
(),
nickname
);
if
(
map
!=
null
)
{
Integer
imUserId
=
Integer
.
parseInt
(
map
.
get
(
"userId"
).
toString
());
//String access_token=map.get("access_token").toString();
String
imPassword
=
map
.
get
(
"password"
).
toString
();
if
(
imUserId
!=
null
&&
imUserId
>
0
&&
StringUtils
.
isNotBlank
(
imPassword
))
{
String
imPassword
=
map
.
get
(
"password"
).
toString
();
if
(
imUserId
!=
null
&&
imUserId
>
0
&&
StringUtils
.
isNotBlank
(
imPassword
))
{
AppUserLogin
userLogin
=
new
AppUserLogin
();
userLogin
.
setId
(
userid
);
userLogin
.
setImPassword
(
imPassword
);
userLogin
.
setImUserid
(
imUserId
);
userLogin
.
setUsername
(
username
);
appUserLoginBiz
.
updateSelectiveById
(
userLogin
);
log
.
info
(
username
+
"----userLogin updateSelectiveById---username====="
+
username
+
"----imPassword===="
+
imPassword
);
log
.
info
(
username
+
"----userLogin updateSelectiveById---username====="
+
username
+
"----imPassword===="
+
imPassword
);
}
//data.put("imToken",access_token);
data
.
put
(
"imUserId"
,
imUserId
);
data
.
put
(
"imUserId"
,
imUserId
);
}
if
(
data
!=
null
)
{
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
...
...
@@ -301,32 +299,32 @@ public class AppPermissionService {
* 自动登录
*/
public
JSONObject
autoLogin
(
Integer
userid
,
String
username
,
String
headimgurl
,
String
nickname
)
{
JSONObject
data
=
new
JSONObject
();
AppUserVo
userVo
=
appUserDetailBiz
.
getUserInfoById
(
userid
);
if
(
userVo
!=
null
)
{
data
.
put
(
"nickname"
,
nickname
);
data
.
put
(
"headerurl"
,
headimgurl
);
if
(
StringUtils
.
isNotBlank
(
userVo
.
getNickname
()))
{
data
.
put
(
"nickname"
,
userVo
.
getNickname
());
}
if
(
StringUtils
.
isNotBlank
(
userVo
.
getHeadimgurl
()))
{
data
.
put
(
"headerurl"
,
userVo
.
getHeadimgurl
());
}
data
.
put
(
"certificationStatus"
,
userVo
.
getCertificationStatus
());
// 缓存操作
String
token
=
""
;
String
imtoken_
=
""
;
//userRedisTemplate.opsForValue().set("token_" + userid,token, SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
//userRedisTemplate.opsForValue().set("imtoken_" + userid,imtoken_,SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
// 返回结果
// data.put("token", token);
data
.
put
(
"username"
,
StringUtils
.
isNotEmpty
(
username
)?
username:
userVo
.
getUsername
());
data
.
put
(
"userId"
,
userid
);
data
.
put
(
"imUserId"
,
userVo
.
getImUserid
());
//更新登录时间 和 ip
String
clientIp
=
getIp
();
appUserLoginBiz
.
updateLoginInfo
(
userid
,
clientIp
);
JSONObject
data
=
new
JSONObject
();
AppUserVo
userVo
=
appUserDetailBiz
.
getUserInfoById
(
userid
);
if
(
userVo
!=
null
)
{
data
.
put
(
"nickname"
,
nickname
);
data
.
put
(
"headerurl"
,
headimgurl
);
if
(
StringUtils
.
isNotBlank
(
userVo
.
getNickname
()))
{
data
.
put
(
"nickname"
,
userVo
.
getNickname
());
}
if
(
StringUtils
.
isNotBlank
(
userVo
.
getHeadimgurl
()))
{
data
.
put
(
"headerurl"
,
userVo
.
getHeadimgurl
());
}
data
.
put
(
"certificationStatus"
,
userVo
.
getCertificationStatus
());
// 缓存操作
String
token
=
""
;
String
imtoken_
=
""
;
//userRedisTemplate.opsForValue().set("token_" + userid,token, SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
//userRedisTemplate.opsForValue().set("imtoken_" + userid,imtoken_,SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
// 返回结果
// data.put("token", token);
data
.
put
(
"username"
,
StringUtils
.
isNotEmpty
(
username
)
?
username
:
userVo
.
getUsername
());
data
.
put
(
"userId"
,
userid
);
data
.
put
(
"imUserId"
,
userVo
.
getImUserid
());
//更新登录时间 和 ip
String
clientIp
=
getIp
();
appUserLoginBiz
.
updateLoginInfo
(
userid
,
clientIp
);
}
return
data
;
...
...
@@ -401,7 +399,7 @@ public class AppPermissionService {
userLogin
.
setUpdatetime
(
now
);
appUserLoginBiz
.
updateSelectiveById
(
userLogin
);
AppUserVo
userVo
=
appUserDetailBiz
.
getUserInfoById
(
userid
);
AppUserDetail
userDetail
=
new
AppUserDetail
();
AppUserDetail
userDetail
=
new
AppUserDetail
();
if
(
userVo
==
null
)
{
userDetail
.
setUserid
(
userid
);
userDetail
.
setHeadimgurl
(
headimgurl
);
...
...
@@ -611,9 +609,9 @@ public class AppPermissionService {
//实名认证
@Transactional
public
ObjectRestResponse
upAuthentication
(
Integer
userid
,
String
name
,
String
idNumber
,
Integer
status
)
{
log
.
error
(
"userid===="
+
userid
+
"-----name===="
+
name
+
"----idNumber==="
+
idNumber
+
"---status==="
+
status
);
if
(
userid
==
null
||
userid
==
0
||
(
status
==
1
&&
StringUtils
.
isBlank
(
idNumber
)&&
StringUtils
.
isBlank
(
name
)))
{
public
ObjectRestResponse
upAuthentication
(
Integer
userid
,
String
name
,
String
idNumber
,
Integer
status
)
{
log
.
error
(
"userid===="
+
userid
+
"-----name===="
+
name
+
"----idNumber==="
+
idNumber
+
"---status==="
+
status
);
if
(
userid
==
null
||
userid
==
0
||
(
status
==
1
&&
StringUtils
.
isBlank
(
idNumber
)
&&
StringUtils
.
isBlank
(
name
)))
{
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
}
try
{
...
...
@@ -625,16 +623,16 @@ public class AppPermissionService {
return
ObjectRestResponse
.
createFailedResultWithObj
(
ResultCode
.
EXIST_CODE
,
"用户已认证"
,
userVo
.
getIdNumber
());
}
if
(
status
==
1
)
{
String
username
=
userVo
.
getUsername
();
String
username
=
userVo
.
getUsername
();
AppUserLogin
user
=
new
AppUserLogin
();
user
.
setId
(
userid
);
user
.
setUsername
(
username
);
user
.
setIdNumber
(
idNumber
);
user
.
setCertificationStatus
(
1
);
appUserLoginBiz
.
updateSelectiveById
(
user
);
if
(
StringUtils
.
isBlank
(
userVo
.
getRealname
()))
{
Integer
id
=
userVo
.
getId
();
userVo
=
new
AppUserVo
();
if
(
StringUtils
.
isBlank
(
userVo
.
getRealname
()))
{
Integer
id
=
userVo
.
getId
();
userVo
=
new
AppUserVo
();
userVo
.
setId
(
id
);
userVo
.
setUserid
(
userid
);
userVo
.
setRealname
(
name
);
...
...
@@ -652,7 +650,7 @@ public class AppPermissionService {
//注册im
public
Map
<
String
,
Object
>
registerIm
(
String
username
,
String
password
,
String
nickname
)
{
log
.
error
(
"------注册registerIm----username====="
+
username
+
"-----password==="
+
password
+
"---nickname==="
+
nickname
);
log
.
error
(
"------注册registerIm----username====="
+
username
+
"-----password==="
+
password
+
"---nickname==="
+
nickname
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"telephone"
,
username
);
map
.
put
(
"password"
,
password
);
...
...
@@ -661,7 +659,7 @@ public class AppPermissionService {
log
.
error
(
"registerIm->response:{}"
,
response
);
if
(
response
.
getStatus
()
==
ResultCode
.
SUCCESS_CODE
)
{
String
result
=
response
.
getMessage
();
log
.
error
(
"------im注册----result======"
+
result
);
log
.
error
(
"------im注册----result======"
+
result
);
if
(
StringUtils
.
isNotBlank
(
result
))
{
JSONObject
object
=
JSONObject
.
parseObject
(
result
);
password
=
object
.
getString
(
"password"
);
...
...
@@ -669,13 +667,13 @@ public class AppPermissionService {
map
.
put
(
"password"
,
password
);
}
JSONObject
data
=
object
.
getJSONObject
(
"data"
);
log
.
error
(
"------im注册----data======"
+
data
);
log
.
error
(
"------im注册----data======"
+
data
);
if
(
data
!=
null
)
{
map
.
put
(
"userId"
,
data
.
getString
(
"userId"
));
// map.put("access_token", data.getString("access_token"));
// map.put("access_token", data.getString("access_token"));
}
else
{
map
.
put
(
"userId"
,
""
);
// map.put("access_token", "");
// map.put("access_token", "");
}
}
}
...
...
@@ -686,7 +684,7 @@ public class AppPermissionService {
//登录im
public
String
loginIm
(
String
username
,
String
password
,
Integer
userId
)
{
log
.
error
(
"------登录loginIm----username====="
+
username
+
"-----password==="
+
password
+
"---userId==="
+
userId
);
log
.
error
(
"------登录loginIm----username====="
+
username
+
"-----password==="
+
password
+
"---userId==="
+
userId
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"telephone"
,
username
);
map
.
put
(
"password"
,
password
);
...
...
@@ -696,38 +694,40 @@ public class AppPermissionService {
String
access_token
=
""
;
if
(
response
.
getStatus
()
==
ResultCode
.
SUCCESS_CODE
)
{
String
result
=
response
.
getMessage
();
log
.
error
(
"------im登录----result======"
+
result
);
log
.
error
(
"------im登录----result======"
+
result
);
if
(
StringUtils
.
isNotBlank
(
result
))
{
JSONObject
object
=
JSONObject
.
parseObject
(
result
);
JSONObject
data
=
object
.
getJSONObject
(
"data"
);
log
.
error
(
"------im登录----data======"
+
data
);
log
.
error
(
"------im登录----data======"
+
data
);
if
(
data
!=
null
)
{
access_token
=
data
.
getString
(
"access_token"
);
}
}
}
log
.
error
(
"------im登录----access_token======"
+
access_token
);
log
.
error
(
"------im登录----access_token======"
+
access_token
);
return
access_token
;
}
//自动领取新人优惠卷
public
String
authCoupn
(
Integer
userId
)
{
public
String
authCoupn
(
Integer
userId
)
{
try
{
return
activityFeign
.
led
(
userId
);
}
catch
(
Exception
e
)
{
return
activityFeign
.
led
(
userId
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
return
null
;
}
}
/**
* 通过用户id登录*** Unbelievable! ! !
*
* @param uid
* @return
*/
public
JSONObject
appletLoginByUserId
(
Integer
uid
)
{
JSONObject
data
=
autoLogin
(
uid
,
null
,
null
,
null
);
if
(
data
.
getDate
(
"userId"
)
!=
null
)
{
if
(
data
.
getDate
(
"userId"
)
!=
null
)
{
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
}
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NOTEXIST_CODE
,
"用户不存在"
);
...
...
@@ -743,7 +743,7 @@ public class AppPermissionService {
* @param nickname
*/
@Transactional
public
JSONObject
applyRegister
(
String
username
,
String
password
,
String
headimgurl
,
String
nickname
,
Integer
small_id
)
{
public
JSONObject
applyRegister
(
String
username
,
String
password
,
String
headimgurl
,
String
nickname
,
Integer
small_id
)
{
// 判断参数
if
(
StringUtils
.
isBlank
(
username
)
||
StringUtils
.
isBlank
(
password
))
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
...
...
@@ -782,31 +782,31 @@ public class AppPermissionService {
setCreateIPInfo
(
rsUserDetail
);
appUserDetailBiz
.
insertSelective
(
rsUserDetail
);
log
.
error
(
"注册:新增用户详情: "
+
userid
);
//临时会员绑定
insertUserMemberByUserIdAndPhone
(
userid
,
username
);
//上线绑定
relationBiz
.
bindByUserId
(
userid
,
small_id
);
//临时会员绑定
insertUserMemberByUserIdAndPhone
(
userid
,
username
);
//上线绑定
relationBiz
.
bindByUserId
(
userid
,
small_id
);
//发送短信通知用户
thirdFeign
.
sendCode
(
username
,
password
,
SystemConfig
.
TEMPLATECODE
);
thirdFeign
.
sendCode
(
username
,
password
,
SystemConfig
.
TEMPLATECODE
);
// 登录结果要做做统一处理
JSONObject
data
=
autoLogin
(
userid
,
username
,
headimgurl
,
nickname
);
// 到im注册,获取返回结果
Map
<
String
,
Object
>
map
=
registerIm
(
username
,
appUserLogin
.
getPassword
(),
nickname
);
if
(
map
!=
null
)
{
Integer
imUserId
=
Integer
.
parseInt
(
map
.
get
(
"userId"
).
toString
());
Map
<
String
,
Object
>
map
=
registerIm
(
username
,
appUserLogin
.
getPassword
(),
nickname
);
if
(
map
!=
null
)
{
Integer
imUserId
=
Integer
.
parseInt
(
map
.
get
(
"userId"
).
toString
());
//String access_token=map.get("access_token").toString();
String
imPassword
=
map
.
get
(
"password"
).
toString
();
if
(
imUserId
!=
null
&&
imUserId
>
0
&&
StringUtils
.
isNotBlank
(
imPassword
))
{
String
imPassword
=
map
.
get
(
"password"
).
toString
();
if
(
imUserId
!=
null
&&
imUserId
>
0
&&
StringUtils
.
isNotBlank
(
imPassword
))
{
AppUserLogin
userLogin
=
new
AppUserLogin
();
userLogin
.
setId
(
userid
);
userLogin
.
setImPassword
(
imPassword
);
userLogin
.
setImUserid
(
imUserId
);
userLogin
.
setUsername
(
username
);
appUserLoginBiz
.
updateSelectiveById
(
userLogin
);
log
.
info
(
username
+
"----userLogin updateSelectiveById---username====="
+
username
+
"----imPassword===="
+
imPassword
);
log
.
info
(
username
+
"----userLogin updateSelectiveById---username====="
+
username
+
"----imPassword===="
+
imPassword
);
}
//data.put("imToken",access_token);
data
.
put
(
"imUserId"
,
imUserId
);
data
.
put
(
"imUserId"
,
imUserId
);
}
if
(
data
!=
null
)
{
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
...
...
@@ -820,41 +820,41 @@ public class AppPermissionService {
}
/**
*通过小程序注册
* 通过小程序注册
*
* @param username
* @return
*/
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRED
)
public
JSONObject
appletRegistry
(
String
username
,
String
headimgurl
,
String
nickname
,
Integer
small_id
)
{
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRED
)
public
JSONObject
appletRegistry
(
String
username
,
String
headimgurl
,
String
nickname
,
Integer
small_id
)
{
try
{
// 是否已存在
AppUserLogin
user
=
appUserLoginBiz
.
checkeUserLogin
(
username
);
JSONObject
data
=
new
JSONObject
();
JSONObject
data
=
new
JSONObject
();
if
(
null
==
user
)
{
String
password
=
"12345678"
;
data
=
applyRegister
(
username
,
password
,
headimgurl
,
nickname
,
small_id
);
}
else
{
Integer
userid
=
user
.
getId
();
String
password
=
"12345678"
;
data
=
applyRegister
(
username
,
password
,
headimgurl
,
nickname
,
small_id
);
}
else
{
Integer
userid
=
user
.
getId
();
//上线绑定
relationBiz
.
bindByUserId
(
userid
,
small_id
);
relationBiz
.
bindByUserId
(
userid
,
small_id
);
//登录
data
=
appletLoginByUserId
(
userid
);
data
=
appletLoginByUserId
(
userid
);
}
return
data
;
return
data
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXCEPTION_CODE
,
"出现异常"
);
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRED
)
public
void
insertUserMemberByUserIdAndPhone
(
Integer
userId
,
String
phone
)
throws
Exception
{
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRED
)
public
void
insertUserMemberByUserIdAndPhone
(
Integer
userId
,
String
phone
)
throws
Exception
{
List
<
BaseUserMemberExportDTO
>
memberExportDTOS
=
baseUserMemberExportBiz
.
findUserMemberExportDataByPhoneAndHashEffective
(
phone
);
if
(
CollectionUtils
.
isNotEmpty
(
memberExportDTOS
)){
insertUserMemberByExistUserMemberExportData
(
userId
,
memberExportDTOS
);
if
(
CollectionUtils
.
isNotEmpty
(
memberExportDTOS
))
{
insertUserMemberByExistUserMemberExportData
(
userId
,
memberExportDTOS
);
baseUserMemberExportBiz
.
updateUserMemberExportDataToLoseEfficacyByPhone
(
phone
);
}
}
...
...
@@ -862,55 +862,63 @@ public class AppPermissionService {
private
void
insertUserMemberByExistUserMemberExportData
(
Integer
userId
,
List
<
BaseUserMemberExportDTO
>
userMemberExportDTOS
)
throws
Exception
{
UserMemberDTO
userMemberDTO
;
for
(
BaseUserMemberExportDTO
userMemberExportDTO
:
userMemberExportDTOS
)
{
userMemberDTO
=
new
UserMemberDTO
();
userMemberDTO
.
setUserId
(
userId
);
userMemberDTO
.
setRentFreeDays
(
userMemberExportDTO
.
getRentFreeDays
());
userMemberDTO
.
setMemberLevel
(
userMemberExportDTO
.
getMemberLevel
());
userMemberDTO
.
setTotalNumber
(
userMemberExportDTO
.
getTotalNumber
());
userMemberDTO
.
setDiscount
(
userMemberExportDTO
.
getDiscount
());
userMemberDTO
.
setIsBind
(
1
);
baseUserMemberBiz
.
updUserMemberByUserId
(
userMemberDTO
);
}
}
for
(
BaseUserMemberExportDTO
userMemberExportDTO
:
userMemberExportDTOS
)
{
userMemberDTO
=
new
UserMemberDTO
();
userMemberDTO
.
setUserId
(
userId
);
userMemberDTO
.
setRentFreeDays
(
userMemberExportDTO
.
getRentFreeDays
());
userMemberDTO
.
setMemberLevel
(
userMemberExportDTO
.
getMemberLevel
());
userMemberDTO
.
setTotalNumber
(
userMemberExportDTO
.
getTotalNumber
());
userMemberDTO
.
setDiscount
(
userMemberExportDTO
.
getDiscount
());
userMemberDTO
.
setIsBind
(
1
);
baseUserMemberBiz
.
updUserMemberByUserId
(
userMemberDTO
);
}
}
/**
* ip地址 信息解析
*
* @param appUserDetail
*/
public
void
setCreateIPInfo
(
AppUserDetail
appUserDetail
){
public
void
setCreateIPInfo
(
AppUserDetail
appUserDetail
)
{
String
crtHost
=
appUserDetail
.
getCrtHost
();
if
(
log
.
isDebugEnabled
()){
log
.
debug
(
"解析的地址:【{}】"
,
crtHost
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"解析的地址:【{}】"
,
crtHost
);
}
try
{
String
ipAddress
=
restTemplate
.
getForObject
(
String
.
format
(
"%s%s"
,
IPAddress
.
BASE_IP_PARSING_URL
,
crtHost
),
String
.
class
);
String
data
=
JSONObject
.
parseObject
(
ipAddress
).
getString
(
IPAddress
.
BASE_DATA
);
JSONObject
ipJsonObject
=
JSONObject
.
parseObject
(
data
);
String
cityName
=
ipJsonObject
.
getString
(
IPAddress
.
CITY_NAME
);
RegionDTO
regionDTO
=
regionFeign
.
getRegionByCityName
(
StringUtils
.
isEmpty
(
cityName
)?
"东莞"
:
cityName
);
if
(
null
!=
regionDTO
){
appUserDetail
.
setProvinceCode
(
Integer
.
valueOf
(
String
.
valueOf
(
regionDTO
.
getParentId
())));
appUserDetail
.
setCityCode
(
Integer
.
valueOf
(
String
.
valueOf
(
regionDTO
.
getId
())));
analyticalIPByWebSiteAndIPAddress
(
IPAddress
.
BASE_IP_PARSING_URL2
,
crtHost
,
appUserDetail
);
}
catch
(
Exception
e
)
{
try
{
analyticalIPByWebSiteAndIPAddress
(
IPAddress
.
BASE_IP_PARSING_URL1
,
crtHost
,
appUserDetail
);
}
catch
(
Exception
ex
)
{
log
.
error
(
"解析地址失败:【{}】"
,
ex
.
getMessage
());
}
}
catch
(
Exception
e
){
log
.
error
(
"地址解析失败:【{}】"
,
e
.
getMessage
());
}
}
private
void
analyticalIPByWebSiteAndIPAddress
(
String
url
,
String
crtHost
,
AppUserDetail
appUserDetail
)
{
String
ipAddress
=
restTemplate
.
getForObject
(
String
.
format
(
"%s%s"
,
url
,
crtHost
),
String
.
class
);
String
data
=
JSONObject
.
parseObject
(
ipAddress
).
getString
(
IPAddress
.
BASE_DATA
);
JSONObject
ipJsonObject
=
JSONObject
.
parseObject
(
data
);
String
cityName
=
ipJsonObject
.
getString
(
IPAddress
.
CITY_NAME
);
RegionDTO
regionDTO
=
regionFeign
.
getRegionByCityName
(
StringUtils
.
isEmpty
(
cityName
)
?
"东莞"
:
cityName
);
if
(
null
!=
regionDTO
)
{
appUserDetail
.
setProvinceCode
(
Integer
.
valueOf
(
String
.
valueOf
(
regionDTO
.
getParentId
())));
appUserDetail
.
setCityCode
(
Integer
.
valueOf
(
String
.
valueOf
(
regionDTO
.
getId
())));
}
}
/**
* @author libin
* @version 1.0.0
* @dec ip 解析返回的地址信息
*/
private
static
class
IPAddress
{
public
static
final
String
BASE_IP_PARSING_URL
=
"http://ip.taobao.com/service/getIpInfo.php?ip="
;
public
static
final
String
BASE_DATA
=
"data"
;
public
static
final
String
PROVINCE_CODE
=
"region_id"
;
public
static
final
String
CITY_CODE
=
"city_id"
;
public
static
final
String
CITY_NAME
=
"city"
;
public
static
final
String
PROVINCE_NAME
=
"region"
;
private
static
class
IPAddress
{
public
static
final
String
BASE_IP_PARSING_URL1
=
"http://ip.taobao.com/service/getIpInfo.php?ip="
;
public
static
final
String
BASE_IP_PARSING_URL2
=
"https://www.mxnzp.com/api/ip/aim_ip?ip="
;
public
static
final
String
BASE_DATA
=
"data"
;
public
static
final
String
CITY_NAME
=
"city"
;
}
}
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