Module: Cpay::Sand::Fastpay

Extended by:
Fastpay
Included in:
Fastpay
Defined in:
lib/cpay.rb

Instance Method Summary collapse

Instance Method Details

#notify(c_params) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/cpay.rb', line 98

def notify(c_params)
  sign = c_params[:sign]
  data = c_params[:data]
  publickey = c_params[:publickey]
  ret = {
      code: -1,
      msg: '',
      data: {}
  }
  begin
    if Utils.rsa_verify(data, sign, publickey)
      data = JSON data
      ret[:data] = data
      ret[:code] = 0

      ret[:cpay] = {
          ok: data['body']['orderStatus'] == '1',
          msg: '',
          next: data['head']['respCode'] != '000000',
      }
    else
      ret[:code] = 2
    end
  rescue Exception => ex
    ret[:msg] = ex.to_s
    ret[:code] = -1
  end
  ret
end

#pay(c_params) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/cpay.rb', line 62

def pay(c_params)
  time = Time.now.strftime('%Y%m%d%H%M%S')
  b_params = {
      body: {
          userId: c_params[:userid].to_s, #用户ID
          orderCode: c_params[:orderid].to_s, #订单号
          orderTime: time,
          totalAmount: c_params[:amount].to_s.rjust(12, '0'), #订单金额
          subject: c_params[:subject].to_s, #订单标题
          body: c_params[:body].to_s, #订单描述
          currencyCode: 156,
          notifyUrl: c_params[:notifyurl].to_s, #异步通知地址
          frontUrl: c_params[:fronturl].to_s, #前端跳转地址
      },
      method: "sandPay.fastPay.quickPay.index"
  }
  res = base_pay_act b_params, c_params, true

  if res[:code] = 0
    return %Q{
<form action="https://cashier.sandpay.com.cn/fastPay/quickPay/index" method="post" hidden="hidden">
<textarea name="charset">#{res[:data][:charset]}</textarea>
<textarea name="signType">#{res[:data][:signType]}</textarea>
<textarea name="data">#{res[:data][:data]}</textarea>
<textarea name="sign">#{res[:data][:sign]}</textarea>
</form>
<script type="text/javascript">
  document.forms[0].submit();
</script>
}
  else
    return "生成订单失败,请稍后重试"
  end

end

#queryOrder(c_params) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cpay.rb', line 128

def queryOrder(c_params)
  b_params = {
      body: {
          orderCode: c_params[:orderid].to_s, #订单号
      },
      method: "sandpay.trade.query",
      uri: URI("https://cashier.sandpay.com.cn/gateway/api/order/query")

  }
  ret = base_pay_act b_params, c_params, false
  ret[:cpay] = {
      next: ret[:data]['head']['respCode'] == '030096',
      ok: ret[:data]['body']['oriRespCode'] == '000000' && ret[:data]['body']['orderStatus'] == '00',
      msg: ret[:data]['oriRespMsg']
  }
  ret
end