eloan 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/eloan.gemspec +38 -0
- data/lib/eloan/api.rb +33 -0
- data/lib/eloan/api_loader.rb +12 -0
- data/lib/eloan/client.rb +21 -0
- data/lib/eloan/configuration.rb +10 -0
- data/lib/eloan/helper/payment.rb +31 -0
- data/lib/eloan/helper/request.rb +139 -0
- data/lib/eloan/helper/service.rb +45 -0
- data/lib/eloan/helper/signature.rb +32 -0
- data/lib/eloan/version.rb +3 -0
- data/lib/eloan.rb +25 -0
- data/lib/generators/eloan/config_generator.rb +12 -0
- data/lib/generators/eloan/templates/eloan.rb +9 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 41a645a3fffcd50a8f0aff6a4fdcb96616f92eaecba5c563b26f554ab68dee16
|
4
|
+
data.tar.gz: ab68ec411e84d44706a6c1b53bb8a760bb1bd846bbf194919873cc91aadd4e7d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f2b80ac48a679ff09fc136057334b6fedca924ca5aed8815ea0c5866d0f770aa0b92b06b765996d8addfe10b4dca48a5f2c5a7778c645ee090d83289d4f1fad
|
7
|
+
data.tar.gz: ee98fe390c79c31bafd0052349456ac97544bf1914020d3c070bac4a425507486d95606370b267618cc00331927ca2604fea6c30c143a45fb4d4efae1fbc511c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at qiang.ruan@mdslife.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 rqiang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Eloan
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/eloan`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'eloan'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install eloan
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/eloan. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Eloan project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/eloan/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "eloan"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/eloan.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "eloan/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "eloan"
|
8
|
+
spec.version = Eloan::VERSION
|
9
|
+
spec.authors = ["rqiang"]
|
10
|
+
spec.email = ["ruan88qiang@sina.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{ 小贷通支付 }
|
13
|
+
spec.description = %q{ 小贷通支付 }
|
14
|
+
spec.homepage = "https://github.com/rqiang88/eloan"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rest-client"
|
38
|
+
end
|
data/lib/eloan/api.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'eloan/helper/payment'
|
2
|
+
require 'eloan/helper/service'
|
3
|
+
require 'eloan/helper/signature'
|
4
|
+
require 'eloan/helper/request'
|
5
|
+
|
6
|
+
module Eloan
|
7
|
+
module Api
|
8
|
+
include Helper::Service
|
9
|
+
include Helper::Signature
|
10
|
+
include Helper::Payment
|
11
|
+
include Helper::Request
|
12
|
+
|
13
|
+
|
14
|
+
def pay code, data = {}
|
15
|
+
request = request_params(code)
|
16
|
+
url = generate_request_url(request[:url])
|
17
|
+
request_method = request[:method]
|
18
|
+
|
19
|
+
options = handle_params(generate_default_params.merge(data))
|
20
|
+
default_params = request[:default]
|
21
|
+
default_params.keys.each{|k| options[k] = default_params[k] if options[k].blank? }
|
22
|
+
options["signature"] = hexdigest(handle_request_data(request_method, url, options))
|
23
|
+
|
24
|
+
response = execute(request_method, url, options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def verify options
|
28
|
+
signature = options.delete('signature')
|
29
|
+
data = handle_response_data options
|
30
|
+
verify?(data, signature)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Eloan
|
2
|
+
module ApiLoader
|
3
|
+
class << self
|
4
|
+
def with(config)
|
5
|
+
raise "app_key not allow blank" if config.app_key.blank?
|
6
|
+
raise "app_token not allow blank" if config.app_token.blank?
|
7
|
+
raise "app_key not allow blank and length less then 7" if config.platform.blank? || config.platform.length > 6
|
8
|
+
Client.new(config)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/eloan/client.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'eloan/api'
|
2
|
+
|
3
|
+
module Eloan
|
4
|
+
class Client
|
5
|
+
include Api
|
6
|
+
|
7
|
+
attr_accessor :configurate
|
8
|
+
|
9
|
+
def initialize(config)
|
10
|
+
@configurate = config
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute(request_method, url, options)
|
14
|
+
response = RestClient::Request.execute(method: request_method,
|
15
|
+
url: URI.escape(url), headers: {params: options})
|
16
|
+
|
17
|
+
p raw_response response
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Eloan
|
2
|
+
module Helper
|
3
|
+
module Payment
|
4
|
+
### 生成公共请求参数
|
5
|
+
|
6
|
+
# 生成默认参数
|
7
|
+
def generate_default_params
|
8
|
+
{
|
9
|
+
app_token: configurate.app_token,
|
10
|
+
client_name: configurate.client_name,
|
11
|
+
company_name: configurate.company_name,
|
12
|
+
request_seq: generate_request_seq,
|
13
|
+
request_date: generate_request_date
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
# 生成流水
|
19
|
+
def generate_request_seq
|
20
|
+
length = 6 - configurate.platform.length
|
21
|
+
_ljust = 8 + length
|
22
|
+
configurate.platform + Time.now.strftime("%Y%m%d%H%M%S") + rand(1000 * 1000).to_s.rjust(_ljust, '0')
|
23
|
+
end
|
24
|
+
|
25
|
+
# 生成请求日期
|
26
|
+
def generate_request_date
|
27
|
+
Date.today.strftime("%Y%m%d")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module Eloan
|
2
|
+
module Helper
|
3
|
+
module Request
|
4
|
+
def request_params(code)
|
5
|
+
case code
|
6
|
+
when '101'
|
7
|
+
{
|
8
|
+
url: '/v1/users/add-cash-card',
|
9
|
+
method: 'POST',
|
10
|
+
notity: true,
|
11
|
+
default: {
|
12
|
+
'cert_type' => '00',
|
13
|
+
'card_type' => 'D',
|
14
|
+
'bg_return_url' => configurate.bg_return_url
|
15
|
+
}
|
16
|
+
}
|
17
|
+
when '102'
|
18
|
+
{
|
19
|
+
url: '/v1/users/add-withhold-card',
|
20
|
+
method: 'POST',
|
21
|
+
notity: true,
|
22
|
+
default: {
|
23
|
+
'cert_type' => '00',
|
24
|
+
'card_type' => 'D',
|
25
|
+
'bg_return_url' => configurate.bg_return_url
|
26
|
+
}
|
27
|
+
}
|
28
|
+
when '103'
|
29
|
+
{
|
30
|
+
url: '/v1/users/relieve-withhold-card',
|
31
|
+
method: 'POST',
|
32
|
+
default: {
|
33
|
+
'cert_type' => '00'
|
34
|
+
}
|
35
|
+
}
|
36
|
+
when '201'
|
37
|
+
{
|
38
|
+
url: '/v1/trade/loan',
|
39
|
+
method: 'POST',
|
40
|
+
notity: true,
|
41
|
+
default: {
|
42
|
+
'business_type' => '00',
|
43
|
+
'product_type' => '00',
|
44
|
+
'loan_purpose' => '00',
|
45
|
+
'loan_period' => '1',
|
46
|
+
'loan_period_type' => '01',
|
47
|
+
'entrusted_flag' => 'N',
|
48
|
+
'user_cert_type' => '00',
|
49
|
+
'user_cash_method' => 'T1',
|
50
|
+
'installment_number' => '1',
|
51
|
+
'payment_method' => '02',
|
52
|
+
'bg_return_url' => configurate.bg_return_url
|
53
|
+
}
|
54
|
+
}
|
55
|
+
when '202'
|
56
|
+
{
|
57
|
+
url: '/v1/trade/repay',
|
58
|
+
method: 'POST',
|
59
|
+
notity: true,
|
60
|
+
default: {
|
61
|
+
'business_type' => '00',
|
62
|
+
'product_type' => '00',
|
63
|
+
'cert_type' => '00',
|
64
|
+
'repay_mode' => '0',
|
65
|
+
'back_cert_type' => '00',
|
66
|
+
'bg_return_url' => configurate.bg_return_url
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
when '204'
|
71
|
+
{
|
72
|
+
url: '/v1/trade/loan/cash',
|
73
|
+
method: 'POST',
|
74
|
+
notity: true,
|
75
|
+
default: {
|
76
|
+
'bg_return_url' => configurate.bg_return_url
|
77
|
+
}
|
78
|
+
}
|
79
|
+
when '301'
|
80
|
+
{
|
81
|
+
url: '/v1/users/query/add-cash-card',
|
82
|
+
method: 'GET',
|
83
|
+
default: {
|
84
|
+
'cert_type' => '00'
|
85
|
+
}
|
86
|
+
}
|
87
|
+
when '302'
|
88
|
+
{
|
89
|
+
url: '/v1/query/trade/loan',
|
90
|
+
method: 'GET',
|
91
|
+
default: {}
|
92
|
+
}
|
93
|
+
when '303'
|
94
|
+
{
|
95
|
+
url: '/v1/query/users/add-withhold-card',
|
96
|
+
method: 'GET',
|
97
|
+
default: {
|
98
|
+
'cert_type' => '00'
|
99
|
+
}
|
100
|
+
}
|
101
|
+
when '304'
|
102
|
+
{
|
103
|
+
url: '/v1/query/trade/repay',
|
104
|
+
method: 'GET',
|
105
|
+
default: {}
|
106
|
+
}
|
107
|
+
when '305'
|
108
|
+
{
|
109
|
+
url: '/v1/query/card/bin',
|
110
|
+
method: 'GET',
|
111
|
+
default: {}
|
112
|
+
}
|
113
|
+
when '306'
|
114
|
+
{
|
115
|
+
url: '/v1/query/bind/card',
|
116
|
+
method: 'GET',
|
117
|
+
default: {
|
118
|
+
'cert_type' => '00'
|
119
|
+
}
|
120
|
+
}
|
121
|
+
when '307'
|
122
|
+
{
|
123
|
+
url: '/v1/query/loan/cash',
|
124
|
+
method: 'GET',
|
125
|
+
default: {}
|
126
|
+
}
|
127
|
+
when '308'
|
128
|
+
{
|
129
|
+
url: '/v1/query/clients/balance',
|
130
|
+
method: 'GET',
|
131
|
+
default: {}
|
132
|
+
}
|
133
|
+
else
|
134
|
+
{}
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Eloan
|
2
|
+
module Helper
|
3
|
+
module Service
|
4
|
+
def generate_request_url(url='')
|
5
|
+
[default_url, url] * ''
|
6
|
+
end
|
7
|
+
|
8
|
+
def handle_params(options={})
|
9
|
+
ActiveSupport::HashWithIndifferentAccess.new(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def raw_response(response)
|
13
|
+
return {status: :fail, code: 502, message: '请求失败,请稍后重试'} unless response.code.to_i == 200
|
14
|
+
|
15
|
+
response = JSON.parse response.body
|
16
|
+
response_code = response['response_code']
|
17
|
+
|
18
|
+
if response_code.last(2).to_s == '00'
|
19
|
+
status, code, message = 'success', 200, 'success'
|
20
|
+
else
|
21
|
+
if request_params(response_code.first(3))[:notify] && response_code.last(2).to_s == '00'
|
22
|
+
status, code, message = 'success', 201, '处理中'
|
23
|
+
else
|
24
|
+
message = response['bind_error_message'].present? ? response['bind_error_message'] : response['response_message']
|
25
|
+
status, code = 'fail', 202
|
26
|
+
end
|
27
|
+
end
|
28
|
+
{status: status, code: code, message: message, data: response}
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def default_url
|
34
|
+
if production?
|
35
|
+
else
|
36
|
+
'https://mertest.cloudpnr.com/api/eloan'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def production?
|
41
|
+
configurate.env == 'production'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Eloan
|
2
|
+
module Helper
|
3
|
+
module Signature
|
4
|
+
def hexdigest(data)
|
5
|
+
digest = OpenSSL::Digest.new('SHA256')
|
6
|
+
OpenSSL::HMAC.hexdigest(digest, configurate.app_key, data)
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify?(data, signature)
|
10
|
+
hexdigest(data) == signature
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle_request_data(request_method, url, params)
|
14
|
+
data = [request_method, url, change_params(params)] * ''
|
15
|
+
end
|
16
|
+
|
17
|
+
def handle_response_data(params)
|
18
|
+
params.delete('signature')
|
19
|
+
data = change_params(params)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def change_params(params)
|
25
|
+
data = params.sort.map do |k, v|
|
26
|
+
"#{k}=#{v}" if v.present?
|
27
|
+
end
|
28
|
+
data.compact * '&'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/eloan.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "eloan/version"
|
2
|
+
require "active_support"
|
3
|
+
require "rest-client"
|
4
|
+
|
5
|
+
module Eloan
|
6
|
+
extend ActiveSupport::Autoload
|
7
|
+
|
8
|
+
autoload :Client
|
9
|
+
autoload :Configuration
|
10
|
+
autoload :ApiLoader
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def configuration
|
14
|
+
yield configure
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure
|
18
|
+
@config ||= Configuration.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def api
|
22
|
+
@eloan ||= ApiLoader.with(configure)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Eloan
|
2
|
+
module Generators
|
3
|
+
class ConfigGenerator < Rails::Generators::Base
|
4
|
+
desc 'Generate eloan configs'
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def copy_file
|
8
|
+
template 'eloan.rb', 'config/initializers/eloan.rb'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Eloan.configuration do |config|
|
2
|
+
config.client_name = '委托人名' # null: false
|
3
|
+
config.app_token = 'app_token' # null: false
|
4
|
+
config.app_key = 'app_key' # null: false
|
5
|
+
config.company_name = 'YLPH' # null: false, 生产环境请替换
|
6
|
+
config.env = '使用环境' # null: false, values: [production, development]
|
7
|
+
config.platform = '自定义平台号' # null: false, 生成流水时候使用,根据流水号区别平台
|
8
|
+
config.bg_return_url = '' # null: false 异步通知回调地址
|
9
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eloan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rqiang
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-25 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: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: " 小贷通支付 "
|
56
|
+
email:
|
57
|
+
- ruan88qiang@sina.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- eloan.gemspec
|
73
|
+
- lib/eloan.rb
|
74
|
+
- lib/eloan/api.rb
|
75
|
+
- lib/eloan/api_loader.rb
|
76
|
+
- lib/eloan/client.rb
|
77
|
+
- lib/eloan/configuration.rb
|
78
|
+
- lib/eloan/helper/payment.rb
|
79
|
+
- lib/eloan/helper/request.rb
|
80
|
+
- lib/eloan/helper/service.rb
|
81
|
+
- lib/eloan/helper/signature.rb
|
82
|
+
- lib/eloan/version.rb
|
83
|
+
- lib/generators/eloan/config_generator.rb
|
84
|
+
- lib/generators/eloan/templates/eloan.rb
|
85
|
+
homepage: https://github.com/rqiang88/eloan
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata:
|
89
|
+
allowed_push_host: https://rubygems.org
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.7.9
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: 小贷通支付
|
110
|
+
test_files: []
|