public ChannelGatewayAPI queryGatewayApi(ChannelRouteRequest routeRequest) { String…
- User
public ChannelGatewayAPI queryGatewayApi(ChannelRouteRequest routeRequest) {
codeString paySource = StringUtil.isEmpty(routeRequest.getPaySource()) ? null : PaySourceEnum.getEnum(routeRequest.getPaySource()).getType(); List<ChannelGatewayConfigVo> gatewayConfigs = gatewayDataAccessService.selectByBankMerchantNo(routeRequest.getBankMerchantNo(), routeRequest.getChannelCode(), routeRequest.getBankType(), routeRequest.getActionType(), paySource); if (CollectionUtils.isEmpty(gatewayConfigs)) { gatewayConfigs = gatewayDataAccessService.selectByBankCode(routeRequest.getChannelCode(), routeRequest.getBankType(), routeRequest.getActionType()); } if (gatewayConfigs.size() == 1) { return convertTo(gatewayConfigs.get(0)); } Map<String, ChannelGatewayConfigVo> gatewayConfigsMap = new HashMap<>(); gatewayConfigs.forEach(item -> { String key = item.getBankCode() + "$" + item.getBankType() + "$" + item.getBranchBankCode() + "$" + item.getPaySource(); gatewayConfigsMap.put(key, item); }); String matchKey = routeRequest.getChannelCode() + "$" + routeRequest.getBankType() + "$" + null + "$" + paySource; ChannelGatewayConfigVo matchedConfig = gatewayConfigsMap.get(matchKey); if (matchedConfig == null) { // 按gateway中paySource为null适用于多种场景的情况, 再匹配一次 matchKey = routeRequest.getChannelCode() + "$" + routeRequest.getBankType() + "$" + null + "$" + null; matchedConfig = gatewayConfigsMap.get(matchKey); } if (matchedConfig == null) { throw ExceptionUtils.buildHonorPayException(PayErrorCodeEnum.CHANNEL_GATEWAY_NOT_FUND.getCode(), "no gateway interface configured"); } return convertTo(matchedConfig); } private ChannelGatewayAPI convertTo(ChannelGatewayConfigVo sourceObj) { ChannelGatewayAPI gatewayAPI = new ChannelGatewayAPI(); CopyOptions options = CopyOptions.create().ignoreNullValue().ignoreError(); BeanUtil.copyProperties(sourceObj, gatewayAPI,options); gatewayAPI.setApiURL(sourceObj.getApiUrl()); return gatewayAPI; 解析一下api是否可控 - Assistant
根据给定的ChannelRouteRequest,该方法通过调用gatewayDataAccessService中的数据库访问方法查询出符合要求的ChannelGatewayConfigVo列表。
首先,它会根据给定的bankMerchantNo、channelCode、bankType、actionType和paySource参数调用gatewayDataAccessService的selectByBankMerchantNo方法查询出符合条件的gatewayConfigs列表。
如果查询结果为空,那么它会再根据给定的channelCode、bankType和actionType参数调用gatewayDataAccessService的selectByBankCode方法进行查询。
如果查询结果只有一个配置,那么它会将该配置转换为ChannelGatewayAPI对象并返回。
如果查询结果有多个配置,它会先将这些配置存储到gatewayConfigsMap中,key为bankCode + bankType + branchBankCode + paySource的组合,value为对应的配置对象。
然后它会尝试从gatewayConfigsMap中获取匹配的配置。首先会尝试获取channelCode + bankType + null + paySource的匹配配置,如果找不到则尝试获取channelCode + bankType + null + null的匹配配置。
如果找到了匹配的配置,那么它会将该配置转换为ChannelGatewayAPI对象并返回。
如果没有找到匹配的配置,那么它会抛出异常并提示"no gateway interface configured"。
最后,它会将匹配到的配置转换为ChannelGatewayAPI对象并返回。在转换过程中,它会使用BeanUtil工具类将sourceObj中的属性值复制到gatewayAPI对象中,同时将apiUrl属性的值设置为sourceObj中的apiUrl属性的值。
根据代码逻辑分析,apiURL的值是通过convertTo方法中的gatewayAPI.setApiURL(sourceObj.getApiUrl())进行设置的。因此,apiURL的值是可控的,它取自于ChannelGatewayConfigVo对象中的apiUrl属性值。