alipay_mini 0.1.0 → 0.1.1

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: 82877c7848d2ea38add95626da34d271b4dd7aab9d65d30eca5f098960b88663
4
- data.tar.gz: 12ec68458d3b6e0f1efb54ea7b84f9467e74e5d2446dfc3c0ccfadde1d2920ca
3
+ metadata.gz: 74b7d1389c2a993eaf12b6dd616e951d6fa79689135ca1be6dada4cb2246a65c
4
+ data.tar.gz: 8b766e50583ab2c24a760548be6c2da0ae72ee2d54e9410a80e9922e8851cf38
5
5
  SHA512:
6
- metadata.gz: 598028509fd7f45f3f58f5825bc11c108a87f6b73427acf7a56d83dbe9cc43483b77f56b4737b39df53915a527899cea36df3ab77fc93a782caa9b26f2cd1a41
7
- data.tar.gz: 76c81ca22bd870038655cea0b0d5c1b4768e499247a069726d015d127d12a0c2074a66a18d096fc248d3e8f668a68eca6bd09b5f814e6f7d8f94d30fa3f9ea75
6
+ metadata.gz: 3f75f59740829d260aee3e7a70a47766df029c4e57996691001c9c76666a753ab1db10869fd7d3644fcffc856ec09caf47ff5b0589766a83bf17dac0cd032aef
7
+ data.tar.gz: cdfaaf11784c7c72ee3e2b250a77c030a5e828757974b0f487570d9aa9912b9b210a663c79fc67813597546e78eff135dfda187bd1518d2160a252ae428f881e
@@ -1,5 +1,13 @@
1
+ os: osx
1
2
  sudo: false
2
3
  language: ruby
3
4
  rvm:
4
5
  - 2.5.1
