从多个客服帐号中,获取接待数最少的客服

@param array $customServices 完整客服帐号的数组,帐号格式为：帐号前缀@公众号微信号
@return string|false
8767
public function getMinAcceptedCustomService(array $customServices)
    {
        if (!$customServices) {
            return false;
        }

        if (count($customServices) === 1) {
            return $customServices[0];
        }

        $onlineList = $this->getOnLineList();
        if (!$onlineList) {
            return false;
        }

        // 将会话数最少的客服排在前面
        $onlineList = wei()->coll->orderBy($onlineList['kf_online_list'], 'accepted_case', SORT_ASC);
        foreach ($onlineList as $customService) {
            if (in_array($customService['kf_account'], $customServices)) {
                return $customService['kf_account'];
            }
        }

        return false;
    }
54051
public function call(string $service, $uri = '', array $params = [])
    {
        if (is_array($uri) || empty($uri)) {
            $params = $uri ? $uri : [];
            $url = explode('.', $service);
            $service = array_shift($url);
            $uri = implode('.', $url);
        }

        $data = $this->packer->pack($params ? ['call' => $uri, 'data' => $params] : ['call' => $uri]);

        try {
            $client = $this->factory->make($this->driver)->call($this->selector->select($service), $data);
        } catch (Exception $exception) {
            throw new ServiceException($exception);
        } finally {
            /* 服务上报，事件触发 */
            $serverInfo = compact('service', 'uri', 'params');
            $callParams = isset($exception) ? ['microservice.call.failed', [$this, $exception, $serverInfo]] : ['microservice.call', [$this, $serverInfo]];
            $this->app['events']->dispatch(...$callParams);
        }

        $this->statusCode = $client->getStatusCode();
        $content = $client->getContent();
        $this->content = $content ?
            new ServiceData($this->packer->unpack($content)) :
            null;

        return $this->content;
    }
831741
protected function parseServiceCodes(array $options)
    {
        $services = [];
        foreach ($options['service_codes'] as $serviceCode) {
            if (!array_key_exists(strtoupper($serviceCode), self::getServiceCodes())) {
                $message = sprintf(
                    'Unsupported service code: "%s". Supported services are %s',
                    $serviceCode,
                    implode(', ', array_keys(self::getServiceCodes()))
                );
                throw new \InvalidArgumentException($message);
            }
            $services[] = $serviceCode;
        }

        return $services;
    }
195834
protected function getService($service) {
		$service = strtolower($service);
		$services = $this->getServices();
		if (!isset($services[$service])) {
			throw new EAuthException(Yii::t('eauth', 'Undefined service name: {service}.', array('{service}' => $service)), 500);
		}
		return $services[$service];
	}
497177
private function fieldsForService(string $service): array
    {
        switch ($service) {
            case self::CITY_EXTENDED_SERVICE:
                return [
                    'countryCode',
                    'regionCode',
                    'locality',
                    'postalCode',
                    'latitude',
                    'longitude',
                    'metroCode',
                    'areaCode',
                    'isp',
                    'organization',
                ];
            case self::OMNI_SERVICE:
                return [
                    'countryCode',
                    'countryName',
                    'regionCode',
                    'region',
                    'locality',
                    'latitude',
                    'longitude',
                    'metroCode',
                    'areaCode',
                    'timezone',
                    'continentCode',
                    'postalCode',
                    'isp',
                    'organization',
                    'domain',
                    'asNumber',
                    'netspeed',
                    'userType',
                    'accuracyRadius',
                    'countryConfidence',
                    'cityConfidence',
                    'regionConfidence',
                    'postalConfidence',
                    'error',
                ];
            default:
                throw new UnsupportedOperation(sprintf('Unknown MaxMind service %s', $service));
        }
    }
555826
public function getServiceConfig()
    {
        return array(
            'initializers' => array(
                function ($instance, $sm) {
                    if ($instance instanceof \DlcBase\Module\ModuleNamespaceAwareInterface) {
                        $class           = get_class($instance);
                        $moduleNamespace = substr($class, 0, strpos($class, '\\'));
                        $instance->setModuleNamespace($moduleNamespace);
                    }
                }
            ),
        );
    }
1142902
public function getServiceIds()
    {
        return array_unique(array_merge(array_keys($this->getDefinitions()), array_keys($this->aliasDefinitions), parent::getServiceIds()));
    }
186996
protected function getServiceUrls($service)
    {
        if (!$this->_config) {
            $httpClient = new HttpClient();
            $httpClient->transport = CurlTransport::class;
            $requests = [];
            foreach ($this->discoverUrls as $discoverUrl) {
                $requests[] = $httpClient->get($discoverUrl);
            }
            $responses = $httpClient->batchSend($requests);

            $list = [];
            foreach ($responses as $response) {
                foreach ($response->data as $name => $url) {
                    $list[$name][] = $url;
                }
            }

            $this->_config = $list;
        }

        if (isset($this->_config[$service]) && $this->_config[$service]) {
            return $this->_config[$service];
        } else {
            throw new ErrorException('不存在该服务，请检查服务中心');
        }
    }
