Create the data array for the payload

@param RequestInterface $request
@param string           $nonce The none which is generated
@param int              $timestamp The timestamp which is generated

@return string[] The data-array
420096
private function createDataElement(RequestInterface $request, $nonce, $timestamp)
    {
        $data = [];
        if ($request->getMethod() === 'POST') {
            $data[] = rawurlencode($request->getBody()->getContents());
        }
        $data[] = rawurlencode('oauth_consumer_key=' . $this->key);
        $data[] = rawurlencode('oauth_nonce=' . $nonce);
        $data[] = rawurlencode('oauth_signature_method=HMAC-SHA256');
        $data[] = rawurlencode('oauth_timestamp=' . $timestamp);
        $data[] = rawurlencode('oauth_version=1.0');

        return $data;
    }
855280
protected function validNonce($nonce)
    {
        $value = base64_decode($nonce);
        if ($value === false) {
            return false;
        }
        $parts = explode(':', $value);
        if (count($parts) !== 2) {
            return false;
        }
        list($expires, $checksum) = $parts;
        if ($expires < microtime(true)) {
            return false;
        }
        $secret = $this->getConfig('secret');
        $check = hash_hmac('sha1', $expires . ':' . $secret, $secret);

        return hash_equals($check, $checksum);
    }
429242
protected function getMockHeadersForRequest(RequestInterface $request): array
    {
        try {
            $file = $this->getMockFilePathForRequest($request, self::TYPE_HEADERS);

            return json_decode(file_get_contents($file), true);
        } catch (MockNotFoundException $e) {
            return [];
        }
    }
927461
protected function nonce()
    {
        $action = ($this->getParameter('action') == null) ?
                    $this->RequestContext->getControls()->getControl('action')
                  : $this->getParameter('action');

        return $this->Nonces->create($action);
    }
387183
protected function getStreamContextArray(RequestInterface $request, array $options): array
    {
        $headers = $request->getHeaders();
        unset($headers['Host']);
        $context = [
            'http' => [
                // values from the request
                'method' => $request->getMethod(),
                'header' => \implode("\r\n", $this->toHeaders($headers)),
                'content' => $request->getBody()->__toString(),
                'protocol_version' => $request->getProtocolVersion(),

                // values from the current client
                'ignore_errors' => true,
                'follow_location' => $options['allow_redirects'] && $options['max_redirects'] > 0,
                'max_redirects' => $options['max_redirects'] + 1,
                'timeout' => $options['timeout'],
            ],
            'ssl' => [
                'verify_peer' => $options['verify'],
                'verify_host' => $options['verify'],
            ],
        ];

        if (null !== $options['proxy']) {
            $context['http']['proxy'] = $options['proxy'];
            $context['http']['request_fulluri'] = true;
        }

        return $context;
    }
933851
public static String generateEventMessageSignature(String token, String timestamp,String nonce) {
		String[] array = new String[]{token,timestamp,nonce};
		Arrays.sort(array);
		String s = StringUtils.arrayToDelimitedString(array, "");
		return DigestUtils.shaHex(s);
	}
1371934
private function createRequest(RequestInterface $request)
    {
        $options = [
            'exceptions' => false,
            'allow_redirects' => false,
        ];

        $options['version'] = $request->getProtocolVersion();
        $options['headers'] = $request->getHeaders();
        $body = (string) $request->getBody();
        $options['body'] = '' === $body ? null : $body;

        return $this->client->createRequest(
            $request->getMethod(),
            (string) $request->getUri(),
            $options
        );
    }
301944
protected function createHeaders(RequestInterface $request, array $options)
	{
		$headers         = [];
		$request_headers = $request->getHeaders();

		foreach ($request_headers as $name => $values) {
			$header = strtoupper($name);

			// cURL does not support 'Expect-Continue', skip all 'EXPECT' headers
			if ($header === 'EXPECT') {
				continue;
			}

			if ($header === 'CONTENT-LENGTH') {
				if (array_key_exists(CURLOPT_POSTFIELDS, $options)) {
					$values = [strlen($options[CURLOPT_POSTFIELDS])];
				}
				// Force content length to '0' if body is empty
				else if (!array_key_exists(CURLOPT_READFUNCTION, $options)) {
					$values = [0];
				}
			}

			foreach ($values as $value) {
				$headers[] = $name.': '.$value;
			}
		}

		// Although cURL does not support 'Expect-Continue', it adds the 'Expect'
		// header by default, so we need to force 'Expect' to empty.
		$headers[] = 'Expect:';

		return $headers;
	}
622331
private function createStream(
        RequestInterface $request,
        &$http_response_header
    ) {
        static $methods;
        if (!$methods) {
            $methods = array_flip(get_class_methods(__CLASS__));
        }

        $params = [];
        $options = $this->getDefaultOptions($request);
        foreach ($request->getConfig()->toArray() as $key => $value) {
            $method = "add_{$key}";
            if (isset($methods[$method])) {
                $this->{$method}($request, $options, $value, $params);
            }
        }

        $this->applyCustomOptions($request, $options);
        $context = $this->createStreamContext($request, $options, $params);

        return $this->createStreamResource(
            $request,
            $options,
            $context,
            $http_response_header
        );
    }