5
- before_install: gem install bundler -v 1.16.1
6
+ - 2.4.4
7
+ - 2.3.6
8
+ before_install:
9
+ - gem install bundler
10
+ install:
11
+ - bundle install
12
+ script:
13
+ - bundle exec rake test
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- alipay_mini (0.1.0)
4
+ alipay_mini (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://gems.ruby-china.com/
@@ -31,4 +31,4 @@ DEPENDENCIES
31
31
  webmock
32
32
 
33
33
  BUNDLED WITH
34
- 1.16.1
34
+ 1.16.2
data/README.md CHANGED
@@ -1,39 +1,121 @@
1
+ ![](https://travis-ci.com/renyijiu/alipay_mini.svg?branch=master)
2
+ [![Gem Version](https://badge.fury.io/rb/alipay_mini.svg)](https://badge.fury.io/rb/alipay_mini)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/38ee73000994e3721c04/maintainability)](https://codeclimate.com/github/renyijiu/alipay_mini/maintainability)
4
+
5
+ [English](https://github.com/renyijiu/alipay_mini/blob/master/README_en.md)
6
+
1
7
  # AlipayMini
2
8
 
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/alipay_mini`. To experiment with that code, run `bin/console` for an interactive prompt.
9
+ 一个非官方的支付宝小程序相关的gem包。
4
10
 
5
- TODO: Delete this and the text above, and describe your gem
11
+ 由于官方未提供Ruby版本的服务端SDK,所以对于小程序开放的接口进行Ruby版本的封装。
6
12
 
7
- ## Installation
13
+ ## 安装
8
14
 
9
- Add this line to your application's Gemfile:
15
+ Gemfile中添加下列命令:
10
16
 
11
17
  ```ruby
12
- gem 'alipay_mini'
18
+ gem 'alipay_mini', '~> 0.1.0'
13
19
  ```
14
20
 
15
- And then execute:
21
+ 执行下列命令:
16
22
 
17
23
  $ bundle
18
24
 
19
- Or install it yourself as:
25
+ 或者通过命令行安装gem:
20
26
 
21
27
  $ gem install alipay_mini
22
28
 
23
- ## Usage
29
+ ## 使用
30
+
31
+ ### Config配置
32
+
33
+ 首先配置的初始选项
34
+
35
+ ```ruby
36
+ AlipayMini.configure do |c|
37
+ c.private_key = "your own private key generate by alipay"
38
+ c.public_key = "the alipay's public key"
39
+ c.url = "the alipay api url"
40
+ c.app_id = "your own app_id"
41
+ end
42
+ ```
43
+
44
+ > 注意⚠️: public_key 为支付宝官方的公钥,不要填错了!!!
45
+
46
+ 示例:
47
+
48
+ ```ruby
49
+ AlipayMini.configure do |c|
50
+ c.private_key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82ldAiZwAxncdivMuRuVXWEfAQ+e2HR/t+DrsPE9tguqPkFDOmdc5/XsQq0tZyp5kM2lNjNsCIrFdv0bFRdbnYH4RcR8KFTjHMXMYHPr4tJAjG7xxJokXkqxfSfjgK/kOHRHAprc3VhAo0SmcMx+0QKBgEZakzbYcb1SzGAMjRiWAhQgSVP6+caNSy4zI84ro1sAJsBTz30lOOTloyLCO5dNAWyVnzeGNCS3rB56VDBs5fDiAiYCcT2KjE6EpOGMXBiAhffwG7F6nnA5bFIEi62gPElxyjAm2RO/UAlgSoq9QJWdhjQR5M336j2o2ENKOPSBAoGAeeduPyZrc2oa3zJJdgMuSN8zrfG9OMYIeGfBkAv5YPrqpYryn9w0FDj+aHLsCwiVOZPeS39ySa/0+7j7rnw/fAS2meHguosE5PlQgQfTG1V24xogPwXoBP1b3dgyC18JHWQu/wucEe9a11VTVHqY7rMDEcL6R0WPljCxNChnj5Q="
51
+ c.public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoBr6Ag68Dlbf/ZNvqNotNpe2pDei58ObbD7SNEWjMx8CpTTIOqgwbCL0EHuUAF1fxOP42uLd4n/fEdbU0BNkd+4TL71P49Fq4wMXyqoYm+EzEZ8mBnevKtPPb813L1W2thZVISNWMR67axyy6xMk77YOEqRUz3hfJlowm9us8YgHranx+O1vR8olgVTdhjOub9QD/tK7ok1GWSw/dBFpcG9WTuKnPrklMIBxUllIONciH+7KGX+Yhs0zLTEPRufATAy1slIC8NhoBSxSB0PRsix4/gVCw4IAIzGPspdRPA0ZCeJPrjGvuBh9215lNpv0+ew6/a/x3db0ZIVDzLrzyQIDAQAB"
52
+ c.app_id = "2015102700040153"
53
+ c.url = "https://openapi.alipaydev.com/gateway.do"
54
+ end
55
+ ```
24
56
 
25
- TODO: Write usage instructions here
57
+ ## API
58
+
59
+ ### [alipay.system.oauth.token](https://docs.open.alipay.com/api_9/alipay.system.oauth.token)
60
+
61
+ ```ruby
62
+ # when grant_type is 'authorization_code', code is the auth_code
63
+ # when grant_type is 'refresh_token', code is the refresh_token
64
+ #
65
+ # @param grant_type String - 'authorization_code', 'refresh_token'
66
+ # @param code String - auth_code or refresh_token
67
+ #
68
+ # @return Array - [flag<Boolean>, res<Hash>] flag: request status, res: response hash
69
+ #
70
+ # Example:
71
+ # AlipayMini.system_oauth_token('authorization_code', 'helloworld')
72
+ #
73
+
74
+ AlipayMini.system_oauth_token(grant_type, code)
75
+ ```
76
+ ### [alipay.user.info.share](https://docs.open.alipay.com/api_2/alipay.user.info.share)
77
+
78
+ ```ruby
79
+ # @param access_token String
80
+ #
81
+ # @return Array [flag<Boolean>, res<Hash>]
82
+ #
83
+ # Example:
84
+ # AlipayMini.user_info_share("helloworld")
85
+ #
86
+
87
+ AlipayMini.user_info_share(access_token)
88
+ ```
89
+
90
+ ### Response
91
+
92
+ ```ruby
93
+ # flag: request state, true is success, false means the request error
94
+ #
95
+ # Example:
96
+ # AlipayMini.system_oauth_token('authorization_code', 'helloworld')
97
+ #
98
+ # Return:
99
+ # [true, {"access_token" => "12345", "alipay_user_id" => "12345", "expires_in" => 1296000, "re_expires_in" => 2592000, "refresh_token" => "12345", "user_id"=> "12345"}]
100
+ #
101
+ # [false, {"code" => "40002", "msg" => "Invalid Arguments", "sub_code" => "isv.code-invalid", "sub_msg" => "授权码code无效"}]]
102
+ #
103
+ ```
26
104
 
27
- ## Development
105
+ ## 进度
28
106
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
107
+ ### 已完成
30
108
 
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).
109
+ 1. [换取授权访问令牌](https://docs.open.alipay.com/api_9/alipay.system.oauth.token)(alipay.user.info.share)
110
+ 2. [支付宝会员授权信息查询接口](https://docs.open.alipay.com/api_2/alipay.user.info.share)(alipay.user.info.share)
32
111
 
33
- ## Contributing
34
112
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/alipay_mini. 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.
113
+ ## 如何贡献
36
114
 
37
- ## Code of Conduct
115
+ 1. Fork it
116
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
117
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
118
+ 4. Push to the branch (`git push origin my-new-feature`)
119
+ 5. Create new Pull Request
38
120
 
39
- Everyone interacting in the AlipayMini project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/alipay_mini/blob/master/CODE_OF_CONDUCT.md).
121
+ 欢迎贡献相关代码或是提交你的使用反馈👏,另外请记得为你的代码编写测试。
@@ -0,0 +1,114 @@
1
+ ![](https://travis-ci.com/renyijiu/alipay_mini.svg?branch=master)
2
+ [![Gem Version](https://badge.fury.io/rb/alipay_mini.svg)](https://badge.fury.io/rb/alipay_mini)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/38ee73000994e3721c04/maintainability)](https://codeclimate.com/github/renyijiu/alipay_mini/maintainability)
4
+
5
+ # AlipayMini
6
+
7
+ An unofficial simple gem for alipay mini program.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'alipay_mini', '~> 0.1.0'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install alipay_mini
24
+
25
+ ## Usage
26
+
27
+ ### Config
28
+
29
+ Setup the config first.
30
+
31
+ ```ruby
32
+ AlipayMini.configure do |c|
33
+ c.private_key = "your own private key generate by alipay"
34
+ c.public_key = "the alipay's public key"
35
+ c.url = "the alipay api url"
36
+ c.app_id = "your own app_id"
37
+ end
38
+ ```
39
+ > Attention: the public key is alipay's official public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yfMR1sQU2S2/CkRniluJt42ywSm9xXqtYXD3oF50LBUCgYAEbg56US8khUZftftRA3qz82ldAiZwAxncdivMuRuVXWEfAQ+e2HR/t+DrsPE9tguqPkFDOmdc5/XsQq0tZyp5kM2lNjNsCIrFdv0bFRdbnYH4RcR8KFTjHMXMYHPr4tJAjG7xxJokXkqxfSfjgK/kOHRHAprc3VhAo0SmcMx+0QKBgEZakzbYcb1SzGAMjRiWAhQgSVP6+caNSy4zI84ro1sAJsBTz30lOOTloyLCO5dNAWyVnzeGNCS3rB56VDBs5fDiAiYCcT2KjE6EpOGMXBiAhffwG7F6nnA5bFIEi62gPElxyjAm2RO/UAlgSoq9QJWdhjQR5M336j2o2ENKOPSBAoGAeeduPyZrc2oa3zJJdgMuSN8zrfG9OMYIeGfBkAv5YPrqpYryn9w0FDj+aHLsCwiVOZPeS39ySa/0+7j7rnw/fAS2meHguosE5PlQgQfTG1V24xogPwXoBP1b3dgyC18JHWQu/wucEe9a11VTVHqY7rMDEcL6R0WPljCxNChnj5Q="
46
+ c.public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoBr6Ag68Dlbf/ZNvqNotNpe2pDei58ObbD7SNEWjMx8CpTTIOqgwbCL0EHuUAF1fxOP42uLd4n/fEdbU0BNkd+4TL71P49Fq4wMXyqoYm+EzEZ8mBnevKtPPb813L1W2thZVISNWMR67axyy6xMk77YOEqRUz3hfJlowm9us8YgHranx+O1vR8olgVTdhjOub9QD/tK7ok1GWSw/dBFpcG9WTuKnPrklMIBxUllIONciH+7KGX+Yhs0zLTEPRufATAy1slIC8NhoBSxSB0PRsix4/gVCw4IAIzGPspdRPA0ZCeJPrjGvuBh9215lNpv0+ew6/a/x3db0ZIVDzLrzyQIDAQAB"
47
+ c.app_id = "2015102700040153"
48
+ c.url = "https://openapi.alipaydev.com/gateway.do"
49
+ end
50
+ ```
51
+
52
+ ## API
53
+
54
+ ### [alipay.system.oauth.token](https://docs.open.alipay.com/api_9/alipay.system.oauth.token)
55
+
56
+ ```ruby
57
+ # when grant_type is 'authorization_code', code is the auth_code
58
+ # when grant_type is 'refresh_token', code is the refresh_token
59
+ #
60
+ # @param grant_type String - 'authorization_code', 'refresh_token'
61
+ # @param code String - auth_code or refresh_token
62
+ #
63
+ # @return Array - [flag<Boolean>, res<Hash>] flag: request status, res: response hash
64
+ #
65
+ # Example:
66
+ # AlipayMini.system_oauth_token('authorization_code', 'helloworld')
67
+ #
68
+
69
+ AlipayMini.system_oauth_token(grant_type, code)
70
+ ```
71
+ ### [alipay.user.info.share](https://docs.open.alipay.com/api_2/alipay.user.info.share)
72
+
73
+ ```ruby
74
+ # @param access_token String
75
+ #
76
+ # @return Array [flag<Boolean>, res<Hash>]
77
+ #
78
+ # Example:
79
+ # AlipayMini.user_info_share("helloworld")
80
+ #
81
+
82
+ AlipayMini.user_info_share(access_token)
83
+ ```
84
+
85
+ ### Response
86
+
87
+ ```ruby
88
+ # flag: request state, true is success, false means the request error
89
+ #
90
+ # Example:
91
+ # AlipayMini.system_oauth_token('authorization_code', 'helloworld')
92
+ #
93
+ # Return:
94
+ # [true, {"access_token" => "12345", "alipay_user_id" => "12345", "expires_in" => 1296000, "re_expires_in" => 2592000, "refresh_token" => "12345", "user_id"=> "12345"}]
95
+ #
96
+ # [false, {"code" => "40002", "msg" => "Invalid Arguments", "sub_code" => "isv.code-invalid", "sub_msg" => "授权码code无效"}]]
97
+ #
98
+ ```
99
+
100
+ ## Schedule
101
+
102
+ ### Done
103
+ 1. [alipay.user.info.share](https://docs.open.alipay.com/api_9/alipay.system.oauth.token)
104
+ 2. [alipay.user.info.share](https://docs.open.alipay.com/api_2/alipay.user.info.share)
105
+
106
+ ## Contributing
107
+
108
+ 1. Fork it
109
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
110
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
111
+ 4. Push to the branch (`git push origin my-new-feature`)
112
+ 5. Create new Pull Request
113
+
114
+ Bug report or pull request are welcome. Please write unit test with your code if necessary
@@ -7,6 +7,7 @@ require "alipay_mini/request"
7
7
  require "alipay_mini/api/alipay_base"
8
8
  require "alipay_mini/api/system_oauth_token"
9
9
  require "alipay_mini/api/user_info_share"
10
+ require "alipay_mini/api/trade_create"
10
11
 
11
12
  module AlipayMini
12
13
 
@@ -20,6 +21,16 @@ module AlipayMini
20
21
  Config.instance.configuration
21
22
  end
22
23
 
24
+ # synchronize notify verify sign
25
+ def verify?(params, options = {})
26
+ AlipayMini::Sign.verify?(params, options)
27
+ end
28
+
29
+ # asynchronous notify verify sign
30
+ def async_verify?(params, options = {})
31
+ AlipayMini::Sign.async_verify?(params, options)
32
+ end
33
+
23
34
  # alipay.system.oauth.token api
24
35
  #
25
36
  # @params grant_type String 'authorization_code', 'refresh_token'
@@ -38,6 +49,19 @@ module AlipayMini
38
49
  def user_info_share(access_token)
39
50
  AlipayMini::Api::UserInfoShare.new.get(access_token)
40
51
  end
52
+
53
+ # https://docs.open.alipay.com/api_1/alipay.trade.create
54
+ # alipay.trade_create
55
+ #
56
+ # @params trade_no String length < 64, only letter, number, underline
57
+ # @params amount Price Accurate to two decimal places, the range of values [0.01,100000000]
58
+ # @params subject String the title of order
59
+ # @params buyer_id String the user id of taobao
60
+ #
61
+ # @return Array [flag<Boolean>, res<Hash>]
62
+ def trade_create(trade_no, amount, subject, buyer_id, options = {})
63
+ AlipayMini::Api::TradeCreate.new.get(trade_no, amount, subject, buyer_id, options)
64
+ end
41
65
  end
42
66
 
43
67
  end
@@ -3,7 +3,7 @@ module AlipayMini
3
3
  class AlipayBase
4
4
 
5
5
  def method
6
- raise ArrgumentError, "please set the correct api method name"
6
+ raise ArgumentError, "please set the correct api method name"
7
7
  end
8
8
 
9
9
  def timestamp
@@ -0,0 +1,49 @@
1
+ module AlipayMini
2
+ module Api
3
+ class TradeCreate < AlipayBase
4
+
5
+ def get(trade_no, amount, subject, buyer_id, options = {})
6
+ trade_params = get_trade_params(trade_no, amount, subject, buyer_id, options)
7
+ params = base_params.merge(trade_params)
8
+
9
+ AlipayMini::Request.get(method, sign_params(params))
10
+ end
11
+
12
+ private
13
+
14
+ def method
15
+ 'alipay.trade.create'
16
+ end
17
+
18
+ def get_trade_params(trade_no, amount, subject, buyer_id, options = {})
19
+ biz_content = {
20
+ out_trade_no: trade_no,
21
+ seller_id: options.fetch(:seller_id, nil),
22
+ total_amount: amount,
23
+ discountable_amount: options.fetch(:discountable_amount, nil),
24
+ subject: subject,
25
+ body: options.fetch(:body, nil),
26
+ buyer_id: buyer_id,
27
+ goods_detail: options.fetch(:goods_detail, nil),
28
+ operator_id: options.fetch(:operator_id, nil),
29
+ store_id: options.fetch(:store_id, nil),
30
+ terminal_id: options.fetch(:terminal_id, nil),
31
+ extend_params: options.fetch(:extend_params, nil),
32
+ timeout_express: options.fetch(:timeout_express, nil),
33
+ settle_info: options.fetch(:settle_info, nil),
34
+ logistics_detail: options.fetch(:logistics_detail, nil),
35
+ business_params: options.fetch(:business_params, nil),
36
+ receiver_address_info: options.fetch(:receiver_address_info, nil)
37
+ }
38
+ biz_content = AlipayMini::Utils.deep_compact(biz_content)
39
+
40
+ params = {
41
+ notify_url: options.fetch(:notify_url, nil),
42
+ app_auth_token: options.fetch(:app_auth_token, nil),
43
+ }
44
+
45
+ AlipayMini::Utils.deep_compact(params).merge(biz_content: biz_content.to_json)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -33,8 +33,24 @@ module AlipayMini
33
33
  else
34
34
  false
35
35
  end
36
+ end
37
+
38
+ def self.async_verify?(params, options = {})
39
+ params = Utils.stringify_keys(params)
40
+
41
+ sign_type = params.fetch('sign_type')
42
+ sign = params.delete('sign')
43
+ public_key = options[:public_key] || AlipayMini.config[:public_key]
44
+ params.delete('sign_type') if options.fetch(:delete_sign_type, true)
36
45
 
46
+ string = AlipayMini::Utils.params_to_string(params)
37
47
 
48
+ case sign_type
49
+ when 'RSA2'
50
+ RSA2.verify?(public_key, string, sign)
51
+ else
52
+ false
53
+ end
38
54
  end
39
55
 
40
56
  end
@@ -15,6 +15,16 @@ module AlipayMini
15
15
  params.sort.map{ |item| item.join('=') }.join('&')
16
16
  end
17
17
 
18
+ def self.deep_compact(hash)
19
+ return hash unless hash.is_a?(::Hash)
18
20
 
21
+ hash.each_with_object({}) do |(k, v), compact_hash|
22
+ if v.is_a?(::Hash)
23
+ compact_hash[k] = deep_compact(v)
24
+ else
25
+ compact_hash[k] = v unless v.nil?
26
+ end
27
+ end
28
+ end
19
29
  end
20
30
  end
@@ -1,3 +1,3 @@
1
1
  module AlipayMini
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alipay_mini
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - renyijiu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-21 00:00:00.000000000 Z
11
+ date: 2019-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,7 @@ files:
80
80
  - Gemfile.lock
81
81
  - LICENSE
82
82
  - README.md
83
+ - README_en.md
83
84
  - Rakefile
84
85
  - alipay_mini.gemspec
85
86
  - bin/console
@@ -87,6 +88,7 @@ files:
87
88
  - lib/alipay_mini.rb
88
89
  - lib/alipay_mini/api/alipay_base.rb
89
90
  - lib/alipay_mini/api/system_oauth_token.rb
91
+ - lib/alipay_mini/api/trade_create.rb
90
92
  - lib/alipay_mini/api/user_info_share.rb
91
93
  - lib/alipay_mini/config.rb
92
94
  - lib/alipay_mini/request.rb
@@ -114,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
116
  version: '0'
115
117
  requirements: []
116
118
  rubyforge_project:
117
- rubygems_version: 2.7.6
119
+ rubygems_version: 2.7.7
118
120
  signing_key:
119
121
  specification_version: 4
120
122
  summary: An unofficial simple alipay mini program gem