|
@ -7,6 +7,7 @@ import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.constant.ModuleConstant; |
|
|
import com.epmet.constant.ModuleConstant; |
|
|
|
|
|
import com.epmet.constant.ThirdRedisKeyConstant; |
|
|
import com.epmet.constant.ThirdRunTimeInfoConstant; |
|
|
import com.epmet.constant.ThirdRunTimeInfoConstant; |
|
|
import com.epmet.dao.*; |
|
|
import com.epmet.dao.*; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.form.*; |
|
@ -263,13 +264,14 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
HashMap<String,Map> hashMap = JSON.parseObject(authInfo, HashMap.class); |
|
|
HashMap<String,Map> hashMap = JSON.parseObject(authInfo, HashMap.class); |
|
|
Map map = hashMap.get(ModuleConstant.AUTHORIZATION_INFO); |
|
|
Map map = hashMap.get(ModuleConstant.AUTHORIZATION_INFO); |
|
|
authorizationInfoResultDTO = mapToEntity(map, AuthorizationInfoResultDTO.class); |
|
|
authorizationInfoResultDTO = mapToEntity(map, AuthorizationInfoResultDTO.class); |
|
|
|
|
|
String authAppId = authorizationInfoResultDTO.getAuthorizer_appid(); |
|
|
log.info("授权信息:"+map); |
|
|
log.info("授权信息:"+map); |
|
|
String expiresIn = authorizationInfoResultDTO.getExpires_in(); |
|
|
String expiresIn = authorizationInfoResultDTO.getExpires_in(); |
|
|
Date expiresInTime = this.countExpirationTime(expiresIn); |
|
|
Date expiresInTime = this.countExpirationTime(expiresIn); |
|
|
//授权信息分为两张表,基础信息authorization_info,授权列表func_info
|
|
|
//授权信息分为两张表,基础信息authorization_info,授权列表func_info
|
|
|
// 1. 基础信息
|
|
|
// 1. 基础信息
|
|
|
AuthorizationInfoFormDTO authInfoDTO = new AuthorizationInfoFormDTO(); |
|
|
AuthorizationInfoFormDTO authInfoDTO = new AuthorizationInfoFormDTO(); |
|
|
authInfoDTO.setAuthorizerAppid(authorizationInfoResultDTO.getAuthorizer_appid()); |
|
|
authInfoDTO.setAuthorizerAppid(authAppId); |
|
|
authInfoDTO.setAuthorizerAccessToken(authorizationInfoResultDTO.getAuthorizer_access_token()); |
|
|
authInfoDTO.setAuthorizerAccessToken(authorizationInfoResultDTO.getAuthorizer_access_token()); |
|
|
authInfoDTO.setAuthorizerRefreshToken(authorizationInfoResultDTO.getAuthorizer_refresh_token()); |
|
|
authInfoDTO.setAuthorizerRefreshToken(authorizationInfoResultDTO.getAuthorizer_refresh_token()); |
|
|
authInfoDTO.setExpiresInTime(expiresInTime); |
|
|
authInfoDTO.setExpiresInTime(expiresInTime); |
|
@ -283,20 +285,19 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
List<FuncInfoFormDTO> funcInfos = new ArrayList<>(); |
|
|
List<FuncInfoFormDTO> funcInfos = new ArrayList<>(); |
|
|
List<Map> func_info = authorizationInfoResultDTO.getFunc_info(); |
|
|
List<Map> func_info = authorizationInfoResultDTO.getFunc_info(); |
|
|
log.info("权限列表信息:"+func_info); |
|
|
log.info("权限列表信息:"+func_info); |
|
|
for (Map map1 : func_info) { |
|
|
func_info.forEach(func -> { |
|
|
List key = (List)map1.keySet(); |
|
|
func.forEach((key,value) -> { |
|
|
FuncInfoFormDTO fu = new FuncInfoFormDTO(); |
|
|
FuncInfoFormDTO fu = new FuncInfoFormDTO(); |
|
|
String funcscopeCategory = key.get(NumConstant.ZERO).toString(); |
|
|
fu.setFuncscopeCategory((String) key); |
|
|
fu.setFuncscopeCategory(funcscopeCategory); |
|
|
Map funcScope = (Map) value; |
|
|
Map funcscope = (Map) map1.get(funcscopeCategory); |
|
|
fu.setFuncscopeId(funcScope.get(ModuleConstant.ID).toString()); |
|
|
String funcscopeId = funcscope.get("id").toString(); |
|
|
fu.setAuthorizationInfoAppid(authAppId); |
|
|
fu.setFuncscopeId(funcscopeId); |
|
|
fu.setCustomerId(customerId); |
|
|
fu.setAuthorizationInfoAppid(authorizationInfoResultDTO.getAuthorizer_appid()); |
|
|
funcInfos.add(fu); |
|
|
fu.setCustomerId(customerId); |
|
|
}); |
|
|
funcInfos.add(fu); |
|
|
}); |
|
|
} |
|
|
|
|
|
//先逻辑删除,在插入
|
|
|
//先逻辑删除,在插入
|
|
|
funcInfoDao.updateOldFuncInfo(customerId,authorizationInfoResultDTO.getAuthorizer_appid()); |
|
|
funcInfoDao.updateOldFuncInfo(customerId,authAppId); |
|
|
funcInfoDao.insertFuncInfo(funcInfos); |
|
|
funcInfoDao.insertFuncInfo(funcInfos); |
|
|
// 授权信息放入缓存
|
|
|
// 授权信息放入缓存
|
|
|
redisThird.setAuthInfo(authorizationInfoResultDTO,customerId,clientType); |
|
|
redisThird.setAuthInfo(authorizationInfoResultDTO,customerId,clientType); |
|
@ -328,7 +329,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
//第三方平台AppId
|
|
|
//第三方平台AppId
|
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPID,componentAppId); |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APPID,componentAppId); |
|
|
jsonObject.put(ModuleConstant.AUTHORIZER_REFRESH_TOKEN,willOverDueDTO.getAuthorizerRefreshToken()); |
|
|
jsonObject.put(ModuleConstant.AUTHORIZER_REFRESH_TOKEN,willOverDueDTO.getAuthorizerRefreshToken()); |
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_AUTHORIZER_TOKEN_URL, JSON.toJSONString(jsonObject)).getData(); |
|
|
String componentAccessToken = redisThird.getComponentAccessToken(); |
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_AUTHORIZER_TOKEN_URL + componentAccessToken, JSON.toJSONString(jsonObject)).getData(); |
|
|
Map map = JSON.parseObject(data, HashMap.class); |
|
|
Map map = JSON.parseObject(data, HashMap.class); |
|
|
//authorizer_access_token
|
|
|
//authorizer_access_token
|
|
|
String authorizerAccessToken = map.get(ModuleConstant.AUTHORIZER_ACCESS_TOKEN).toString(); |
|
|
String authorizerAccessToken = map.get(ModuleConstant.AUTHORIZER_ACCESS_TOKEN).toString(); |
|
@ -408,7 +410,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APP_ID,componentAppId); |
|
|
jsonObject.put(ModuleConstant.COMPONENT_APP_ID,componentAppId); |
|
|
jsonObject.put(ModuleConstant.AUTHORIZER_APP_ID,authAppId); |
|
|
jsonObject.put(ModuleConstant.AUTHORIZER_APP_ID,authAppId); |
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_GET_AUTHORIZER_INFO, JSON.toJSONString(jsonObject)).getData(); |
|
|
String componentAccessToken = redisThird.getComponentAccessToken(); |
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_GET_AUTHORIZER_INFO + componentAccessToken , JSON.toJSONString(jsonObject)).getData(); |
|
|
Map<String,Map> map = JSON.parseObject(data, Map.class); |
|
|
Map<String,Map> map = JSON.parseObject(data, Map.class); |
|
|
Map authorizerInfo = map.get(ModuleConstant.AUTHORIZER_INFO); |
|
|
Map authorizerInfo = map.get(ModuleConstant.AUTHORIZER_INFO); |
|
|
log.info("授权信息:"+authorizerInfo); |
|
|
log.info("授权信息:"+authorizerInfo); |
|
@ -498,12 +501,14 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
log.info("开始创建开放平台账号并绑定"); |
|
|
log.info("开始创建开放平台账号并绑定"); |
|
|
Integer authCount = customerMpDao.selectAuthCount(customerId); |
|
|
Integer authCount = customerMpDao.selectAuthCount(customerId); |
|
|
String openPlatformId = null; |
|
|
String openPlatformId = null; |
|
|
|
|
|
String authorizerRefreshToken = redisThird.getAuthorizerRefreshToken(customerId + ThirdRedisKeyConstant.COLON + clientType); |
|
|
if (authCount==NumConstant.ZERO){ |
|
|
if (authCount==NumConstant.ZERO){ |
|
|
log.info("未查询到该客户授权信息,先创建开放平台账号,再绑定"); |
|
|
log.info("未查询到该客户授权信息,先创建开放平台账号,再绑定"); |
|
|
//没有任何一个小程序/公众号授权,【先创建,再绑定】
|
|
|
//没有任何一个小程序/公众号授权,【先创建,再绑定】
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
jsonObject.put(ModuleConstant.APP_ID,authAppId); |
|
|
jsonObject.put(ModuleConstant.APP_ID,authAppId); |
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_CREATE_OPEN, JSON.toJSONString(jsonObject)).getData(); |
|
|
// 此处的 access_token 为 【authorizer_access_token】
|
|
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_CREATE_OPEN + authorizerRefreshToken, JSON.toJSONString(jsonObject)).getData(); |
|
|
Map<String,String> map = JSON.parseObject(data, Map.class); |
|
|
Map<String,String> map = JSON.parseObject(data, Map.class); |
|
|
CreateOpenResultDTO createOpen = new CreateOpenResultDTO(); |
|
|
CreateOpenResultDTO createOpen = new CreateOpenResultDTO(); |
|
|
createOpen.setErrCode(Integer.valueOf(map.get(ModuleConstant.ERR_CODE))); |
|
|
createOpen.setErrCode(Integer.valueOf(map.get(ModuleConstant.ERR_CODE))); |
|
@ -532,7 +537,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
jsonObject.put(ModuleConstant.LOW_APP_ID,componentAppId); |
|
|
jsonObject.put(ModuleConstant.LOW_APP_ID,componentAppId); |
|
|
jsonObject.put(ModuleConstant.OPEN_APP_ID,openAppId); |
|
|
jsonObject.put(ModuleConstant.OPEN_APP_ID,openAppId); |
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_BIND_OPEN, JSON.toJSONString(jsonObject)).getData(); |
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_BIND_OPEN + authorizerRefreshToken, JSON.toJSONString(jsonObject)).getData(); |
|
|
Map<String,String> map = JSON.parseObject(data, Map.class); |
|
|
Map<String,String> map = JSON.parseObject(data, Map.class); |
|
|
CreateOpenResultDTO createOpen = new CreateOpenResultDTO(); |
|
|
CreateOpenResultDTO createOpen = new CreateOpenResultDTO(); |
|
|
createOpen.setErrCode(Integer.valueOf(map.get(ModuleConstant.ERR_CODE))); |
|
|
createOpen.setErrCode(Integer.valueOf(map.get(ModuleConstant.ERR_CODE))); |
|
|