【问题标题】:Using Guzzle php to create oauth1 signature使用 Guzzle php 创建 oauth1 签名
【发布时间】:2019-05-23 11:53:35
【问题描述】:

我想使用Magento 1.x REST API 从网上商店获取所有产品。它使用OAUTH1,但我在使用PHPGuzzle 时遇到了一些麻烦。我有以下信息:

$consumerKey = '..';
$consumerSecret = '..';
$token = '..';
$tokenSecret = '..';

使用Postman 我已经可以获取所有产品,所以我确定这些值是正确的。我现在的问题是如何创建签名?我有以下代码,但似乎是错误的:

private function buildSignature()
{
    $nonce = uniqid(mt_rand(1, 1000));
    $timestamp = time();
    $consumerKey = 'xx';
    $consumerSecret = 'xx';
    $token = 'xx';
    $tokenSecret = 'xx';

    $base = 'GET&'. rawurlencode('https://www.magentoshop.com/api/rest/products') .'&'.
        rawurlencode('oauth_consumer_key='. $consumerKey) .'&'.
        rawurlencode('oauth_nonce='. $nonce) .'&'.
        rawurlencode('oauth_signature_method=HMAC-SHA1') .'&'.
        rawurlencode('oauth_timestamp='. $timestamp) .'&'.
        rawurlencode('oauth_token='. $token) .'&'.
        rawurlencode('oauth_version=1.0')
    ;
    $key = rawurlencode($consumerSecret) .'&'. rawurlencode($tokenSecret);

    return base64_encode(hash_hmac('sha1', $base, $key, true));
}

我得到的回复总是:"{"messages":{"error":[{"code":401,"message":"oauth_problem=signature_invalid"}]}}"

我做错了什么?

【问题讨论】:

    标签: php laravel magento oauth guzzle


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2019-12-25
    • 1970-01-01
    • 2016-06-11
    • 2020-05-03
    • 2013-09-01
    • 2020-08-18
    • 2021-09-13
    • 2019-02-14
    相关资源
    最近更新 更多