本文整理汇总了PHP中OAuthRequest::sign_request方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuthRequest::sign_request方法的具体用法?PHP OAuthRequest::sign_request怎么用?PHP OAuthRequest::sign_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuthRequest
的用法示例。
在下文中一共展示了OAuthRequest::sign_request方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param object An optional KConfig object with configuration options
*/
public function __construct($config = array())
{
if (is_array($config)) {
$config = new KConfig($config);
}
parent::__construct($config);
$params = new KConfig();
$this->_data = KConfig::unbox($config->data);
if (is_array($this->_data)) {
$params->append($this->_data);
}
$params->append(array('oauth_version' => $config->version));
$this->_internal_request = OAuthRequest::from_consumer_and_token($config->consumer, $config->token, $config->method, $config->url, KConfig::unbox($params));
if (!empty($config->signature)) {
$this->_internal_request->sign_request($config->signature, $config->consumer, $config->token);
}
$this->_options = $config->options;
}
示例2: sign
/**
* Sign the request using OAuth. This uses the consumer token and key
* but 2 legged oauth doesn't require an access token and key. In situations where you want to
* do a 'reverse phone home' (aka: gadget does a makeRequest to your server
* and your server wants to retrieve more social information) this is the prefered
* method.
*
* @param string $method the method (get/put/delete/post)
* @param string $url the url to sign (http://site/social/rest/people/1/@me)
* @param array $params the params that should be appended to the url (count=20 fields=foo, etc)
* @param string $postBody for POST/PUT requests, the postBody is included in the signature
* @return string the signed url
*/
public function sign($method, $url, $params = array(), $postBody = false, &$headers = array())
{
$oauthRequest = new OAuthRequest($method, $url, $params);
$params = $this->mergeParameters($params);
foreach ($params as $key => $val) {
if (is_array($val)) {
$val = implode(',', $val);
}
$oauthRequest->set_parameter($key, $val);
}
if ($postBody && strlen($postBody)) {
if ($this->useBodyHash) {
$bodyHash = base64_encode(sha1($postBody, true));
$oauthRequest->set_parameter("oauth_body_hash", $bodyHash);
}
if ($this->useBodyHack) {
$oauthRequest->set_parameter($postBody, '');
}
}
$oauthRequest->sign_request($this->signatureMethod, $this->consumerToken, $this->accessToken);
if ($postBody && $this->useBodyHack) {
unset($oauthRequest->parameters[$postBody]);
}
$signedUrl = $oauthRequest->to_url();
return $signedUrl;
}
示例3: _performRequest
/**
* Performs a OAuthRequest, returning the response
* You can give a token to force signatures with this
* token. If none given, the token used when creating
* this instance of CampusNotesAPI is used
* @param OAuthRequest $req
* @param OAuthToken $token
* @return string
* @throws CNApiException
*/
private function _performRequest(OAuthRequest $req, OAuthToken $token = null)
{
$token = $token ? $token : $this->oauth_token;
$req->sign_request($this->hmac_signature_method, $this->oauth_consumer, $token);
$curl = curl_init();
$params = $req->get_parameters();
foreach (array_keys($params) as $i) {
if (substr($i, 0, 6) == 'oauth_') {
unset($params[$i]);
}
}
$url = $req->get_normalized_http_url();
if ($req->get_normalized_http_method() == 'POST') {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));
} else {
if (count($params)) {
$url .= '?' . http_build_query($params);
}
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array($req->to_header()));
$rtn = curl_exec($curl);
if (!$rtn) {
throw new OAuthClientException(curl_error($curl));
} else {
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200) {
throw new OAuthClientException($rtn);
} else {
return $rtn;
}
}
}
示例4: __build_oauth_header
private function __build_oauth_header($linkedin_url)
{
$request = new OAuthRequest('GET', $linkedin_url, array('oauth_nonce' => OAuthRequest::generate_nonce(), 'oauth_timestamp' => OAuthRequest::generate_timestamp(), 'oauth_version' => '1.0', 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_consumer_key' => $this->oaConsumerKey, 'oauth_token' => OAUTH_USER_TOKEN));
$request->sign_request($this->signature, new OAuthConsumer('', $this->oaConsumerSecret), new OAuthToken('', '95b27494-0a99-47c0-a66c-533cef4b8a28'));
return $request->to_header();
}