reapal 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f666bd5dcc641e0493de86b32007b2a1f7126a64
4
- data.tar.gz: 737efdcae2f36ec7c1b6566a744c3b734ce9ea3b
3
+ metadata.gz: b2b8e99a85cdd0e5502e22b10d9e24682807e051
4
+ data.tar.gz: 21f711b8f01acedb9d2ce46a021f7ac136421e4c
5
5
  SHA512:
6
- metadata.gz: fcb581a2aa92fc6bbeaa692735f753d0bd6f399bcd123c46c20a2fefa0ca4826598720d384ddf7e181e2a1d41c5ef11578bbc7aeddd1ffacc34260a29b012e8d
7
- data.tar.gz: 80ab50ee402a58d45458830682df502418a2888dd4bcf656862e4b48c36d7a3b17765001da966abf9298cae1226262bb6f48deaf534bb44bd698fdbd8e53dbfa
6
+ metadata.gz: 716347461f3350e848eff7a1f6c35c26851116e4bbdf3ad063e83fda89daab81811dd0f4478ae3c9917dffcb1b14328934f1dace912983856fb1372b7e3e427a
7
+ data.tar.gz: b6808b06c2f6605f8d60a1a0c3326cf826cfe81955e2447ecfc47ee1b9c5d150f88a54e9d8679e01d3889118e1c537f5ea1bfe38f3c15d1ff9fab0f59fb51f59
data/.gitignore CHANGED
@@ -8,6 +8,7 @@
8
8
  /tmp/
9
9
 
10
10
  .byebug_history
11
+ reapal-*.gem
11
12
  Gemfile.lock
12
13
 
13
14
  # rspec failure tracking
data/README.md CHANGED
@@ -27,13 +27,50 @@ TODO: Write usage instructions here
27
27
  ### logger
28
28
 
29
29
  ``` ruby
30
- SuckerPunch.logger = Logger.new('sucker_punch.log')
31
- SuckerPunch.logger # => #<Logger:0x007fa1f28b83f0>
30
+ Reapal.logger = Logger.new('reapal.log')
31
+ Reapal.logger # => #<Logger:0x007fa1f28b83f0>
32
32
  ```
33
33
 
34
34
  * Note: If Reapal is being used within a Rails application, Reapal's logger is set to Rails.logger by default. *
35
35
 
36
- ## Development
36
+ ## 开发
37
+
38
+ ### 怎么加入
39
+
40
+ ```
41
+ # 先 fork 此项目
42
+ # checkout 自己的项目后操作:
43
+ $ git remote -v # 查看主机源,如果只有自己的 origin 那还没有设置 upstream
44
+ $ git remote add upstream https://github.com/omniaccountcorp/reapal
45
+ $ git fetch upstream
46
+ $ git checkout master
47
+ $ git merge --no-ff upstream/master
48
+ # 如果有冲突解决...
49
+ $ git add 修改的文件
50
+ $ git commit -m 'merge from origin-git'
51
+ $ git push origin [自己开发的分支]
52
+ ```
53
+
54
+ ### 开发新 api 指南
55
+ 1. 根据 service 名字,确定好 module ,新 api 文件名,方法名,比如:
56
+ ``` ruby
57
+ # 假如服务名: reapal.trust.mobileModify
58
+ # 文件名:lib/reapal/api/trust/mobile_modify.rb
59
+ module Reapal
60
+ module Api
61
+ module MobileModify
62
+ def mobile_modify(...)
63
+ # ...
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ ```
70
+ 2. 新 api 文件中写好注释(记得标明是文档中的哪一节),确定好函数输入输出
71
+ 3. 写 spec
72
+ 4. 实现 api
73
+ 5. 测试通过后向作者提交 spec
37
74
 
38
75
  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.
39
76
 
@@ -7,19 +7,19 @@ require "base64"
7
7
  require 'macaddr'
8
8
  require 'byebug'
9
9
  require 'logger'
10
+ require 'bigdecimal'
11
+ require 'bigdecimal/util'
10
12
 
11
13
  require "reapal/version"
12
14
  require "reapal/utils"
15
+ require "reapal/extensions"
13
16
  require "reapal/sign/md5"
