| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -143,7 +143,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    AuthCodeResultDTO authCodeResultDTO = authorizationInfoDao.selectCustomerIdByAuthAppId(authAppId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    String clientType = authCodeResultDTO.getClientType(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    String customerId = authCodeResultDTO.getCustomerId(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    this.updateCustomerMpAppIdAndCreateOpenPlatform(customerId,authAppId,clientType); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    this.createAndBindOpenAccount(customerId,authAppId,clientType); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    this.updateCustomerMpAppId(customerId,authAppId,clientType); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    authCodeDao.updateAppId(customerId,clientType,authAppId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    this.saveAuthAccountInfo(customerId,authAppId,clientType); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    break; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -349,8 +350,9 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                formDTO.setExpiresInTime(expiresInTime); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                formDTO.setCustomerId(customerId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                formDTO.setAuthAppid(authAppId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                formDTO.setClientType(clientType); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                //先逻辑删除,在插入
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                authorizationInfoDao.updateOldAuthorizerAccessToken(willOverDueDTO.getCustomerId(),clientType); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                authorizationInfoDao.updateOldAuthorizerAccessToken(customerId,clientType); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                authorizationInfoDao.insertAuthorizerAccessToken(formDTO); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                //缓存 refreshAuthorizerAccessToken
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -495,7 +497,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @author zxc | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Transactional(rollbackFor = Exception.class) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void updateCustomerMpAppIdAndCreateOpenPlatform(String customerId,String authAppId,String clientType){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void updateCustomerMpAppId(String customerId,String authAppId,String clientType){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        log.info("==========回填customer_mp开始=========="); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        AuthCodeFormDTO formDTO = new AuthCodeFormDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        formDTO.setClientType(clientType); | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -506,6 +508,82 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        log.info("==========回填customer_mp结束=========="); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void createAndBindOpenAccount(String customerId,String authAppId,String clientType){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        log.info("开始创建开放平台账号并绑定"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        List<String> authCount = customerMpDao.selectAuthCount(customerId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String openPlatformId = null; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (authCount.size()>0){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            openPlatformId = openPlatformAccountDao.selectOpenAppIdByCustomerId(customerId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        Map<String, Object> authorizerRefreshToken = redisThird.getAuthorizerRefreshToken(customerId + ThirdRedisKeyConstant.COLON + clientType); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String authorizerAccessToken = authorizerRefreshToken.get("authorizerAccessToken").toString(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (authCount.size()==NumConstant.ZERO){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            log.info("未查询到该客户授权信息,先创建开放平台账号,再绑定"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            //没有任何一个小程序/公众号授权,【先创建,再绑定】
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            JSONObject jsonObject = new JSONObject(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            // 此处的 access_token 为 【authorizer_access_token】
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_CREATE_OPEN + authorizerAccessToken, JSON.toJSONString(jsonObject)).getData(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            Map<String,Object> map = JSON.parseObject(data, Map.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            openPlatformId = map.get(ModuleConstant.OPEN_APP_ID).toString(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            CreateOpenResultDTO createOpen = new CreateOpenResultDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            createOpen.setErrCode((Integer)map.get(ModuleConstant.ERR_CODE)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            createOpen.setErrMsg(map.get(ModuleConstant.ERR_MSG).toString()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            createOpen.setOpenAppId(map.get(ModuleConstant.OPEN_APP_ID).toString()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            switch (createOpen.getErrCode()){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case NumConstant.ZERO: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    log.info(CREATE_AND_BIND_SUCCESS); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    CreateOpenFormDTO coForm = new CreateOpenFormDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    coForm.setOpenid(map.get(ModuleConstant.OPEN_APP_ID).toString()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    coForm.setCustomerId(customerId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    //插入 open_platform_account 表
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    openPlatformAccountDao.insertOpenPlatFormAccount(coForm); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    break; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case NumConstant.ONE_NEG: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    throw new RenException(SYSTEM_ERROR); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case ModuleConstant.FORTY_THOUSAND_AND_THIRTEEN: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    throw new RenException(INVALID_APP_ID); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case ModuleConstant.EIGHTY_NINE_THOUSAND: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    throw new RenException(ACCOUNT_HAS_BOUND_OPEN); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        }else if (authCount.size()>NumConstant.ZERO && !authCount.contains(authAppId)){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            log.info("该客户已创建过开放平台账号,直接绑定"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            JSONObject jsonObject = new JSONObject(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            jsonObject.put(ModuleConstant.OPEN_APP_ID,openPlatformId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_BIND_OPEN + authorizerAccessToken, JSON.toJSONString(jsonObject)).getData(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            Map<String,Object> map = JSON.parseObject(data, Map.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            CreateOpenResultDTO createOpen = new CreateOpenResultDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            createOpen.setErrCode((Integer)map.get(ModuleConstant.ERR_CODE)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            createOpen.setErrMsg(map.get(ModuleConstant.ERR_MSG).toString()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            switch (createOpen.getErrCode()){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case NumConstant.ZERO: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    log.info(BIND_SUCCESS); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    break; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case NumConstant.ONE_NEG: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    throw new RenException(SYSTEM_ERROR); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case ModuleConstant.FORTY_THOUSAND_AND_THIRTEEN: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    throw new RenException(INVALID_APP_ID); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case ModuleConstant.EIGHTY_NINE_THOUSAND: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    throw new RenException(ACCOUNT_HAS_BOUND_OPEN); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case ModuleConstant.EIGHTY_NINE_THOUSAND_AND_ONE: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    throw new RenException(NOT_SAME_CONTRACTOR); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case ModuleConstant.EIGHTY_NINE_THOUSAND_AND_THREE: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    throw new RenException(NOT_ALLOWED_OPERATE); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                case ModuleConstant.EIGHTY_NINE_THOUSAND_AND_FOUR: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    throw new RenException(TO_LIMIT); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //插入 binding_account
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        BindingAccountFormDTO bindingAccount = new BindingAccountFormDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        bindingAccount.setOpenPlatformAccountId(openPlatformId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        bindingAccount.setAuthAppId(authAppId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        bindingAccount.setClientType(clientType); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        bindingAccount.setCustomerId(customerId); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        bindingAccountDao.insertBindingAccount(bindingAccount); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        log.info("创建绑定账号结束"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @Description  map 转 Entity | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @param map | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |