jieshun-parking 0.4.0 → 0.6.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: df11031bd27943deeac558a8e200255fad232335c3b8bf143b987aa70560964c
4
- data.tar.gz: 8f11af9940434a8fd38cce628f6d01ab0f87fd18cecd3f546e328ecd28166803
3
+ metadata.gz: 7affdd12e82772721285b712751dba4b980cb3a81d5cecce5cabdefdae90f173
4
+ data.tar.gz: b165205b7afd678bb3bc322dfc66c41ce3e8ef2d33235fffc9a9ad63039b7698
5
5
  SHA512:
6
- metadata.gz: a7df802493278b25dc262c992e89349842ceea36b90c9d204e9e71db922f532e5cf2ee6df7d1544668c92efa0f6f16be25e94c3ccfda1d788a78cde289f028ec
7
- data.tar.gz: 467e451adbbcccd4cb52c7e46c342ef192713877bc0141d5c9725045eaafbd05bfd8ee33fc0d64f0669da2c6493a161cfccc31b1c5b04f12f93d48e050f1e7c7
6
+ metadata.gz: 7413aa9df7e55f9e5f7960c11941be91caafc49240bcd9f80bcfd011e7e69580f53e037f7c500c5eccfd4127c4823cb74d28c75bfdbe8d2ac826f82236201d7e
7
+ data.tar.gz: c400cea30d101b5ec74a99066827e119fa445155d1a5222ce6752451d59c925e82c7af3157114d741780c9a0145c189a04316424eb4e5ae553a44aa2d9b9a2e7
@@ -5,6 +5,7 @@ require 'digest'
5
5
  module Jieshun
6
6
  module Parking
7
7
 
8
+ # 捷顺订单 API Client, 对应文档为 捷慧通云平台接口规范_2.1.doc 和 捷慧通云平台接口标准协议_http_V3.0.1.doc
8
9
  class Client
9
10
 
10
11
  REDIS_AUTH_KEY = 'jieshun.parking.auth.token'
@@ -0,0 +1,67 @@
1
+ module Jieshun
2
+ module Parking
3
+ # 捷顺数据中心 Client, 目前主要用来获取图片, 对应文档为 QX205_数据中心标准推送协议-1.1.6(1)
4
+ class DataCenterClient
5
+
6
+ REDIS_AUTH_KEY = 'jieshun.parking.datacenter.auth.token'
7
+
8
+ def initialize(configuration, http_client = StandardHttpClient.new)
9
+ @configuration = configuration
10
+ @http_client = http_client
11
+ @redis_client = RedisClient.new(@configuration.redis_config)
12
+ end
13
+
14
+ def get_auth_token
15
+ @redis_client.redis_get(REDIS_AUTH_KEY)
16
+ end
17
+
18
+ def login_if_required
19
+ auth_token = get_auth_token
20
+ if Jieshun::Parking.always_login || auth_token.nil? || auth_token.empty?
21
+ hash = { pno: @configuration.pno, secret: @configuration.secret }
22
+ @http_client.post_json("#{@configuration.server_url}/api/login", {}, hash) do |result|
23
+ auth_token = result.body['tn']
24
+ expire_time = result.body['timeOut'] - 1000
25
+ @redis_client.redis_set(REDIS_AUTH_KEY, auth_token, expire_time) # token will be expired after 2 hours
26
+ yield(auth_token)
27
+ end
28
+ else
29
+ yield(auth_token)
30
+ end
31
+ end
32
+
33
+ def get_picture_base64(file_path)
34
+ data_items = []
35
+ data_items << { filePath: file_path }
36
+ unify_call("/api/pic/picSearch", data_items.to_json) do |result|
37
+ yield(result)
38
+ end
39
+ end
40
+
41
+ def unify_call(api_path, data_items)
42
+ login_if_required do |auth_token|
43
+ ts = Time.now.strftime("%Y%m%d%H%M%S%L")
44
+ sn = generate_signature("#{@configuration.secret}#{ts}#{data_items}")
45
+ hash = {
46
+ pno: @configuration.pno,
47
+ tn: auth_token,
48
+ ts: ts,
49
+ sn: sn,
50
+ dataItems: data_items
51
+ }
52
+
53
+ @http_client.post_json("#{@configuration.server_url}/#{api_path}", { }, hash) do |result|
54
+ yield(result)
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ def generate_signature(payload)
61
+ md5_string = Digest::MD5.hexdigest(payload)
62
+ md5_string.upcase
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,18 @@
1
+ module Jieshun
2
+ module Parking
3
+
4
+ class DataCenterConfiguration
5
+
6
+ attr_reader :server_url, :pno, :secret, :redis_config
7
+
8
+ def initialize(server_url, pno, secret, redis_config)
9
+ @server_url = server_url
10
+ @pno = pno
11
+ @secret = secret
12
+ @redis_config = redis_config
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -2,8 +2,9 @@ module Jieshun
2
2
  module Parking
3
3
  class DataReceiver
4
4
 
5
- def initialize(secret)
5
+ def initialize(secret, verify_signature)
6
6
  @secret = secret
7
+ @verify_signature = verify_signature
7
8
  end
8
9
 
9
10
  def receive(params, options)
@@ -18,7 +19,7 @@ module Jieshun
18
19
  error_handler.call({ resultCode: 1, message: '处理失败' })
19
20
  end
20
21
  end
21
- verify_signature(params, { error_handler: internal_error_handler })
22
+ verify_signature(params, { error_handler: internal_error_handler }) if @verify_signature
22
23
  return nil if error_occurred
23
24
  JSON.parse(params['dataItems'])
24
25
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jieshun
4
4
  module Parking
5
- VERSION = "0.4.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'logger'
3
4
  require_relative "parking/version"
4
5
  require_relative "parking/configuration"
5
6
  require_relative "parking/client"
@@ -10,7 +11,9 @@ require_relative "parking/redis/redis_client"
10
11
  require_relative "parking/helpers/retry"
11
12
  require_relative "parking/data_receiver"
12
13
  require_relative "parking/errors/invalid_signature_error"
13
- require 'logger'
14
+ require_relative "parking/data_center_client"
15
+ require_relative "parking/data_center_configuration"
16
+
14
17
 
15
18
 
16
19
  module Jieshun
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.4.0
4
+ version: 0.6.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-11 00:00:00.000000000 Z
11
+ date: 2023-07-19 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_center_client.rb
54
+ - lib/jieshun/parking/data_center_configuration.rb
53
55
  - lib/jieshun/parking/data_receiver.rb
54
56
  - lib/jieshun/parking/errors/invalid_signature_error.rb
55
57
  - lib/jieshun/parking/helpers/retry.rb