jieshun-parking 0.5.0 → 0.6.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35a77584f90c94349799eb8ba1489c2d567a4f394cb11bd05f321c2b881593c7
|
4
|
+
data.tar.gz: f0ad2a2811a35bc67f6b4804bd30a9014e31bc4881d9256002b4c52b66b7b2b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89783f0a838b668dc8849ef997d9fe03a59c45479970a786f9a9a59432c1020279952cfe32510c9dad19fab3f61a60b33e318b096e23ff2486a145d3dd3eb381
|
7
|
+
data.tar.gz: 6f650550391e3bb33a523de19c8ca5828d4eb5548ad1e06a3638c06f4ee2329b2cc8d1916beb1ca41d32e3bf517475c10b5214286470c07ff7be1a62a83e99bf
|
@@ -0,0 +1,82 @@
|
|
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
|
+
image = result.body['dataItems'].first['image']
|
38
|
+
mime_type = detect_mime_type(image)
|
39
|
+
yield( { mime_type_prefix: "data:#{mime_type};base64,", content: image } )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def detect_mime_type(base64_content)
|
44
|
+
return "application/pdf" if content_matches?(base64_content, ['JVBERi0'])
|
45
|
+
return "image/gif" if content_matches?(base64_content, ['R0lGODdh', 'R0lGODlh'])
|
46
|
+
return "image/png" if content_matches?(base64_content, ['iVBORw0KGgo'])
|
47
|
+
return "image/jpg" if content_matches?(base64_content, ['/9j/'])
|
48
|
+
return "image/bmp" if content_matches?(base64_content, ['Qk'])
|
49
|
+
"application/octet-stream"
|
50
|
+
end
|
51
|
+
|
52
|
+
def content_matches?(base64_content, prefixes)
|
53
|
+
prefixes.any? { |prefix| base64_content.start_with?(prefix) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def unify_call(api_path, data_items)
|
57
|
+
login_if_required do |auth_token|
|
58
|
+
ts = Time.now.strftime("%Y%m%d%H%M%S%L")
|
59
|
+
sn = generate_signature("#{@configuration.secret}#{ts}#{data_items}")
|
60
|
+
hash = {
|
61
|
+
pno: @configuration.pno,
|
62
|
+
tn: auth_token,
|
63
|
+
ts: ts,
|
64
|
+
sn: sn,
|
65
|
+
dataItems: data_items
|
66
|
+
}
|
67
|
+
|
68
|
+
@http_client.post_json("#{@configuration.server_url}/#{api_path}", { }, hash) do |result|
|
69
|
+
yield(result)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def generate_signature(payload)
|
76
|
+
md5_string = Digest::MD5.hexdigest(payload)
|
77
|
+
md5_string.upcase
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
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
|
data/lib/jieshun/parking.rb
CHANGED
@@ -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
|
-
|
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
|
+
version: 0.6.1
|
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
|
+
date: 2023-07-20 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
|