|  | @ -1,7 +1,9 @@ | 
			
		
	
		
		
			
				
					|  |  | package com.epmet.service.impl; |  |  | package com.epmet.service.impl; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import cn.hutool.core.convert.Convert; | 
			
		
	
		
		
			
				
					|  |  | import com.alibaba.fastjson.JSON; |  |  | import com.alibaba.fastjson.JSON; | 
			
		
	
		
		
			
				
					|  |  | import com.alibaba.fastjson.JSONObject; |  |  | import com.alibaba.fastjson.JSONObject; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.alibaba.fastjson.TypeReference; | 
			
		
	
		
		
			
				
					|  |  | import com.alibaba.nacos.client.config.utils.IOUtils; |  |  | import com.alibaba.nacos.client.config.utils.IOUtils; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.commons.tools.constant.NumConstant; |  |  | import com.epmet.commons.tools.constant.NumConstant; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.commons.tools.exception.RenException; |  |  | import com.epmet.commons.tools.exception.RenException; | 
			
		
	
	
		
		
			
				
					|  | @ -77,6 +79,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
		
			
				
					|  |  |     private BusinessInfoDao businessInfoDao; |  |  |     private BusinessInfoDao businessInfoDao; | 
			
		
	
		
		
			
				
					|  |  |     @Autowired |  |  |     @Autowired | 
			
		
	
		
		
			
				
					|  |  |     private EpmetUserOpenFeignClient epmetUserOpenFeignClient; |  |  |     private EpmetUserOpenFeignClient epmetUserOpenFeignClient; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     @Autowired | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     private AuthResultRecordDao authResultRecordDao; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     @Value("${third.platform.appId}") |  |  |     @Value("${third.platform.appId}") | 
			
		
	
		
		
			
				
					|  |  |     private String componentAppId; |  |  |     private String componentAppId; | 
			
		
	
	
		
		
			
				
					|  | @ -136,16 +140,16 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
		
			
				
					|  |  |                     log.info(ModuleConstant.TICKET_UNDERLINE_KEY+":"+ComponentVerifyTicket); |  |  |                     log.info(ModuleConstant.TICKET_UNDERLINE_KEY+":"+ComponentVerifyTicket); | 
			
		
	
		
		
			
				
					|  |  |                     break; |  |  |                     break; | 
			
		
	
		
		
			
				
					|  |  |                 case ModuleConstant.AUTHORIZED: //授权成功
 |  |  |                 case ModuleConstant.AUTHORIZED: //授权成功
 | 
			
		
	
		
		
			
				
					
					|  |  |                     // 更改customer_mp 授权信息,appId,并绑定
 |  |  |                     this.disposeAuthResult(result); | 
			
				
				
			
		
	
		
		
			
				
					|  |  |                     String authCode = result.get(ModuleConstant.AUTHORIZATION_CODE_HUMP); |  |  |  | 
			
		
	
		
		
			
				
					|  |  |                     String authAppId = result.get(ModuleConstant.AUTHORIZER_APP_ID_HUMP); |  |  |  | 
			
		
	
		
		
			
				
					|  |  |                     log.info("=============================="+authCode); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  |                     break; |  |  |                     break; | 
			
		
	
		
		
			
				
					|  |  |                 case ModuleConstant.UNAUTHORIZED://用户取消授权
 |  |  |                 case ModuleConstant.UNAUTHORIZED://用户取消授权
 | 
			
		
	
		
		
			
				
					|  |  |                     //todo 取消授权
 |  |  |                     //todo 取消授权
 | 
			
		
	
		
		
			
				
					|  |  |                     String authorizerAppId = result.get(ModuleConstant.AUTHORIZER_APP_ID_HUMP); |  |  |                     String authorizerAppId = result.get(ModuleConstant.AUTHORIZER_APP_ID_HUMP); | 
			
		
	
		
		
			
				
					|  |  |                     customerMpDao.updateAuthorizationFlag(authorizerAppId); |  |  |                     customerMpDao.updateAuthorizationFlag(authorizerAppId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     this.disposeAuthResult(result); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     break; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 case ModuleConstant.UPDATE_AUTHORIZED://授权变更
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     this.disposeAuthResult(result); | 
			
		
	
		
		
			
				
					|  |  |                     break; |  |  |                     break; | 
			
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |         } catch (Exception e) { |  |  |         } catch (Exception e) { | 
			
		
	
	
		
		
			
				
					|  | @ -161,6 +165,24 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
		
			
				
					|  |  |         return ModuleConstant.SUCCESS; |  |  |         return ModuleConstant.SUCCESS; | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @Description  授权结果插入 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @param result | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @author zxc | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     public void disposeAuthResult(Map<String,String> result){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         Map tempMap = result; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         Map<String,Object> data = tempMap; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         AuthResultRecordFormDTO authResultRecord = mapToEntity(data, AuthResultRecordFormDTO.class); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         authResultRecord.setWechatCreateTime(this.sToDate(result.get(ModuleConstant.CREATE_TIME))); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         if (result.containsKey(ModuleConstant.AUTHORIZATION_CODE_EXPIRED_TIME)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             authResultRecord.setExpiredTime(this.sToDate(result.get(ModuleConstant.AUTHORIZATION_CODE_EXPIRED_TIME))); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         authResultRecord.setComponentAppId(componentAppId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         authResultRecordDao.insertAuthResultRecord(authResultRecord); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     /** |  |  |     /** | 
			
		
	
		
		
			
				
					|  |  |      * @Description  定时获取 (令牌,component_access_token) 第三方与微信交互使用的component_access_token |  |  |      * @Description  定时获取 (令牌,component_access_token) 第三方与微信交互使用的component_access_token | 
			
		
	
		
		
			
				
					|  |  |      * 每十分钟执行一次,判断是否有马上超时的(15分钟以内算马上超时) |  |  |      * 每十分钟执行一次,判断是否有马上超时的(15分钟以内算马上超时) | 
			
		
	
	
		
		
			
				
					|  | @ -329,6 +351,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
		
			
				
					|  |  |                 String componentAccessToken = redisThird.getComponentAccessToken(); |  |  |                 String componentAccessToken = redisThird.getComponentAccessToken(); | 
			
		
	
		
		
			
				
					|  |  |                 String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_AUTHORIZER_TOKEN_URL + componentAccessToken, JSON.toJSONString(jsonObject)).getData(); |  |  |                 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); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 if (!map.containsKey(ModuleConstant.ERR_CODE)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     log.info(REFRESH_AUTH_ACCESS_TOKEN); | 
			
		
	
		
		
			
				
					|  |  |                     //authorizer_access_token
 |  |  |                     //authorizer_access_token
 | 
			
		
	
		
		
			
				
					|  |  |                     String authorizerAccessToken = map.get(ModuleConstant.AUTHORIZER_ACCESS_TOKEN).toString(); |  |  |                     String authorizerAccessToken = map.get(ModuleConstant.AUTHORIZER_ACCESS_TOKEN).toString(); | 
			
		
	
		
		
			
				
					|  |  |                     String expiresIn = map.get(ModuleConstant.EXPIRES_IN).toString(); |  |  |                     String expiresIn = map.get(ModuleConstant.EXPIRES_IN).toString(); | 
			
		
	
	
		
		
			
				
					|  | @ -351,6 +375,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |                     //缓存 refreshAuthorizerAccessToken
 |  |  |                     //缓存 refreshAuthorizerAccessToken
 | 
			
		
	
		
		
			
				
					|  |  |                     redisThird.setAuthorizerRefreshToken(authorizationInfo); |  |  |                     redisThird.setAuthorizerRefreshToken(authorizationInfo); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |             }); |  |  |             }); | 
			
		
	
		
		
			
				
					|  |  |             log.info("更新authorizer_access_token成功"); |  |  |             log.info("更新authorizer_access_token成功"); | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
	
		
		
			
				
					|  | @ -388,6 +413,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
		
			
				
					|  |  |         redisThird.setAuthCode(formDTO); |  |  |         redisThird.setAuthCode(formDTO); | 
			
		
	
		
		
			
				
					|  |  |         AuthorizationInfoResultDTO authorizationInfoResultDTO = this.authInfoByAuthCode(authCode, customerId, clientType); |  |  |         AuthorizationInfoResultDTO authorizationInfoResultDTO = this.authInfoByAuthCode(authCode, customerId, clientType); | 
			
		
	
		
		
			
				
					|  |  |         String authAppId = authorizationInfoResultDTO.getAuthorizer_appid(); |  |  |         String authAppId = authorizationInfoResultDTO.getAuthorizer_appid(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         // todo ================================================
 | 
			
		
	
		
		
			
				
					|  |  |         AuthCodeResultDTO authCodeResultDTO = authorizationInfoDao.selectCustomerIdByAuthAppId(authAppId); |  |  |         AuthCodeResultDTO authCodeResultDTO = authorizationInfoDao.selectCustomerIdByAuthAppId(authAppId); | 
			
		
	
		
		
			
				
					|  |  |         this.createAndBindOpenAccount(customerId,authAppId,clientType); |  |  |         this.createAndBindOpenAccount(customerId,authAppId,clientType); | 
			
		
	
		
		
			
				
					|  |  |         this.updateCustomerMpAppId(customerId,authAppId,clientType); |  |  |         this.updateCustomerMpAppId(customerId,authAppId,clientType); | 
			
		
	
	
		
		
			
				
					|  | @ -499,12 +525,15 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
		
			
				
					|  |  |     @Transactional(rollbackFor = Exception.class) |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
		
			
				
					|  |  |     public void updateCustomerMpAppId(String customerId,String authAppId,String clientType){ |  |  |     public void updateCustomerMpAppId(String customerId,String authAppId,String clientType){ | 
			
		
	
		
		
			
				
					|  |  |         log.info("==========回填customer_mp开始=========="); |  |  |         log.info("==========回填customer_mp开始=========="); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         Integer checkBindCount = customerMpDao.checkBind(authAppId, clientType); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         if (checkBindCount == NumConstant.ZERO) { | 
			
		
	
		
		
			
				
					|  |  |             AuthCodeFormDTO formDTO = new AuthCodeFormDTO(); |  |  |             AuthCodeFormDTO formDTO = new AuthCodeFormDTO(); | 
			
		
	
		
		
			
				
					|  |  |             formDTO.setClientType(clientType); |  |  |             formDTO.setClientType(clientType); | 
			
		
	
		
		
			
				
					|  |  |             formDTO.setAuthAppId(authAppId); |  |  |             formDTO.setAuthAppId(authAppId); | 
			
		
	
		
		
			
				
					|  |  |             formDTO.setCustomerId(customerId); |  |  |             formDTO.setCustomerId(customerId); | 
			
		
	
		
		
			
				
					|  |  |             //回填customer_mp的appId 只需以上三个字段
 |  |  |             //回填customer_mp的appId 只需以上三个字段
 | 
			
		
	
		
		
			
				
					|  |  |             customerMpDao.updateAppIDByCustomerIdAndClient(formDTO); |  |  |             customerMpDao.updateAppIDByCustomerIdAndClient(formDTO); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |         log.info("==========回填customer_mp结束=========="); |  |  |         log.info("==========回填customer_mp结束=========="); | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -635,10 +664,27 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
		
			
				
					|  |  |         return date; |  |  |         return date; | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @Description  查询客户Id | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @param tokenDto | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @author zxc | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					|  |  |     public String getLoginUserCustomerId(TokenDto tokenDto){ |  |  |     public String getLoginUserCustomerId(TokenDto tokenDto){ | 
			
		
	
		
		
			
				
					|  |  |         LoginUserDetailsFormDTO dto = new LoginUserDetailsFormDTO(); |  |  |         LoginUserDetailsFormDTO dto = new LoginUserDetailsFormDTO(); | 
			
		
	
		
		
			
				
					|  |  |         BeanUtils.copyProperties(tokenDto,dto); |  |  |         BeanUtils.copyProperties(tokenDto,dto); | 
			
		
	
		
		
			
				
					|  |  |         LoginUserDetailsResultDTO data = epmetUserOpenFeignClient.getLoginUserDetails(dto).getData(); |  |  |         LoginUserDetailsResultDTO data = epmetUserOpenFeignClient.getLoginUserDetails(dto).getData(); | 
			
		
	
		
		
			
				
					|  |  |         return data.getCustomerId(); |  |  |         return data.getCustomerId(); | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @Description  时间戳(秒级)转换 Date | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @param t | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @author zxc | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     public Date sToDate(String t){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         Long aLong = Long.valueOf(t + "000"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         Date date = new Date(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         date.setTime(aLong); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         return date; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | } |  |  | } | 
			
		
	
	
		
		
			
				
					|  | 
 |