本文整理汇总了PHP中GuzzleHttp\Message\RequestInterface::setQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::setQuery方法的具体用法?PHP RequestInterface::setQuery怎么用?PHP RequestInterface::setQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::setQuery方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signRequest
/**
* Signs the specified request with an SellerCenter API signing protocol by using the
* provided SellerCenter API credentials and adding the required headers to the request
*
* @param RequestInterface $request Request to add a signature to
* @param CredentialsInterface $credentials Signing credentials
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
$parameters = $request->getQuery()->toArray();
$parameters['UserID'] = $credentials->getId();
$parameters['Version'] = '1.0';
$parameters['Action'] = $request->getConfig()->get('command')->getName();
$parameters['Timestamp'] = gmdate(DateTime::ISO8601);
// the keys MUST be in alphabetical order to correct signature calculation
ksort($parameters);
$parameters['Signature'] = rawurlencode(hash_hmac('sha256', http_build_query($parameters, '', '&', PHP_QUERY_RFC3986), $credentials->getKey(), false));
$request->setQuery($parameters);
}
示例2: clientCall
protected function clientCall($path, $method = 'GET', $data = array())
{
if ($this->request instanceof RequestInterface) {
$this->request = $this->client->createRequest($method);
}
$this->request->setPath($path);
$this->request->setMethod($method);
$this->request->setQuery($data);
if (isset($this->accessToken)) {
$this->request->getQuery()->set('access_token', $this->accessToken);
}
$response = $this->client->send($this->request);
return $response->json();
}
示例3: getSignature
/**
* Calculate signature for request
*
* @param RequestInterface $request Request to generate a signature for
*
* @return string
*
* @throws \RuntimeException
*/
public function getSignature(RequestInterface $request)
{
// For POST|PUT set the JSON body string as the params
if ($request->getMethod() == 'POST' || $request->getMethod() == 'PUT') {
$params = $request->getBody()->__toString();
// Make sure to remove any other query params
$request->setQuery([]);
} else {
$params = Query::fromString($request->getQuery(), Query::RFC1738)->toArray();
$params = $this->prepareParameters($params);
// Re-Set the query to the properly ordered query string
$request->setQuery($params);
$request->getQuery()->setEncodingType(Query::RFC1738);
}
$baseString = $this->createBaseString($request, $params);
return base64_encode($this->sign_HMAC_SHA256($baseString));
}
示例4: add_query
private function add_query(RequestInterface $request, $value)
{
if ($value instanceof Query) {
$original = $request->getQuery();
// Do not overwrite existing query string variables by overwriting
// the object with the query string data passed in the URL
$request->setQuery($value->overwriteWith($original->toArray()));
} elseif (is_array($value)) {
// Do not overwrite existing query string variables
$query = $request->getQuery();
foreach ($value as $k => $v) {
if (!isset($query[$k])) {
$query[$k] = $v;
}
}
} else {
throw new \InvalidArgumentException('query value must be an array ' . 'or Query object');
}
}
示例5: send
/**
* Set HTTP request to activeCollab API
* @param RequestInterface $request
* @param bool $authenticate
* @return object
* @throws Exception\ApiException
* @throws Exception\AuthenticationFailedException
*/
public function send(RequestInterface $request, $authenticate = true)
{
$request->addHeader('Accept', 'application/json');
if ($authenticate) {
$request->setQuery($request->getQuery()->set('auth_api_token', $this->api_token));
}
/** @var ResponseInterface $response */
$response = $this->client->send($request);
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
switch ($response->getStatusCode()) {
case 403:
throw new AuthenticationFailedException($response);
default:
throw new ApiException($response);
}
}
return $this->parseResponse($request, $response);
}
示例6: getSignature
/**
* Calculate signature for request
*
* @param RequestInterface $request Request to generate a signature for
*
* @return string
*/
public function getSignature(RequestInterface $request)
{
// For POST|PUT set the JSON body string as the params
if ($request->getMethod() == 'POST' || $request->getMethod() == 'PUT') {
$params = $request->getBody()->__toString();
/**
* If you don't seek() back to the beginning then attempting to
* send a JSON body > 1MB will probably fail.
*
* @link http://stackoverflow.com/q/32359664/99071
* @link https://groups.google.com/forum/#!topic/guzzle/vkF5druf6AY
*/
$request->getBody()->seek(0);
// Make sure to remove any other query params
$request->setQuery([]);
} else {
$params = Query::fromString($request->getQuery(), Query::RFC1738)->toArray();
$params = $this->prepareParameters($params);
// Re-Set the query to the properly ordered query string
$request->setQuery($params);
$request->getQuery()->setEncodingType(Query::RFC1738);
}
$baseString = $this->createBaseString($request, $params);
return base64_encode($this->sign_HMAC_SHA256($baseString));
}
示例7: withQuery
public function withQuery(Query $query)
{
$this->expectedRequest->setQuery($query);
return $this;
}