432680
private function updateCspHeaders(Response $response, array $nonces = [])
    {
        $nonces = array_replace([
            'csp_script_nonce' => $this->generateNonce(),
            'csp_style_nonce' => $this->generateNonce(),
        ], $nonces);

        $ruleIsSet = false;

        $headers = $this->getCspHeaders($response);

        foreach ($headers as $header => $directives) {
            foreach (['script-src' => 'csp_script_nonce', 'style-src' => 'csp_style_nonce'] as $type => $tokenName) {
                if ($this->authorizesInline($directives, $type)) {
                    continue;
                }
                if (!isset($headers[$header][$type])) {
                    if (isset($headers[$header]['default-src'])) {
                        $headers[$header][$type] = $headers[$header]['default-src'];
                    } else {
                        // If there is no script-src/style-src and no default-src, no additional rules required.
                        continue;
                    }
                }
                $ruleIsSet = true;
                if (!\in_array('\'unsafe-inline\'', $headers[$header][$type], true)) {
                    $headers[$header][$type][] = '\'unsafe-inline\'';
                }
                $headers[$header][$type][] = sprintf('\'nonce-%s\'', $nonces[$tokenName]);
            }
        }

        if (!$ruleIsSet) {
            return $nonces;
        }

        foreach ($headers as $header => $directives) {
            $response->headers->set($header, $this->generateCspHeader($directives));
        }

        return $nonces;
    }
37250
public int checkNonce(String nonce, HttpRequest request)
    {
        try
        {
            byte[] n = B64Code.decode(nonce.toCharArray());
            if (n.length!=24)
                return -1;
            
            long ts=0;
            long sk=nonceSecret;
            byte[] n2 = new byte[16];
            for (int i=0;i<8;i++)
            {
                n2[i]=n[i];
                n2[8+i]=(byte)(sk&0xff);
                sk=sk>>8;
                ts=(ts<<8)+(0xff&(long)n[7-i]);
            }
            
            long age=request.getTimeStamp()-ts;
	    if (log.isDebugEnabled()) log.debug("age="+age);
            
            byte[] hash=null;
            try
            {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.reset();
                md.update(n2,0,16);
                hash = md.digest();
            }
            catch(Exception e)
            {
                log.fatal(this,e);
            }
            
            for (int i=0;i<16;i++)
                if (n[i+8]!=hash[i])
                    return -1;
                
            if(maxNonceAge>0 && (age<0 || age>maxNonceAge))
                return 0; // stale
            
            return 1;
        }
        catch(Exception e)
        {
            log.debug("",e);
        }
        return -1;
    }
287946
public function generateNonce(RequestInterface $request)
    {
        return sha1(uniqid('', true) . $request->getUri()->getHost() . $request->getUri()->getPath());
    }
862548
public function encryptXml($xml, $timestamp , $nonce)
    {
        $errorCode = $this->getMessageCrypt()->encryptMsg($xml, $timestamp, $nonce, $xml);
        if ($errorCode) {
            $this->lastError = [
                'errcode' => $errorCode,
                'errmsg' => 'XML数据加密失败!'
            ];
            return false;
        }
        return $xml;
    }
402560
public function decryptMsg($xml, $msg_signature = null, $timeStamp = null, $nonce = null)
    {
        $appId          = Api::getAppId();
        $token          = Api::getToken();
        $encodingAesKey = Api::getEncoding_Aes_Key();

        $msg_signature = !empty($msg_signature) ? $msg_signature : $_GET['msg_signature'];
        $timeStamp     = !empty($timeStamp) ? $timeStamp : $_GET['timestamp'];
        $nonce         = !empty($nonce) ? $nonce : $_GET['nonce'];

        $pc  = new WXBizMsgCrypt($token, $encodingAesKey, $appId);
        $msg = '';

        $errCode = $pc->decryptMsg($msg_signature, $timeStamp, $nonce, $xml, $msg);

        if ($errCode == 0) {
            return $msg;
        } else {
            exit($errCode);
        }
    }
143088
private String makeNonce(String timestamp) {
		byte[] bytes = new byte[10];
		random.nextBytes(bytes);
		StringBuilder sb = new StringBuilder(timestamp);
		sb.append("-");
		for (int i = 0; i < bytes.length; ++i) {
			String b = Integer.toHexString(bytes[i] & 0xff);
			if (b.length() < 2) {
				sb.append("0");
			}
			sb.append(b);
		}
		return sb.toString();
	}
24435
public function saveConsumerNonce($nonce)
    {

        $expires = date("{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
        $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . " (consumer_pk, value, expires) VALUES (%d, %s, %s)",
                       $nonce->getConsumer()->getRecordId(), DataConnector::quoted($nonce->getValue()),
                       DataConnector::quoted($expires));
        $ok = mysql_query($sql);

        return $ok;

    }
985456
public function checkSignature($signature = null, $timestamp = null, $nonce = null)
    {
        $request = Yii::$app->request;
        $signature === null && $signature = $request->get('signature', '');
        $timestamp === null && $timestamp = $request->get('timestamp', '');
        $nonce === null && $nonce = $request->get('nonce', '');
        $tmpArr = [$this->token, $timestamp, $nonce];
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        return sha1($tmpStr) == $signature;
    }