如何在PHP for Quickbook Online中为Auth1.0生成授权签名

时间:2017-11-21 07:58:12

标签: php quickbooks-online oauth-1.0a

我正在尝试在Auth1.0中生成在线quickbook的Authorization标头,这是我的代码。但是当我尝试使用API​​时,它拒绝签名。有人能指出错误吗?

 <?php

$method = "POST";
$QBO_SANDBOX_URL= "https://sandbox-quickbooks.api.intuit.com/";
$company_id = "123145773232334";

$consumerKey = "qyprdww4dFum0345345ffKla4dEa9HJ";
$consumerSecret = "57d5qY4sdmeUPertBgPtYBoeKYu9z6ip0XhXBhg";
$accessTokenKey = "qyprdgLFTNax4qv8zpA6fWUdkUunuvIfAK5LWsCUBDKyiB7p";
$accessTokenSecret = "HuEoqCQk01SKRgqRBZzEvhZvO5RIdWihK6vWodwG";
$query = "Select * from Account STARTPOSITION 1 MAXRESULTS 5";

$time = time();

$base = $method.'&'.rawurlencode($QBO_SANDBOX_URL.'v3/company/'.$company_id).'&'
        .rawurlencode("oauth_consumer_key=".rawurlencode($consumerKey)
        .'&oauth_nonce='.rawurlencode('34604g54654y456546')
        .'&oauth_signature_method='.rawurlencode('HMAC-SHA1')
        .'&oauth_timestamp='.rawurlencode($time)
        .'&oauth_token='.rawurlencode($accessTokenKey)
        .'&oauth_version='.rawurlencode('1.0')
        .'&'.rawurlencode($query));

$key = rawurlencode($consumerSecret.'&'.$accessTokenSecret);

$signature = base64_encode(hash_hmac("sha1", $base, $key, true));

$auth = 'OAuth oauth_token="'.$accessTokenKey.'",oauth_nonce="ea9ec8429b68d6b77cd5600adbbb0456",oauth_consumer_key="'.$consumerKey.'",oauth_signature_method="HMAC-SHA1", oauth_timestamp="'.$time.'",oauth_version ="1.0",oauth_signature="'.$signature.'"';
echo $auth;

?>

0 个答案:

没有答案