Ruby中是否有任何库生成签名,'X-PAYPAL-AUTHORIZATION'头,代表通过paypal权限API授权我们的帐户持有人进行调用。我已经完成了权限流,并获得了所需的访问令牌tokenSecret。我觉得我生成的签名错误,因为我所有的调用与生成的‘X-贝宝授权’失败。它们造成下列错误:
为NVP呼叫我得到:
You do not have permissions to make this API call
和GetBasicPersonalData调用:
Authentication failed. API credentials are incorrect.
有没有人在Ruby经历过这个?什么是生成签名的最佳方式。Paypal刚刚在Paypal,Java中提供了一些SDK,但没有提供生成签名的算法。
谢谢,
尼莱什
发布于 2012-04-17 15:32:31
看看PayPal权限创业板。
具体来说,lib/paypal_paypal/x_pp_Authization.rb要求'cgi‘要求'openssl’要求'base64‘。
class Hash
def to_paypal_permissions_query
collect do |key, value|
"#{key}=#{value}"
end.sort * '&'
end
end
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module XPPAuthorization
public
def x_pp_authorization_header url, api_user_id, api_password, access_token, access_token_verifier
timestamp = Time.now.to_i.to_s
signature = x_pp_authorization_signature url, api_user_id, api_password, timestamp, access_token, access_token_verifier
{ 'X-PAYPAL-AUTHORIZATION' => "token=#{access_token},signature=#{signature},timestamp=#{timestamp}" }
end
public
def x_pp_authorization_signature url, api_user_id, api_password, timestamp, access_token, access_token_verifier
# no query params, but if there were, this is where they'd go
query_params = {}
key = [
paypal_encode(api_password),
paypal_encode(access_token_verifier),
].join("&")
params = query_params.dup.merge({
"oauth_consumer_key" => api_user_id,
"oauth_version" => "1.0",
"oauth_signature_method" => "HMAC-SHA1",
"oauth_token" => access_token,
"oauth_timestamp" => timestamp,
})
sorted_query_string = params.to_paypal_permissions_query
base = [
"POST",
paypal_encode(url),
paypal_encode(sorted_query_string)
].join("&")
base = base.gsub /%([0-9A-F])([0-9A-F])/ do
"%#{$1.downcase}#{$2.downcase}" # hack to match PayPal Java SDK bit for bit
end
digest = OpenSSL::HMAC.digest('sha1', key, base)
Base64.encode64(digest).chomp
end
# The PayPalURLEncoder java class percent encodes everything other than 'a-zA-Z0-9 _'.
# Then it converts ' ' to '+'.
# Ruby's CGI.encode takes care of the ' ' and '*' to satisfy PayPal
# (but beware, URI.encode percent encodes spaces, and does nothing with '*').
# Finally, CGI.encode does not encode '.-', which we need to do here.
def paypal_encode str
s = str.dup
CGI.escape(s).gsub('.', '%2E').gsub('-', '%2D')
end
end
end
end样本参数:
url = 'https://svcs.sandbox.paypal.com/Permissions/GetBasicPersonalData'
api_user_id = 'caller_1234567890_biz_api1.yourdomain.com'
api_password = '1234567890'
access_token = 'YJGjMOmTUqVPlKOd1234567890-jdQV3eWCOLuCQOyDK1234567890'
access_token_verifier = 'PgUjnwsMhuuUuZlPU1234567890'发布于 2012-03-07 03:49:22
使用URL "https://svcs.paypal.com/Permissions/GetBasicPersonalData".生成的X-PAYPAL授权头[] (参见第23页和第7章链接)
说明“您没有权限进行此API调用”的NVP表示您的API凭据是正确的,只是您的帐户对您试图调用的特定API没有权限。您要提交的两个调用之间的某些内容是不使用相同的API凭据。
为NVP呼叫我得到:
什么NVP电话?
TransactionSearch (见下面的评论)
此外,如果您还没有这样做,您将希望使用沙箱应用程序ID在沙箱测试,您将需要申请一个应用程序ID与开发者技术服务(DTS)在PayPal,以获得一个应用程序ID的现场。
编辑:
要使用TransactionSearch API,您应该提交的全部内容如下。您不需要指定任何额外的标题。
USER=xxxxxxxxxxxxxxxxxx
PWD=xxxxxxxxxxxxxxxxxx
SIGNATURE=xxxxxxxxxxxxxxxxxx
METHOD=TransactionSearch
VERSION=86.0
STARTDATE=2009-10-11T00:00:00Z
TRANSACTIONID=1234567890
//And for submitting API calls on bob's behalf, if his PayPal email was bob@bob.com:
SUBJECT=bob@bob.comhttps://stackoverflow.com/questions/9578895
复制相似问题