14
17
  require "reapal/encrypt/rsa"
15
18
  require "reapal/encrypt/aes"
16
19
  require "reapal/http/communicate"
17
20
  require "reapal/http/response"
18
-
19
21
  # 自动加载所有 api
20
- Dir["#{File.dirname(__FILE__)}/reapal/api/**/*.rb"].each { |file|
21
- require file
22
- }
22
+ Dir["#{File.dirname(__FILE__)}/reapal/api/**/*.rb"].each { |file| require file }
23
23
 
24
24
  require "reapal/client"
25
25
 
@@ -0,0 +1,58 @@
1
+ # coding: utf-8
2
+
3
+ module Reapal
4
+ module Api
5
+ module Agreement
6
+ module BalanceQuery
7
+
8
+ # 1.6 查询余额(API)
9
+ #
10
+ # @param contracts [ String ] 用户协议号
11
+ #
12
+ # @return [ Hash ] 结果集
13
+ # * :success [bool] 查询结果是否有效
14
+ # * :data [Hash] 成功数据
15
+ # * :total_amount [BigDecimal] 账户总额
16
+ # * :usable_amount [BigDecimal] 可用金额
17
+ # * :tender_amount [BigDecimal] 投标金额
18
+ #
19
+ def balance_query(contracts)
20
+ service = 'reapal.trust.balanceQuery'
21
+ post_path = '/reagw/agreement/agreeApi.htm'
22
+
23
+ params = {
24
+ contracts: contracts,
25
+ applyTime: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
26
+ }
27
+
28
+ response = Http.post(service, params, @config, post_path)
29
+
30
+ # 如果数据不合法
31
+ unless response.data_valid
32
+ return {success: false}
33
+ end
34
+
35
+ # 如果网络出错,包括超时或者非200类数据
36
+ unless response.http_response.kind_of?(Net::HTTPSuccess)
37
+ return {success: false}
38
+ end
39
+
40
+ # 如果 api 出异常
41
+ if response.data[:errorCode]
42
+ return {success: false}
43
+ end
44
+
45
+ {
46
+ success: true,
47
+ data: {
48
+ total_amount: response.data[:totalAmount].to_d,
49
+ usable_amount: response.data[:usableAmount].to_d,
50
+ tender_amount: response.data[:tenderAmount].to_d,
51
+ }
52
+ }
53
+ end
54
+
55
+ end # module Agree
56
+ end
57
+ end
58
+ end
@@ -2,23 +2,19 @@
2
2
 
3
3
  module Reapal
4
4
  module Api
5
- module Agreement
6
- module AgreeQuery
5
+ module Trust
6
+ module ContractQuery
7
7
 
8
- # 个人一键签约(API)
8
+ # 1.5 签约查询,支持个人和企业(API)
9
9
  #
10
- # @param flow_id [ String ] 订单号
11
- # @param true_name [ String ] 真实姓名
12
- # @param identity_id [ String ] 身份证号
13
- # @param phone [ String ] 手机号
14
- # @param bus_way [ String ] 00:PC端;01:手机端;02:Pad端;03:其它
10
+ # @param ori_flow_id [ String ] 原订单号
15
11
  #
16
12
  # @return [ Hash ] 结果集
17
13
  # * :result [String] "S"/"F"/"P"
18
14
  # * :error_msg [String] 错误提示
19
15
  # * :data [Hash] 成功数据,解析和【个人签约API】/【企业签约API】一致
20
16
  #
21
- def agree_query(ori_flow_id)
17
+ def contract_query(ori_flow_id)
22
18
  # TODO(tony): 目前我们只用个人签约,个人签约都是同步返回,所以先不做实现
23
19
  raise "Not Implement"
