|
|
@ -72,7 +72,7 @@ public class SdtServiceImpl implements SdtService { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
SdtGetAccessTokenResult sdtResult = JSON.parseObject(stringResult.getMsg(), SdtGetAccessTokenResult.class); |
|
|
|
SdtGetAccessTokenResult sdtResult = JSON.parseObject(stringResult.getData(), SdtGetAccessTokenResult.class); |
|
|
|
if (!sdtResult.success()) { |
|
|
|
log.error("【山东通】刷新accessToken失败:{}", sdtResult.getErrmsg()); |
|
|
|
return; |
|
|
@ -88,7 +88,7 @@ public class SdtServiceImpl implements SdtService { |
|
|
|
sdtAppInfoDao.updateById(updateEntity); |
|
|
|
|
|
|
|
// token刷新了以后,要刷新缓存中的token,这样下次才能获取到最新的token
|
|
|
|
String key = RedisKeys.getOpenApiAccessTokenKey(customerIdInner); |
|
|
|
String key = RedisKeys.getSdtAccessToken(customerIdInner); |
|
|
|
|
|
|
|
redisUtils.set(key, access_token, expires_in); |
|
|
|
}); |
|
|
@ -129,17 +129,14 @@ public class SdtServiceImpl implements SdtService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String getCachedAccessToken(String customerId) { |
|
|
|
String key = RedisKeys.getOpenApiAccessTokenKey(customerId); |
|
|
|
String key = RedisKeys.getSdtAccessToken(customerId); |
|
|
|
String accessToken = redisUtils.getString(key); |
|
|
|
if (StringUtils.isNotBlank(accessToken)) { |
|
|
|
return accessToken; |
|
|
|
} |
|
|
|
|
|
|
|
// db中查询
|
|
|
|
LambdaQueryWrapper<SdtAppInfoEntity> query = new LambdaQueryWrapper<>(); |
|
|
|
query.eq(SdtAppInfoEntity::getCustomerId, customerId); |
|
|
|
SdtAppInfoEntity sdtAppInfoEntity = sdtAppInfoDao.selectOne(query); |
|
|
|
|
|
|
|
SdtAppInfoEntity sdtAppInfoEntity = getSdtInfoByCustomerId(customerId); |
|
|
|
if (sdtAppInfoEntity == null) { |
|
|
|
log.error("【查询山东通AccessToken】失败,原因:该客户id没有配置山东通相关信息"); |
|
|
|
return null; |
|
|
@ -148,22 +145,44 @@ public class SdtServiceImpl implements SdtService { |
|
|
|
accessToken = sdtAppInfoEntity.getAccessToken(); |
|
|
|
Date expiresAt = sdtAppInfoEntity.getExpiresAt(); |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(accessToken)) { |
|
|
|
redisUtils.set(key, accessToken, getExpireIn(expiresAt)); |
|
|
|
Long expireIn = getExpireIn(expiresAt); |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(accessToken) && expireIn > 0) { |
|
|
|
// 没过期,可以用
|
|
|
|
redisUtils.set(key, accessToken, expireIn); |
|
|
|
return accessToken; |
|
|
|
} else { |
|
|
|
// 配置了appInfo,但是没有accessToken,刷新token,刷新缓存,然后重新从缓存中取
|
|
|
|
// 配置了appInfo,但是没有accessToken或者accessToken已经过期,刷新token,刷新缓存,然后重新从缓存中取
|
|
|
|
refreshAccessToken(customerId); |
|
|
|
return redisUtils.getString(key); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 使用客户id查询山东通信息 |
|
|
|
* @author wxz |
|
|
|
* @date 2022/11/6 上午12:25 |
|
|
|
* @param customerId |
|
|
|
* @return SdtAppInfoEntity |
|
|
|
*/ |
|
|
|
private SdtAppInfoEntity getSdtInfoByCustomerId(String customerId) { |
|
|
|
LambdaQueryWrapper<SdtAppInfoEntity> query = new LambdaQueryWrapper<>(); |
|
|
|
query.eq(SdtAppInfoEntity::getCustomerId, customerId); |
|
|
|
return sdtAppInfoDao.selectOne(query); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public SdtStaffInfoResult getUserInfoByCode(String authCode, String customerId) { |
|
|
|
SdtAppInfoEntity sdtAppInfoEntity = getSdtInfoByCustomerId(customerId); |
|
|
|
if (sdtAppInfoEntity == null) { |
|
|
|
log.error("【查询山东通AccessToken】失败,原因:该客户id没有配置山东通相关信息"); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
HashMap<String, Object> params = new HashMap<>(); |
|
|
|
params.put("access_token", getCachedAccessToken(customerId)); |
|
|
|
params.put("code", authCode); |
|
|
|
Result<String> sdtResult = HttpClientManager.getInstance().sendGet(API_GET_USER_INFO_URL, params); |
|
|
|
Result<String> sdtResult = HttpClientManager.getInstance().sendGet(sdtAppInfoEntity.getApiAddress() + API_GET_USER_INFO_URL, params); |
|
|
|
if (!sdtResult.success()) { |
|
|
|
// http状态判断
|
|
|
|
log.error("【山东通登录】查询用户编码-http错误:{}", sdtResult.getMsg()); |
|
|
@ -182,10 +201,16 @@ public class SdtServiceImpl implements SdtService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public SdtStaffDetailResult getUserDetailByUserId(String userId, String customerId) { |
|
|
|
SdtAppInfoEntity sdtAppInfoEntity = getSdtInfoByCustomerId(customerId); |
|
|
|
if (sdtAppInfoEntity == null) { |
|
|
|
log.error("【查询山东通AccessToken】失败,原因:该客户id没有配置山东通相关信息"); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
HashMap<String, Object> userDetailParams = new HashMap<>(); |
|
|
|
userDetailParams.put("access_token", getCachedAccessToken(customerId)); |
|
|
|
userDetailParams.put("userid", userId); |
|
|
|
Result<String> userDetailResult = HttpClientManager.getInstance().sendGet(API_GET_USER_DETAIL_URL, userDetailParams); |
|
|
|
Result<String> userDetailResult = HttpClientManager.getInstance().sendGet(sdtAppInfoEntity.getApiAddress() + API_GET_USER_DETAIL_URL, userDetailParams); |
|
|
|
if (!userDetailResult.success()) { |
|
|
|
// http状态判断
|
|
|
|
log.error("【山东通登录】查询用户详细信息-http错误:{}", userDetailResult.getMsg()); |
|
|
|