251069
public function create(array $rules, string $methods = 'GET, POST'): bool
    {
        //规则不可为空
        if (!$rules) {
            return false;
        }

        //生成前置和后置
        $final_rules = ['S' => [], 'D' => [], 'PRE' => [], 'POST' => []];
        if ($this->pre) {
            $pre_id                      = self::$counter['pre']++;
            $pre_rules                   = $this->parse($this->pre, $this->namespaces['pre']);
            $this->pre                   = [];
            $final_rules['PRE'][$pre_id] = $pre_rules;
        }
        if ($this->post) {
            $post_id                       = self::$counter['post']++;
            $post_rules                    = $this->parse($this->post, $this->namespaces['post']);
            $this->post                    = [];
            $final_rules['POST'][$post_id] = $post_rules;
        }

        //生成主规则
        foreach ($rules as $url => $rule) {
            $r      = preg_match_all('/\{(\w+?)\}/', $url, $params); //匹配动态规则
            $params = $params[1];
            if ($r) {
                $url  = '#^' . preg_replace('/\{(\w+?)\}/', '([^\\#/?]*?)', $url) . '$#'; //将{}替换
                $type = 'D';
            } else {
                $type = 'S';
            }
            $final_rules[$type][$url] = [
                'pre'    => $pre_id ?? null,
                'post'   => $post_id ?? null,
                'main'   => $this->parse($rule, $this->namespaces['main']),
                'params' => $params, //动态参数名
            ];
        }
        //解析完后再检查路由是否冲突
        foreach (explode(',', $methods) as $method) {
            $method = strtoupper(trim($method));
            $this->check($final_rules, $method); //检查路由是否冲突
            if (isset(self::$rules[$method])) {
                foreach ($final_rules as $type => $value) {
                    self::$rules[$method][$type] = self::$rules[$method][$type] + $value; //用+保持索引
                }
            } else {
                self::$rules[$method] = $final_rules;
            }
        }
        return true;
    }
753261
public function getServices()
	{
		$services = false;
		if (!empty($this->cache) && Yii::$app->has($this->cache)) {
			/** @var $cache \yii\caching\Cache */
			$cache = Yii::$app->get($this->cache);
			$services = $cache->get('EAuth.services');
		}

		if (false === $services || !is_array($services)) {
			$services = [];
			foreach ($this->services as $service => $options) {
				/** @var $class ServiceBase */
				$class = $this->getIdentity($service);
				$services[$service] = (object)[
					'id' => $class->getServiceName(),
					'title' => $class->getServiceTitle(),
					'type' => $class->getServiceType(),
					'jsArguments' => $class->getJsArguments(),
				];
			}
			if (isset($cache)) {
				$cache->set('EAuth.services', $services, $this->cacheExpire);
			}
		}
		return $services;
	}
1216573
private function addServices()
    {
        if (!$this->container->getDefinitions()) {
            return '';
        }

        $code = "services:\n";
        foreach ($this->container->getDefinitions() as $id => $definition) {
            $code .= $this->addService($id, $definition);
        }

        $aliases = $this->container->getAliases();
        foreach ($aliases as $alias => $id) {
            while (isset($aliases[(string) $id])) {
                $id = $aliases[(string) $id];
            }
            $code .= $this->addServiceAlias($alias, $id);
        }

        return $code;
    }
399365
public function getServiceDescription()
	{
		return array(
			$this->name . '.init' => array(
				"parameters" => array(
					array( "type" => "string", "name" => "site", "optional" => false ),
					array( "type" => "array", "name" => "items", "optional" => false ),
				),
				"returns" => "array",
			),
			$this->name . '.finish' => array(
				"parameters" => array(
					array( "type" => "string", "name" => "site", "optional" => false ),
					array( "type" => "array", "name" => "items", "optional" => false ),
				),
				"returns" => "array",
			),
			$this->name . '.deleteItems' => array(
				"parameters" => array(
					array( "type" => "string", "name" => "site", "optional" => false ),
					array( "type" => "array", "name" => "items", "optional" => false ),
				),
				"returns" => "array",
			),
			$this->name . '.saveItems' => array(
				"parameters" => array(
					array( "type" => "string", "name" => "site", "optional" => false ),
					array( "type" => "array", "name" => "items", "optional" => false ),
				),
				"returns" => "array",
			),
			$this->name . '.searchItems' => array(
				"parameters" => array(
					array( "type" => "string", "name" => "site", "optional" => false ),
					array( "type" => "array", "name" => "condition", "optional" => true ),
					array( "type" => "integer", "name" => "start", "optional" => true ),
					array( "type" => "integer", "name" => "limit", "optional" => true ),
					array( "type" => "string", "name" => "sort", "optional" => true ),
					array( "type" => "string", "name" => "dir", "optional" => true ),
					array( "type" => "array", "name" => "options", "optional" => true ),
				),
				"returns" => "array",
			),
		);
	}
