kingdee_api 0.1.0 → 0.2.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: 934391e85b391da659c8495785ac56eca320131a646f6e268e2a590d5bd55ef4
4
- data.tar.gz: 41fad52c3356633f04bc7409acfa42be1576597f5d17302b27c22d59c4629d3b
3
+ metadata.gz: 3844e8f110340b22a5ce2fee881312eb287edbeeb1fa084e01ceecdb3f45a184
4
+ data.tar.gz: fd06db0771832756880ac57c8c7b6c46a971558250fa27d74ce3c075bb60f04a
5
5
  SHA512:
6
- metadata.gz: d51d6d431c9a39f77f121086f527cf5903e65f3fec8bf7a07394c57e7767596fdb3d5b1de9b8734e617c38ce1786c5e537fb2287a1bd3838b7ed61f9762490a2
7
- data.tar.gz: 05dc1efb059ab4e576b5855539d86e56f11cfdba2093c96594cc5351a33e6b5d185bc52a3c9c60926f5ead6c12963d526d50114fb0f465695567f7f0b67123b4
6
+ metadata.gz: c46d228823ae8deecae26b398cbd5271c80c4c1b8c9fd4dfb6add430f09fe85af391963fa8f26e9f395e51608916659d4da31ee097a5d3433071572a8cd4c1e8
7
+ data.tar.gz: 05e091ae93665b846b56038d95eab7c8326e2fcf7922d5c60721677a1d28e4de2654db41d6937d9853003d1853b6041e6ae942dd99922232d916ae9d4036a574
data/.env ADDED
@@ -0,0 +1,6 @@
1
+ # load env
2
+ export KINGDEE_CLIENT_ID=327910
3
+ export KINGDEE_CLIENT_SECRET=c195564b8d1f1d4ad839ff83eea3eefa
4
+ export KINGDEE_APP_KEY=gsKeflPn
5
+ export KINGDEE_APP_SECRET=8b081c4ea0f9cbb569cf6f5c8f720774083e8f81
6
+ export KINGDEE_DOMAIN=https://tf.jdy.com
data/README.md CHANGED
@@ -11,7 +11,6 @@
11
11
  - 📦 支持 GET、POST 等多种 HTTP 方法
12
12
  - 📎 支持文件上传功能
13
13
  - 🚀 简单易用的 API 接口
14
- - 🧩 模块化设计,配置、签名、请求和响应组件彼此解耦
15
14
 
16
15
  ## 安装
17
16
 
@@ -32,7 +32,7 @@ module KingdeeApi
32
32
 
33
33
  private
34
34
 
35
- attr_reader :configuration, :signer, :http_adapter
35
+ attr_reader :signer, :http_adapter
36
36
 
37
37
  def coerce_configuration(config)
38
38
  return config if config.is_a?(Configuration)
@@ -4,24 +4,45 @@ module KingdeeApi
4
4
  module Request
5
5
  HOST = 'https://api.kingdee.com'
6
6
 
7
- def get(path, params = nil)
8
- query_with('GET', path: path, params: params)
7
+ def get(path, params: nil)
8
+ if not params.nil?
9
+ params = params.sort.to_h
10
+ end
11
+
12
+ uri = URI("#{HOST}#{path}")
13
+ uri.query = URI.encode_www_form(params) unless params.nil?
14
+ data = Net::HTTP.get(uri, get_headers_with(path, params: ))
15
+
16
+ JSON.parse(data)
9
17
  end
10
18
 
11
- def post
19
+
20
+ def post(path, params: nil)
21
+ uri = URI("#{HOST}#{path}")
22
+ response = Net::HTTP.post(uri, JSON.generate(params.sort.to_h), post_headers_with(path))
23
+
24
+ JSON.parse(response.body)
12
25
  end
13
26
 
14
27
  private
15
- def query_with(method, path:, params: nil)
16
- # ✅ 构造请求 URL
17
- uri = URI("#{HOST}#{path}")
18
- uri.query = URI.encode_www_form(params) unless params.nil?
19
28
 
