lanmao 0.8.0 → 0.9.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
  SHA1:
3
- metadata.gz: 0fb9d6c75b1a564e976855ea056aded6334dc027
4
- data.tar.gz: afb203332578bf14eff346c2f9e42f71f01e86cb
3
+ metadata.gz: 8380f0c51719efea1617de41d1e12fe9e61240b7
4
+ data.tar.gz: 42f342ffcb5d985cc1d7e9728428a6f7bc160d88
5
5
  SHA512:
6
- metadata.gz: fff7e1075da4f5eaca292e34e6166eefe681767dde85d0930e3143f0f896eb567c83bbd5311220e6290317a5b61a98d25050b06751e81b00ae94c70a15f23f16
7
- data.tar.gz: b67fa97980854416b9d09c34227f201224114ae5055e44633efa5e7987f853defb7c81be127deba1c44e5e1a82c55d9c3798c01725cd5da0a3cdfaa34565dd0f
6
+ metadata.gz: 23d955c27c0438bd1e140f4818e75113f71b3c008127644a9a1f32e248eb843fc042a7143ba06dbebf1129a7126a5bf3bf0271dca806f351a431f567561f4e3c
7
+ data.tar.gz: ae843e35a747a680f24eba63dfb354a53b2c2e6e6dae5f66e5c800fb4bc382f80b3599c417664b6959753569a4e986abff4f4a1a3d63a03961bb06db4617a96f
@@ -49,6 +49,33 @@ module Lanmao
49
49
  res
50
50
  end
51
51
 
52
+ def download_post(service, params, type)
53
+ request = Http::Request.new(params, @config, service, type)
54
+ response = request.post
55
+ res = {
56
+ result: 'P', # 默认
57
+ request_params: params,
58
+ response: response,
59
+ flow_id: nil,
60
+ code: nil,
61
+ error_code: nil,
62
+ error_msg: nil,
63
+ data: nil,
64
+ }
65
+ result = JSON.parse(response).with_indifferent_access rescue {}
66
+ if "1" == result[:code]
67
+ res[:result] = "F"
68
+ res[:code] = result[:code]
69
+ res[:error_code] = result[:errorCode]
70
+ res[:error_msg] = result[:errorMessage]
71
+ else
72
+ res[:result] = "S"
73
+ res[:data] = response
74
+ end
75
+
76
+ res
77
+ end
78
+
52
79
  end # CommunicateResultHelper
53
80
  end
54
81
  end
@@ -22,7 +22,7 @@ module Lanmao
22
22
  fileDate: file_date
23
23
  }
24
24
 
25
- res = operate_post(:operate, service, params, :service)
25
+ res = download_post(service, params, :download)
26
26
 
27
27
  res
28
28
  end
@@ -5,7 +5,7 @@ module Lanmao
5
5
 
6
6
  # 跳转到新网 Form 类的 api,统一返回处理
7
7
  #
8
- # @param service [ String ] 富民的服务
8
+ # @param service [ String ] 新网的服务
9
9
  # @param params [ Hash ] 参数
10
10
  #
11
11
  # @return [ Hash ] 结果集
@@ -17,7 +17,7 @@ module Lanmao
17
17
  # * :amount [Number] 金额
18
18
  # * :balance [Number] 操作后账户余额
19
19
  #
20
- def withdraw_form(flow_id, platform_user_no, expired, redirect_url, amount, withdraw_type='NORMAL', withdraw_form='IMMEDIATE', commission=0.0)
20
+ def withdraw_form(flow_id, platform_user_no, expired, redirect_url, amount, withdraw_type='NORMAL', withdraw_form='IMMEDIATE', commission=nil)
21
21
 
22
22
  service = "WITHDRAW"
23
23
 
@@ -6,17 +6,19 @@ module Lanmao
6
6
  require 'active_support/all'
7
7
 
8
8
  def initialize(params, config, service, type)
9
- Time.zone = "Beijing"
10
9
  @params = params
11
10
  @params[:timestamp] = Time.now.in_time_zone("Beijing").strftime('%Y%m%d%H%M%S') # 时间戳
12
11
 
13
12
  @config = config
14
13
  @service = service
14
+ @type = type
15
15
 
16
16
  @url = if :gateway == type # 网关模式
17
17
  @config[:path] + "/gateway"
18
18
  elsif :service == type # 直连模式
19
19
  @config[:path] + "/service"
20
+ elsif :download == type # 对账文件下载模式
21
+ @config[:path] + "/download"
20
22
  else
21
23
  @config[:path]
22
24
  end
@@ -60,16 +62,22 @@ module Lanmao
60
62
  # 5. send http request
61
63
  Lanmao.logger.info "#{identifier} 发送的报文为:\n#{post_body}\n"
62
64
  http_response = RestClient.post(@url, post_body)
65
+
63
66
  Lanmao.logger.info "#{identifier} 返回的报文为:\n#{http_response.body.force_encoding('utf-8')}\n"
64
67
 
68
+ # 直接返回,数据以字节流形式在 response body 中输出,无签名
69
+ return http_response.body if @type == :download
70
+
65
71
  # 6. create response
66
72
  @response = Lanmao::Http::Response.new(service: @service,
67
73
  flow_id: flow_id,
68
74
  http_response: http_response,
69
75
  raw_body: http_response.body,
70
76
  data: Utils.symbolize_keys(JSON.parse(http_response.body)),
71
- data_valid: true)
72
- # data_valid: Sign.verify(res, @config))
77
+ # data_valid: true
78
+ data_valid: Sign::RSA.verify(http_response.body, http_response.headers[:sign], @config)
79
+ )
80
+
73
81
  end
74
82
 
75
83
  def flow_id
@@ -3,12 +3,24 @@ module Lanmao
3
3
  module Sign
4
4
  module RSA
5
5
 
6
+ #签名
6
7
  def self.sign(content, private_key)
7
- sign = private_key.sign('sha1', content.force_encoding("utf-8"))
8
+ sign = private_key.sign("sha1", content.force_encoding("utf-8"))
8
9
  signature = Base64.encode64(sign)
9
10
  signature = signature.delete("\n").delete("\r")
10
11
  end
11
12
 
13
+ ## 验签
14
+ def self.verify(data, sign, config) ##如何从data里分离出原始数据和签名数据
15
+ if sign
16
+ sign = Base64.decode64(sign)
17
+ digester = OpenSSL::Digest::SHA1.new
18
+ config[:public_key].verify(digester, sign, data)
19
+ else
20
+ true
21
+ end
22
+ end # verify
23
+
12
24
  end
13
25
  end
14
26
  end
@@ -1,3 +1,3 @@
1
1
  module Lanmao
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.1"
3
3
  end
data/lib/lanmao.rb CHANGED
@@ -18,6 +18,7 @@ require "lanmao/sign/rsa"
18
18
  require "lanmao/http/request"
19
19
  require "lanmao/http/response"
20
20
 
21
+
21
22
  # 自动加载所有 api
22
23
  Dir["#{File.dirname(__FILE__)}/lanmao/api/**/*.rb"].each { |file| require file }
23
24
  # 自动加载所有 form
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lanmao
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tony
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-07 00:00:00.000000000 Z
11
+ date: 2018-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler