Class: Chinapay::Request::Tencent

Inherits:
Object
  • Object
show all
Defined in:
lib/chinapay/request/tencent.rb

Constant Summary collapse

GATEWAY_URL =
"https://www.tenpay.com/cgi-bin/v1.0/pay_gate.cgi"

Instance Method Summary collapse

Constructor Details

#initialize(title, total_fee, notify_url, attach, bank_type) ⇒ Tencent



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chinapay/request/tencent.rb', line 7

def initialize(title, total_fee, notify_url, attach, bank_type)
  @cmdno = 1
  @date  = Date.today.strftime("%Y%m%d")
  @bank_type = bank_type
  @desc = title || "即时到账充值"

  @bargainor_id = Chinapay.config["tencent"]["parter"]
  @key = Chinapay.config["tencent"]["key"]

  @sp_billno = Time.now.to_i + Time.now.tv_usec * 1000 + $$
  @transaction_id = "#{@bargainor_id}#{@date}#{@sp_billno}"

  @total_fee = (total_fee * 100).to_i
  @fee_type = 1

  @return_url = notify_url
  @attach = attach || ''

  @spbill_create_ip = '127.0.0.1'
  @cs = "utf-8"
end

Instance Method Details

#paramsObject



40
41
42
43
44
45
46
# File 'lib/chinapay/request/tencent.rb', line 40

def params
        "cmdno=#{@cmdno}&date=#{@date}&bank_type=#{@bank_type}&desc=#{CGI.escape(@desc)}" +
"&purchaser_id=&bargainor_id=#{@bargainor_id}&transaction_id=#{@transaction_id}" +
"&sp_billno=#{@sp_billno}&total_fee=#{@total_fee}&fee_type=#{@fee_type}" +
"&return_url=#{CGI.escape(@return_url)}&attach=#{CGI.escape(@attach)}" +
"&spbill_create_ip=#{@spbill_create_ip}&cs=#{@cs}"
end

#signObject



29
30
31
# File 'lib/chinapay/request/tencent.rb', line 29

def sign
  @sign ||= Digest::MD5.hexdigest(sign_params).downcase
end

#sign_paramsObject



33
34
35
36
37
38
# File 'lib/chinapay/request/tencent.rb', line 33

def sign_params
        "cmdno=#{@cmdno}&date=#{@date}&bargainor_id=#{@bargainor_id}&transaction_id=#{@transaction_id}" +
"&sp_billno=#{@sp_billno}&total_fee=#{@total_fee}&fee_type=#{@fee_type}" +
"&return_url=#{@return_url}&attach=#{CGI.escape(@attach)}" +
"&spbill_create_ip=#{@spbill_create_ip}&key=#{@key}"
end

#urlObject



48
49
50
# File 'lib/chinapay/request/tencent.rb', line 48

def url
  "#{GATEWAY_URL}?#{params}&sign=#{sign}"
end