ll_pay 0.1.0 → 0.2.0

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: 6dddd23347f12ddb6a86db48b9e846d81a0d5095
4
- data.tar.gz: '03965dd8a2e35b14b611bfe61dded3e4b4b83699'
3
+ metadata.gz: 791510ce280d6c3f20c4e96e6714cd0aa85665ed
4
+ data.tar.gz: 59919fc5997650a09c8af3f623233f954913d899
5
5
  SHA512:
6
- metadata.gz: e68e3ceeeae6feb2dd39c60df8efe1868f473cc00de44ce4425fb95cf679cb999d049b6a251a8dcc5992a84dc7dab082986bceede78db81f8179ea20e1264e3f
7
- data.tar.gz: 7dc7e9804f97e65abc3f50969e87fea14206395a2549a39355cafa465aece77359ee18a34ee6a7512f860753c4f71116e5cb498037e99bdfdeee90af22b03168
6
+ metadata.gz: 2ac0d647acd857a3e446ec78442c04da6faaca2c013f6d8ba8fd92f14f73c3e099ba75fd324d50fd2a1881212a49166345884d282816b31feb26b89954ca2ddf
7
+ data.tar.gz: 7e89e51c6abbbc516a1616ee8a8014bd484b60c34a7796e02406d4c1b9ebec2808151f09b187561830284dad5abe3ae5071d9d11988b20c75e683115eeb7e925
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # LlPay
1
+ LlPay [![Gem Version][version-badge]][rubygems] [![Build Status][travis-badge]][travis] [![Code Climate][codeclimate-badge]][codeclimate] [![Code Coverage][codecoverage-badge]][codecoverage]
2
+ =======
2
3
 
