Class: ChinabankModel
- Inherits:
-
Object
- Object
- ChinabankModel
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/models/chinabank.rb
Instance Attribute Summary collapse
-
#remark1 ⇒ Object
备注.
-
#remark2 ⇒ Object
备注.
-
#v_amount ⇒ Object
订单总金额.
-
#v_md5info ⇒ Object
MD5校验码.
-
#v_mid ⇒ Object
商户编号.
-
#v_moneytype ⇒ Object
币种.
-
#v_oid ⇒ Object
订单编号.
-
#v_url ⇒ Object
消费者完成购物后返回的商户页面,URL参数是以http://开头的完整URL地址.
Class Method Summary collapse
Instance Method Summary collapse
- #account ⇒ Object
-
#initialize(attributes = {}) ⇒ ChinabankModel
constructor
A new instance of ChinabankModel.
- #invalid_sign? ⇒ Boolean
- #key ⇒ Object
- #notify ⇒ Object
-
#notify_url ⇒ Object
商家系统用来处理网银支付结果的url.
- #partner ⇒ Object
- #send_notify ⇒ Object
- #sign ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ ChinabankModel
Returns a new instance of ChinabankModel.
37 38 39 40 41 42 |
# File 'lib/models/chinabank.rb', line 37 def initialize(attributes = {}) @attributes = attributes attributes.each do |name, value| send("#{name}=", value) if respond_to? name end end |
Instance Attribute Details
#remark1 ⇒ Object
备注
25 26 27 |
# File 'lib/models/chinabank.rb', line 25 def remark1 @remark1 end |
#remark2 ⇒ Object
备注
25 26 27 |
# File 'lib/models/chinabank.rb', line 25 def remark2 @remark2 end |
#v_amount ⇒ Object
订单总金额
13 14 15 |
# File 'lib/models/chinabank.rb', line 13 def v_amount @v_amount end |
#v_md5info ⇒ Object
MD5校验码
22 23 24 |
# File 'lib/models/chinabank.rb', line 22 def v_md5info @v_md5info end |
#v_mid ⇒ Object
商户编号
7 8 9 |
# File 'lib/models/chinabank.rb', line 7 def v_mid @v_mid end |
#v_moneytype ⇒ Object
币种
16 17 18 |
# File 'lib/models/chinabank.rb', line 16 def v_moneytype @v_moneytype end |
#v_oid ⇒ Object
订单编号
10 11 12 |
# File 'lib/models/chinabank.rb', line 10 def v_oid @v_oid end |
#v_url ⇒ Object
消费者完成购物后返回的商户页面,URL参数是以http://开头的完整URL地址
19 20 21 |
# File 'lib/models/chinabank.rb', line 19 def v_url @v_url end |
Class Method Details
Instance Method Details
#account ⇒ Object
65 66 67 68 |
# File 'lib/models/chinabank.rb', line 65 def account @account ||= self.class.accounts.assoc self.partner @account ||= [] end |
#invalid_sign? ⇒ Boolean
44 45 46 47 48 49 |
# File 'lib/models/chinabank.rb', line 44 def invalid_sign? text = @attributes["v_amount"]+@attributes["v_moneytype"]+@attributes["v_oid"]+@attributes["v_mid"]+@attributes["v_url"]+self.key self.sign == Digest::MD5.hexdigest(text) ? false : true rescue => e true end |
#key ⇒ Object
71 72 73 |
# File 'lib/models/chinabank.rb', line 71 def key self.account[1].to_s end |
#notify ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/models/chinabank.rb', line 80 def notify @notify ||= { "v_oid" => v_oid, "v_pstatus" => v_pstatus, "v_amount" => v_amount, "v_pstring" => v_pstring, "v_pmode" => v_pmode, "v_moneytype" => v_moneytype, "v_md5str" => notify_sign, "remark1" => remark1, "remark2" => remark2 }.delete_if { |k, v| v.to_s.length == 0} end |
#notify_url ⇒ Object
商家系统用来处理网银支付结果的url
61 62 63 |
# File 'lib/models/chinabank.rb', line 61 def notify_url self.v_url end |
#partner ⇒ Object
56 57 58 |
# File 'lib/models/chinabank.rb', line 56 def partner self.v_mid end |
#send_notify ⇒ Object
93 94 95 96 97 |
# File 'lib/models/chinabank.rb', line 93 def send_notify url = URI.parse notify_url res = Net::HTTP.post_form url, self.notify res.body end |
#sign ⇒ Object
52 53 54 |
# File 'lib/models/chinabank.rb', line 52 def sign self.v_md5info end |