new_alipay 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46625bdc1bd808457c5e746d43e74a5d83e27183
4
- data.tar.gz: 53b1202549e0ea1255c2370f147635a2f5cea095
3
+ metadata.gz: 772beb0e34d4ff45feeb336eafca28b10079754f
4
+ data.tar.gz: 749cc846504255b5e06436e237bbb918cefd81dc
5
5
  SHA512:
6
- metadata.gz: ef2d0e7e85112d78e64f4484412eb2b99749255540c4443251446a83b45b7cbc181a5ba0106bc4ac31eaf19437def966e938ae38643a277153120da28e1bbc84
7
- data.tar.gz: 63dee58909b1c66e5729b6f25cb5d80daa388b969294e53ec0878bfb2b8a27fc97696c0d91ceceac3a4cd9755a849d1027d14652a8b5709de36f9e8da9d84cd1
6
+ metadata.gz: be78f2560cfca0da02f29081d2ff01d2e49287f3e2799722002144f83f9ea6aaf21a8a2880f96a4a19d1e042703c18ea4166e9fbe9db3b0ea6a0e81d81bf6f66
7
+ data.tar.gz: ed5d09af6c65d7080118e82e3f07aaca8798e9ee059bca8b098299a64bfbd7bf66452069b4a1b2faff69bebe5219b3bf3a7fe30b539ef6b621d897dcfb02bd02
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- new_alipay (0.1.3)
4
+ new_alipay (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://ruby.taobao.org/
data/README.md CHANGED
@@ -91,6 +91,24 @@ NewAlipay.account_name='xxxx公司/你的真实姓名'
91
91
 
92
92
  })
93
93
  ```
94
+ ####验证付款结果
95
+ ```ruby
96
+ request_result = NewAlipay::BatchTrans.verify_notify?({
97
+ _input_charset: 'utf-8',
98
+ batch_fee: 0.01,
99
+ account_name: 'xxxx公司',
100
+ partner: '208890xxxxyyyy',
101
+ batch_no: '20160331xxxxxx',
102
+ sign: 'bc98542c95d33b08752qweq2a1ce162c8d',
103
+ detail_data: '201603316694019891235827213^152xxxxyyyy^xxxx^0.01^测试支付&email=yyyyxxx@qq.com&notify_url=http://test.yourserver.com/',
104
+ pay_date: '2016-03-31',
105
+ batch_num: 1,
106
+ service: 'batch_trans_notify',
107
+ sign_type: 'MD5'
108
+ })
109
+ puts request_result
110
+ #=>true
111
+ ```
94
112
 
95
113
  ## Development
96
114
 
@@ -4,6 +4,12 @@ module NewAlipay
4
4
  #支付宝网关地址(新)
5
5
  ALIPAY_GATEWAY_NEW = 'https://mapi.alipay.com/gateway.do?'
6
6
 
7
+ #HTTPS形式消息验证地址
8
+ HTTPS_VERIFY_URL = 'https://mapi.alipay.com/gateway.do?service=notify_verify&'
9
+
10
+ # HTTP形式消息验证地址
11
+ HTTP_VERIFY_URL = 'http://notify.alipay.com/trade/notify_query.do?'
12
+
7
13
  module_function
8
14
  # 建立请求,以表单HTML形式构造(默认)
9
15
  # @param para_temp 请求参数数组
@@ -31,5 +37,25 @@ module NewAlipay
31
37
  "#{ALIPAY_GATEWAY_NEW}#{sorted_signing_str_array.join('&')}"
32
38
  end
33
39
 
40
+ #params.except(*request.env.keys.push(:route_info))
41
+ # @param post_params 除去系统变量的参数
42
+ def verify_notify?(post_params)
43
+ verifing_sign = Digest::MD5.hexdigest(post_params.reject { |p| [:sign, :sign_type].include?(p) }
44
+ .inject([]) { |memo, (key, v)| memo << "#{key}=#{v}"; memo }
45
+ .sort! { |m, n| m.to_s <=> n.to_s }.join('&')+NewAlipay.key)
46
+ verifing_sign == post_params[:sign]
47
+
48
+ begin
49
+ conn = Faraday.new(:url => 'https://mapi.alipay.com') do |faraday|
50
+ faraday.request :url_encoded # form-encode POST params
51
+ faraday.response :logger # log requests to STDOUT
52
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
53
+ end
54
+ response = conn.get '/gateway.do', {:service => 'notify_verify', partner: NewAlipay.partner, notify_id: post_params[:notify_id]}
55
+ response.body.to_s == 'true'
56
+ rescue Exception => e
57
+ false
58
+ end
59
+ end
34
60
  end
35
61
  end
@@ -1,3 +1,3 @@
1
1
  module NewAlipay
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: new_alipay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - saxer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler