告警微信接口失败

@param Http $http
@param array $credential
358246
protected function logError(Http $http, $credential = [])
    {
        $this->logApi($http);

        // HTTP请求失败由HTTP自行告警
        if (!$http->isSuccess()) {
            return;
        }

        $credential['currentTime'] = time();

        // 移除结尾的请求ID,使相同信息合并成一条
        $message = explode(' hint', $http['errmsg'])[0];
        $message = rtrim($message, ',');
        $level = isset($this->logLevels[$http['errcode']]) ? $this->logLevels[$http['errcode']] : 'warning';
        $this->logger->log($level, '微信接口失败: ' . $http['errcode'] . ' ' . $message, [
            'url' => $http->getUrl(),
            'data' => $http->getData(),
            'res' => $http->getResponse(),
            'ret' => $this->getResult(),
            'credential' => $credential,
        ]);
    }
872319
public static function sign(
        array $credentials,
        $httpMethod,
        $path,
        $headers,
        $params,
        $options = array()
    ) {
        //设定签名有效时间
        if (!isset($options[AipSignOption::EXPIRATION_IN_SECONDS])) {
            //默认值1800秒
            $expirationInSeconds = AipSignOption::DEFAULT_EXPIRATION_IN_SECONDS;
        } else {
            $expirationInSeconds = $options[AipSignOption::EXPIRATION_IN_SECONDS];
        }

        //解析ak sk
        $accessKeyId = $credentials['ak'];
        $secretAccessKey = $credentials['sk'];

        //设定时间戳，注意：如果自行指定时间戳需要为UTC时间
        if (!isset($options[AipSignOption::TIMESTAMP])) {
            //默认值当前时间
            $timestamp = gmdate('Y-m-d\TH:i:s\Z');
        } else {
            $timestamp = $options[AipSignOption::TIMESTAMP];
        }

        //生成authString
        $authString = AipSampleSigner::BCE_AUTH_VERSION . '/' . $accessKeyId . '/'
            . $timestamp . '/' . $expirationInSeconds;

        //使用sk和authString生成signKey
        $signingKey = hash_hmac('sha256', $authString, $secretAccessKey);

        //生成标准化URI
        $canonicalURI = AipHttpUtil::getCanonicalURIPath($path);

        //生成标准化QueryString
        $canonicalQueryString = AipHttpUtil::getCanonicalQueryString($params);

        //填充headersToSign，也就是指明哪些header参与签名
        $headersToSign = null;
        if (isset($options[AipSignOption::HEADERS_TO_SIGN])) {
            $headersToSign = $options[AipSignOption::HEADERS_TO_SIGN];
        }

        //生成标准化header
        $canonicalHeader = AipHttpUtil::getCanonicalHeaders(
            AipSampleSigner::getHeadersToSign($headers, $headersToSign)
        );

        //整理headersToSign，以';'号连接
        $signedHeaders = '';
        if ($headersToSign !== null) {
            $signedHeaders = strtolower(
                trim(implode(";", $headersToSign))
            );
        }

        //组成标准请求串
        $canonicalRequest = "$httpMethod\n$canonicalURI\n"
            . "$canonicalQueryString\n$canonicalHeader";

        //使用signKey和标准请求串完成签名
        $signature = hash_hmac('sha256', $canonicalRequest, $signingKey);

        //组成最终签名串
        $authorizationHeader = "$authString/$signedHeaders/$signature";

        return $authorizationHeader;
    }
1340945
public function setCredentialObject(TokenCredential $credential, $userId = null, $default = true)
    {
        $key = $userId == null ? 'default' : $userId;
        $this->credentialHashmap[$key] = $credential;
        if ($default) {
            $this->defaultAccountName = $key;
        }
        return $this;
    }
278790
public function retrieveByCredentials(array $credentials)
    {
        // First we will add each credential element to the query as a where clause.
        // Then we can execute the query and, if we found a user, return it in a
        // generic "user" object that will be utilized by the Guard instances.
        $query = $this->conn->table($this->table);

        foreach ($credentials as $key => $value) {
            if (! Str::contains($key, 'password')) {
                $query->where($key, $value);
            }
        }

        // Now we are ready to execute the query to see if we have an user matching
        // the given credentials. If not, we will just return nulls and indicate
        // that there are no matching users for these given credential arrays.
        $user = $query->first();

        if (! is_null($user)) {
            return new GenericUser((array) $user);
        }
    }
