0

我正在尝试自定义接口提供程序 qiwi 这是我的代码:

http = Net::HTTP.new('w.qiwi.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
body = {
  :bill_id => "BILL-#{payment.id}",
  :user => 'tel:' + params[:qiwi][:phone],
  :amount => payment.amount,
  :ccy => 'RUB',
  :comment => "",
  :prv_name => 'Company'
}.to_param
key = "Basic " + Base64.encode64s("secret_key")
http.send_request('POST', "/qiwi-notify.php HTTP/1.1", body, {'Accept' => application/xml', 'Authorization' => key})

我需要执行以下操作:

POST /qiwi-notify.php HTTP/1.1
Accept: application/xml
Content-type: application/x-www-form-urlencoded
Authorization: Basic MjA0Mjp0ZXN0Cg==
bill_id=BILL-
1&status=paid&error=0&amount=1.00&user=tel%3A%2B79031811737&prv_nam
e=TEST&ccy=RUB&comment=test&command=bill
Response should XML-doc:
HTTP/1.1 200 OK
Content-Type: text/xml
<?xml version="1.0"?> <result><result_code>0</result_code></result>

如何在下面实现请求 privednny,我的代码不起作用 谢谢

4

1 回答 1

1

您没有明确说明您的问题是什么,但是在查看代码之前,有一些问题甚至可以被解释。

:bill_id => "BILL-#{payment.id}"

最后需要一个,

http.send_request('POST', "/qiwi-notify.php HTTP/1.1", body, {'Accept' => application/xml', 'Authorization' => key})

之前缺少撇号application/xml'

有了这些修复,代码最终看起来像

http = Net::HTTP.new('w.qiwi.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
body = {
  :bill_id => "BILL-#{payment.id}",
  :user => 'tel:' + params[:qiwi][:phone],
  :amount => payment.amount,
  :ccy => 'RUB',
  :comment => "",
  :prv_name => 'Company'
}.to_param
key = "Basic " + Base64.encode64s("secret_key")
http.send_request('POST', "/qiwi-notify.php HTTP/1.1", body, {'Accept' => 'application/xml', 'Authorization' => key})
于 2013-10-15T10:14:26.997 回答