24
20
 
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ module Reapal
4
+ module Api
5
+ module Trust
6
+ module FindTradePassowrd
7
+
8
+ # 1.9 设置/修改交易密码
9
+ #
10
+ # @param
11
+ #
12
+ # @return [ Hash ] 结果集
13
+ # * :merchant_id
14
+ # * :encryptkey
15
+ # * :data
16
+ # * :url
17
+ # * :method
18
+ #
19
+ def find_trade_password(contracts, busway='01')
20
+ service = 'reapal.trust.findTradePassword'
21
+ post_path = '/reagw/findTradePassword/findTradePassword.htm'
22
+
23
+ params = {
24
+ contracts: contracts,
25
+ busway: busway,
26
+ applyTime: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
27
+ }
28
+
29
+ request = Http.get_body(service, params, @config)
30
+ request[:method] = :post
31
+ request[:url] = config[:server_url] + post_path
32
+
33
+ request
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ module Reapal
4
+ module Api
5
+ module Trust
6
+ module MobileModify
7
+
8
+ # 1.7 签约手机号修改
9
+ #
10
+ # @param
11
+ #
12
+ # @return [ Hash ] 结果集
13
+ # * :merchant_id
14
+ # * :encryptkey
15
+ # * :data
16
+ # * :url
17
+ # * :method
18
+ #
19
+ def mobile_modify(contracts, new_phone, busway='01')
20
+ service = 'reapal.trust.mobileModify'
21
+ post_path = '/reagw/user/rest.htm'
22
+
23
+ params = {
24
+ contracts: contracts,
25
+ mobile: new_phone,
26
+ busway: busway,
27
+ returnUrl: '',
28
+ notifyUrl: '',
29
+ applyTime: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
30
+ }
31
+
32
+ request = Http.get_body(service, params, @config)
33
+ request[:method] = :post
34
+ request[:url] = config[:server_url] + post_path
35
+
36
+ request
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,83 @@
1
+ # coding: utf-8
2
+
3
+ module Reapal
4
+ module Api
5
+ module Trust
6
+ module OnekeyBatchContract
7
+
8
+ # 1.1 个人一键签约(API)新版本,迁移老数据
9
+ #
10
+ # @param flow_id [ String ] 订单号
11
+ #
12
+ # @return [ Hash ] 结果集
13
+ # * :result [String] "S"/"F"/"P"
14
+ # * :error_msg [String] 错误提示
15
+ # * :error_code [String] 融宝的错误编号
16
+ # * :data [Hash] 成功数据,返回的数据不一定是上送数据,比如手机号。所以要以返回数据为准
17
+ # * :contracts [String] 用户签约协议号
18
+ # * :userName [String] 姓名
19
+ # * :userIdentity [String] 身份证
20
+ # * :userMobile [String] 手机号
21
+ #
22
+ def onekey_batch_contract(flow_id, true_name, identity_id, phone, is_to_sms,
23
+ bank_code, card_id, card_province, card_city, card_branch, card_sub_branch,
24
+ bus_way='01')
25
+ service = 'reapal.trust.onekeyBatchContract'
26
+ post_path = '/reagw/agreement/agree.htm'
27
+
28
+ params = {
29
+ orderNo: flow_id,
30
+ userName: true_name,
31
+ userIdentity: identity_id,
32
+ userMobile: phone,
33
+ busway: bus_way,
34
+ remark: '',
35
+ isToSms: is_to_sms,
36
+ bankCode: bank_code,
37
+ bankAccountNo: card_id,
38
+ accountProvince: card_province,
39
+ accountCity: card_city,
40
+ branch: card_branch,
41
+ subbranch: card_sub_branch,
42
+ applyTime: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
43
+ }
44
+
45
+ response = Http.post(service, params, @config, post_path)
46
+
47
+ error_result = {
48
+ data: nil,
49
+ result: "F",
50
+ error_msg: "未知错误",
51
+ }
52
+
53
+ # 如果数据不合法
54
+ unless response.data_valid
55
+ error_result[:error_msg] = "返回数据不合法"
56
+ return error_result
57
+ end
58
+
59
+ # 如果网络出错,包括超时或者非200类数据
60
+ unless response.http_response.kind_of?(Net::HTTPSuccess)
61
+ error_result[:error_msg] = "网络出错"
62
+ return error_result
63
+ end
64
+
65
+ # 个人签约只有返回码是 '0000', '0007' 才成功
66
+ if ['0000', '0007'].include?(response.data[:resultCode])
67
+ return {
68
+ data: response.data,
69
+ result: "S",
70
+ error_msg: nil,
71
+ }
72
+ else
73
+ # 普通错误
74
+ error_result[:error_code] = response.data[:errorCode]
75
+ error_result[:error_msg] = response.data[:errorMsg]
76
+ return error_result
77
+ end
78
+ end
79
+
80
+ end # module Agree
81
+ end
82
+ end
83
+ end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module Reapal
4
4
  module Api
