请你帮帮我。我正在尝试为 7 Digital 的高级 API 生成 HMAC-SHA1 哈希,但是我无法获得正确的签名。我关注了这篇文章https://oauth1.wp-api.org/docs/basics/Signing.html并得到了以下代码:
public function __construct(){
$this->timestamp = time();
$this->_nonce = rand();
$this->consumerKey = 'KEY';
$this->consumerSecret = 'SECRET';
$this->signitureMethod = 'HMAC-SHA1';
}
public function buildSignature()
{
$method = 'GET&';
$url = 'https://api.7digital.com/1.2/oauth/requesttoken';
$params = 'oauth_consumer_key='.$this->consumerKey.'&oauth_nonce='.$this->_nonce.'&oauth_signature_method=HMAC-SHA1&oauth_timestamp='.$this->timestamp.'&oauth_version=1.0';
$baseString = $method.urlencode($url).'&'.urlencode($params);
$key = $this->consumerKey . '&' . $this->consumerSecret;
$signature = hash_hmac( 'sha1', $baseString, $key );
$string = 'https://api.7digital.com/1.2/oauth/requesttoken?oauth_consumer_key='.$this->consumerKey.'&oauth_nonce='.$this->_nonce.'&oauth_signature_method=HMAC-SHA1&oauth_timestamp='.$this->timestamp.'&oauth_version=1.0&oauth_signature='.$signature;
echo $string;
}
请注意,我还尝试使用 base64_encode 对签名进行编码不起作用,并且还尝试像这样对密钥进行 urlencode:
$key = urlencode($this->consumerKey) . '&' . urlencode($this->consumerSecret);
我也使用过那里的参考页面。
以上输出:
非常感谢您的帮助,在此先感谢您!!