移动支付,每次调支付宝接口的时候都显示创建交易异常,请重新创建后再付款!
mapi网关的RSA的公钥什么的都填了!哪位能告诉我到底怎么回事!
谢谢!
def alipay
@payment=Payment.new(:user=>current_user, :channel=> :alipay, :amount=> params[:amount],
:subject=>params[:subject], :detail=>"[#{params[:subject]}]#{current_user.name}",
:out_order_id=>params[:order_id], :out_order_type=>params[:order_type])
Payment.transaction do
if @payment.save
Alipay.pid = Setting.alipay["partner_id"]
Alipay.sign_type="RSA"
Alipay.key = <<-EOF
-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJfS4Xizv5pJdS/A
aVQFP1E0UsxVsKYQTsOR+vSlYvr2QU37h2OocmkYEM2NeKCuzeJ6QZ2lXaVR4KM/
hjK+cQZzlZ/RGEz6wAyiPBQpVQ9tDDo+FSPi+1txWdP4x+bt9iTvyAG/RCHSvkx/
CfFkgGqneliLIOOks4Ee0IfLNDnbAgMBAAECgYBKGpAazgFTWU9tg0rZm8YP6K4R
NjIGnCcVpgcLqj3pqJCvc3nd1rYhPbHV4ptiMnAjfvDP9YsDyjcO906VLgcUEonQ
8e1lf21cxCLLBrC3Z6OeXKIHRTDER1ammIAb6tC8IpO6XFeQATDtz1RWmjlRwRfz
Hin3zj3QSltnTHR5oQJBAMpRrVpIhACxpl7Q0xIpqSom4sY499SR0ImKR4gnMJrg
d5jDgULc5J/3jVn3wO0fkr+ZXfEfwJRL8QeBfPT80i0CQQDAG1wrd/sRqIDzClQg
MvABkTK3ZpfAPRkiTiP919Vigk3DebC6PC4dWlR6jtQfibkPFHPYnHm4CdfstAbm
gyknAkAR6ILor+yHRzJLyD42qFth8Mk39IjzVujXk9bbFWT3AJLgEcYaTgUqp7Xq
VcTM+HN75C5tjnr0ZXhzSqHt6YcNAkEAsR9IzwdTpMdRBUULpZhxc3B1a2WbGvL6
XoffZWd/5dCwdD+Z80wTVJr5cvqHmAB6cO3xldFH5KimviaKijR6VwJAEh+Lfjzc
vv/yNI0GOAIkp7ovIXVdmJ/+L+6f74bTrvXHIQJ90fHxlpg+dPiO1tymuwbIAV5R
z1vjmQIYCzYkTA==
-----END PRIVATE KEY-----
EOF
Alipay.debug_mode=true
s=Alipay::Mobile::Service.mobile_securitypay_pay_string(
:out_trade_no=> @payment.trade_number,
:notify_url=>ERB::Util.url_encode("https://#{Setting.host}/pay_notify/alipay"),
:subject=>@payment.subject,
:total_fee=>@payment.amount,
:body=>@payment.detail
)
render_json_success({:pay=>s})
else
render_logic_error"支付订单创建失败, 请稍后再试或联系客服"
end
end
end
def alipay
@payment=Payment.new(:user=>current_user, :channel=> :alipay, :amount=> params[:amount],
:subject=>params[:subject], :detail=>"[#{params[:subject]}]#{current_user.name}",
:out_order_id=>params[:order_id], :out_order_type=>params[:order_type])
Payment.transaction do
if @payment.save
alipay_client = Alipay::Client.new(
url: 'https://openapi.alipay.com/gateway.do',
app_id: '2017000000000000',
app_private_key: APP_PRIVATE_KEY,
alipay_public_key: ALIPAY_PUBLIC_KEY,
format: 'json',
charset: 'UTF-8',
sign_type: 'RSA2'
)
s=alipay_client.sdk_execute(
method: 'alipay.trade.app.pay',
biz_content: {
out_trade_no: @payment.trade_number,
product_code: 'QUICK_MSECURITY_PAY',
total_amount: @payment.amount,
subject: @payment.subject
}.to_json,
timestamp: Time.now.to_formatted_s(:day_time)
)
render_json_success({:pay=>s})
else
render_logic_error"支付订单创建失败, 请稍后再试或联系客服"
end
end
这么写对吧?您给看下
帮看下,谢谢。报的错误是 Neither PUB key nor PRIV key: nested asn1 error 但是我用生成密钥的生成器,匹配密钥是匹配成功的。
module Alipay
module Sign
class RSA2
def self.sign(key, string)
rsa = OpenSSL::PKey::RSA.new(key)
Base64.strict_encode64(rsa.sign('sha256', string))
end
def self.verify?(key, string, sign)
rsa = OpenSSL::PKey::RSA.new(key)
rsa.verify('sha256', Base64.strict_decode64(sign), string)
end
end
end
end
大佬!rsa = OpenSSL::PKey::RSA.new(key) 传进私钥一直报错,是什么问题啊?
Neither PUB key nor PRIV key: nested asn1 error 之前也遇到过,但是上次你告诉我的 openapi 分支,就没遇到过这个错误了,请问怎么回事,求解答
格式是对的
Alipay::APP_PRIVATE_KEY = <<-EOF
-----BEGIN PRIVATE KEY-----
64string
p0b0nFOF5drEbEsqjw74Xqb4WPDC9Ac7P5zDZcW7+cgTsDWSgaGn
-----END PRIVATE KEY-----
rsa = OpenSSL::PKey::RSA.new(key) 这个没太懂,看源码,只能传 intger 和,pem 的
APP_PRIVATE_KEY="-----BEGIN *RSA* PRIVATE KEY-----\n
Key 的开头格式就不对。