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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46bcd901bec7bc92348482c30732a1e3dcbddec7
4
- data.tar.gz: 19029f9578fd3dac6dfb76618d29035c5256a493
3
+ metadata.gz: e84190e0e1890628fff77282b759e0ac2268d089
4
+ data.tar.gz: 535159eea4660ac79d1818c1a648b2517e5df6ea
5
5
  SHA512:
6
- metadata.gz: 6a3625a6d57048af035b894591c7329f67824be864cb59c135bfa36cf6d121589a0101d8cd3b73a58d7a3599527284d2d9332713d63a0469d6886bf4bf49d9a2
7
- data.tar.gz: 2a9c92556e5b315ae02bef742d3ccccb9adf77bc05019ed15a2d4bb1376843fdde24a49476f80a23ac285bbe0a355dc77f92d440464ad9721bdfc4eb5dba1e33
6
+ metadata.gz: 5377abc3b6ee19ba8d2502c9cbcb62f562e8fd56b6fdc50246ad632cbf20fd96ef8dba6ac923ca50d46291d72b503189a48454026a5bd92bd76b8d72fcd08982
7
+ data.tar.gz: 2eb388f3a86ef3842d28128582d26377bef5a08a385c12ce6cb9d3dbe5043a4d672d8a582a98c3b293edcdf3883d3b5eea0ca507248b9b47f2eb40b2a4986afc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- new_alipay (0.1.1)
4
+ new_alipay (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module NewAlipay
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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, :rsa_private_key_path
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))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: new_alipay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - saxer