3
4
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ll_pay`. To experiment with that code, run `bin/console` for an interactive prompt.
4
5
 
@@ -22,7 +23,16 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
+ ### Config
27
+
28
+ Create `config/initializers/ll_pay.rb` and put following configurations into it.
29
+
30
+ ```ruby
31
+
32
+ LlPay.oid_partner = "oid_partner" # lianlian pay 商户编号
33
+ LlPay.rsa_pri_key = "rsa_pri_key" # 商户RSA密钥
34
+ LlPay.md5_key = "md5_key" # 商户 MD5
35
+ ```
26
36
 
27
37
  ## Development
28
38
 
@@ -0,0 +1,7 @@
1
+ module LlPay
2
+ module Notify
3
+ def self.verify?(params, options = {})
4
+ Sign.verify?(params, options) && LlPay.oid_partner == params[:oid_partner]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'http' # https://github.com/httprb/http
4
+
5
+ module LlPay
6
+ module QueryOrder
7
+ def self.query_single_order(sign_type, no_order, dt_order)
8
+ query_order_hash = { oid_partner: LlPay.oid_partner, dt_order: dt_order, no_order: no_order }
9
+
10
+ if sign_type == 'RSA'
11
+ query_order_hash[:sign_type] = 'RSA'
12
+ query_order_hash[:sign] = LlPay::Sign::RSA.sign(LlPay.rsa_pri_key, params_to_string(query_order_hash))
13
+ else
14
+ query_order_hash[:sign_type] = 'MD5'
15
+ query_order_hash[:sign] = LlPay::Sign::MD5.sign(LlPay.md5_key, params_to_string(query_order_hash))
16
+ end
17
+
18
+ http_response = HTTP.post('https://yintong.com.cn/queryapi/orderquery.htm',
19
+ json: query_order_hash)
20
+
21
+ response_hash = JSON.parse(http_response.body.to_s)
22
+
23
+ if http_response.code == 200
24
+ if response_hash['ret_code'] == 0000 && LlPay::Sign.verify?(params_to_string(response_hash))
25
+ return response_hash
26
+ else
27
+ return response_hash
28
+ end
29
+ else
30
+ return
31
+ end
32
+ end
33
+
34
+ def self.params_to_string(params)
35
+ params.sort.map do |k, v|
36
+ "#{k}=#{v}" if v.to_s != '' && k.to_s != 'sign'
37
+ end.compact.join('&')
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ require 'json'
2
+
3
+ module LlPay
4
+ module Service
5
+
6
+ SECURITY_PAY_REQUIRED_PARAMS = %w(notify_url no_order dt_order busi_partner money_order valid_order user_id)
7
+ def self.securitypay_pay_json(params, options = {})
8
+ params = LlPay::Utils.stringify_keys(params)
9
+ options = LlPay::Utils.stringify_keys(options)
10
+
11
+ params[:sign_type] = options[:sign_type] || LlPay.sign_type
12
+
13
+ params = { oid_partner: LlPay.oid_partner }.merge(params)
14
+
15
+ params[:sign] = LlPay::Sign.generate(params)
16
+
17
+ params.to_json
18
+ end
19
+
20
+ def self.check_required_params(params, names)
21
+ names.each do |name|
22
+ warn("ll_pay Warn: missing required option: #{name}") unless params.has_key?(name)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ require 'digest/md5'
2
+
3
+ module LlPay
4
+ module Sign
5
+ class MD5
6
+ def self.sign(key, string)
7
+ Digest::MD5.hexdigest("#{string}&key=#{key}")
8
+ end
9
+
10
+ def self.verify?(key, string, sign)
11
+ sign == sign(key, string)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+
4
+ module LlPay
5
+ module Sign
6
+ class RSA
7
+ def self.sign(prikey, string)
8
+ rsa = OpenSSL::PKey::RSA.new(prikey)
9
+ Base64.strict_encode64(rsa.sign('sha1', string))
10
+ end
11
+
12
+ def self.verify?(pubkey, string, sign)
13
+ rsa = OpenSSL::PKey::RSA.new(pubkey)
14
+ rsa.verify('sha1', Base64.strict_decode64(sign), string)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,53 @@
1
+ require 'digest/md5'
2
+
3
+ module LlPay
4
+ module Sign
5
+ def self.generate(params, options = {})
6
+ params = LlPay::Utils.stringify_keys(params)
7
+ options = LlPay::Utils.stringify_keys(options)
8
+
9
+ sign_type = params[:sign_type]
10
+ md5_key = options[:md5_key] || LlPay.md5_key
11
+ rsa_pri_key = options[:rsa_pri_key] || LlPay.rsa_pri_key
12
+ string = params_to_string(params)
13
+
14
+ case sign_type
15
+ when 'MD5'
16
+ MD5.sign(md5_key, string)
17
+ when 'RSA'
18
+ RSA.sign(rsa_pri_key, string)
19
+ else
20
+ raise ArgumentError, "invalid sign_type #{sign_type}, allow value: 'MD5', 'RSA'"
21
+ end
22
+ end
23
+
24
+ def self.verify?(params, options = {})
25
+ params = LlPay::Utils.stringify_keys(params)
26
+ options = LlPay::Utils.stringify_keys(options)
27
+
28
+ sign_type = params[:sign_type]
29
+ sign = params.delete(:sign)
30
+ string = params_to_string(params)
31
+
32
+ case sign_type
33
+ when 'MD5'
34
+ md5_key = options[:md5_key] || LlPay.md5_key
35
+ MD5.verify?(md5_key, string, sign)
36
+ when 'RSA'
37
+ RSA.verify?(options[:rsa_pub_key] || LlPay::YT_PUB_KEY, string, sign)
38
+ else
39
+ false
40
+ end
41
+ end
42
+
43
+ def self.params_to_string(params)
44
+ params_string = params.sort.map do |k, v|
45
+ "#{k}=#{v}" if v.to_s != '' && k.to_s != 'sign'
46
+ end.compact.join('&')
47
+
48
+ params_string[0] = '' if params_string[0] == '&'
49
+
50
+ params_string
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,11 @@
1
+ module LlPay
2
+ module Utils
3
+ def self.stringify_keys(hash)
4
+ new_hash = {}
5
+ hash.each do |key, value|
6
+ new_hash[(key.to_sym rescue key) || key] = value
7
+ end
8
+ new_hash
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module LlPay
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/ll_pay.rb CHANGED
@@ -1,5 +1,21 @@
1
- require "ll_pay/version"
1
+ require 'll_pay/version'
2
+ require 'll_pay/sign'
3
+ require 'll_pay/sign/md5'
4
+ require 'll_pay/sign/rsa'
5
+ require 'll_pay/notify'
6
+ require 'll_pay/query_order'
7
+ require 'll_pay/service'
8
+ require 'll_pay/utils'
2
9
 
3
10
  module LlPay
4
- # Your code goes here...
11
+ # 银通公钥
12
+ YT_PUB_KEY = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSS/DiwdCf/aZsxxcacDnooGph3d2JOj5GXWi+q3gznZauZjkNP8SKl3J2liP0O6rU/Y/29+IUe+GTMhMOFJuZm1htAtKiu5ekW0GlBMWxf4FPkYlQkPE0FtaoMP3gYfh+OwI+fIRrpW3ySn3mScnc6Z700nU/VYrRkfcSCbSnRwIDAQAB\n-----END PUBLIC KEY-----".freeze
13
+ @sign_type = 'MD5'
14
+
15
+ class << self
16
+ attr_accessor :oid_partner # 商户编号
17
+ attr_accessor :rsa_pri_key # 私钥
18
+ attr_accessor :md5_key # md5
19
+ attr_accessor :sign_type
20
+ end
5
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ll_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - houdelin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-26 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -85,6 +85,13 @@ files:
85
85
  - LICENSE.txt
86
86
  - README.md
87
87
  - lib/ll_pay.rb
88
+ - lib/ll_pay/notify.rb
89
+ - lib/ll_pay/query_order.rb
90
+ - lib/ll_pay/service.rb
91
+ - lib/ll_pay/sign.rb
92
+ - lib/ll_pay/sign/md5.rb
93
+ - lib/ll_pay/sign/rsa.rb
94
+ - lib/ll_pay/utils.rb
88
95
  - lib/ll_pay/version.rb
89
96
  homepage: https://github.com/bayetech/ll_pay
90
97
  licenses:
@@ -106,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
113
  version: '0'
107
114
  requirements: []
108
115
  rubyforge_project:
109
- rubygems_version: 2.6.6
116
+ rubygems_version: 2.4.8
110
117
  signing_key:
111
118
  specification_version: 4
112
119
  summary: An unofficial lianlian (for apple pay) pay gem.