ralipay 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ralipay.rb +105 -1
- data/lib/ralipay/common.rb +2 -1
- data/lib/ralipay/version.rb +1 -1
- data/test/test_ralipay.rb +1 -66
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e26d6b6be75cf675ea3f45be20a3c3c19fb872e
|
|
4
|
+
data.tar.gz: bac3081e027abaca474b97d580bba955fde3442c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef23cdd4fc18774115e557884915af3414ed1a69a594a7dfb548edac6f31bfbf30db6d8936e1ca94ce2d084e15d6c785dd639cdb6acdea63a71405f94588ecb9
|
|
7
|
+
data.tar.gz: f93e780a7af61d8e4eaa4286cb19adf865bc0b4a81f559d9b37c659a0e9f8adcbd21deab411481f349243bea05304fc16b7349429a3bd396d785cfd70242d7f4
|
data/lib/ralipay.rb
CHANGED
|
@@ -8,6 +8,8 @@ module Ralipay
|
|
|
8
8
|
require 'date'
|
|
9
9
|
require 'nokogiri'
|
|
10
10
|
require 'cgi'
|
|
11
|
+
require 'uri'
|
|
12
|
+
require 'open-uri'
|
|
11
13
|
|
|
12
14
|
include Ralipay::Common
|
|
13
15
|
|
|
@@ -24,7 +26,8 @@ module Ralipay
|
|
|
24
26
|
:total_fee => '',
|
|
25
27
|
:out_user => '',
|
|
26
28
|
:rsa_private_key_path => '',
|
|
27
|
-
:rsa_public_key_path => ''
|
|
29
|
+
:rsa_public_key_path => '',
|
|
30
|
+
:key => ''
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
#固定参数,无需修改
|
|
@@ -241,4 +244,105 @@ module Ralipay
|
|
|
241
244
|
|
|
242
245
|
end
|
|
243
246
|
|
|
247
|
+
class WebPayment
|
|
248
|
+
|
|
249
|
+
def initialize(configs)
|
|
250
|
+
#@todo 入参合法性验证
|
|
251
|
+
$global_configs = $global_configs.merge configs
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def sign(params)
|
|
255
|
+
params_kv = params.sort.map do |kv|
|
|
256
|
+
kv.join('=')
|
|
257
|
+
end
|
|
258
|
+
sign = Digest::MD5.hexdigest(params_kv.join('&') + $global_configs[:key])
|
|
259
|
+
params['sign_type'] = 'MD5'
|
|
260
|
+
params['sign'] = sign
|
|
261
|
+
params
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
#生成web支付地址
|
|
265
|
+
def generate_pay_url
|
|
266
|
+
params = Hash.new
|
|
267
|
+
params['service'] = 'create_direct_pay_by_user'
|
|
268
|
+
params['_input_charset'] = 'utf-8'
|
|
269
|
+
params['payment_type'] = '1'
|
|
270
|
+
params['partner'] = $global_configs[:partner]
|
|
271
|
+
params['seller_email'] = $global_configs[:seller_email]
|
|
272
|
+
params['subject'] = $global_configs[:subject]
|
|
273
|
+
params['out_trade_no'] = $global_configs[:out_trade_no]
|
|
274
|
+
params['total_fee'] = $global_configs[:total_fee]
|
|
275
|
+
params['show_url'] = $global_configs[:merchant_url]
|
|
276
|
+
params['return_url'] = $global_configs[:call_back_url]
|
|
277
|
+
params['notify_url'] = $global_configs[:notify_url]
|
|
278
|
+
all_params = sign(params)
|
|
279
|
+
all_params_kv = all_params.map do |key,value|
|
|
280
|
+
key + '=' + value
|
|
281
|
+
end
|
|
282
|
+
'https://www.alipay.com/cooperate/gateway.do?' + URI.encode(all_params_kv.join('&'))
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
#同步回调验证,支付后跳转,前端GET方式获得参数,传入hash symbol,该方法只返回bool
|
|
286
|
+
def callback_verify? gets
|
|
287
|
+
sign = gets[:sign]
|
|
288
|
+
gets = Ralipay::Common::para_filter(gets)
|
|
289
|
+
for_sign = Ralipay::Common::create_link_string(gets)
|
|
290
|
+
for_sign = CGI.unescape for_sign
|
|
291
|
+
sign == Ralipay::Common::md5_sign(for_sign + $global_configs[:key])
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
#同步回调验证,支付后跳转,前端GET方式获得参数,传入hash symbol,该方法返回支付状态,并安全的返回回调参数hash,失败返回false
|
|
295
|
+
def callback_verify gets
|
|
296
|
+
origin_params = gets
|
|
297
|
+
sign = gets[:sign]
|
|
298
|
+
gets = Ralipay::Common::para_filter(gets)
|
|
299
|
+
for_sign = Ralipay::Common::create_link_string(gets)
|
|
300
|
+
for_sign = CGI.unescape for_sign
|
|
301
|
+
if sign == Ralipay::Common::md5_sign(for_sign + $global_configs[:key])
|
|
302
|
+
origin_params
|
|
303
|
+
else
|
|
304
|
+
false
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
#异步回调验证,支付宝主动通知,前端POST xml方式获得参数,该方法只返回bool
|
|
309
|
+
#成功请自行向支付宝打印纯文本success
|
|
310
|
+
#如验签失败或未输出success支付宝会24小时根据策略重发总共7次,需考虑重复通知的情况
|
|
311
|
+
def notify_verify? posts
|
|
312
|
+
origin_params = posts
|
|
313
|
+
sign = posts[:sign]
|
|
314
|
+
posts = Ralipay::Common::para_filter(posts)
|
|
315
|
+
for_sign = Ralipay::Common::create_link_string(posts)
|
|
316
|
+
for_sign = CGI.unescape for_sign
|
|
317
|
+
if sign == Ralipay::Common::md5_sign(for_sign + $global_configs[:key])
|
|
318
|
+
response = open('http://notify.alipay.com/trade/notify_query.do?' + 'partner=' + $global_configs[:partner] + '¬ify_id=' + origin_params[:notify_id]).read
|
|
319
|
+
response == 'true'
|
|
320
|
+
else
|
|
321
|
+
false
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
#异步回调验证,支付宝主动通知,前端POST xml方式获得参数,该方法返回支付状态,并安全的返回回调参数hash,失败返回false
|
|
326
|
+
#成功请自行向支付宝打印纯文本success
|
|
327
|
+
#如验签失败或未输出success支付宝会24小时根据策略重发总共7次,需考虑重复通知的情况
|
|
328
|
+
def notify_verify posts
|
|
329
|
+
origin_params = posts
|
|
330
|
+
sign = posts[:sign]
|
|
331
|
+
posts = Ralipay::Common::para_filter(posts)
|
|
332
|
+
for_sign = Ralipay::Common::create_link_string(posts)
|
|
333
|
+
for_sign = CGI.unescape for_sign
|
|
334
|
+
if sign == Ralipay::Common::md5_sign(for_sign + $global_configs[:key])
|
|
335
|
+
response = open('http://notify.alipay.com/trade/notify_query.do?' + 'partner=' + $global_configs[:partner] + '¬ify_id=' + origin_params[:notify_id]).read
|
|
336
|
+
if response == 'true'
|
|
337
|
+
origin_params
|
|
338
|
+
else
|
|
339
|
+
false
|
|
340
|
+
end
|
|
341
|
+
else
|
|
342
|
+
false
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
end
|
|
347
|
+
|
|
244
348
|
end
|
data/lib/ralipay/common.rb
CHANGED
|
@@ -2,6 +2,7 @@ module Ralipay::Common
|
|
|
2
2
|
|
|
3
3
|
require 'openssl'
|
|
4
4
|
require 'base64'
|
|
5
|
+
require 'digest/md5'
|
|
5
6
|
|
|
6
7
|
#生成签名结果
|
|
7
8
|
def self.build_sign data_array
|
|
@@ -49,7 +50,7 @@ module Ralipay::Common
|
|
|
49
50
|
|
|
50
51
|
#MD5签名
|
|
51
52
|
def self.md5_sign(for_sign_string)
|
|
52
|
-
|
|
53
|
+
Digest::MD5.hexdigest for_sign_string
|
|
53
54
|
end
|
|
54
55
|
|
|
55
56
|
#验签
|
data/lib/ralipay/version.rb
CHANGED
data/test/test_ralipay.rb
CHANGED
|
@@ -4,72 +4,6 @@ require 'ralipay'
|
|
|
4
4
|
|
|
5
5
|
class TestRalipay < Test::Unit::TestCase
|
|
6
6
|
|
|
7
|
-
#def test_generate_wap_pay_url
|
|
8
|
-
# configs = {
|
|
9
|
-
# :partner => '2088701817081672',
|
|
10
|
-
# :seller_email => 'service@iiseeuu.com',
|
|
11
|
-
# :rsa_private_key_path => '/Users/ZhouYT/Desktop/rsa_private_key.pem',
|
|
12
|
-
# :rsa_public_key_path => '/Users/ZhouYT/Desktop/alipay_public_key.pem',
|
|
13
|
-
# :subject => '测试商品',
|
|
14
|
-
# :out_trade_no => '1222222233',
|
|
15
|
-
# :total_fee => '0.01',
|
|
16
|
-
# :notify_url => 'http://180.110.74.118/post.php',
|
|
17
|
-
# :merchant_url => 'http://www.iiseeuu.com',
|
|
18
|
-
# :call_back_url => 'http://www.iiseeuu.com'
|
|
19
|
-
# }
|
|
20
|
-
# assert_equal "需要手动访问url进行测试",
|
|
21
|
-
# Ralipay::WapPayment.new(configs).generate_pay_url
|
|
22
|
-
#end
|
|
23
|
-
|
|
24
|
-
#def test_callback_verify
|
|
25
|
-
# configs = {
|
|
26
|
-
# :partner => '2088701817081672',
|
|
27
|
-
# :seller_email => 'service@iiseeuu.com',
|
|
28
|
-
# :rsa_private_key_path => '/Users/ZhouYT/Desktop/rsa_private_key.pem',
|
|
29
|
-
# :rsa_public_key_path => '/Users/ZhouYT/Desktop/alipay_public_key.pem',
|
|
30
|
-
# :subject => '测试商品',
|
|
31
|
-
# :out_trade_no => '1222222232',
|
|
32
|
-
# :total_fee => '1',
|
|
33
|
-
# :notify_url => 'http://180.110.74.118/post.php',
|
|
34
|
-
# :merchant_url => 'http://www.iiseeuu.com',
|
|
35
|
-
# :call_back_url => 'http://www.iiseeuu.com'
|
|
36
|
-
# }
|
|
37
|
-
# #'out_trade_no=1222222232&request_token=requestToken&result=success&trade_no=2013032325639837&sign=cANAWkI1dgF1WeyRpp%2F0xzfKXXo50JxRyUxcDh6z%2BZbps1YFiWYRTSUmdCx7HT%2BjAG79ebMWEVIf2HmdIYEIzQDJwu2nl0fElqRgcm9%2BT%2B5b75DbtUg9COla1tr34NLpOcM0P0lcq6byNM0wFbdycUIIoH5Z6JKu66B1YuQLNag%3D&sign_type=0001'
|
|
38
|
-
# gets = {
|
|
39
|
-
# :out_trade_no => '1222222232',
|
|
40
|
-
# :request_token => 'requestToken',
|
|
41
|
-
# :result => 'success',
|
|
42
|
-
# :trade_no => '2013032325639837',
|
|
43
|
-
# :sign => 'cANAWkI1dgF1WeyRpp%2F0xzfKXXo50JxRyUxcDh6z%2BZbps1YFiWYRTSUmdCx7HT%2BjAG79ebMWEVIf2HmdIYEIzQDJwu2nl0fElqRgcm9%2BT%2B5b75DbtUg9COla1tr34NLpOcM0P0lcq6byNM0wFbdycUIIoH5Z6JKu66B1YuQLNag%3D',
|
|
44
|
-
# :sign_type => '0001'
|
|
45
|
-
# }
|
|
46
|
-
# assert_equal true,
|
|
47
|
-
# Ralipay::WapPayment.new(configs).callback_verify?(gets)
|
|
48
|
-
#end
|
|
49
|
-
|
|
50
|
-
#def test_notify_verify
|
|
51
|
-
# configs = {
|
|
52
|
-
# :partner => '2088701817081672',
|
|
53
|
-
# :seller_email => 'service@iiseeuu.com',
|
|
54
|
-
# :rsa_private_key_path => '/Users/ZhouYT/Desktop/rsa_private_key.pem',
|
|
55
|
-
# :rsa_public_key_path => '/Users/ZhouYT/Desktop/alipay_public_key.pem',
|
|
56
|
-
# :subject => '测试商品',
|
|
57
|
-
# :out_trade_no => '1222222233',
|
|
58
|
-
# :total_fee => '1',
|
|
59
|
-
# :notify_url => 'http://180.110.74.118/post.php',
|
|
60
|
-
# :merchant_url => 'http://www.iiseeuu.com',
|
|
61
|
-
# :call_back_url => 'http://www.iiseeuu.com'
|
|
62
|
-
# }
|
|
63
|
-
# posts = {
|
|
64
|
-
# :service => 'alipay.wap.trade.create.direct',
|
|
65
|
-
# :sign => 'pCEWVfxBWqvpndkXmCPbd70Tqfo7IG3tP68WmH4wWuUDylb6Rv2RzOghs7m+ANtAx+NyCIuE4KpoonS4qZrc16Qh7/bnwZL2C4FHQJ903HrV0c4n/Pdko0owksnb9VYUGMEppVEBvYPap0bP1GZsbCtI1iuXb2cI1h4vlK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g4FIOp8cv0qOtI/UQPWGbGAy4qys7+sJN/wkboLpdWKLhwgPzto9TM0jN5GZMeA35+2wGcuPAe/SNqhvWM9r8xeCniuSDjesHWWN5bkiYzB4cb0n+E72Yh5WmwJw87ySuXAQWgONxnzgjX0LAGiinoBoufBqmpi/f8vAV3sJFEzkGZxFLSO1Us1ldSi16IqnPTdNtaQAe0N+QYnALM10rmsuGp4/jJatFWFMnmi06AMLcC31who0SD/xItGl6riSkX0yDqWQJzCvZUrrZJoqXJ7XBZoCQscL3Ug2RCKrGba/Ekc10EQINiX99XzYUPVK8xKxO4WW/7T00rZ8B1YjnUaBdWKGdmWmv0itnLx6rK8NWBw=='
|
|
69
|
-
# }
|
|
70
|
-
# assert_equal true,
|
|
71
|
-
# Ralipay::WapPayment.new(configs).notify_verify?(posts)
|
|
72
|
-
#end
|
|
73
7
|
|
|
74
8
|
def test_para_filter
|
|
75
9
|
input_para = {:a => 'abc', :sign_type => 'abc', :c => '', :d => nil}
|
|
@@ -83,4 +17,5 @@ class TestRalipay < Test::Unit::TestCase
|
|
|
83
17
|
Ralipay::Common::create_link_string(input_para)
|
|
84
18
|
end
|
|
85
19
|
|
|
20
|
+
|
|
86
21
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ralipay
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- RaymondChou
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-
|
|
11
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|