555675
protected function alterService(DockerService $service)
    {
        if ($this->internal) {
            $service
                ->setNetworks([
                    'internal'
                ])
                ->setlabels([
                    'traefik.enable=false'
                ]);

            if ($this->bindPorts) {
                $service->setPorts(
                    $this->getPorts('0000')
                );
            }
        } else {
            $service->setPorts($this->getPorts());
        }

        return $service;
    }
759352
public function getServiceDescription()
	{
		$desc = parent::getServiceDescription();

		$catdesc = array(
			'Catalog.getTree' => array(
				"parameters" => array(
					array( "type" => "string", "name" => "site", "optional" => false ),
					array( "type" => "array", "name" => "items", "optional" => false ),
				),
				"returns" => "array",
			),
			'Catalog.insertItems' => array(
				"parameters" => array(
					array( "type" => "string", "name" => "site", "optional" => false ),
					array( "type" => "array", "name" => "items", "optional" => false ),
					array( "type" => "string", "name" => "parentid", "optional" => true ),
					array( "type" => "string", "name" => "refid", "optional" => true ),
				),
				"returns" => "array",
			),
			'Catalog.moveItems' => array(
				"parameters" => array(
					array( "type" => "string", "name" => "site", "optional" => false ),
					array( "type" => "array", "name" => "items", "optional" => false ),
					array( "type" => "string", "name" => "oldparentid", "optional" => false ),
					array( "type" => "string", "name" => "newparentid", "optional" => false ),
					array( "type" => "string", "name" => "refid", "optional" => true ),
				),
				"returns" => "array",
			),
		);

		return array_merge( $desc, $catdesc );
	}
989462
public function validatePluginManagerServiceExist($service, $services)
    {
        if ($service == '') {
            return null;
        }

        if (!in_array($service, array_values($services))) {
            throw new \InvalidArgumentException(sprintf('Plugin "%s" is invalid.', $service));
        }

        return $service;
    }
241611
public function checkIdPSettings($settings)
    {
        assert('is_array($settings)');

        if (!is_array($settings) || empty($settings)) {
            return array('invalid_syntax');
        }

        $errors = array();

        if (!isset($settings['idp']) || empty($settings['idp'])) {
            $errors[] = 'idp_not_found';
        } else {
            $idp = $settings['idp'];
            if (!isset($idp['entityId']) || empty($idp['entityId'])) {
                $errors[] = 'idp_entityId_not_found';
            }

            if (!isset($idp['singleSignOnService'])
                || !isset($idp['singleSignOnService']['url'])
                || empty($idp['singleSignOnService']['url'])
            ) {
                $errors[] = 'idp_sso_not_found';
            } else if (!filter_var($idp['singleSignOnService']['url'], FILTER_VALIDATE_URL)) {
                $errors[] = 'idp_sso_url_invalid';
            }

            if (isset($idp['singleLogoutService'])
                && isset($idp['singleLogoutService']['url'])
                && !empty($idp['singleLogoutService']['url'])
                && !filter_var($idp['singleLogoutService']['url'], FILTER_VALIDATE_URL)
            ) {
                $errors[] = 'idp_slo_url_invalid';
            }

            if (isset($settings['security'])) {
                $security = $settings['security'];

                $existsX509 = isset($idp['x509cert']) && !empty($idp['x509cert']);
                $existsMultiX509Sign = isset($idp['x509certMulti']) && isset($idp['x509certMulti']['signing']) && !empty($idp['x509certMulti']['signing']);
                $existsMultiX509Enc = isset($idp['x509certMulti']) && isset($idp['x509certMulti']['encryption']) && !empty($idp['x509certMulti']['encryption']);

                $existsFingerprint = isset($idp['certFingerprint']) && !empty($idp['certFingerprint']);
                if (!($existsX509 || $existsFingerprint || $existsMultiX509Sign)
                ) {
                    $errors[] = 'idp_cert_or_fingerprint_not_found_and_required';
                }
                if ((isset($security['nameIdEncrypted']) && $security['nameIdEncrypted'] == true)
                    && !($existsX509 || $existsMultiX509Enc)
                ) {
                    $errors[] = 'idp_cert_not_found_and_required';
                }
            }
        }

        return $errors;
    }
118309
public function getServiceDescription($service)
    {
        if ($this->serviceIsObject($service)) {
            return get_class($service);
        }
        return $this->formatServiceDescription($service, is_scalar($service));
    }