wx_pay 0.17.0 → 0.18.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
  SHA256:
3
- metadata.gz: 161782a3a1d52339e8ff2e0f3bfc408071fca7452e0390832e78af0294154f19
4
- data.tar.gz: b8251fb2072d5dda662e27e7f2e27d88a785f5cb0737dca9c1f955817ad1f07c
3
+ metadata.gz: 58376390f703eda446bc3b8c692d11c9aeb001e6fde882515ecb1fce1f490aa4
4
+ data.tar.gz: fa597c10df24591e2e62c460b64c4c73a5deb46e41ec4f85bd9a99cd4b05cac5
5
5
  SHA512:
6
- metadata.gz: f14c5ff39a759e960b3578f68a94a6120cef8b69fc9ed5349b40182f493b733999064fdb0105e1f525283146fbf3ea96e90381b38d1f2fbf5eca018dd3a88d26
7
- data.tar.gz: aad7882af734bafc4e3bca5a91f49dd1442726a42ca31e041cdc6b005b9d4d7bde6e9feba91b13b37ce0532692b17a8419feb64e03bff3239ead289694a7d97d
6
+ metadata.gz: 5815550a0ae5ce7568c6389329f0a4c3f856fa6de917e706f3c856bc4aed6b19fa57bd5477c40e6bf6df7ff228939e7bba05e70945d514dc4f982990fbb09af8
7
+ data.tar.gz: 3eb50fdd268f845f2a7e931f37de8672bb8128f23bfb9d99b88c1931db63b5afc85aadbb2c421e6c3d58e4b05a35484a99fcd31280fb750d81539b65ffbb89cb
@@ -361,6 +361,30 @@ module WxPay
361
361
  r
362
362
  end
363
363
 
364
+ DOWNLOAD_FUND_FLOW_REQUIRED_FIELDS = [:bill_date, :account_type]
365
+ def self.download_fund_flow(params, options = {})
366
+ params = {
367
+ appid: options.delete(:appid) || WxPay.appid,
368
+ mch_id: options.delete(:mch_id) || WxPay.mch_id,
369
+ nonce_str: SecureRandom.uuid.tr('-', ''),
370
+ key: options.delete(:key) || WxPay.key
371
+ }.merge(params)
372
+
373
+ check_required_options(params, DOWNLOAD_FUND_FLOW_REQUIRED_FIELDS)
374
+
375
+ options = {
376
+ ssl_client_cert: options.delete(:apiclient_cert) || WxPay.apiclient_cert,
377
+ ssl_client_key: options.delete(:apiclient_key) || WxPay.apiclient_key,
378
+ verify_ssl: OpenSSL::SSL::VERIFY_NONE
379
+ }.merge(options)
380
+
381
+ r = invoke_remote("/pay/downloadfundflow", make_payload(params, WxPay::Sign::SIGN_TYPE_HMAC_SHA256), options)
382
+
383
+ yield r if block_given?
384
+
385
+ r
386
+ end
387
+
364
388
  def self.sendgroupredpack(params, options={})
