wechat-pay 1.0.4 → 1.0.6
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 +4 -4
- data/.github/workflows/test.yml +33 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.yardopts +3 -0
- data/Gemfile +16 -0
- data/README.md +92 -0
- data/Rakefile +19 -0
- data/lib/wechat-pay/version.rb +1 -1
- data/wechat-pay.gemspec +26 -0
- metadata +9 -2
- data/lib/set_base_envrionment.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f70f650e820e974fc587e7913dbd17290c515f77ce5666e6267fcd5a8dadce7
|
4
|
+
data.tar.gz: 77b844c39432a5141b3ed9a837e03e3d07657b9668b9001828d479072dc20d79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ce9abbf28b2bc2e49a2c45ca0b6ce732dd4707e241fd065e7d8408e4ce09c9f23b97d73fa9b48dda9efd49ca6055e42130df7f7e30f0f0fbd875932dd530cc1
|
7
|
+
data.tar.gz: 8f590370a5cb1b0aacaeb874edad07325c72cc6391f4247efbb20bbccb731f7d9dc44a7815de3a6c9e8c19ca1c03683390b96fb4a6913f3d732ae3e3d2bdef29
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
pull_request:
|
12
|
+
branches: [ master ]
|
13
|
+
|
14
|
+
jobs:
|
15
|
+
test:
|
16
|
+
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
strategy:
|
19
|
+
matrix:
|
20
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
21
|
+
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
- name: Set up Ruby
|
25
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
26
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
27
|
+
# uses: ruby/setup-ruby@v1
|
28
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
29
|
+
with:
|
30
|
+
ruby-version: ${{ matrix.ruby-version }}
|
31
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
32
|
+
- name: Run tests
|
33
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Declare your gem's dependencies in tenpay.gemspec.
|
6
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
7
|
+
# development dependencies will be added by default to the :development group.
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
# Declare any dependencies that are still in development here instead of in
|
11
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
12
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
13
|
+
# your gem to rubygems.org.
|
14
|
+
|
15
|
+
# To use debugger
|
16
|
+
gem 'rubocop', require: false
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Wechat Pay
|
2
|
+
|
3
|
+
A simple Wechat pay ruby gem, without unnecessary magic or wrapper. Just a simple wrapper for api V3. Refer to [wx_pay](https://github.com/jasl/wx_pay)
|
4
|
+
|
5
|
+
Please read official document first: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/pages/index.shtml
|
6
|
+
|
7
|
+
If you want check the present public api, you can find them in the [Document](https://www.rubydoc.info/github/lanzhiheng/wechat-pay/master/index)。
|
8
|
+
|
9
|
+
Summary:
|
10
|
+
|
11
|
+
`WechatPay::Direct` will contain the public api for direct connection merchant(直连商户)and `WechatPay::Ecommerce` will contain the public api for ecommerce(服务商,电商平台)。For more detail you can refer to the wechat document.
|
12
|
+
|
13
|
+
- 直连商户: https://pay.weixin.qq.com/wiki/doc/apiv3/index.shtml
|
14
|
+
- 服务商: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/index.shtml
|
15
|
+
- 电商平台(电商收付通): https://pay.weixin.qq.com/wiki/doc/apiv3_partner/open/pay/chapter3_3_3.shtml
|
16
|
+
|
17
|
+
If you find any issue in this repo, don't shy to create issues https://github.com/lanzhiheng/wechat-pay/issues
|
18
|
+
|
19
|
+
For more Information,you can check my posts: https://www.lanzhiheng.com/posts/preview/ruby-gem-for-wechat-pay-v3
|
20
|
+
|
21
|
+
# Installation
|
22
|
+
|
23
|
+
Add this line to your Gemfile:
|
24
|
+
|
25
|
+
```
|
26
|
+
gem 'wechat-pay'
|
27
|
+
```
|
28
|
+
|
29
|
+
or development version
|
30
|
+
|
31
|
+
```
|
32
|
+
gem 'wechat-pay', :github => 'lanzhiheng/wechat-pay'
|
33
|
+
```
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
```
|
38
|
+
$ bundle
|
39
|
+
```
|
40
|
+
|
41
|
+
# Usage
|
42
|
+
|
43
|
+
## Configuration
|
44
|
+
|
45
|
+
Create `config/initializer/wechat_pay.rb`and put following configurations into it
|
46
|
+
|
47
|
+
``` ruby
|
48
|
+
WechatPay.apiclient_key = File.read('apiclient_key.pem')
|
49
|
+
WechatPay.platform_cert = File.read('platform_cert.pem') # You should comment this line before downloaded platform_cert.
|
50
|
+
WechatPay.apiclient_cert = File.read('apiclient_cert.pem')
|
51
|
+
WechatPay.app_id = 'Your App Id'
|
52
|
+
WechatPay.mch_id = 'Your Mch Id'
|
53
|
+
WechatPay.mch_key = 'Your Mch Key'
|
54
|
+
```
|
55
|
+
|
56
|
+
## Download
|
57
|
+
|
58
|
+
I will provide a simple script for you to download the platform_cert
|
59
|
+
|
60
|
+
``` ruby
|
61
|
+
def download_certificate
|
62
|
+
download_path = 'Your Download Path'
|
63
|
+
raise '必须提供证书下载路径' if download_path.blank?
|
64
|
+
|
65
|
+
response = WechatPay::Ecommerce.get_certificates
|
66
|
+
|
67
|
+
raise '证书下载失败' unless response.code == 200
|
68
|
+
|
69
|
+
result = JSON.parse(response.body)
|
70
|
+
# 需要按生效日期进行排序,获取最新的证书
|
71
|
+
array = result['data'].sort_by { |item| -Time.parse(item['effective_time']).to_i }
|
72
|
+
current_data = array.first
|
73
|
+
encrypt_certificate = current_data['encrypt_certificate']
|
74
|
+
associated_data = encrypt_certificate['associated_data']
|
75
|
+
nonce = encrypt_certificate['nonce']
|
76
|
+
ciphertext = encrypt_certificate['ciphertext']
|
77
|
+
|
78
|
+
content = WechatPay::Sign.decrypt_the_encrypt_params(
|
79
|
+
associated_data: associated_data,
|
80
|
+
nonce: nonce,
|
81
|
+
ciphertext: ciphertext
|
82
|
+
)
|
83
|
+
|
84
|
+
File.open(download_path, 'w') do |f|
|
85
|
+
f.write(content)
|
86
|
+
end
|
87
|
+
|
88
|
+
puts '证书下载成功'
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
task :default => :spec
|
9
|
+
rescue LoadError
|
10
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rdoc/task'
|
14
|
+
Rake::RDocTask.new do |rdoc|
|
15
|
+
rdoc.rdoc_dir = 'rdoc'
|
16
|
+
rdoc.title = "wechat-pay #{WechatPay::VERSION}"
|
17
|
+
rdoc.rdoc_files.include('README*')
|
18
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
19
|
+
end
|
data/lib/wechat-pay/version.rb
CHANGED
data/wechat-pay.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
|
5
|
+
require 'wechat-pay/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'wechat-pay'
|
9
|
+
s.version = WechatPay::VERSION
|
10
|
+
s.summary = 'Wechat Pay in api V3'
|
11
|
+
s.description = 'A simple Wechat pay ruby gem in api V3.'
|
12
|
+
s.authors = ['lanzhiheng']
|
13
|
+
s.email = 'lanzhihengrj@gmail.com'
|
14
|
+
s.files = %x(git ls-files -z).split("\x0").reject do |f|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
16
|
+
end
|
17
|
+
s.required_ruby_version = '>= 2.5'
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
s.homepage = 'https://github.com/lanzhiheng/wechat-pay/'
|
20
|
+
s.license = 'MIT'
|
21
|
+
|
22
|
+
s.add_runtime_dependency 'activesupport', '>= 3.2', '~> 6.0.0'
|
23
|
+
s.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.0'
|
24
|
+
s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.3'
|
25
|
+
s.add_development_dependency 'rspec', '~> 3.10.0'
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat-pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lanzhiheng
|
@@ -90,7 +90,13 @@ executables: []
|
|
90
90
|
extensions: []
|
91
91
|
extra_rdoc_files: []
|
92
92
|
files:
|
93
|
-
-
|
93
|
+
- ".github/workflows/test.yml"
|
94
|
+
- ".gitignore"
|
95
|
+
- ".rspec"
|
96
|
+
- ".yardopts"
|
97
|
+
- Gemfile
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
94
100
|
- lib/wechat-pay.rb
|
95
101
|
- lib/wechat-pay/direct.rb
|
96
102
|
- lib/wechat-pay/ecommerce.rb
|
@@ -106,6 +112,7 @@ files:
|
|
106
112
|
- lib/wechat-pay/helper.rb
|
107
113
|
- lib/wechat-pay/sign.rb
|
108
114
|
- lib/wechat-pay/version.rb
|
115
|
+
- wechat-pay.gemspec
|
109
116
|
homepage: https://github.com/lanzhiheng/wechat-pay/
|
110
117
|
licenses:
|
111
118
|
- MIT
|
data/lib/set_base_envrionment.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
WechatPay.apiclient_key = File.read('./apiclient_key.pem')
|
4
|
-
WechatPay.platform_cert = File.read('platform_cert.pem')
|
5
|
-
WechatPay.apiclient_cert = File.read('apiclient_cert.pem')
|
6
|
-
WechatPay.app_id = 'wxf50e9a05a23a7624'
|
7
|
-
WechatPay.mch_id = '1607189890'
|
8
|
-
WechatPay.mch_key = 'b76a5cc5fae2d222dba6caf5537204c4'
|