1035706
private function sendFopenRequest($url, $authentication = null)
    {
        $context = null;

        if (null !== $authentication) {
            $context = stream_context_create(array('http' => array(
                'header' => 'Authorization: Basic '.base64_encode($authentication),
            )));
        }

        $result = false;

        for ($i = 0; $i < 5; $i++) {
            if ($result = @file_get_contents($url, null, $context)) {
                break;
            }

            sleep(1);
        }

        if (false === $result) {
            throw new \RuntimeException(sprintf('Unable to read "%s", does the host locally resolve?', $url));
        }

        return $result;
    }
1175720
public function getOauthConsumer(\common_http_Credentials $credentials)
	{
        if (!$credentials instanceof \core_kernel_classes_Resource) {
            throw new \tao_models_classes_oauth_Exception('Unsupported credential type '.get_class($credentials));
        }
	    $values = $credentials->getPropertiesValues(array(
			self::PROPERTY_OAUTH_KEY,
			self::PROPERTY_OAUTH_SECRET,
			self::PROPERTY_OAUTH_CALLBACK
	    ));
	    if (empty($values[self::PROPERTY_OAUTH_KEY]) || empty($values[self::PROPERTY_OAUTH_SECRET])) {
	        throw new \tao_models_classes_oauth_Exception('Incomplete oauth consumer definition for '.$credentials->getUri());
	    }
	    $consumer_key = (string)current($values[self::PROPERTY_OAUTH_KEY]);
	    $secret = (string)current($values[self::PROPERTY_OAUTH_SECRET]);
	    if (!empty($values[self::PROPERTY_OAUTH_CALLBACK])) {
	        $callbackUrl = (string)current($values[self::PROPERTY_OAUTH_CALLBACK]);
	        if (empty($callbackUrl)) {
	            $callbackUrl = null;
	        }
	    } else {
	        $callbackUrl = null;
	    }
        return new OAuthConsumer($consumer_key, $secret, $callbackUrl);
	}
372257
static function OutputHeaders($realm = "Login Required", $terminate = true)
	{
		header("WWW-Authenticate: Basic realm=\"".$realm."\"");
		header("Status: 401 Unauthorized");
		header("HTTP-Status: 401 Unauthorized");
		if ($terminate) die();
	}
459835
public function authenticate(Credential $credential)
    {
        if (!$credential->username || !$credential->password) {
            $this->status = Authentication::EMPTY_CREDENTIAL;

            return false;
        }

        $datamapper = new DataMapper('users');

        $user = $datamapper->findOne(['username' => $credential->username]);

        if ($user->isNull()) {
            $this->status = Authentication::USER_NOT_FOUND;

            return false;
        }

        if (!Hasher::verify($credential->password, $user->password)) {
            $this->status = Authentication::INVALID_CREDENTIAL;

            return false;
        }

        $credential->bind($user);

        $this->status = Authentication::SUCCESS;

        return true;
    }
1203047
public function authentication(Request $request, array $credentials)
    {
        if (!isset($credentials['username'], $credentials['password'])) {
            return $request;
        }
        if (!isset($credentials['realm'])) {
            $credentials = $this->_getServerInfo($request, $credentials);
        }
        if (!isset($credentials['realm'])) {
            return $request;
        }
        $value = $this->_generateHeader($request, $credentials);

        return $request->withHeader('Authorization', $value);
    }
351439
public static function sign(RequestInterface $request, Credentials $credentials)
    {
        /**
         * @var RequestInterface $request
         */

        $signatureHeaders   = [];
        $base64Md5          = '';
        $contentLength      = '';

        if ($request->getBody()->getSize() !== 0) {
            $base64Md5 = Hmac::md5HashBase64(
                $request->getBody()
                    ->getContents()
            );

            $contentLength = strlen((string)$request->getBody());
            $signatureHeaders = array_merge(
                $signatureHeaders,
                [
                    'content-type'      => $request->getHeader('content-type'),
                    'content-md5'       => $base64Md5,
                    'content-length'    => $contentLength
                ]);
        }

        $parsedUrl = parse_url($request->getUri());
        $targetUrl = $parsedUrl["path"];
        if (!empty($parsedUrl["query"])) {
            $targetUrl = $targetUrl . "?" . $parsedUrl["query"];
        }

        $requestLine = $request->getMethod() . " " . $targetUrl . " HTTP/1.1";

        $signatureHeaders['date'] = $date = gmdate("D, d M Y H:i:s", time()) . " GMT";
        $signatureHeaders['request-line'] = $requestLine;

        $headersString      = Hmac::getHeadersString($signatureHeaders);
        $signatureString    = Hmac::getSignatureString($signatureHeaders);
        $signatureHash      = Hmac::shaHashBase64($signatureString, $credentials->getSecret());
        $authHeader         = sprintf(
            'hmac username="%s", algorithm="hmac-%s", headers="%s", signature="%s"',
            $credentials->getAccessKey(),
            Hmac::ALGORITHM_SHA256,
            $headersString,
            $signatureHash
        );

        $request = $request->withHeader('Authorization', $authHeader)
            ->withHeader('Date', $date);

        if ($request->getBody()->getSize()) {
            return $request->withHeader('Content-Type', $request->getHeader('content-type'))
                ->withHeader('Content-MD5', $base64Md5)
                ->withHeader('Content-Length', $contentLength);
        }

        return $request;
    }