20
- http = Net::HTTP.new(uri.host, uri.port)
21
- http.use_ssl = true
29
+ def base_headers
30
+ {
31
+ "Content-Type" => "application/json",
32
+ "X-Api-ClientID" => client_id,
33
+ "X-Api-Auth-Version" => "2.0",
34
+ "X-Api-TimeStamp" => timestamp,
35
+ "X-Api-SignHeaders" => "X-Api-TimeStamp,X-Api-Nonce",
36
+ "X-Api-Nonce" => nonce,
37
+ "X-Api-Signature" => 'placeholder',
38
+ "app-token" => token,
39
+ "X-GW-Router-Addr" => domain
40
+ }
41
+ end
22
42
 
43
+ def get_headers_with(path, params: nil)
23
44
  x_api_signature = x_api_signature_with(
24
- method: method,
45
+ method: 'GET',
25
46
  path: path,
26
47
  params: params,
27
48
  nonce: nonce,
@@ -29,25 +50,20 @@ module KingdeeApi
29
50
  client_secret: client_secret
30
51
  )
31
52
 
32
- request_class = Net::HTTP.const_get(method.capitalize)
33
- request = request_class.new(uri)
34
- request["Content-Type"] = "application/json"
35
- request["X-Api-ClientID"] = client_id
36
- request["X-Api-Auth-Version"] = "2.0"
37
- request["X-Api-TimeStamp"] = timestamp
38
- request["X-Api-SignHeaders"] = "X-Api-TimeStamp,X-Api-Nonce"
39
- request["X-Api-Nonce"] = nonce
40
- request["X-Api-Signature"] = "#{x_api_signature}"
41
- request["app-token"] = token
42
- request["X-GW-Router-Addr"] = domain
43
-
44
- response = http.request(request)
45
-
46
- pp response.body
47
- puts "[HTTP] #{response.code}"
48
- # puts JSON.parse(response.body)
49
- # app-token: object false 用于调用星辰接口,有效期为24小时
50
- response.body
53
+ base_headers.merge("X-Api-Signature" => x_api_signature)
51
54
  end
55
+ def post_headers_with(path)
56
+ x_api_signature = x_api_signature_with(
57
+ method: 'POST',
58
+ path: path,
59
+ params: nil,
60
+ nonce: nonce,
61
+ timestamp: timestamp,
62
+ client_secret: client_secret
63
+ )
64
+ base_headers.merge("X-Api-Signature" => x_api_signature)
65
+ end
66
+
67
+
52
68
  end
53
69
  end
@@ -41,9 +41,6 @@ module KingdeeApi
41
41
  "app_signature" => app_signature #app_signature
42
42
  })
43
43
 
44
- pp uri.query
45
- pp uri.host
46
- pp uri.to_s
47
44
  http = Net::HTTP.new(uri.host, uri.port)
48
45
  http.use_ssl = true
49
46
 
@@ -59,8 +56,7 @@ module KingdeeApi
59
56
 
60
57
  response = http.request(request)
61
58
 
62
- puts "[HTTP] #{response.code}"
63
- puts JSON.parse(response.body)
59
+
64
60
  # app-token: object false 用于调用星辰接口,有效期为24小时
65
61
  JSON.parse(response.body)["data"]["app-token"]
66
62
  end
@@ -73,10 +69,10 @@ module KingdeeApi
73
69
  if params.nil? || params.empty?
74
70
  encoded_params = ''
75
71
  else
76
- encoded_params = params.sort.to_h.map do |k, v|
77
- "#{double_encode(k)}=#{double_encode(v)}"
78
- end.join("&")
79
- end
72
+ encoded_params = params.sort.to_h.map do |k, v|
73
+ "#{double_encode(k)}=#{double_encode(v)}"
74
+ end.join("&")
75
+ end
80
76
 
81
77
  headers_block = [
82
78
  "x-api-nonce:#{nonce}",
@@ -91,7 +87,7 @@ module KingdeeApi
91
87
  "" # ⚠️ 末尾必须换行
92
88
  ].join("\n")
93
89
 
94
- puts sign_plain
90
+
95
91
 
96
92
 
97
93
  Base64.strict_encode64(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KingdeeApi
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kingdee_api
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
  - 钟声
@@ -17,6 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".env"
20
21
  - CHANGELOG.md
21
22
  - LICENSE.txt
22
23
  - README.md