5
- module Agreement
6
- module Agree
5
+ module Trust
6
+ module OnekeyContract
7
7
 
8
- # 个人一键签约(API)
8
+ # 1.2 个人一键签约(API)
9
9
  #
10
10
  # @param flow_id [ String ] 订单号
11
11
  # @param true_name [ String ] 真实姓名
@@ -23,7 +23,7 @@ module Reapal
23
23
  # * :userIdentity [String] 身份证
24
24
  # * :userMobile [String] 手机号
25
25
  #
26
- def agree(flow_id, true_name, identity_id, phone, bus_way='01')
26
+ def onekey_contract(flow_id, true_name, identity_id, phone, bus_way='01')
27
27
  service = 'reapal.trust.onekeyContract'
28
28
  post_path = '/reagw/agreement/agree.htm'
29
29
 
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+
3
+ module Reapal
4
+ module Api
5
+ module Trust
6
+ module WithdrawApply
7
+
8
+ # 2.7 提现申请
9
+ #
10
+ # @param
11
+ #
12
+ # @return [ Hash ] 结果集
13
+ # * :merchant_id
14
+ # * :encryptkey
15
+ # * :data
16
+ # * :url
17
+ # * :method
18
+ #
19
+ def withdraw_apply(contracts, flow_id, money, charge, busway='01')
20
+ service = 'reapal.trust.withdrawApply'
21
+ post_path = '/reagw/service/withdraw.htm'
22
+
23
+ params = {
24
+ orderNo: flow_id,
25
+ contracts: contracts,
26
+ amount: money,
27
+ charge: charge,
28
+ busway: busway,
29
+ returnUrl: '',
30
+ notifyUrl: '',
31
+ applyTime: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
32
+ }
33
+
34
+ request = Http.get_body(service, params, @config)
35
+ request[:method] = :post
36
+ request[:url] = config[:server_url] + post_path
37
+
38
+ request
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ module NilClassExtension
2
+ def to_d
3
+ 0.to_d
4
+ end
5
+ end
6
+
7
+ NilClass.send(:include, NilClassExtension)
@@ -47,8 +47,7 @@ module Reapal
47
47
  result
48
48
  end
49
49
 
50
- private
51
-
50
+ # 表单的 body
52
51
  def self.get_body(service, params, config)
53
52
  data = {
54
53
  version: VERSION,
@@ -67,6 +66,8 @@ module Reapal
67
66
  }
68
67
  end
69
68
 
69
+ private
70
+
70
71
  def self.unpack_body(body_string, config)
71
72
  # 返回是 json 字符串格式
72
73
  body = Utils.symbolize_keys(JSON.parse(body_string))
@@ -1,3 +1,3 @@
1
1
  module Reapal
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reapal
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
  - tony
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-21 00:00:00.000000000 Z
11
+ date: 2017-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -124,11 +124,17 @@ files:
124
124
  - bin/console
125
125
  - bin/setup
126
126
  - lib/reapal.rb
127
- - lib/reapal/api/agreement/agree.rb
128
- - lib/reapal/api/agreement/agree_query.rb
127
+ - lib/reapal/api/trust/balance_query.rb
128
+ - lib/reapal/api/trust/contract_query.rb
129
+ - lib/reapal/api/trust/find_trade_password.rb
130
+ - lib/reapal/api/trust/mobile_modify.rb
131
+ - lib/reapal/api/trust/onekey_batch_contract.rb
132
+ - lib/reapal/api/trust/onekey_contract.rb
133
+ - lib/reapal/api/trust/withdraw_apply.rb
129
134
  - lib/reapal/client.rb
130
135
  - lib/reapal/encrypt/aes.rb
131
136
  - lib/reapal/encrypt/rsa.rb
137
+ - lib/reapal/extensions.rb
132
138
  - lib/reapal/http/communicate.rb
133
139
  - lib/reapal/http/response.rb
134
140
  - lib/reapal/railtie.rb