365
389
  params = {
366
390
  wxappid: options.delete(:appid) || WxPay.appid,
@@ -420,13 +444,13 @@ module WxPay
420
444
  end
421
445
  end
422
446
 
423
- def xmlify_payload(params)
424
- sign = WxPay::Sign.generate(params)
447
+ def xmlify_payload(params, sign_type = WxPay::Sign::SIGN_TYPE_MD5)
448
+ sign = WxPay::Sign.generate(params, sign_type)
425
449
  params.delete(:key) if params[:key]
426
450
  "<xml>#{params.map { |k, v| "<#{k}>#{v}</#{k}>" }.join}<sign>#{sign}</sign></xml>"
427
451
  end
428
452
 
429
- def make_payload(params)
453
+ def make_payload(params, sign_type = WxPay::Sign::SIGN_TYPE_MD5)
430
454
  if WxPay.sandbox_mode?
431
455
  r = get_sandbox_signkey
432
456
  if r['return_code'] == WxPay::Result::SUCCESS_FLAG
@@ -439,7 +463,7 @@ module WxPay
439
463
  warn("WxPay Warn: fetch sandbox sign key failed #{r['return_msg']}")
440
464
  end
441
465
  end
442
- xmlify_payload(params)
466
+ xmlify_payload(params, sign_type)
443
467
  end
444
468
 
445
469
  def invoke_remote(url, payload, options = {})
@@ -2,14 +2,26 @@ require 'digest/md5'
2
2
 
3
3
  module WxPay
4
4
  module Sign
5
- def self.generate(params)
5
+
6
+ SIGN_TYPE_MD5 = 'MD5'
7
+ SIGN_TYPE_HMAC_SHA256 = 'HMAC-SHA256'
8
+
9
+ def self.generate(params, sign_type = SIGN_TYPE_MD5)
6
10
  key = params.delete(:key)
7
11
 
8
12
  query = params.sort.map do |k, v|
9
13
  "#{k}=#{v}" if v.to_s != ''
10
14
  end.compact.join('&')
11
15
 
12
- Digest::MD5.hexdigest("#{query}&key=#{key || WxPay.key}").upcase
16
+ string_sign_temp = "#{query}&key=#{key || WxPay.key}"
17
+
18
+ if sign_type == SIGN_TYPE_MD5
19
+ Digest::MD5.hexdigest(string_sign_temp).upcase
20
+ elsif sign_type == SIGN_TYPE_HMAC_SHA256
21
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, string_sign_temp).upcase
22
+ else
23
+ warn("WxPay Warn: unknown sign_type : #{sign_type}")
24
+ end
13
25
  end
14
26
 
15
27
  def self.verify?(params, options = {})
@@ -1,3 +1,3 @@
1
1
  module WxPay
2
- VERSION = '0.17.0'.freeze
2
+ VERSION = '0.18.0'.freeze
3
3
  end
@@ -14,19 +14,29 @@ class WxPay::SignTest < MiniTest::Test
14
14
  total_fee: 1
15
15
  }
16
16
 
17
- @sign = '729A68AC3DE268DBD9ADE442382E7B24'
17
+ @sign_md5 = '729A68AC3DE268DBD9ADE442382E7B24'
18
+ @sign_hmac_sha256 = 'A58C01F990B45A4D0E496F835B2739E391C6C734927B1DA740DC873E607FB42A'
18
19
  end
19
20
 
20
21
  def test_generate_sign
21
- assert_equal @sign, WxPay::Sign.generate(@params)
22
+ assert_equal @sign_md5, WxPay::Sign.generate(@params)
23
+ end
24
+
25
+ def test_generate_sign_md5
26
+ assert_equal @sign_md5, WxPay::Sign.generate(@params, WxPay::Sign::SIGN_TYPE_MD5)
27
+ end
28
+
29
+ def test_generate_sign_hmac_sha256
30
+ @params.merge!(key: "key")
31
+ assert_equal @sign_hmac_sha256, WxPay::Sign.generate(@params, WxPay::Sign::SIGN_TYPE_HMAC_SHA256)
22
32
  end
23
33
 
24
34
  def test_verify_sign
25
- assert WxPay::Sign.verify?(@params.merge(:sign => @sign))
35
+ assert WxPay::Sign.verify?(@params.merge(:sign => @sign_md5))
26
36
  end
27
37
 
28
38
  def test_verify_sign_when_fails
29
- assert !WxPay::Sign.verify?(@params.merge(:danger => 'danger', :sign => @sign))
39
+ assert !WxPay::Sign.verify?(@params.merge(:danger => 'danger', :sign => @sign_md5))
30
40
  end
31
41
 
32
42
  def test_accept_pars_key_to_generate_sign
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wx_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-09 00:00:00.000000000 Z
11
+ date: 2018-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.7.4
135
+ rubygems_version: 2.7.6
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: An unofficial simple wechat pay gem