jieshun-parking 0.3.2 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 288d7fa55a1555378f7e4bd63be5db44682ecc4846f5f3176191159090c4109a
4
- data.tar.gz: 5e30655f14c80cb6c268b61625f816ac9b9668886e09efdcb3640ef72e5b642d
3
+ metadata.gz: 5be4e784240125770a952744f2e828089616f238995a85545ac75fb744c3d548
4
+ data.tar.gz: 9218197798e8c6caa1db8368d63e66532b53f4ef5e7502151b5da83eb56dc1f4
5
5
  SHA512:
6
- metadata.gz: 6fcd4d51fdb450d4a75d6b3f82ecaf82b4c02f3a8e0715408fb18b3611b478bb3bed232d86c307f910fc19d26be37b0dd006685fb020b81cc408e3bf3b53e410
7
- data.tar.gz: c54aea863303f1d876137676c7d5db25928c19cc303f65fe0e3e8e10026783d7b1cdfdab08fe3458fb6f2480efce1badae87d5ea543a733761d94ba7d4646db5
6
+ metadata.gz: 7bc0bbc483e94dc947f30cd06fecd850d0ffab71567c1ae164f07517d607bee4df65cb6da7956093496a0240cfb51a337133503196066fcf53caccebcb704ed5
7
+ data.tar.gz: 87dca10de575d89d167c2ea0ad15c2393a467f6fe7bccbbefc48d9216ef8f68803f0265c25ae4da6a68a50d66a3513605989883889c6ec4e705096778c775e1b
@@ -0,0 +1,54 @@
1
+ module Jieshun
2
+ module Parking
3
+ class DataReceiver
4
+
5
+ def initialize(secret, verify_signature)
6
+ @secret = secret
7
+ @verify_signature = verify_signature
8
+ end
9
+
10
+ def receive(params, options)
11
+ error_handler = options[:error_handler]
12
+ error_occurred = false
13
+ internal_error_handler = lambda do |error|
14
+ error_occurred = true
15
+ if error.is_a?(Jieshun::Parking::InvalidSignatureError)
16
+ error_handler.call({ resultCode: 205, message: '验签失败' })
17
+ else
18
+ #TODO process other errors like ip unbind
19
+ error_handler.call({ resultCode: 1, message: '处理失败' })
20
+ end
21
+ end
22
+ verify_signature(params, { error_handler: internal_error_handler }) if @verify_signature
23
+ return nil if error_occurred
24
+ JSON.parse(params['dataItems'])
25
+ end
26
+
27
+ def verify_signature(params, options)
28
+ signature_param = params['sn']
29
+ signature = generate_signature(params)
30
+ unless signature_param == signature
31
+ error_handler = options[:error_handler]
32
+ if error_handler
33
+ error_handler.call(Jieshun::Parking::InvalidSignatureError.new)
34
+ else
35
+ raise Jieshun::Parking::InvalidSignatureError.new
36
+ end
37
+ end
38
+ end
39
+
40
+ require 'digest'
41
+
42
+ def generate_signature(params)
43
+ # sn:签名(sign),使用md5算法对密钥和ts以及dataItem进行签名,签名后的值为大写,规则如下:
44
+ # sn=md5(secret+ts+dataItems)
45
+ timestamp = params['ts']
46
+ data_items = params['dataItems']
47
+ payload = "#{@secret}#{timestamp}#{data_items}"
48
+ md5_string = Digest::MD5.hexdigest(payload)
49
+ md5_string.upcase
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,6 @@
1
+ module Jieshun
2
+ module Parking
3
+ class InvalidSignatureError < RuntimeError
4
+ end
5
+ end
6
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jieshun
4
4
  module Parking
5
- VERSION = "0.3.2"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
@@ -8,6 +8,8 @@ require_relative "parking/http/http_client"
8
8
  require_relative "parking/http/standard_http_client"
9
9
  require_relative "parking/redis/redis_client"
10
10
  require_relative "parking/helpers/retry"
11
+ require_relative "parking/data_receiver"
12
+ require_relative "parking/errors/invalid_signature_error"
11
13
  require 'logger'
12
14
 
13
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jieshun-parking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LCola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-10 00:00:00.000000000 Z
11
+ date: 2023-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -50,6 +50,8 @@ files:
50
50
  - lib/jieshun/parking.rb
51
51
  - lib/jieshun/parking/client.rb
52
52
  - lib/jieshun/parking/configuration.rb
53
+ - lib/jieshun/parking/data_receiver.rb
54
+ - lib/jieshun/parking/errors/invalid_signature_error.rb
53
55
  - lib/jieshun/parking/helpers/retry.rb
54
56
  - lib/jieshun/parking/http/http_client.rb
55
57
  - lib/jieshun/parking/http/standard_http_client.rb