Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
0077db66
Commit
0077db66
authored
Jul 21, 2023
by
tianbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
小程序获取登录token接口修改
parent
3dd0d74e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
105 deletions
+92
-105
LoginController.java
.../amos/boot/module/tzs/biz/controller/LoginController.java
+83
-97
application-dev3.properties
...le-tzs-biz/src/main/resources/application-dev3.properties
+9
-8
No files found.
amos-boot-system-tzs/amos-boot-module-tzs-biz/src/main/java/com/yeejoin/amos/boot/module/tzs/biz/controller/LoginController.java
View file @
0077db66
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
biz
.
controller
;
package
com
.
yeejoin
.
amos
.
boot
.
module
.
tzs
.
biz
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.yeejoin.amos.component.robot.AmosRequestContext
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.boot.biz.common.bo.ReginParams
;
import
com.yeejoin.amos.component.feign.config.TokenOperation
;
import
com.yeejoin.amos.component.feign.model.FeignClientResult
;
import
com.yeejoin.amos.feign.privilege.Privilege
;
import
com.yeejoin.amos.feign.privilege.model.AgencyUserModel
;
import
com.yeejoin.amos.feign.privilege.model.ApplicationModel
;
import
com.yeejoin.amos.feign.privilege.model.CompanyModel
;
import
com.yeejoin.amos.feign.privilege.model.IdPasswordAuthModel
;
import
com.yeejoin.amos.feign.privilege.util.DesUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.typroject.tyboot.core.foundation.context.RequestContext
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* @author zjw
* @author zjw
* @date 2020-03-30
* @date 2020-03-30
*/
*/
@RestController
@RestController
@RequestMapping
(
value
=
"/
api/loginBytoken
"
)
@RequestMapping
(
value
=
"/
weapp/api
"
)
@Api
(
tags
=
"
通过userName登录A
pi"
)
@Api
(
tags
=
"
小程序登录a
pi"
)
public
class
LoginController
{
public
class
LoginController
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
LoginController
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
LoginController
.
class
);
// @Autowired
// private RedisTemplate<String, String> redisTemplate;
//
// @Value("${outSystem.user.password}")
// private String password;
//
// @Value("${amos.system.user.product}")
// private String product;
//
// @Value("${amos.system.user.app-key}")
// private String appKey;
@Autowired
@Autowired
private
RedisTemplate
<
String
,
String
>
redisTemplate
;
AmosRequestContext
amosRequestContext
;
@Value
(
"${outSystem.user.password}"
)
// @TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
private
String
password
;
// @ApiOperation(value = "通过userId登录", notes = "查询设备指标")
// @GetMapping(value = "/{userId}")
@Value
(
"${amos.system.user.product}"
)
// synchronized public ReginParams getBindEquipment(@PathVariable("userId") String userId) throws Exception {
private
String
product
;
//
// if (ObjectUtils.isEmpty(userId)){
@Value
(
"${amos.system.user.app-key}"
)
// throw new Exception("用户信息不存在");
private
String
appKey
;
// }
// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
// .getRequestAttributes()).getRequest();
// String token = "wxxcxdl";
// ReginParams reginParams;
// reginParams = JSON.parseObject(redisTemplate.opsForValue().get(buildKey(userId, token)), ReginParams.class);
// if(reginParams == null){
// reginParams = getLogin(userId, token);
// }else{
// RequestContext.setProduct(product);
// if (!TokenOperation.refresh(reginParams.getToken())) {
// reginParams = getLogin(userId, token);
// }
// }
// return reginParams;
// }
//
// private ReginParams getLogin(String userId, String token) throws Exception{
// ReginParams reginParams = new ReginParams();
// IdPasswordAuthModel dPasswordAuthModel = new IdPasswordAuthModel();
// dPasswordAuthModel.setLoginId(userId);
// dPasswordAuthModel.setPassword(DesUtil.encode(password, "qaz"));
// RequestContext.setProduct(product);
// FeignClientResult feignClientResult = Privilege.authClient.idpassword(dPasswordAuthModel);
// if (ObjectUtils.isEmpty(feignClientResult.getResult())){
// throw new Exception("缺失登录信息");
// }
// // 调用平台授权接口
// Map<String ,String > re = (Map<String, String>) feignClientResult.getResult();
// String amosToken = re.get("token");
//
// logger.info("应用授权开始======================================"+amosToken);
// RequestContext.setToken(amosToken);
// RequestContext.setProduct(product);
// RequestContext.setAppKey(appKey);
//
// List<ApplicationModel> fd = Privilege.applicationClient.queryUserService().getResult();
//
// logger.info("应用授权结束======================================"+JSON.toJSONString(fd)+amosToken);
//
// AgencyUserModel userModel = (AgencyUserModel) Privilege.agencyUserClient.getme().getResult();
// CompanyModel companyModel = userModel.getCompanys().get(0);
//
// reginParams.setToken(amosToken);
// reginParams.setUserModel(userModel);
// redisTemplate.opsForValue().set(buildKey(userId, token), JSONObject.toJSONString(reginParams),28, TimeUnit.DAYS);
// return reginParams;
// }
//
//
// private String buildKey(String userId, String token) {
// return "region_" + userId + "_" + token;
// }
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
,
needAuth
=
false
)
@ApiOperation
(
value
=
"通过userId登录"
,
notes
=
"查询设备指标"
)
@ApiOperation
(
value
=
"获取机器人登录token"
,
notes
=
"获取机器人登录token"
)
@GetMapping
(
value
=
"/{userId}"
)
@GetMapping
(
value
=
"/acquireToken"
)
synchronized
public
ReginParams
getBindEquipment
(
@PathVariable
(
"userId"
)
String
userId
)
throws
Exception
{
synchronized
public
String
getRobotLoginToken
()
{
return
amosRequestContext
.
getToken
();
if
(
ObjectUtils
.
isEmpty
(
userId
)){
throw
new
Exception
(
"用户信息不存在"
);
}
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
String
token
=
"wxxcxdl"
;
ReginParams
reginParams
;
reginParams
=
JSON
.
parseObject
(
redisTemplate
.
opsForValue
().
get
(
buildKey
(
userId
,
token
)),
ReginParams
.
class
);
if
(
reginParams
==
null
){
reginParams
=
getLogin
(
userId
,
token
);
}
else
{
RequestContext
.
setProduct
(
product
);
if
(!
TokenOperation
.
refresh
(
reginParams
.
getToken
()))
{
reginParams
=
getLogin
(
userId
,
token
);
}
}
return
reginParams
;
}
private
ReginParams
getLogin
(
String
userId
,
String
token
)
throws
Exception
{
ReginParams
reginParams
=
new
ReginParams
();
IdPasswordAuthModel
dPasswordAuthModel
=
new
IdPasswordAuthModel
();
dPasswordAuthModel
.
setLoginId
(
userId
);
dPasswordAuthModel
.
setPassword
(
DesUtil
.
encode
(
password
,
"qaz"
));
RequestContext
.
setProduct
(
product
);
FeignClientResult
feignClientResult
=
Privilege
.
authClient
.
idpassword
(
dPasswordAuthModel
);
if
(
ObjectUtils
.
isEmpty
(
feignClientResult
.
getResult
())){
throw
new
Exception
(
"缺失登录信息"
);
}
// 调用平台授权接口
Map
<
String
,
String
>
re
=
(
Map
<
String
,
String
>)
feignClientResult
.
getResult
();
String
amosToken
=
re
.
get
(
"token"
);
logger
.
info
(
"应用授权开始======================================"
+
amosToken
);
RequestContext
.
setToken
(
amosToken
);
RequestContext
.
setProduct
(
product
);
RequestContext
.
setAppKey
(
appKey
);
List
<
ApplicationModel
>
fd
=
Privilege
.
applicationClient
.
queryUserService
().
getResult
();
logger
.
info
(
"应用授权结束======================================"
+
JSON
.
toJSONString
(
fd
)+
amosToken
);
AgencyUserModel
userModel
=
(
AgencyUserModel
)
Privilege
.
agencyUserClient
.
getme
().
getResult
();
CompanyModel
companyModel
=
userModel
.
getCompanys
().
get
(
0
);
reginParams
.
setToken
(
amosToken
);
reginParams
.
setUserModel
(
userModel
);
redisTemplate
.
opsForValue
().
set
(
buildKey
(
userId
,
token
),
JSONObject
.
toJSONString
(
reginParams
),
28
,
TimeUnit
.
DAYS
);
return
reginParams
;
}
private
String
buildKey
(
String
userId
,
String
token
)
{
return
"region_"
+
userId
+
"_"
+
token
;
}
}
}
}
amos-boot-system-tzs/amos-boot-module-tzs-biz/src/main/resources/application-dev3.properties
View file @
0077db66
...
@@ -153,10 +153,11 @@ tzs.cylinder.info.cron=0 0 1 * * ?
...
@@ -153,10 +153,11 @@ tzs.cylinder.info.cron=0 0 1 * * ?
# ??????????
# ??????????
minio.url.path
=
http://172.16.10.210:9000/
minio.url.path
=
http://172.16.10.210:9000/
## ɼǰ
## 生成监管码前缀域名(预发布环境使用)
regulatory_code_prefix
=
https://nav.sspai.top/tzs?code=
regulatory_code_prefix
=
https://sxtzsb.sxsei.com:9435/tzs?code=
## 生成监管码前缀域名(生产环境使用)
#regulatory_code_prefix=https://sxtzsb.sxsei.com:19435/tzs?code=
outSystem.user.password
=
a1234560
amos.system.user.app-key
=
AMOS_STUDIO
#outSystem.user.password=a1234560
amos.system.user.product
=
STUDIO_APP_WEB
#amos.system.user.app-key=AMOS_STUDIO
\ No newline at end of file
#
amos.system.user.product
=
STUDIO_APP_WEB
\ No newline at end of file
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