Class: ActFunc::PayGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/act_func/pay_gateway.rb

Constant Summary collapse

URL_UTF8 =

支付接口地址

"https://pay3.chinabank.com.cn/PayGate?encoding=UTF-8"
URL =

图片和css文件地址

"https://pay3.chinabank.com.cn"

Class Method Summary collapse

Class Method Details

.pay(v_mid, key, v_url, remark2, v_oid, v_amount, v_moneytype = "CNY") ⇒ Object

功能:网银在线,网管支付; 参数:

v_mid


19
20
21
22
23
24
25
26
27
# File 'lib/act_func/pay_gateway.rb', line 19

def self.pay(v_mid, key, v_url, remark2, v_oid, v_amount, v_moneytype = "CNY")
  v_md5info = Digest::MD5.hexdigest(v_amount.to_s + v_moneytype + v_oid + v_mid + v_url + key).upcase
  response = Func.post(URL_UTF8, {'v_mid' => v_mid, 'v_oid' => v_oid, 'v_amount' => v_amount, 'v_moneytype' => v_moneytype, 'v_url' => v_url, 'v_md5info' => v_md5info, 'remark2' => remark2})
  html = Iconv.iconv('utf-8', 'gbk', response.body).first
  html.scan(/[href|src]=("[^"]*.[css|js|gif|jpg]")/).each do |h|
    html = html.gsub(h[0], URL+eval(h[0]).gsub('..', ''))
  end
  html
end

.receive(params, key) ⇒ Object

功能:自动验证结果参数:params参数key商户的md5密钥返回:如果支付成功返回订单号,否则返回nil



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/act_func/pay_gateway.rb', line 34

def self.receive(params, key)
  v_oid = params["v_oid"]
  v_pstatus = params["v_pstatus"]
  v_md5str = params["v_md5str"] #该参数的MD5字符串的顺序为:v_oid,v_pstatus,v_amount,v_moneytype,key
  v_amount = params["v_amount"]
  v_moneytype = params["v_moneytype"]
  # 20(表示支付成功)
  # 30(表示支付失败)
  if v_pstatus=="20" && v_md5str==Digest::MD5.hexdigest(v_oid+v_pstatus+v_amount+v_moneytype+key)
    return params["v_oid"]
  else
    return nil
  end
end