diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FuncInfoDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FuncInfoDao.java index 722a1b889d..28fb939847 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FuncInfoDao.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FuncInfoDao.java @@ -46,6 +46,6 @@ public interface FuncInfoDao extends BaseDao { * @param customerId * @author zxc */ - void updateOldFuncInfo(@Param("customerId")String customerId); + void updateOldFuncInfo(@Param("customerId")String customerId,@Param("authAppId")String authAppId); } \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java index de326be7d7..7cda9307d6 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/redis/RedisThird.java @@ -1,19 +1,15 @@ package com.epmet.redis; import com.epmet.commons.tools.redis.RedisUtils; -import com.epmet.constant.ModuleConstant; import com.epmet.constant.ThirdRedisKeyConstant; import com.epmet.dto.form.AuthCodeFormDTO; import com.epmet.dto.form.AuthorizationInfoFormDTO; -import com.epmet.dto.form.AuthorizerAccessTokenFormDTO; import com.epmet.dto.result.AuthorizationInfoResultDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; -import java.util.concurrent.TimeUnit; - /** * @Author zxc * @CreateTime 2020/7/7 9:33 @@ -73,9 +69,8 @@ public class RedisThird { /** * @Description 缓存 刷新令牌 【授权信息(不包括 授权给开发者的权限集列表)】 - * (在授权的公众号具备API权限时,才有此返回值),刷新令牌主要用于第三方平台获取和刷新已授权用户的 authorizer_access_token。 - * 一旦丢失,只能让用户重新授权,才能再次拿到新的刷新令牌。用户重新授权后,之前的刷新令牌会失效 * @param authInfoDTO + * key = 前缀+客户ID+客户端类型 * @author zxc */ public void setAuthorizerRefreshToken(AuthorizationInfoFormDTO authInfoDTO){ @@ -85,7 +80,7 @@ public class RedisThird { /** * @Description 获取刷新 - * @param key = epmet:wechartthird:authorizerrefreshtoken:customerId:clientType + * @param key = epmet:wechartthird:authorizerrefreshtoken:customerId:clientType 前缀+客户ID+客户端类型 * @author zxc */ public String getAuthorizerRefreshToken(String key){ @@ -94,7 +89,7 @@ public class RedisThird { /** * @Description 缓存授权码 auth_Code - * @param + * key = ""前缀+客户ID+客户端类型 * @author zxc */ public void setAuthCode(AuthCodeFormDTO formDTO){ @@ -105,7 +100,7 @@ public class RedisThird { /** * @Description 获取授权码 * 授权码, 会在授权成功时(回调url)返回给第三方平台【code、expiresIn】 - * @param key + * @param key = "epmet:wechartthird:authcode:customerId:clientType"前缀+客户ID+客户端类型 * @author zxc */ public String getAuthCode(String key){ @@ -115,21 +110,12 @@ public class RedisThird { /** * @Description 缓存授权信息【完整的,包括 授权给开发者的权限集列表 】 * @param authInfo + * key = "epmet:wechartthird:authinfo:customerId:clientType"前缀+客户ID+客户端类型 * @author zxc */ - public void setAuthInfo(AuthorizationInfoResultDTO authInfo){ - redisUtils.set(ThirdRedisKeyConstant.AUTH_INFO_REDIS_KEY,authInfo,-1); + public void setAuthInfo(AuthorizationInfoResultDTO authInfo,String customerId,String clientType){ + String key = ThirdRedisKeyConstant.AUTH_INFO_REDIS_KEY+ThirdRedisKeyConstant.COLON+customerId+ThirdRedisKeyConstant.COLON+clientType; + redisUtils.set(key,authInfo,-1); } - /** - * @Description 缓存 刷新后的 授权方令牌 【authorizer_access_token】 和 刷新令牌 【authorizer_refresh_token】 - * @param refreshAccessToken - * @param clientType - * @author zxc - */ - /*public void setAuthorizerRefreshToken(AuthorizerAccessTokenFormDTO refreshAccessToken,String clientType){ - String key = ThirdRedisKeyConstant.AUTHORIZER_REFRESH_TOKEN_REDIS_KEY + ThirdRedisKeyConstant.COLON + refreshAccessToken.getCustomerId()+ThirdRedisKeyConstant.COLON+clientType; - redisUtils.set(key,refreshAccessToken,-1); - }*/ - } diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java index 6e2916dac6..ba736b599d 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java +++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java @@ -280,6 +280,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe HashMap 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 funcInfos = new ArrayList<>(); List 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 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 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("创建绑定账号结束"); } /** diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/bootstrap.yml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/bootstrap.yml index 56a7c1b6dd..0eaf3270c2 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/bootstrap.yml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/bootstrap.yml @@ -100,7 +100,7 @@ pagehelper: reasonable: false third: platform: - appId: wx9681884b28ed7927 - appSecret: xxx + appId: wxd63ff476314c7c3e + appSecret: 4733aa5ba6dfe0efc569ebac7c4fe56b aesKey: d6dbde92c67e11eabac1c03fd56f7847qazxswedcvg token: 1ae5f230c67f11eabac1c03fd56f7847 \ No newline at end of file diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml index c3af697392..b05ed32662 100644 --- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml +++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FuncInfoDao.xml @@ -25,7 +25,7 @@ - update func_info set del_flag = 0 where customer_id = #{customerId} + update func_info set del_flag = 0 where customer_id = #{customerId} AND authorization_info_appid = #{authAppId} \ No newline at end of file