|
|
@ -280,6 +280,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
HashMap<String,Map> hashMap = JSON.parseObject(authInfo, HashMap.class); |
|
|
|
Map map = hashMap.get(ModuleConstant.AUTHORIZATION_INFO); |
|
|
|
authorizationInfoResultDTO = mapToEntity(map, AuthorizationInfoResultDTO.class); |
|
|
|
log.info("授权信息:"+map); |
|
|
|
String expiresIn = authorizationInfoResultDTO.getExpires_in(); |
|
|
|
Date expiresInTime = this.countExpirationTime(expiresIn); |
|
|
|
//授权信息分为两张表,基础信息authorization_info,授权列表func_info
|
|
|
@ -298,6 +299,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
log.info(START_INSERT_FUNC_INFO); |
|
|
|
List<FuncInfoFormDTO> funcInfos = new ArrayList<>(); |
|
|
|
List<Map> func_info = authorizationInfoResultDTO.getFunc_info(); |
|
|
|
log.info("权限列表信息:"+func_info); |
|
|
|
for (Map map1 : func_info) { |
|
|
|
List key = (List)map1.keySet(); |
|
|
|
FuncInfoFormDTO fu = new FuncInfoFormDTO(); |
|
|
@ -311,10 +313,10 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
funcInfos.add(fu); |
|
|
|
} |
|
|
|
//先逻辑删除,在插入
|
|
|
|
funcInfoDao.updateOldFuncInfo(customerId); |
|
|
|
funcInfoDao.updateOldFuncInfo(customerId,authorizationInfoResultDTO.getAuthorizer_appid()); |
|
|
|
funcInfoDao.insertFuncInfo(funcInfos); |
|
|
|
// 授权信息放入缓存
|
|
|
|
redisThird.setAuthInfo(authorizationInfoResultDTO); |
|
|
|
redisThird.setAuthInfo(authorizationInfoResultDTO,customerId,clientType); |
|
|
|
//authorizer_refresh_token 放入缓存
|
|
|
|
redisThird.setAuthorizerRefreshToken(authInfoDTO); |
|
|
|
log.info(END_GET_AUTH_INFO); |
|
|
@ -332,6 +334,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
//查询 即将过期的 authorizer_access_token
|
|
|
|
List<WillOverDueResultDTO> willOverDueResultDTOS = authorizationInfoDao.checkWillOverDue(); |
|
|
|
if (willOverDueResultDTOS.size() != NumConstant.ZERO && null != willOverDueResultDTOS){ |
|
|
|
log.info("查询到即将过期的authorizer_access_token"); |
|
|
|
willOverDueResultDTOS.forEach(willOverDueDTO -> { |
|
|
|
String authAppId = willOverDueDTO.getAuthAppId(); |
|
|
|
String customerId = willOverDueDTO.getCustomerId(); |
|
|
@ -366,6 +369,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
//缓存 refreshAuthorizerAccessToken
|
|
|
|
redisThird.setAuthorizerRefreshToken(authorizationInfo); |
|
|
|
}); |
|
|
|
log.info("更新authorizer_access_token成功"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@ -378,6 +382,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public void redirectUri(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
log.info("开始执行回调URL"); |
|
|
|
try { |
|
|
|
request.setCharacterEncoding(ModuleConstant.UTF8); |
|
|
|
response.setCharacterEncoding(ModuleConstant.UTF8); |
|
|
@ -389,6 +394,9 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
String authCode = request.getParameter(ModuleConstant.AUTH_CODE); |
|
|
|
String expiresIn = request.getParameter(ModuleConstant.EXPIRES_IN); |
|
|
|
Date expiresInTime = this.countExpirationTime(expiresIn); |
|
|
|
if (StringUtils.isBlank(customerId)||StringUtils.isBlank(client)||StringUtils.isBlank(authCode)||StringUtils.isBlank(expiresIn)){ |
|
|
|
log.info("客户ID = "+customerId+", 客户端类型为 = "+client+", 授权码为 = "+authCode+", 有效期 = "+expiresIn); |
|
|
|
} |
|
|
|
// AuthorizationInfoResultDTO authorizationInfo = this.authInfoByAuthCode(authCode, customerId,client);
|
|
|
|
//authCode存数据库
|
|
|
|
AuthCodeFormDTO formDTO = new AuthCodeFormDTO(); |
|
|
@ -402,7 +410,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
authCodeDao.insertRedirectAuthCode(formDTO); |
|
|
|
//authCode存缓存
|
|
|
|
redisThird.setAuthCode(formDTO); |
|
|
|
|
|
|
|
log.info("回调结束"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -413,15 +421,18 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void saveAuthAccountInfo(String customerId, String authAppId,String clientType) { |
|
|
|
log.info("开始执行保存授权账户基本信息"); |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put(ModuleConstant.COMPONENT_APP_ID,componentAppId); |
|
|
|
jsonObject.put(ModuleConstant.AUTHORIZER_APP_ID,authAppId); |
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(ThirdApiConstant.API_GET_AUTHORIZER_INFO, JSON.toJSONString(jsonObject)).getData(); |
|
|
|
Map<String,Map> map = JSON.parseObject(data, Map.class); |
|
|
|
Map authorizerInfo = map.get(ModuleConstant.AUTHORIZER_INFO); |
|
|
|
log.info("授权信息:"+authorizerInfo); |
|
|
|
// 存在 “miniprograminfo” 字段为小程序,不存在为公众号
|
|
|
|
boolean keyExist = authorizerInfo.containsKey(ModuleConstant.MINI_PROGRAM_INFO); |
|
|
|
if (keyExist == true){ |
|
|
|
log.info("授权方为小程序 并 开始插入信息"); |
|
|
|
MiniInfoFormDTO miniInfoFormDTO = this.mapToEntity(authorizerInfo, MiniInfoFormDTO.class); |
|
|
|
miniInfoFormDTO.setCustomerId(customerId); |
|
|
|
miniInfoFormDTO.setClientType(clientType); |
|
|
@ -471,6 +482,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
}); |
|
|
|
miniCategoryInfoDao.insertCategoryInfo(categoryInfoList); |
|
|
|
}else { |
|
|
|
log.info("授权方为公众号 并 开始插入信息"); |
|
|
|
PaInfoFormDTO paInfoFormDTO = this.mapToEntity(authorizerInfo, PaInfoFormDTO.class); |
|
|
|
//公众号基本信息插入
|
|
|
|
paInfoDao.insertPaInfo(paInfoFormDTO); |
|
|
@ -489,7 +501,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
}); |
|
|
|
businessInfoDao.insertBusinessInfo(businessInfoList); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("保存授权方基本信息结束"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -500,9 +512,11 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void updateCustomerMpAppIdAndCreateOpenPlatform(String customerId,String authAppId,String clientType){ |
|
|
|
log.info("开始创建开放平台账号并绑定"); |
|
|
|
Integer authCount = customerMpDao.selectAuthCount(customerId); |
|
|
|
String openPlatformId = null; |
|
|
|
if (authCount==NumConstant.ZERO){ |
|
|
|
log.info("未查询到该客户授权信息,先创建开放平台账号,再绑定"); |
|
|
|
//没有任何一个小程序/公众号授权,【先创建,再绑定】
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put(ModuleConstant.APP_ID,authAppId); |
|
|
@ -530,6 +544,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
openPlatformAccountDao.insertOpenPlatFormAccount(coForm); |
|
|
|
openPlatformId = coForm.getId(); |
|
|
|
}else if (authCount>NumConstant.ZERO){ |
|
|
|
log.info("该客户已创建过开放平台账号,直接绑定"); |
|
|
|
String openAppId = openPlatformAccountDao.selectOpenAppIdByCustomerId(customerId); |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put(ModuleConstant.LOW_APP_ID,componentAppId); |
|
|
@ -570,6 +585,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
|
bindingAccount.setClientType(clientType); |
|
|
|
bindingAccount.setCustomerId(customerId); |
|
|
|
bindingAccountDao.insertBindingAccount(bindingAccount); |
|
|
|
log.info("创建绑定账号结束"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|