480306
public function clientCredentials($scope = 'public')
    {
        if (is_array($scope)) {
            $scope = implode(' ', $scope);
        }

        $token_response = $this->request(self::CLIENT_CREDENTIALS_TOKEN_ENDPOINT, array(
            'grant_type' => 'client_credentials',
            'scope' => $scope
        ), "POST", false);

        return $token_response;
    }
1207224
public function getELB($region, $credential)
    {
        if (!$config = $this->getConfigWithCredentials($region, $credential)) {
            return null;
        }

        return $this->aws->createElasticLoadBalancing($config);
    }
534125
function http($url, $method, $postfields=null, $headers=array())
    {
        $this->http_info = array();
        $ci = curl_init();
        /* Curl settings */
        curl_setopt($ci, CURLOPT_USERAGENT, self::USER_AGENT);
        curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, self::CONNECT_TIMEOUT);
        curl_setopt($ci, CURLOPT_TIMEOUT, self::REQUEST_TIMEOUT);
        curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);

        // Set request headers if any
        if (is_array($headers) && !empty($headers)){
            $this->http_request_headers = $headers;
            curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
        }

        curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, self::SSL_VERIFY_PEER);
        curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
        curl_setopt($ci, CURLOPT_HEADER, false);

        // Make sure the post fields are string
        if (is_array($postfields) && !empty($postfields)) {
            $postfields = http_build_query($postfields);
        }

        switch ($method) {
            case 'POST':
                curl_setopt($ci, CURLOPT_POST, true);
                if (!empty($postfields)) {
                    $this->http_post = $postfields;
                    curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
                }
                break;
            case 'DELETE':
                curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
                if (!empty($postfields)) {
                    $url = "{$url}?{$postfields}";
                }
        }

        curl_setopt($ci, CURLOPT_URL, $url);
        $response = curl_exec($ci);
        $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
        $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
        $this->http_url = $url;
        curl_close($ci);

        return $response;
    }
807782
private function getConfigWithCredentials($region, $credential)
    {
        if (!in_array($region, self::$awsRegions, true)) {
            $this->logger->critical(self::ERR_INVALID_REGION, [
                'specified_region' => $region,
            ]);

            return null;
        }

        $credentials = null;

        if ($credential instanceof AWSStaticCredential) {
            $credentials = $this->credentialProvider->getStaticCredentials($credential);

        } elseif ($credential instanceof AWSRoleCredential) {
            $credentials = $this->credentialProvider->getRoleCredentials($credential, $region);
        }

        if (!$credentials) {
            $this->logger->critical(self::ERR_INVALID_CREDENTIAL);
            return null;
        }

        return [
            'region' => $region,
            'credentials' => $credentials,
        ];
    }
397785
public function getStaticCredentials(AWSStaticCredential $credential)
    {
        if ($this->useHostCredentials) {
            return $this->hostCredentials;
        }

        if (!$secret = $this->getSecret($credential)) {
            $this->logger->critical(self::ERR_INVALID_SECRET);
            return null;
        }

        return [
            'key' => $credential->key(),
            'secret' => $secret,
        ];
    }
599566
function http($url, $method, $postfields = NULL) {
    $this->http_info = array();
    $ci = curl_init();
    /* Curl settings */
    curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
    curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
    curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
    curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
    curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
    curl_setopt($ci, CURLOPT_HEADER, FALSE);

    switch ($method) {
      case 'POST':
        curl_setopt($ci, CURLOPT_POST, TRUE);
        if (!empty($postfields)) {
          curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
        }
        break;
      case 'DELETE':
        curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
        if (!empty($postfields)) {
          $url = "{$url}?{$postfields}";
        }
    }

    curl_setopt($ci, CURLOPT_URL, $url);
    $response = curl_exec($ci);
    $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
    $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
    $this->url = $url;
    curl_close ($ci);
    return $response;
  }
6167
public function getCD($region, $credential)
    {
        if (!$config = $this->getConfigWithCredentials($region, $credential)) {
            return null;
        }

        return $this->aws->createCodeDeploy($config);
    }