new_alipay 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/new_alipay/version.rb +1 -1
- data/lib/new_alipay.rb +16 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e84190e0e1890628fff77282b759e0ac2268d089
|
4
|
+
data.tar.gz: 535159eea4660ac79d1818c1a648b2517e5df6ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5377abc3b6ee19ba8d2502c9cbcb62f562e8fd56b6fdc50246ad632cbf20fd96ef8dba6ac923ca50d46291d72b503189a48454026a5bd92bd76b8d72fcd08982
|
7
|
+
data.tar.gz: 2eb388f3a86ef3842d28128582d26377bef5a08a385c12ce6cb9d3dbe5043a4d672d8a582a98c3b293edcdf3883d3b5eea0ca507248b9b47f2eb40b2a4986afc
|
data/Gemfile.lock
CHANGED
data/lib/new_alipay/version.rb
CHANGED
data/lib/new_alipay.rb
CHANGED
@@ -6,7 +6,8 @@ require 'base64'
|
|
6
6
|
|
7
7
|
module NewAlipay
|
8
8
|
class << self
|
9
|
-
attr_accessor :seller_email, :partner, :key
|
9
|
+
attr_accessor :seller_email, :partner, :key
|
10
|
+
attr_accessor :rsa_private_key_path, :alipay_public_key_path
|
10
11
|
end
|
11
12
|
module_function
|
12
13
|
|
@@ -30,12 +31,25 @@ module NewAlipay
|
|
30
31
|
rsa_sign(signing_str)
|
31
32
|
end
|
32
33
|
|
34
|
+
#验证是否签名成功
|
35
|
+
def verify_rsa?(params)
|
36
|
+
|
37
|
+
sym_key_params = params.inject({}) { |memo, (key, v)| memo[key.to_s.to_sym]=v; memo }
|
38
|
+
org_sign = sym_key_params[:sign]
|
39
|
+
sym_key_params = sym_key_params.reject { |key, v| [:sign_type, :sign].include? key }
|
40
|
+
sym_key_params = sym_key_params.inject([]) { |memo, (key, v)| memo << "#{key}=#{v}"; memo }
|
41
|
+
sym_key_params = sym_key_params.sort! { |m, n| m.to_s <=> n.to_s }
|
42
|
+
signing_str = sym_key_params.join("&")
|
43
|
+
|
44
|
+
rsa = OpenSSL::PKey::RSA.new File.read(self.alipay_public_key_path || "./config/alipay/quick/key/alipay_public_key.pem")
|
45
|
+
rsa.verify('sha1', Base64::decode64(org_sign), signing_str)
|
46
|
+
end
|
47
|
+
|
33
48
|
#rsa签名
|
34
49
|
def rsa_sign(signing_str)
|
35
50
|
#读取私钥文件
|
36
51
|
private_key_content = File.read(self.rsa_private_key_path || "./config/alipay/quick/key/rsa_private_key.pem")
|
37
52
|
|
38
|
-
p private_key_content
|
39
53
|
private_key = OpenSSL::PKey::RSA.new private_key_content
|
40
54
|
digest = OpenSSL::Digest::SHA1.new
|
41
55
|
sign = Base64::encode64(private_key.sign(digest, signing_str))
|