给定以下 2 个基本字符串:
GET&https%3A%2F%2Fapi.trademe.co.nz%2Fv1%2FMyTradeMe%2FWatchlist%2Fall.json&oauth_consumer_key%3DE55FD61CBB8400F67CED12FD35761BEDED%26oauth_nonce%3D83236f86429111e3963c0e4586dd63b1%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1383267848%26oauth_token%3D2A378A062E35415E242AD38EA01DE72977%26oauth_version%3D1.0
GET&https%3A%2F%2Fapi.trademe.co.nz%2Fv1%2FMyTradeMe%2FWatchlist%2Fall.json&oauth_consumer_key%3DE55FD61CBB8400F67CED12FD35761BEDED%26oauth_nonce%3D83236f86429111e3963c0e4586dd63b1%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1383267856%26oauth_token%3D2A378A062E35415E242AD38EA01DE72977%26oauth_version%3D1.0
这两个字符串的唯一区别是 oauth_timestamp,它们生成的签名如下:
jBy364dHhQ0kVqYSQePXqyzoDQE=
enKa2bqAgghJNXZxRbTx/2ZQYFI=
让我烦恼的是第二个字符串生成一个/
in 签名,但不是第一个,导致 oauth 签名不正确。
这是我生成签名的python代码:
binascii.b2a_base64(hmac.new('{}&{}'.format(settings.OAUTH_SECRET, oauth_token_secret), base_string, sha1).digest())[:-1]