You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.7 KiB
101 lines
3.7 KiB
package com.epmet;
|
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
import com.epmet.common.token.constant.LoginConstant;
|
|
import com.epmet.commons.tools.security.dto.GovTokenDto;
|
|
import com.epmet.commons.tools.utils.CpUserDetailRedis;
|
|
import com.epmet.commons.tools.utils.DateUtils;
|
|
import com.epmet.dto.CustomerAgencyDTO;
|
|
import com.epmet.dto.result.StaffLatestAgencyResultDTO;
|
|
import com.epmet.jwt.JwtTokenProperties;
|
|
import com.epmet.jwt.JwtTokenUtils;
|
|
import com.epmet.service.impl.GovLoginServiceImpl;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Map;
|
|
|
|
@RunWith(SpringRunner.class)
|
|
@SpringBootTest
|
|
public class TokenGenTest {
|
|
|
|
@Autowired
|
|
private JwtTokenProperties jwtTokenProperties;
|
|
|
|
@Autowired
|
|
private JwtTokenUtils jwtTokenUtils;
|
|
|
|
@Autowired
|
|
private CpUserDetailRedis cpUserDetailRedis;
|
|
|
|
@Autowired
|
|
private GovLoginServiceImpl govLoginService;
|
|
|
|
@Test
|
|
public void genToken() {
|
|
String staffId = "wxz";
|
|
String tokenStr = generateGovWxmpToken(staffId);
|
|
int expire = jwtTokenProperties.getExpire();
|
|
GovTokenDto govTokenDto = new GovTokenDto();
|
|
govTokenDto.setApp(LoginConstant.APP_GOV);
|
|
govTokenDto.setClient(LoginConstant.CLIENT_WXMP);
|
|
govTokenDto.setUserId(staffId);
|
|
govTokenDto.setOpenId("");
|
|
govTokenDto.setSessionKey("");
|
|
govTokenDto.setUnionId("");
|
|
govTokenDto.setToken(tokenStr);
|
|
govTokenDto.setUpdateTime(System.currentTimeMillis());
|
|
govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(tokenStr).getTime());
|
|
govTokenDto.setAgencyId("1");
|
|
govTokenDto.setDeptIdList(new HashSet<>(Arrays.asList("1","2","3")));
|
|
govTokenDto.setCustomerId("f76def116c9c2dc0269cc17867af122c");
|
|
cpUserDetailRedis.set(govTokenDto, expire);
|
|
}
|
|
|
|
@Test
|
|
public void saveLatestGovTokenDto() {
|
|
String staffId = "wxz";
|
|
String token = generateGovWxmpToken(staffId);
|
|
int expire = jwtTokenProperties.getExpire();
|
|
GovTokenDto govTokenDto = new GovTokenDto();
|
|
govTokenDto.setApp(LoginConstant.APP_GOV);
|
|
govTokenDto.setClient(LoginConstant.CLIENT_WXMP);
|
|
govTokenDto.setToken(token);
|
|
govTokenDto.setUserId(staffId);
|
|
govTokenDto.setUpdateTime(System.currentTimeMillis());
|
|
govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime());
|
|
//govTokenDto.setAgencyId(staffLatestAgency.getAgencyId());
|
|
//govTokenDto.setCustomerId(staffLatestAgency.getCustomerId());
|
|
|
|
//设置部门,网格,角色列表
|
|
govTokenDto.setDeptIdList(govLoginService.getDeptartmentIdList(staffId));
|
|
govTokenDto.setGridIdList(govLoginService.getGridIdList(staffId));
|
|
CustomerAgencyDTO agency = govLoginService.getAgencyByStaffId(staffId);
|
|
if (agency != null) {
|
|
govTokenDto.setRoleList(govLoginService.queryGovStaffRoles(staffId, agency.getId()));
|
|
}
|
|
govTokenDto.setOrgIdPath(govLoginService.getOrgIdPath(staffId));
|
|
|
|
cpUserDetailRedis.set(govTokenDto, expire);
|
|
}
|
|
|
|
/**
|
|
* @Description 生成token
|
|
* @Date 2020/4/18 23:04
|
|
**/
|
|
private String generateGovWxmpToken(String staffId) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("app", LoginConstant.APP_GOV);
|
|
map.put("client", LoginConstant.CLIENT_WXMP);
|
|
map.put("userId", staffId);
|
|
String token = jwtTokenUtils.createToken(map);
|
|
return token;
|
|
}
|
|
|
|
}
|
|
|