商家私钥
ALIPAY_RSA_PRIVATE_KEY = <<-EOF
-----BEGIN RSA PRIVATE KEY-----
这里是生成的商家私钥,旧版支付接口只能支持RSA(1024长度)
-----END RSA PRIVATE KEY-----
EOF
Helper Method Config
拼接参数
def generate_alipay_params(options = {})
base_params = {
"service" => "mobile.securitypay.pay",
"_input_charset" => "utf-8",
"partner" => "2088121210025141",
"seller_id" => "2088121210025141",
"payment_type" => "1"
}
pay_params = base_params.merge(options)
pay_params.merge({ "sign" => CGI.escape(Order.alipay_sign(pay_params)), "sign_type" => "RSA"})
end
签名
def alipay_sign(params)
string = params.map { |k, v| %Q{#{k}="#{v}"} }.join('&')
rsa = OpenSSL::PKey::RSA.new(ALIPAY_RSA_PRIVATE_KEY)
Base64.strict_encode64(rsa.sign('sha1', string))
end
Action: Use Helper Method
pay_params = generate_alipay_params({
"out_trade_no" => "test_no_01",
"notify_url" => "https://example.com/notify",
"subject" => "test",
"total_fee" => "0.01",
"body" => "test"
})
pay_string = pay_params.map { |k, v| %Q{#{k}="#{v}"} }.join('&')
pay_string = URI.encode(pay_params.map{|k,v| %Q{#{k}="#{v}"}}.join("&")) # 这一步根据用户需要执行
后面找时间加上新版接口