Commit 83f735df authored by tianbo's avatar tianbo

weapp修改

parent 248b0fab
...@@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; ...@@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.utils.Menu; import com.yeejoin.amos.boot.biz.common.utils.Menu;
import com.yeejoin.amos.boot.biz.common.utils.TreeParser; import com.yeejoin.amos.boot.biz.common.utils.TreeParser;
import com.yeejoin.amos.boot.module.app.api.common.MobileLoginParam; import com.yeejoin.amos.boot.module.app.api.common.MobileLoginParam;
import com.yeejoin.amos.boot.module.app.api.dto.EquipExportDto;
import com.yeejoin.amos.boot.module.app.api.dto.TzBaseEnterpriseInfoDto; import com.yeejoin.amos.boot.module.app.api.dto.TzBaseEnterpriseInfoDto;
import com.yeejoin.amos.boot.module.app.api.entity.EquipmentCategory; import com.yeejoin.amos.boot.module.app.api.entity.EquipmentCategory;
import com.yeejoin.amos.boot.module.app.api.entity.PageParam; import com.yeejoin.amos.boot.module.app.api.entity.PageParam;
...@@ -30,7 +29,14 @@ import io.swagger.annotations.ApiOperation; ...@@ -30,7 +29,14 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
...@@ -256,8 +262,8 @@ public class TzsAppController { ...@@ -256,8 +262,8 @@ public class TzsAppController {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(value = "获取机器人登录token", notes = "获取机器人登录token") @ApiOperation(value = "获取机器人登录token", notes = "获取机器人登录token")
@GetMapping(value = "/acquireToken") @GetMapping(value = "/acquireToken")
synchronized public String getRobotLoginToken() { synchronized public ResponseModel<String> getRobotLoginToken() {
return amosRequestContext.getToken(); return ResponseHelper.buildResponse(amosRequestContext.getToken());
} }
/** /**
......
package com.yeejoin.amos.boot.module.app.biz.controller;
import com.yeejoin.amos.boot.module.app.biz.service.impl.TzsAuthServiceImpl;
import com.yeejoin.amos.component.robot.AmosRequestContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
@RestController
@Slf4j
@Api(tags = "wechat小程序接口")
@RequestMapping(value = "/wechat")
public class TzsWeChatController {
@Autowired
AmosRequestContext amosRequestContext;
@Autowired
TzsAuthServiceImpl authServiceImpl;
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(value = "获取机器人登录token", notes = "获取机器人登录token")
@GetMapping(value = "/api/acquireToken")
synchronized public ResponseModel<String> getRobotLoginToken() {
return ResponseHelper.buildResponse(authServiceImpl.getUserToken());
}
}
...@@ -11,28 +11,18 @@ import com.yeejoin.amos.component.robot.AmosRequestContext; ...@@ -11,28 +11,18 @@ import com.yeejoin.amos.component.robot.AmosRequestContext;
@Service @Service
public class StartPlatformTokenService { public class StartPlatformTokenService {
@Value("${admin.product}") @Value("${amos.system.user.product}")
String product; String product;
@Value("${admin.appkey}") @Value("${amos.system.user.app-key}")
String appkey; String appkey;
@Value("${admin.user}")
String user;
@Value("${admin.password}")
String password;
@Value("${amos.secret.key}")
String secretKey;
@Autowired @Autowired
RedisUtil redisUtil; RedisUtil redisUtil;
@Autowired @Autowired
AmosRequestContext amosRequestContext; AmosRequestContext amosRequestContext;
public void getToken() { public void getToken() {
RequestContext.setProduct(product); RequestContext.setProduct(product);
RequestContext.setAppKey(appkey); RequestContext.setAppKey(appkey);
......
...@@ -39,6 +39,7 @@ import com.yeejoin.amos.feign.privilege.util.DesUtil; ...@@ -39,6 +39,7 @@ import com.yeejoin.amos.feign.privilege.util.DesUtil;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
...@@ -82,6 +83,7 @@ public class TzBaseEnterpriseInfoServiceImpl ...@@ -82,6 +83,7 @@ public class TzBaseEnterpriseInfoServiceImpl
RegUnitIcServiceImpl regUnitIcService; RegUnitIcServiceImpl regUnitIcService;
@Autowired @Autowired
@Lazy
RegUnitInfoServiceImpl regUnitInfoService; RegUnitInfoServiceImpl regUnitInfoService;
@Autowired @Autowired
......
...@@ -48,6 +48,11 @@ public class TzsAuthServiceImpl implements TzsAuthService { ...@@ -48,6 +48,11 @@ public class TzsAuthServiceImpl implements TzsAuthService {
@Value("${cti.user.pwd}") @Value("${cti.user.pwd}")
private String ctiUserPwd; private String ctiUserPwd;
@Value("${amos.wechat.robot.user}")
private String weRobotUser;
@Value("${amos.wechat.robot.password}")
private String weRobotPassword;
/** /**
* saveUserRedis设置过期时间 * saveUserRedis设置过期时间
...@@ -58,6 +63,7 @@ public class TzsAuthServiceImpl implements TzsAuthService { ...@@ -58,6 +63,7 @@ public class TzsAuthServiceImpl implements TzsAuthService {
@Autowired @Autowired
private StartPlatformTokenService startPlatformTokenService; private StartPlatformTokenService startPlatformTokenService;
String weChatToken = "WECHAT_TOKEN";
@Override @Override
public List<String> getUserRegionCode() { public List<String> getUserRegionCode() {
...@@ -149,20 +155,18 @@ public class TzsAuthServiceImpl implements TzsAuthService { ...@@ -149,20 +155,18 @@ public class TzsAuthServiceImpl implements TzsAuthService {
} }
private void loginUser(String userName, String password, String token) {
private void loginCtiUser() { String pwd = DesUtil.encode(password, "qaz");
String passwd = DesUtil.encode(ctiUserPwd, "qaz"); IdPasswordAuthModel loginData = new IdPasswordAuthModel();
IdPasswordAuthModel loninData = new IdPasswordAuthModel(); loginData.setLoginId(userName);
loninData.setLoginId(ctiUserName); loginData.setPassword(pwd);
loninData.setPassword(passwd); FeignClientResult loginResult = Privilege.authClient.idpassword(loginData);
FeignClientResult loginResult = Privilege.authClient.idpassword(loninData);
if(loginResult.getStatus() == 200) { if(loginResult.getStatus() == 200) {
HashMap resultMap = (HashMap) loginResult.getResult(); HashMap resultMap = (HashMap) loginResult.getResult();
redisUtils.set(RedisKey.CTI_USER_TOKEN, resultMap.get("token").toString(), redisRegionTimeSecond); redisUtils.set(token, resultMap.get("token").toString(), redisRegionTimeSecond);
} }
} }
public void setRequestContext() { public void setRequestContext() {
// 需要登录后台账号 // 需要登录后台账号
RequestContext.setAppKey("AMOS_STUDIO"); RequestContext.setAppKey("AMOS_STUDIO");
...@@ -173,10 +177,10 @@ public class TzsAuthServiceImpl implements TzsAuthService { ...@@ -173,10 +177,10 @@ public class TzsAuthServiceImpl implements TzsAuthService {
boolean validToken = TokenOperation.refresh(redisUtils.get(RedisKey.CTI_USER_TOKEN).toString()); boolean validToken = TokenOperation.refresh(redisUtils.get(RedisKey.CTI_USER_TOKEN).toString());
// 登陆 // 登陆
if (!validToken) { if (!validToken) {
this.loginCtiUser(); this.loginUser(ctiUserName, ctiUserPwd, RedisKey.CTI_USER_TOKEN);
} }
} else { // 登陆 } else { // 登陆
this.loginCtiUser(); this.loginUser(ctiUserName, ctiUserPwd, RedisKey.CTI_USER_TOKEN);
} }
} }
String ctiToken = redisUtils.get(RedisKey.CTI_USER_TOKEN).toString(); String ctiToken = redisUtils.get(RedisKey.CTI_USER_TOKEN).toString();
...@@ -193,7 +197,6 @@ public class TzsAuthServiceImpl implements TzsAuthService { ...@@ -193,7 +197,6 @@ public class TzsAuthServiceImpl implements TzsAuthService {
} }
private void saveUserRedis(AgencyUserModel user, String token) { private void saveUserRedis(AgencyUserModel user, String token) {
String authToken = RedisKey.buildReginKey(user.getUserId(), token); String authToken = RedisKey.buildReginKey(user.getUserId(), token);
if (redisUtils.hasKey(authToken)) { if (redisUtils.hasKey(authToken)) {
...@@ -229,5 +232,23 @@ public class TzsAuthServiceImpl implements TzsAuthService { ...@@ -229,5 +232,23 @@ public class TzsAuthServiceImpl implements TzsAuthService {
redisUtils.set(authToken, JSONObject.toJSONString(reginParams), redisRegionTimeSecond); redisUtils.set(authToken, JSONObject.toJSONString(reginParams), redisRegionTimeSecond);
} }
public String getUserToken() {
// 需要登录后台账号
RequestContext.setAppKey("AMOS_STUDIO");
RequestContext.setProduct("AMOS_STUDIO_WEB");
synchronized (TzsAuthServiceImpl.class) {
if (redisUtils.hasKey(weChatToken)) {
// 验证token
boolean validToken = TokenOperation.refresh(redisUtils.get(weChatToken).toString());
// 登陆
if (!validToken) {
this.loginUser(weRobotUser, weRobotPassword, weChatToken);
}
} else { // 登陆
this.loginUser(weRobotUser, weRobotPassword, weChatToken);
}
}
String weToken = redisUtils.get(weChatToken).toString();
return weToken;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment