yol_erp_lite 0.0.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 +7 -0
- data/.gitignore +68 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +14 -0
- data/Rakefile +2 -0
- data/lib/yol_erp_lite/client.rb +19 -0
- data/lib/yol_erp_lite/connection.rb +3 -0
- data/lib/yol_erp_lite/connections/base.rb +56 -0
- data/lib/yol_erp_lite/connections/customer.rb +15 -0
- data/lib/yol_erp_lite/connections/material.rb +15 -0
- data/lib/yol_erp_lite/helpers/pkcs7_encoder.rb +28 -0
- data/lib/yol_erp_lite/helpers/prpcrypt.rb +48 -0
- data/lib/yol_erp_lite/models/configuration.rb +13 -0
- data/lib/yol_erp_lite/models/encrypt_message.rb +24 -0
- data/lib/yol_erp_lite/version.rb +3 -0
- data/lib/yol_erp_lite.rb +33 -0
- data/yol_erp_lite.gemspec +27 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2cc35d71d445f54b7fc5af88ec9bfc23c1d017f527aa14f9a6f9647c8ee0fd8d
|
4
|
+
data.tar.gz: 00ae296b4125deb7b35dee5164f20ccd7214ad0d72dc33411d91c8b6ed64a027
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a602aa3786c4a84f426bdfad487b69bf9c29c665ea1e44d2ff7fa4c8c45907072ab3b997a6d191d91b3ade06985134364601bece211846ed3cf24ab73f08ccca
|
7
|
+
data.tar.gz: 2e9a1c16f2a85b01d1d9fe5893609d15d0272fc86ca431820fc4095ed64109d80cb2c009133e09b94a320947da165f7cfca4b4a15bbdaf968be8036475dbca7f
|
data/.gitignore
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
.idea
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.DS_Store
|
5
|
+
*.swp
|
6
|
+
Gemfile.lock
|
7
|
+
GemfileLocal
|
8
|
+
GemfileLocal.lock
|
9
|
+
|
10
|
+
# Ignore all logfiles and tempfiles.
|
11
|
+
/log/*
|
12
|
+
/tmp/*
|
13
|
+
!/log/.keep
|
14
|
+
!/tmp/.keep
|
15
|
+
|
16
|
+
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
|
17
|
+
config/initializers/secret_token.rb
|
18
|
+
config/master.key
|
19
|
+
|
20
|
+
# Only include if you have production secrets in this file, which is no longer a Rails default
|
21
|
+
# config/secrets.yml
|
22
|
+
|
23
|
+
# dotenv
|
24
|
+
# TODO Comment out this rule if environment variables can be committed
|
25
|
+
.env
|
26
|
+
|
27
|
+
## Environment normalization:
|
28
|
+
/.bundle
|
29
|
+
/vendor/bundle
|
30
|
+
|
31
|
+
# these should all be checked in to normalize the environment:
|
32
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
36
|
+
|
37
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
38
|
+
/vendor/assets/bower_components
|
39
|
+
*.bowerrc
|
40
|
+
bower.json
|
41
|
+
|
42
|
+
# Ignore pow environment settings
|
43
|
+
.powenv
|
44
|
+
|
45
|
+
# Ignore Byebug command history file.
|
46
|
+
.byebug_history
|
47
|
+
|
48
|
+
# Ignore node_modules
|
49
|
+
node_modules/
|
50
|
+
|
51
|
+
# Ignore precompiled javascript packs
|
52
|
+
/public/packs
|
53
|
+
/public/packs-test
|
54
|
+
/public/assets
|
55
|
+
|
56
|
+
# Ignore yarn files
|
57
|
+
/yarn-error.log
|
58
|
+
yarn-debug.log*
|
59
|
+
.yarn-integrity
|
60
|
+
|
61
|
+
# Ignore uploaded files in development
|
62
|
+
/storage/*
|
63
|
+
!/storage/.keep
|
64
|
+
|
65
|
+
# Ignore pkg
|
66
|
+
/pkg/*
|
67
|
+
|
68
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2021 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Sso
|
2
|
+
|
3
|
+
This project rocks and uses MIT-LICENSE.
|
4
|
+
|
5
|
+
https://rubygems.org/gems/yol_erp_lite
|
6
|
+
|
7
|
+
[](http://badge.fury.io/rb/yol_erp_lite)
|
8
|
+
|
9
|
+
**有问题请及时提issue**
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "yol_erp_lite", git: "https://github.com/luojie2019/yol_erp_lite.git"
|
13
|
+
```
|
14
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "monitor"
|
2
|
+
require "redis"
|
3
|
+
require 'digest/md5'
|
4
|
+
module YolErpLite
|
5
|
+
class Client
|
6
|
+
|
7
|
+
include Connection::Base
|
8
|
+
include Connection::Customer
|
9
|
+
include Connection::Material
|
10
|
+
|
11
|
+
attr_accessor :host, :corpsecret, :redis
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@host = options[:host] || YolErpLite.configuration.host
|
15
|
+
@corpsecret = options[:corpsecret] || YolErpLite.configuration.corpsecret
|
16
|
+
@redis = options[:redis] || YolErpLite.configuration.redis
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module YolErpLite
|
2
|
+
module Connection
|
3
|
+
module Base
|
4
|
+
def http_post(url, params)
|
5
|
+
uri = URI(url)
|
6
|
+
req = Net::HTTP.new(uri.host, uri.port)
|
7
|
+
header = {'content-type': 'application/json', 'token': get_access_token}
|
8
|
+
req.use_ssl = true if uri.scheme == 'https'
|
9
|
+
res = req.post("#{uri.path}?#{uri.query}", params.to_json, header)
|
10
|
+
handle_res(res)
|
11
|
+
end
|
12
|
+
|
13
|
+
def http_get(path, params)
|
14
|
+
uri = URI.join(host, path)
|
15
|
+
req = Net::HTTP.new(uri.host, uri.port)
|
16
|
+
header = {'token': get_access_token}
|
17
|
+
req.use_ssl = true if uri.scheme == 'https'
|
18
|
+
uri.query = URI.encode_www_form(params)
|
19
|
+
res = req.get("#{uri.path}?#{uri.query}", header)
|
20
|
+
handle_res(res)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_access_token
|
24
|
+
if redis.nil?
|
25
|
+
access_token = get_token(corpsecret)
|
26
|
+
else
|
27
|
+
access_token = redis.get("erp_lite_access_token")
|
28
|
+
if access_token.nil?
|
29
|
+
access_token = redis.get("erp_lite_access_token")
|
30
|
+
if access_token.nil?
|
31
|
+
raise Exception.new("ErpLite access token authorize false, corpsecret: #{corpsecret}")
|
32
|
+
else
|
33
|
+
redis.set("erp_lite_access_token", access_token)
|
34
|
+
redis.expire("erp_lite_access_token", 7200)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
access_token
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def get_token(corpsecret)
|
44
|
+
JWT.encode({exp: (Time.now+7200).to_i}, corpsecret, 'HS256') rescue nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def handle_res(res)
|
48
|
+
if res.code == '200'
|
49
|
+
return JSON.parse(res.body)["data"]
|
50
|
+
else
|
51
|
+
return {:code => res.code}.to_json
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module YolErpLite
|
4
|
+
module PKCS7Encoder
|
5
|
+
extend self
|
6
|
+
|
7
|
+
BLOCK_SIZE = 32
|
8
|
+
|
9
|
+
def decode(text)
|
10
|
+
pad = text[-1].ord
|
11
|
+
pad = 0 if (pad < 1 || pad > BLOCK_SIZE)
|
12
|
+
size = text.size - pad
|
13
|
+
text[0...size]
|
14
|
+
end
|
15
|
+
|
16
|
+
# 对需要加密的明文进行填充补位
|
17
|
+
# 返回补齐明文字符串
|
18
|
+
def encode(text)
|
19
|
+
# 计算需要填充的位数
|
20
|
+
amount_to_pad = BLOCK_SIZE - (text.length % BLOCK_SIZE)
|
21
|
+
amount_to_pad = BLOCK_SIZE if amount_to_pad == 0
|
22
|
+
# 获得补位所用的字符
|
23
|
+
pad_chr = amount_to_pad.chr
|
24
|
+
"#{text}#{pad_chr * amount_to_pad}"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "yol_erp_lite/helpers/pkcs7_encoder"
|
3
|
+
module YolErpLite
|
4
|
+
module Prpcrypt
|
5
|
+
extend self
|
6
|
+
|
7
|
+
# 对密文进行解密.
|
8
|
+
# text 需要解密的密文
|
9
|
+
def decrypt(aes_key, text, app_id)
|
10
|
+
status = 200
|
11
|
+
text = Base64.decode64(text)
|
12
|
+
text = handle_cipher(:decrypt, aes_key, text)
|
13
|
+
result = PKCS7Encoder.decode(text)
|
14
|
+
content = result[16...result.length]
|
15
|
+
len_list = content[0...4].unpack("N")
|
16
|
+
xml_len = len_list[0]
|
17
|
+
xml_content = content[4...4 + xml_len]
|
18
|
+
from_app_id = content[xml_len + 4...content.size]
|
19
|
+
# TODO: refactor
|
20
|
+
if app_id != from_app_id
|
21
|
+
# raise BizErr, "#{__FILE__}:#{__LINE__} Failure because app_id != from_app_id"
|
22
|
+
status = 500
|
23
|
+
end
|
24
|
+
[xml_content, status]
|
25
|
+
end
|
26
|
+
|
27
|
+
# 加密
|
28
|
+
def encrypt(aes_key, text, app_id)
|
29
|
+
text = text.force_encoding("ASCII-8BIT")
|
30
|
+
random = SecureRandom.hex(8)
|
31
|
+
msg_len = [text.length].pack("N")
|
32
|
+
text = "#{random}#{msg_len}#{text}#{app_id}"
|
33
|
+
text = PKCS7Encoder.encode(text)
|
34
|
+
text = handle_cipher(:encrypt, aes_key, text)
|
35
|
+
Base64.encode64(text)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def handle_cipher(action, aes_key, text)
|
40
|
+
cipher = OpenSSL::Cipher.new('AES-256-CBC')
|
41
|
+
cipher.send(action)
|
42
|
+
cipher.padding = 0
|
43
|
+
cipher.key = aes_key
|
44
|
+
cipher.iv = aes_key[0...16]
|
45
|
+
cipher.update(text) + cipher.final
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# 标准的回包
|
3
|
+
# <xml>
|
4
|
+
# <Encrypt><![CDATA[msg_encrypt]]></Encrypt>
|
5
|
+
# <MsgSignature><![CDATA[msg_signature]]></MsgSignature>
|
6
|
+
# <TimeStamp>timestamp</TimeStamp>
|
7
|
+
# <Nonce><![CDATA[nonce]]></Nonce>
|
8
|
+
# </xml>
|
9
|
+
|
10
|
+
module YolErpLite
|
11
|
+
class EncryptMessage
|
12
|
+
include ROXML
|
13
|
+
xml_name :xml
|
14
|
+
|
15
|
+
xml_accessor :Encrypt, :cdata => true
|
16
|
+
xml_accessor :Nonce, :cdata => true
|
17
|
+
xml_accessor :TimeStamp, :as => Integer
|
18
|
+
xml_accessor :MsgSignature, :cdata => true
|
19
|
+
|
20
|
+
def to_xml
|
21
|
+
super.to_xml(:encoding => 'UTF-8', :indent => 0, :save_with => 0)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/yol_erp_lite.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'roxml'
|
2
|
+
require 'multi_xml'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'net/http'
|
5
|
+
require 'jwt'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
require "yol_erp_lite/version"
|
9
|
+
|
10
|
+
require "yol_erp_lite/models/configuration"
|
11
|
+
require "yol_erp_lite/models/encrypt_message"
|
12
|
+
require "yol_erp_lite/helpers/prpcrypt"
|
13
|
+
|
14
|
+
require "yol_erp_lite/connection"
|
15
|
+
require "yol_erp_lite/client"
|
16
|
+
|
17
|
+
module YolErpLite
|
18
|
+
|
19
|
+
class << self
|
20
|
+
|
21
|
+
# A Sso configuration object. See Sso::Configuration.
|
22
|
+
attr_writer :configuration
|
23
|
+
|
24
|
+
def configure
|
25
|
+
yield(configuration)
|
26
|
+
end
|
27
|
+
|
28
|
+
def configuration
|
29
|
+
@configuration ||= Configuration.new
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yol_erp_lite/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yol_erp_lite"
|
8
|
+
spec.version = YolErpLite::VERSION
|
9
|
+
spec.authors = ["luojie"]
|
10
|
+
spec.email = ["luojie@yolanda.hk"]
|
11
|
+
spec.summary = %q{Yolanda middleware for Message.}
|
12
|
+
spec.description = ""
|
13
|
+
spec.homepage = "https://github.com/luojie2019/yol_erp_lite"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency 'nokogiri'
|
25
|
+
spec.add_dependency 'multi_xml'
|
26
|
+
spec.add_dependency 'roxml'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yol_erp_lite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- luojie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_xml
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: roxml
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: ''
|
84
|
+
email:
|
85
|
+
- luojie@yolanda.hk
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/yol_erp_lite.rb
|
96
|
+
- lib/yol_erp_lite/client.rb
|
97
|
+
- lib/yol_erp_lite/connection.rb
|
98
|
+
- lib/yol_erp_lite/connections/base.rb
|
99
|
+
- lib/yol_erp_lite/connections/customer.rb
|
100
|
+
- lib/yol_erp_lite/connections/material.rb
|
101
|
+
- lib/yol_erp_lite/helpers/pkcs7_encoder.rb
|
102
|
+
- lib/yol_erp_lite/helpers/prpcrypt.rb
|
103
|
+
- lib/yol_erp_lite/models/configuration.rb
|
104
|
+
- lib/yol_erp_lite/models/encrypt_message.rb
|
105
|
+
- lib/yol_erp_lite/version.rb
|
106
|
+
- yol_erp_lite.gemspec
|
107
|
+
homepage: https://github.com/luojie2019/yol_erp_lite
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.7.9
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Yolanda middleware for Message.
|
131
|
+
test_files: []
|