Module: ChanPay::Http
- Defined in:
- lib/chan_pay/http/ret_code.rb,
lib/chan_pay/http/communicate.rb
Defined Under Namespace
Modules: OriginalRetCode, RetCode
Constant Summary collapse
- VERSION =
'1.0'- SIGN_TYPE =
'rsa'
Class Method Summary collapse
Class Method Details
.post(partner_id, private_key, public_key, server_uri, service_name, params, time = Time.now) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/chan_pay/http/communicate.rb', line 8 def self.post(partner_id, private_key, public_key, server_uri, service_name, params, time=Time.now) body = pack_body(partner_id, private_key, service_name, params, time) url_encoded_body = url_encode(body) puts "\n[#{service_name}] 发送报文为: \n#{url_encoded_body}\n" result = {} begin response = Net::HTTP.post_form(server_uri, url_encoded_body) if response.is_a?(Net::HTTPSuccess) # 返回 200 才处理 result = Utils.symbolize_keys(JSON.parse(response.body)) unless Sign::RSA.verify?(public_key, result, result[:Sign]) # 验签失败, status 状态处于 pending,这样之后再去询问确保 result[:AcceptStatus] = 'S' result[:Status] = 'P' end else # 非 200 请求 result = RetCode.general_error_response(response.code, RetCode::UNKNOWN_ERROR) end rescue Net::ReadTimeout # 请求超时,当 pending 处理 result = { :AcceptStatus => "S", # 业务受理成功 :RetCode => RetCode::NET_TIMEOUT, :RetMsg => "网络异常(0)", :Status => "P", # 业务 PENDING } end puts "\n[#{service_name}] 返回结果为:\n#{result}" result end |