wechat-ipay 2.0.0 → 2.1.0
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/CHANGELOG.md +2 -2
- data/README.md +14 -14
- data/Rakefile +1 -1
- data/lib/{wechat-pay → wechat-ipay}/direct.rb +21 -21
- data/lib/{wechat-pay → wechat-ipay}/ecommerce/applyment.rb +9 -9
- data/lib/{wechat-pay → wechat-ipay}/ecommerce/balance.rb +7 -7
- data/lib/{wechat-pay → wechat-ipay}/ecommerce/bill.rb +4 -4
- data/lib/{wechat-pay → wechat-ipay}/ecommerce/combine_order.rb +7 -7
- data/lib/{wechat-pay → wechat-ipay}/ecommerce/order.rb +9 -9
- data/lib/{wechat-pay → wechat-ipay}/ecommerce/profitsharing.rb +15 -15
- data/lib/{wechat-pay → wechat-ipay}/ecommerce/refund.rb +10 -10
- data/lib/{wechat-pay → wechat-ipay}/ecommerce/subsidies.rb +4 -4
- data/lib/{wechat-pay → wechat-ipay}/ecommerce/withdraw.rb +9 -9
- data/lib/{wechat-pay → wechat-ipay}/ecommerce.rb +14 -14
- data/lib/{wechat-pay → wechat-ipay}/helper.rb +2 -2
- data/lib/{wechat-pay → wechat-ipay}/sign.rb +15 -15
- data/lib/wechat-ipay/version.rb +5 -0
- data/lib/{wechat-pay.rb → wechat-ipay.rb} +5 -5
- data/wechat-ipay.gemspec +3 -3
- metadata +18 -18
- data/lib/wechat-pay/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c3c0ede615d2ba3525d653d30c7cb37fd1562d72b613d2cb707456349de0f44
|
4
|
+
data.tar.gz: 7d0c510fc331d96cf847adfb52e73bc1192fdba43e5f60379d593d4b158b47c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d81afdc678623d501427e4d65ec709f933143068aeda2e1f14d5e72eb85632d9aaf0ced3f8ae8671d2d6ec8f5821a06ccbf1c682389a03e99884833f84e42540
|
7
|
+
data.tar.gz: eb34d1ee9cce9a1843a510f221227357191e2ba5520450bd2d8778a240b21741b6ee12869db9e668072530ed2e10ea3faebc0a803109c1db8ae1afc626e9c390
|
data/CHANGELOG.md
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
|
8
8
|
## 1.0.8 (05/26/2021)
|
9
9
|
|
10
|
-
* Add api `invoke_transactions_in_native` to `
|
10
|
+
* Add api `invoke_transactions_in_native` to `WechatIpay::Ecommerce`
|
11
11
|
|
12
12
|
## 1.0.7 (05/16/2021)
|
13
13
|
|
14
|
-
* Change `
|
14
|
+
* Change `WechatIpay::Ecommerce.get_certificates` to `WechatIpay::Ecommerce.certificates`
|
15
15
|
* Refactor code and document.
|
data/README.md
CHANGED
@@ -4,32 +4,32 @@ A simple Wechat pay ruby gem, without unnecessary magic or wrapper. Just a simpl
|
|
4
4
|
|
5
5
|
Please read official document first: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/pages/index.shtml
|
6
6
|
|
7
|
-
If you want check the present public api, you can find them in the [Document](https://www.rubydoc.info/github/lanzhiheng/wechat-
|
7
|
+
If you want check the present public api, you can find them in the [Document](https://www.rubydoc.info/github/lanzhiheng/wechat-ipay/master/index)。
|
8
8
|
|
9
9
|
Summary:
|
10
10
|
|
11
|
-
`
|
11
|
+
`WechatIpay::Direct` will contain the public api for direct connection merchant(直连商户)and `WechatIpay::Ecommerce` will contain the public api for ecommerce(服务商,电商平台)。For more detail you can refer to the wechat document.
|
12
12
|
|
13
13
|
- 直连商户: https://pay.weixin.qq.com/wiki/doc/apiv3/index.shtml
|
14
14
|
- 服务商: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/index.shtml
|
15
15
|
- 电商平台(电商收付通): https://pay.weixin.qq.com/wiki/doc/apiv3_partner/open/pay/chapter3_3_3.shtml
|
16
16
|
|
17
|
-
If you find any issue in this repo, don't shy to create issues https://github.com/lanzhiheng/wechat-
|
17
|
+
If you find any issue in this repo, don't shy to create issues https://github.com/lanzhiheng/wechat-ipay/issues
|
18
18
|
|
19
|
-
For more Information,you can check my posts: https://www.lanzhiheng.com/posts/preview/ruby-gem-for-wechat-
|
19
|
+
For more Information,you can check my posts: https://www.lanzhiheng.com/posts/preview/ruby-gem-for-wechat-ipay-v3
|
20
20
|
|
21
21
|
# Installation
|
22
22
|
|
23
23
|
Add this line to your Gemfile:
|
24
24
|
|
25
25
|
```
|
26
|
-
gem 'wechat-
|
26
|
+
gem 'wechat-ipay', '~> 2.0.0'
|
27
27
|
```
|
28
28
|
|
29
29
|
or development version
|
30
30
|
|
31
31
|
```
|
32
|
-
gem 'wechat-
|
32
|
+
gem 'wechat-ipay', :github => 'tianlu1677/wechat-ipay'
|
33
33
|
```
|
34
34
|
|
35
35
|
And then execute:
|
@@ -45,12 +45,12 @@ $ bundle
|
|
45
45
|
Create `config/initializer/wechat_pay.rb`and put following configurations into it
|
46
46
|
|
47
47
|
``` ruby
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
WechatIpay.apiclient_key = File.read('apiclient_key.pem')
|
49
|
+
WechatIpay.platform_cert = File.read('platform_cert.pem') # You should comment this line before downloaded platform_cert.
|
50
|
+
WechatIpay.apiclient_cert = File.read('apiclient_cert.pem')
|
51
|
+
WechatIpay.app_id = 'Your App Id'
|
52
|
+
WechatIpay.mch_id = 'Your Mch Id'
|
53
|
+
WechatIpay.mch_key = 'Your Mch Key'
|
54
54
|
```
|
55
55
|
|
56
56
|
## Download
|
@@ -62,7 +62,7 @@ def download_certificate
|
|
62
62
|
download_path = 'Your Download Path'
|
63
63
|
raise '必须提供证书下载路径' if download_path.blank?
|
64
64
|
|
65
|
-
response =
|
65
|
+
response = WechatIpay::Ecommerce.certificates
|
66
66
|
|
67
67
|
raise '证书下载失败' unless response.code == 200
|
68
68
|
|
@@ -75,7 +75,7 @@ def download_certificate
|
|
75
75
|
nonce = encrypt_certificate['nonce']
|
76
76
|
ciphertext = encrypt_certificate['ciphertext']
|
77
77
|
|
78
|
-
content =
|
78
|
+
content = WechatIpay::Sign.decrypt_the_encrypt_params(
|
79
79
|
associated_data: associated_data,
|
80
80
|
nonce: nonce,
|
81
81
|
ciphertext: ciphertext
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ end
|
|
13
13
|
require 'rdoc/task'
|
14
14
|
Rake::RDocTask.new do |rdoc|
|
15
15
|
rdoc.rdoc_dir = 'rdoc'
|
16
|
-
rdoc.title = "wechat-
|
16
|
+
rdoc.title = "wechat-ipay #{WechatIpay::VERSION}"
|
17
17
|
rdoc.rdoc_files.include('README*')
|
18
18
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
19
19
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'json'
|
4
|
-
require 'wechat-
|
4
|
+
require 'wechat-ipay/helper'
|
5
5
|
|
6
|
-
module
|
6
|
+
module WechatIpay
|
7
7
|
# # 直连商户相关接口封装(常用的已有,待完善)
|
8
8
|
# 文档: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
|
9
9
|
module Direct
|
10
|
-
include
|
10
|
+
include WechatIpayHelper
|
11
11
|
|
12
12
|
# @private
|
13
13
|
# @!macro [attach] define_transaction_method
|
@@ -32,7 +32,7 @@ module WechatPay
|
|
32
32
|
# notify_url: ENV['NOTIFICATION_URL']
|
33
33
|
# }
|
34
34
|
#
|
35
|
-
#
|
35
|
+
# WechatIpay::Direct.invoke_transactions_in_$1(params)
|
36
36
|
# ```
|
37
37
|
# @!method invoke_transactions_in_$1
|
38
38
|
# @!scope class
|
@@ -78,7 +78,7 @@ module WechatPay
|
|
78
78
|
# notify_url: 'the_url'
|
79
79
|
# }
|
80
80
|
#
|
81
|
-
#
|
81
|
+
# WechatIpay::Direct.invoke_combine_transactions_in_$1(params)
|
82
82
|
# ```
|
83
83
|
# @!method invoke_combine_transactions_in_$1
|
84
84
|
# @!scope class
|
@@ -86,7 +86,7 @@ module WechatPay
|
|
86
86
|
const_set("INVOKE_COMBINE_TRANSACTIONS_IN_#{key.upcase}_FIELDS",
|
87
87
|
%i[combine_out_trade_no scene_info sub_orders notify_url].freeze)
|
88
88
|
define_singleton_method("invoke_combine_transactions_in_#{key}") do |params|
|
89
|
-
|
89
|
+
WechatIpay::Ecommerce.send("invoke_combine_transactions_in_#{key}", params)
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -105,7 +105,7 @@ module WechatPay
|
|
105
105
|
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
106
106
|
#
|
107
107
|
# ``` ruby
|
108
|
-
#
|
108
|
+
# WechatIpay::Direct.query_order(combine_out_trade_no: 'C202104302474')
|
109
109
|
# ```
|
110
110
|
#
|
111
111
|
def self.query_combine_order(params)
|
@@ -133,7 +133,7 @@ module WechatPay
|
|
133
133
|
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
134
134
|
#
|
135
135
|
# ``` ruby
|
136
|
-
#
|
136
|
+
# WechatIpay::Direct.close_combine_order(combine_out_trade_no: 'C202104302474')
|
137
137
|
# ```
|
138
138
|
def self.close_combine_order(params)
|
139
139
|
combine_out_trade_no = params.delete(:combine_out_trade_no)
|
@@ -141,7 +141,7 @@ module WechatPay
|
|
141
141
|
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}/close"
|
142
142
|
|
143
143
|
payload = {
|
144
|
-
combine_appid:
|
144
|
+
combine_appid: WechatIpay.app_id
|
145
145
|
}.merge(params)
|
146
146
|
|
147
147
|
payload_json = payload.to_json
|
@@ -165,8 +165,8 @@ module WechatPay
|
|
165
165
|
# Example:
|
166
166
|
#
|
167
167
|
# ``` ruby
|
168
|
-
#
|
169
|
-
#
|
168
|
+
# WechatIpay::Direct.query_order(transaction_id: '4323400972202104305133344444') # by transaction_id
|
169
|
+
# WechatIpay::Direct.query_order(out_trade_no: 'N202104302474') # by out_trade_no
|
170
170
|
# ```
|
171
171
|
#
|
172
172
|
def self.query_order(params)
|
@@ -181,7 +181,7 @@ module WechatPay
|
|
181
181
|
end
|
182
182
|
|
183
183
|
params = params.merge({
|
184
|
-
mchid:
|
184
|
+
mchid: WechatIpay.mch_id
|
185
185
|
})
|
186
186
|
|
187
187
|
method = 'GET'
|
@@ -206,14 +206,14 @@ module WechatPay
|
|
206
206
|
# Example:
|
207
207
|
#
|
208
208
|
# ``` ruby
|
209
|
-
#
|
209
|
+
# WechatIpay::Direct.close_order(out_trade_no: 'N3344445')
|
210
210
|
# ```
|
211
211
|
#
|
212
212
|
def self.close_order(params)
|
213
213
|
out_trade_no = params.delete(:out_trade_no)
|
214
214
|
url = "/v3/pay/transactions/out-trade-no/#{out_trade_no}/close"
|
215
215
|
params = params.merge({
|
216
|
-
mchid:
|
216
|
+
mchid: WechatIpay.mch_id
|
217
217
|
})
|
218
218
|
|
219
219
|
method = 'POST'
|
@@ -235,8 +235,8 @@ module WechatPay
|
|
235
235
|
# Example:
|
236
236
|
#
|
237
237
|
# ``` ruby
|
238
|
-
#
|
239
|
-
#
|
238
|
+
# WechatIpay::Direct.invoke_refund(transaction_id: '4323400972202104305131070170', total: 1, refund: 1, out_refund_no: 'R10000')
|
239
|
+
# WechatIpay::Direct.invoke_refund(out_trade_no: 'N2021', total: 1, refund: 1, out_refund_no: 'R10000').body
|
240
240
|
# ```
|
241
241
|
def self.invoke_refund(params)
|
242
242
|
url = '/v3/refund/domestic/refunds'
|
@@ -268,7 +268,7 @@ module WechatPay
|
|
268
268
|
# Example:
|
269
269
|
#
|
270
270
|
# ``` ruby
|
271
|
-
#
|
271
|
+
# WechatIpay::Direct.query_refund(out_refund_no: 'R10000')
|
272
272
|
# ```
|
273
273
|
#
|
274
274
|
def self.query_refund(params)
|
@@ -297,7 +297,7 @@ module WechatPay
|
|
297
297
|
# Example:
|
298
298
|
#
|
299
299
|
# ``` ruby
|
300
|
-
#
|
300
|
+
# WechatIpay::direct.tradebill(bill_date: '2021-04-30')
|
301
301
|
# ```
|
302
302
|
def self.tradebill(params)
|
303
303
|
path = '/v3/bill/tradebill'
|
@@ -326,7 +326,7 @@ module WechatPay
|
|
326
326
|
# Example:
|
327
327
|
#
|
328
328
|
# ``` ruby
|
329
|
-
#
|
329
|
+
# WechatIpay::Direct.fundflowbill(bill_date: '2021-04-30')
|
330
330
|
# ```
|
331
331
|
#
|
332
332
|
def self.fundflowbill(params)
|
@@ -353,8 +353,8 @@ module WechatPay
|
|
353
353
|
method = 'POST'
|
354
354
|
|
355
355
|
params = {
|
356
|
-
mchid:
|
357
|
-
appid:
|
356
|
+
mchid: WechatIpay.mch_id,
|
357
|
+
appid: WechatIpay.app_id
|
358
358
|
}.merge(params)
|
359
359
|
|
360
360
|
payload_json = params.to_json
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module WechatIpay
|
4
4
|
# 商户进件相关
|
5
5
|
module Ecommerce
|
6
6
|
# 二级商户进件
|
@@ -61,7 +61,7 @@ module WechatPay
|
|
61
61
|
# ```
|
62
62
|
#
|
63
63
|
# ``` ruby
|
64
|
-
#
|
64
|
+
# WechatIpay::Ecommerce.applyment(params)
|
65
65
|
# ```
|
66
66
|
#
|
67
67
|
def self.applyment(payload)
|
@@ -76,7 +76,7 @@ module WechatPay
|
|
76
76
|
for_sign: payload_json,
|
77
77
|
payload: payload_json,
|
78
78
|
extra_headers: {
|
79
|
-
'Wechatpay-Serial' =>
|
79
|
+
'Wechatpay-Serial' => WechatIpay.platform_serial_no
|
80
80
|
}
|
81
81
|
)
|
82
82
|
end
|
@@ -90,8 +90,8 @@ module WechatPay
|
|
90
90
|
# Example:
|
91
91
|
#
|
92
92
|
# ``` ruby
|
93
|
-
#
|
94
|
-
#
|
93
|
+
# WechatIpay::Ecommerce.query_applyment(out_request_no: 'APPLYMENT_00000000005') # by out_request_no
|
94
|
+
# WechatIpay::Ecommerce.query_applyment(applyment_id: '200040444455566667') # by_applyment_id
|
95
95
|
# ```
|
96
96
|
#
|
97
97
|
def self.query_applyment(params)
|
@@ -120,7 +120,7 @@ module WechatPay
|
|
120
120
|
# Example:
|
121
121
|
#
|
122
122
|
# ``` ruby
|
123
|
-
#
|
123
|
+
# WechatIpay::Ecommerce.certificates
|
124
124
|
# ```
|
125
125
|
#
|
126
126
|
def self.certificates
|
@@ -145,7 +145,7 @@ module WechatPay
|
|
145
145
|
# Example:
|
146
146
|
#
|
147
147
|
# ``` ruby
|
148
|
-
#
|
148
|
+
# WechatIpay::Ecommerce.query_settlement(sub_mchid: '16000000')
|
149
149
|
# ```
|
150
150
|
#
|
151
151
|
def self.query_settlement(params)
|
@@ -171,7 +171,7 @@ module WechatPay
|
|
171
171
|
# Example:
|
172
172
|
#
|
173
173
|
# ``` ruby
|
174
|
-
#
|
174
|
+
# WechatIpay::Ecommerce.modify_settlement(sub_mchid: '15000000', account_type: 'ACCOUNT_TYPE_PRIVATE', account_bank: '工商银行', bank_address_code: '110000', account_number: WechatIpay::Sign.sign_important_info('755555555'))
|
175
175
|
# ```
|
176
176
|
#
|
177
177
|
def self.modify_settlement(params)
|
@@ -187,7 +187,7 @@ module WechatPay
|
|
187
187
|
for_sign: payload_json,
|
188
188
|
payload: payload_json,
|
189
189
|
extra_headers: {
|
190
|
-
'Wechatpay-Serial' =>
|
190
|
+
'Wechatpay-Serial' => WechatIpay.platform_serial_no
|
191
191
|
}
|
192
192
|
)
|
193
193
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module WechatIpay
|
4
4
|
# 余额相关
|
5
5
|
module Ecommerce
|
6
6
|
QUERY_REALTIME_BALANCE_FIELDS = [:sub_mchid].freeze # :nodoc:
|
@@ -12,7 +12,7 @@ module WechatPay
|
|
12
12
|
# Example:
|
13
13
|
#
|
14
14
|
# ``` ruby
|
15
|
-
#
|
15
|
+
# WechatIpay::Ecommerce.query_realtime_balance(sub_mchid: '1600000')
|
16
16
|
# ```
|
17
17
|
def self.query_realtime_balance(params)
|
18
18
|
sub_mchid = params.delete(:sub_mchid)
|
@@ -37,7 +37,7 @@ module WechatPay
|
|
37
37
|
# Example:
|
38
38
|
#
|
39
39
|
# ``` ruby
|
40
|
-
#
|
40
|
+
# WechatIpay::Ecommerce.query_endday_balance(sub_mchid: '1600000', date: '2019-08-17')
|
41
41
|
# ```
|
42
42
|
def self.query_endday_balance(params)
|
43
43
|
sub_mchid = params.delete(:sub_mchid)
|
@@ -64,8 +64,8 @@ module WechatPay
|
|
64
64
|
# Example:
|
65
65
|
#
|
66
66
|
# ``` ruby
|
67
|
-
#
|
68
|
-
#
|
67
|
+
# WechatIpay::Ecommerce.query_platform_realtime_balance(account_type: 'BASIC') # basic account
|
68
|
+
# WechatIpay::Ecommerce.query_platform_realtime_balance(account_type: 'FEES') # fees account
|
69
69
|
# ```
|
70
70
|
#
|
71
71
|
def self.query_platform_realtime_balance(params)
|
@@ -91,8 +91,8 @@ module WechatPay
|
|
91
91
|
# Example:
|
92
92
|
#
|
93
93
|
# ``` ruby
|
94
|
-
#
|
95
|
-
#
|
94
|
+
# WechatIpay::Ecommerce.query_platform_endday_balance(account_type: 'BASIC')
|
95
|
+
# WechatIpay::Ecommerce.query_platform_endday_balance(account_type: 'FEES')
|
96
96
|
# ```
|
97
97
|
#
|
98
98
|
def self.query_platform_endday_balance(params)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module WechatIpay
|
4
4
|
# 账单相关
|
5
5
|
module Ecommerce
|
6
6
|
class << self
|
@@ -13,7 +13,7 @@ module WechatPay
|
|
13
13
|
# Example:
|
14
14
|
#
|
15
15
|
# ``` ruby
|
16
|
-
#
|
16
|
+
# WechatIpay::Ecommerce.tradebill(bill_date: '2021-04-30')
|
17
17
|
# ```
|
18
18
|
def tradebill(params)
|
19
19
|
path = '/v3/bill/tradebill'
|
@@ -40,7 +40,7 @@ module WechatPay
|
|
40
40
|
# Example:
|
41
41
|
#
|
42
42
|
# ``` ruby
|
43
|
-
#
|
43
|
+
# WechatIpay::Ecommerce.fundflowbill(bill_date: '2021-04-30')
|
44
44
|
# ```
|
45
45
|
#
|
46
46
|
def fundflowbill(params)
|
@@ -68,7 +68,7 @@ module WechatPay
|
|
68
68
|
# Example:
|
69
69
|
#
|
70
70
|
# ``` ruby
|
71
|
-
#
|
71
|
+
# WechatIpay::Ecommerce.ecommerce_fundflowbill(bill_date: '2021-04-30', account_type: 'ALL', algorithm: 'AEAD_AES_256_GCM')
|
72
72
|
# ```
|
73
73
|
#
|
74
74
|
def ecommerce_fundflowbill(params)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module WechatIpay
|
4
4
|
# 合并订单相关
|
5
5
|
module Ecommerce
|
6
6
|
# @private
|
@@ -33,7 +33,7 @@ module WechatPay
|
|
33
33
|
# notify_url: 'the_url'
|
34
34
|
# }
|
35
35
|
#
|
36
|
-
#
|
36
|
+
# WechatIpay::Ecommerce.invoke_combine_transactions_in_$1(params)
|
37
37
|
# ```
|
38
38
|
# @!method invoke_combine_transactions_in_$1
|
39
39
|
# @!scope class
|
@@ -58,7 +58,7 @@ module WechatPay
|
|
58
58
|
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
59
59
|
#
|
60
60
|
# ``` ruby
|
61
|
-
#
|
61
|
+
# WechatIpay::Ecommerce.query_order(combine_out_trade_no: 'C202104302474')
|
62
62
|
# ```
|
63
63
|
#
|
64
64
|
def self.query_combine_order(params)
|
@@ -84,7 +84,7 @@ module WechatPay
|
|
84
84
|
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
|
85
85
|
#
|
86
86
|
# ``` ruby
|
87
|
-
#
|
87
|
+
# WechatIpay::Ecommerce.close_combine_order(combine_out_trade_no: 'C202104302474')
|
88
88
|
# ```
|
89
89
|
def self.close_combine_order(params)
|
90
90
|
combine_out_trade_no = params.delete(:combine_out_trade_no)
|
@@ -92,7 +92,7 @@ module WechatPay
|
|
92
92
|
url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}/close"
|
93
93
|
|
94
94
|
payload = {
|
95
|
-
combine_appid:
|
95
|
+
combine_appid: WechatIpay.app_id
|
96
96
|
}.merge(params)
|
97
97
|
|
98
98
|
payload_json = payload.to_json
|
@@ -115,8 +115,8 @@ module WechatPay
|
|
115
115
|
method = 'POST'
|
116
116
|
|
117
117
|
params = {
|
118
|
-
combine_mchid:
|
119
|
-
combine_appid:
|
118
|
+
combine_mchid: WechatIpay.mch_id,
|
119
|
+
combine_appid: WechatIpay.app_id
|
120
120
|
}.merge(params)
|
121
121
|
|
122
122
|
payload_json = params.to_json
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module WechatIpay
|
4
4
|
# 订单相关
|
5
5
|
module Ecommerce
|
6
6
|
# @private
|
@@ -25,7 +25,7 @@ module WechatPay
|
|
25
25
|
# notify_url: 'the url'
|
26
26
|
# }
|
27
27
|
#
|
28
|
-
#
|
28
|
+
# WechatIpay::Ecommerce.invoke_transactions_in_$1(params)
|
29
29
|
# ```
|
30
30
|
# @!method invoke_transactions_in_$1
|
31
31
|
# @!scope class
|
@@ -50,8 +50,8 @@ module WechatPay
|
|
50
50
|
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_5.shtml
|
51
51
|
#
|
52
52
|
# ``` ruby
|
53
|
-
#
|
54
|
-
#
|
53
|
+
# WechatIpay::Ecommerce.query_order(sub_mchid: '16000008', transaction_id: '4323400972202104305133344444') # by transaction_id
|
54
|
+
# WechatIpay::Ecommerce.query_order(sub_mchid: '16000008', out_trade_no: 'N202104302474') # by out_trade_no
|
55
55
|
# ```
|
56
56
|
#
|
57
57
|
def self.query_order(params)
|
@@ -66,7 +66,7 @@ module WechatPay
|
|
66
66
|
end
|
67
67
|
|
68
68
|
params = params.merge({
|
69
|
-
sp_mchid:
|
69
|
+
sp_mchid: WechatIpay.mch_id
|
70
70
|
})
|
71
71
|
|
72
72
|
method = 'GET'
|
@@ -89,14 +89,14 @@ module WechatPay
|
|
89
89
|
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_6.shtml
|
90
90
|
#
|
91
91
|
# ``` ruby
|
92
|
-
#
|
92
|
+
# WechatIpay::Ecommerce.close_order(sub_mchid: '16000008', out_trade_no: 'N3344445')
|
93
93
|
# ```
|
94
94
|
#
|
95
95
|
def self.close_order(params)
|
96
96
|
out_trade_no = params.delete(:out_trade_no)
|
97
97
|
url = "/v3/pay/partner/transactions/out-trade-no/#{out_trade_no}/close"
|
98
98
|
params = params.merge({
|
99
|
-
sp_mchid:
|
99
|
+
sp_mchid: WechatIpay.mch_id
|
100
100
|
})
|
101
101
|
|
102
102
|
method = 'POST'
|
@@ -117,8 +117,8 @@ module WechatPay
|
|
117
117
|
method = 'POST'
|
118
118
|
|
119
119
|
params = {
|
120
|
-
sp_appid:
|
121
|
-
sp_mchid:
|
120
|
+
sp_appid: WechatIpay.app_id,
|
121
|
+
sp_mchid: WechatIpay.mch_id
|
122
122
|
}.merge(params)
|
123
123
|
|
124
124
|
payload_json = params.to_json
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module WechatIpay
|
4
4
|
# 分账相关
|
5
5
|
module Ecommerce
|
6
6
|
class << self
|
@@ -14,13 +14,13 @@ module WechatPay
|
|
14
14
|
#
|
15
15
|
# ``` ruby
|
16
16
|
# params = {"out_trade_no"=>"P202104306585", "transaction_id"=>"4323400972202104301286330188", "sub_mchid"=>"160000", "out_order_no"=>"N202104307987", "finish"=>true, "receivers"=>[{"type"=>"MERCHANT_ID", "receiver_account"=>"1607189890", "amount"=>1, "description"=>"平台抽成", "receiver_name"=>"CXOO5SF5sylMhSWjUBHQ6dBN0BTdrGExiziO8OEnJEG/nAa7gw6JTbsFQVhUbXD2er07Gcvt7qsLg7wYEe6iqNKbHHRWvChVVKWcKSyvfMOcRa95lxUkVn2+YdMmQ/Rt2h+xN7HMFMVPh9Py2c3sxnv1hZSraTEBWp577NOVwfSKiDTOAnbLtVtLbJndZ2N/bRXzW/gpbQV6TnnsrKPJ+NQ64kCedaYoO0XvEK1JavJju4kUAw/TnJ78jBMwj0gx2kfrsAgtwGrIGhrqhGcGHwwwPPDk5lS/iVaKpSdMvxOHN/9mrAqgqmvBg9uHRKE4sUqkZWuaiAFvYF9/5sLgjQ=="}]}
|
17
|
-
#
|
17
|
+
# WechatIpay::Ecommerce.request_profitsharing(params)
|
18
18
|
# ```
|
19
19
|
def request_profitsharing(params)
|
20
20
|
url = '/v3/ecommerce/profitsharing/orders'
|
21
21
|
method = 'POST'
|
22
22
|
params = {
|
23
|
-
appid:
|
23
|
+
appid: WechatIpay.app_id
|
24
24
|
}.merge(params)
|
25
25
|
|
26
26
|
payload_json = params.to_json
|
@@ -31,7 +31,7 @@ module WechatPay
|
|
31
31
|
for_sign: payload_json,
|
32
32
|
payload: payload_json,
|
33
33
|
extra_headers: {
|
34
|
-
'Wechatpay-Serial' =>
|
34
|
+
'Wechatpay-Serial' => WechatIpay.platform_serial_no
|
35
35
|
}
|
36
36
|
)
|
37
37
|
end
|
@@ -45,7 +45,7 @@ module WechatPay
|
|
45
45
|
# Example:
|
46
46
|
#
|
47
47
|
# ``` ruby
|
48
|
-
#
|
48
|
+
# WechatIpay::Ecommerce.query_profitsharing(out_order_no: 'N202104288345', sub_mchid: '16000000', transaction_id: '4200001048202104280183691118')
|
49
49
|
# ```
|
50
50
|
#
|
51
51
|
def query_profitsharing(params)
|
@@ -70,8 +70,8 @@ module WechatPay
|
|
70
70
|
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_3.shtml
|
71
71
|
#
|
72
72
|
# ``` ruby
|
73
|
-
#
|
74
|
-
#
|
73
|
+
# WechatIpay::Ecommerce.return_profitsharing(out_order_no: 'P202104306585', sub_mchid: '16000000', out_return_no: 'R20210430223', return_mchid: '180000', amount: 1, description: '分账回退')
|
74
|
+
# WechatIpay::Ecommerce.return_profitsharing(order_id: '3008450740201411110007820472', sub_mchid: '16000000', out_return_no: 'R20210430223', return_mchid: '180000', amount: 1, description: '分账回退')
|
75
75
|
# ```
|
76
76
|
def return_profitsharing(params)
|
77
77
|
url = '/v3/ecommerce/profitsharing/returnorders'
|
@@ -96,8 +96,8 @@ module WechatPay
|
|
96
96
|
# Example:
|
97
97
|
#
|
98
98
|
# ``` ruby
|
99
|
-
#
|
100
|
-
#
|
99
|
+
# WechatIpay::Ecommerce.query_return_profitsharing(sub_mchid: '1608747309', out_order_no: 'P202104306585', out_return_no: 'R202105023455')
|
100
|
+
# WechatIpay::Ecommerce.query_return_profitsharing(sub_mchid: '1608747309', order_id: '3008450740201411110007820472', out_return_no: 'R202105023455')
|
101
101
|
# ```
|
102
102
|
def query_return_profitsharing(params)
|
103
103
|
method = 'GET'
|
@@ -123,7 +123,7 @@ module WechatPay
|
|
123
123
|
# Example:
|
124
124
|
#
|
125
125
|
# ``` ruby
|
126
|
-
#
|
126
|
+
# WechatIpay::Ecommerce.finish_profitsharing(sub_mchid: '160000', out_order_no: 'P202104303106', transaction_id: '4323400972202104305131070133', description: '直接打款到二级商户不分账').bod
|
127
127
|
# ```
|
128
128
|
#
|
129
129
|
def finish_profitsharing(params)
|
@@ -149,7 +149,7 @@ module WechatPay
|
|
149
149
|
# Example:
|
150
150
|
#
|
151
151
|
# ``` ruby
|
152
|
-
#
|
152
|
+
# WechatIpay::Ecommerce.query_profitsharing_amount({ transaction_id: '4323400972202104301286330188' })
|
153
153
|
# ```
|
154
154
|
#
|
155
155
|
def query_profitsharing_amount(params)
|
@@ -175,7 +175,7 @@ module WechatPay
|
|
175
175
|
# Example:
|
176
176
|
#
|
177
177
|
# ``` ruby
|
178
|
-
#
|
178
|
+
# WechatIpay::Ecommerce.add_profitsharing_receivers(type: 'PERSONAL_OPENID', account: 'oly6s5cLmmVzzr8iPyI6mJj7qG2s', name: 'Lan', relation_type: 'DISTRIBUTOR').body
|
179
179
|
# ```
|
180
180
|
#
|
181
181
|
def add_profitsharing_receivers(params)
|
@@ -183,7 +183,7 @@ module WechatPay
|
|
183
183
|
method = 'POST'
|
184
184
|
|
185
185
|
params = {
|
186
|
-
appid:
|
186
|
+
appid: WechatIpay.app_id
|
187
187
|
}.merge(params)
|
188
188
|
|
189
189
|
payload_json = params.to_json
|
@@ -205,7 +205,7 @@ module WechatPay
|
|
205
205
|
# Example:
|
206
206
|
#
|
207
207
|
# ``` ruby
|
208
|
-
#
|
208
|
+
# WechatIpay::Ecommerce.remove_profitsharing_receivers(type: 'PERSONAL_OPENID', account: 'oly6s5cLmmVzzr8iPyI6mJj7qG2s', name: 'Lan', relation_type: 'DISTRIBUTOR').body
|
209
209
|
# ```
|
210
210
|
#
|
211
211
|
def delete_profitsharing_receivers(params)
|
@@ -213,7 +213,7 @@ module WechatPay
|
|
213
213
|
method = 'POST'
|
214
214
|
|
215
215
|
params = {
|
216
|
-
appid:
|
216
|
+
appid: WechatIpay.app_id
|
217
217
|
}.merge(params)
|
218
218
|
|
219
219
|
payload_json = params.to_json
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module WechatIpay
|
4
4
|
# 退款相关
|
5
5
|
module Ecommerce
|
6
6
|
INVOKE_REFUND_FIELDS = %i[sub_mchid out_trade_no total refund out_refund_no].freeze # :nodoc:
|
@@ -12,8 +12,8 @@ module WechatPay
|
|
12
12
|
# Example:
|
13
13
|
#
|
14
14
|
# ``` ruby
|
15
|
-
#
|
16
|
-
#
|
15
|
+
# WechatIpay::Ecommerce.invoke_refund(sub_mchid: '1600000', transaction_id: '4323400972202104305131070170', total: 1, refund: 1, description: '退款', out_refund_no: 'R10000') # by transaction_id
|
16
|
+
# WechatIpay::Ecommerce.invoke_refund(sub_mchid: '1608977559', total: 1, refund: 1, description: '退款', out_trade_no: 'N202104302474', out_refund_no: 'R10000') # by out_trade_no
|
17
17
|
# ```
|
18
18
|
def self.invoke_refund(params)
|
19
19
|
url = '/v3/ecommerce/refunds/apply'
|
@@ -26,7 +26,7 @@ module WechatPay
|
|
26
26
|
|
27
27
|
params = {
|
28
28
|
amount: amount,
|
29
|
-
sp_appid:
|
29
|
+
sp_appid: WechatIpay.app_id
|
30
30
|
}.merge(params)
|
31
31
|
|
32
32
|
make_request(
|
@@ -46,8 +46,8 @@ module WechatPay
|
|
46
46
|
# Example:
|
47
47
|
#
|
48
48
|
# ``` ruby
|
49
|
-
#
|
50
|
-
#
|
49
|
+
# WechatIpay::Ecommerce.query_refund(sub_mchid: '16000000', out_refund_no: 'AFS202104302474')
|
50
|
+
# WechatIpay::Ecommerce.query_refund(sub_mchid: '16000000', refund_id: '50000000382019052709732678859')
|
51
51
|
# ```
|
52
52
|
#
|
53
53
|
def self.query_refund(params)
|
@@ -62,7 +62,7 @@ module WechatPay
|
|
62
62
|
end
|
63
63
|
|
64
64
|
params = params.merge({
|
65
|
-
sp_mchid:
|
65
|
+
sp_mchid: WechatIpay.mch_id
|
66
66
|
})
|
67
67
|
|
68
68
|
method = 'GET'
|
@@ -87,7 +87,7 @@ module WechatPay
|
|
87
87
|
# Example:
|
88
88
|
#
|
89
89
|
# ``` ruby
|
90
|
-
#
|
90
|
+
# WechatIpay::Ecommerce.return_advance_refund(refund_id: '50300908092021043008398036516', sub_mchid: '160000')
|
91
91
|
# ```
|
92
92
|
#
|
93
93
|
def self.return_advance_refund(params)
|
@@ -112,8 +112,8 @@ module WechatPay
|
|
112
112
|
# Example:
|
113
113
|
#
|
114
114
|
# ``` ruby
|
115
|
-
#
|
116
|
-
#
|
115
|
+
# WechatIpay::Ecommerce.query_refund(sub_mchid: '16000000', out_refund_no: 'AFS202104302474')
|
116
|
+
# WechatIpay::Ecommerce.query_refund(sub_mchid: '16000000', refund_id: '50000000382019052709732678859')
|
117
117
|
# ```
|
118
118
|
#
|
119
119
|
def self.query_return_advance_refund(params)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module WechatIpay
|
4
4
|
# 补差相关
|
5
5
|
module Ecommerce
|
6
6
|
REQUEST_SUBSIDIES_FIELDS = %i[sub_mchid transaction_id amount description].freeze # :nodoc:
|
@@ -12,7 +12,7 @@ module WechatPay
|
|
12
12
|
# Example:
|
13
13
|
#
|
14
14
|
# ``` ruby
|
15
|
-
#
|
15
|
+
# WechatIpay::Ecommerce.request_subsidies(sub_mchid: '16000000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差')
|
16
16
|
# ```
|
17
17
|
#
|
18
18
|
def self.request_subsidies(params)
|
@@ -38,7 +38,7 @@ module WechatPay
|
|
38
38
|
# Example:
|
39
39
|
#
|
40
40
|
# ``` ruby
|
41
|
-
#
|
41
|
+
# WechatIpay::Ecommerce.return_subsidies(sub_mchid: '16000000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差', out_order_no: 'P103333')
|
42
42
|
# ```
|
43
43
|
|
44
44
|
def self.return_subsidies(params)
|
@@ -64,7 +64,7 @@ module WechatPay
|
|
64
64
|
# Example:
|
65
65
|
#
|
66
66
|
# ``` ruby
|
67
|
-
#
|
67
|
+
# WechatIpay::Ecommerce.return_subsidies(sub_mchid: '1600000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差', out_order_no: 'P103333')
|
68
68
|
# ```
|
69
69
|
#
|
70
70
|
def self.cancel_subsidies(params)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module WechatIpay
|
4
4
|
# 提现相关
|
5
5
|
module Ecommerce
|
6
6
|
WITHDRAW_FIELDS = %i[sub_mchid out_request_no amount].freeze # :nodoc:
|
@@ -12,7 +12,7 @@ module WechatPay
|
|
12
12
|
# Example:
|
13
13
|
#
|
14
14
|
# ``` ruby
|
15
|
-
#
|
15
|
+
# WechatIpay::Ecommerce.withdraw(sub_mchid: '160000', out_request_no: 'P10000', amount: 1)
|
16
16
|
# ```
|
17
17
|
#
|
18
18
|
def self.withdraw(params)
|
@@ -36,8 +36,8 @@ module WechatPay
|
|
36
36
|
# Example:
|
37
37
|
#
|
38
38
|
# ``` ruby
|
39
|
-
#
|
40
|
-
#
|
39
|
+
# WechatIpay::Ecommerce.query_withdraw(withdraw_id: '335556', sub_mchid: '160000')
|
40
|
+
# WechatIpay::Ecommerce.query_withdraw(out_request_no: 'P1000', sub_mchid: '160000')
|
41
41
|
# ```
|
42
42
|
#
|
43
43
|
def self.query_withdraw(params)
|
@@ -73,8 +73,8 @@ module WechatPay
|
|
73
73
|
# Example:
|
74
74
|
#
|
75
75
|
# ``` ruby
|
76
|
-
#
|
77
|
-
#
|
76
|
+
# WechatIpay::Ecommerce.platform_withdraw(out_request_no: 'P10000', amount: 1, account_type: 'BASIC')
|
77
|
+
# WechatIpay::Ecommerce.platform_withdraw(out_request_no: 'P10000', amount: 1, account_type: 'FEES')
|
78
78
|
# ```
|
79
79
|
#
|
80
80
|
def self.platform_withdraw(params)
|
@@ -98,8 +98,8 @@ module WechatPay
|
|
98
98
|
# Example:
|
99
99
|
#
|
100
100
|
# ``` ruby
|
101
|
-
#
|
102
|
-
#
|
101
|
+
# WechatIpay::Ecommerce.query_platform_withdraw(out_request_no: 'P1000')
|
102
|
+
# WechatIpay::Ecommerce.query_platform_withdraw(withdraw_id: '12313153')
|
103
103
|
# ```
|
104
104
|
#
|
105
105
|
def self.query_platform_withdraw(params)
|
@@ -131,7 +131,7 @@ module WechatPay
|
|
131
131
|
# Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_4.shtml
|
132
132
|
#
|
133
133
|
# ``` ruby
|
134
|
-
#
|
134
|
+
# WechatIpay::Ecommerce.download_exception_withdraw_file(bill_type: 'NO_SUCC', bill_date: '2021-05-10')
|
135
135
|
# ```
|
136
136
|
def self.download_exception_withdraw_file(params)
|
137
137
|
bill_type = params.delete(:bill_type)
|
@@ -1,25 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'json'
|
4
|
-
require 'wechat-
|
5
|
-
require 'wechat-
|
6
|
-
require 'wechat-
|
7
|
-
require 'wechat-
|
8
|
-
require 'wechat-
|
9
|
-
require 'wechat-
|
10
|
-
require 'wechat-
|
11
|
-
require 'wechat-
|
12
|
-
require 'wechat-
|
13
|
-
require 'wechat-
|
4
|
+
require 'wechat-ipay/helper'
|
5
|
+
require 'wechat-ipay/ecommerce/withdraw'
|
6
|
+
require 'wechat-ipay/ecommerce/balance'
|
7
|
+
require 'wechat-ipay/ecommerce/applyment'
|
8
|
+
require 'wechat-ipay/ecommerce/order'
|
9
|
+
require 'wechat-ipay/ecommerce/combine_order'
|
10
|
+
require 'wechat-ipay/ecommerce/profitsharing'
|
11
|
+
require 'wechat-ipay/ecommerce/subsidies'
|
12
|
+
require 'wechat-ipay/ecommerce/refund'
|
13
|
+
require 'wechat-ipay/ecommerce/bill'
|
14
14
|
|
15
|
-
module
|
15
|
+
module WechatIpay
|
16
16
|
# # 服务商相关接口封装(电商平台,服务商有许多接口共用)
|
17
17
|
# 文档: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/open/pay/chapter3_3_3.shtml
|
18
18
|
#
|
19
19
|
# PS: 电商收付通的所有接口已经封装完毕,有需要再补充。
|
20
20
|
#
|
21
21
|
module Ecommerce
|
22
|
-
include
|
22
|
+
include WechatIpayHelper
|
23
23
|
|
24
24
|
# 视频上传
|
25
25
|
#
|
@@ -28,7 +28,7 @@ module WechatPay
|
|
28
28
|
# Example:
|
29
29
|
#
|
30
30
|
# ``` ruby
|
31
|
-
#
|
31
|
+
# WechatIpay::Ecommerce.media_video_upload(File.open('Your Video'))
|
32
32
|
# ```
|
33
33
|
#
|
34
34
|
def self.media_video_upload(video)
|
@@ -63,7 +63,7 @@ module WechatPay
|
|
63
63
|
# Example:
|
64
64
|
#
|
65
65
|
# ``` ruby
|
66
|
-
#
|
66
|
+
# WechatIpay::Ecommerce.media_upload(File.open('Your Image'))
|
67
67
|
# ```
|
68
68
|
def self.media_upload(image)
|
69
69
|
url = '/v3/merchant/media/upload'
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'active_support/concern'
|
4
4
|
|
5
|
-
module
|
5
|
+
module WechatIpayHelper # :nodoc:
|
6
6
|
GATEWAY_URL = 'https://api.mch.weixin.qq.com'
|
7
7
|
|
8
8
|
extend ActiveSupport::Concern
|
@@ -13,7 +13,7 @@ module WechatPayHelper # :nodoc:
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def make_request(method:, path:, for_sign: '', payload: {}, extra_headers: {})
|
16
|
-
authorization =
|
16
|
+
authorization = WechatIpay::Sign.build_authorization_header(method, path, for_sign)
|
17
17
|
headers = {
|
18
18
|
'Authorization' => authorization,
|
19
19
|
'Content-Type' => 'application/json',
|
@@ -5,7 +5,7 @@ require 'base64'
|
|
5
5
|
require 'securerandom'
|
6
6
|
require 'active_support/core_ext/hash'
|
7
7
|
|
8
|
-
module
|
8
|
+
module WechatIpay
|
9
9
|
# # 微信签名相关的封装
|
10
10
|
# 文档: https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_0.shtml
|
11
11
|
#
|
@@ -33,10 +33,10 @@ module WechatPay
|
|
33
33
|
# sub_mchid: 'Your sub mchid',
|
34
34
|
# notify_url: 'the url'
|
35
35
|
# }
|
36
|
-
# result =
|
36
|
+
# result = WechatIpay::Ecommerce.invoke_transactions_in_app(params).body
|
37
37
|
# # => { prepay_id => 'wx201410272009395522657a690389285100' }
|
38
38
|
# prepay_id = result['prepay_id']
|
39
|
-
#
|
39
|
+
# WechatIpay::Sign.generate_app_payment_params_from_prepay_id_and_appid(appid, prepay_id)
|
40
40
|
# # => params for invoking the wechat pay in app
|
41
41
|
# ```
|
42
42
|
|
@@ -47,7 +47,7 @@ module WechatPay
|
|
47
47
|
|
48
48
|
{
|
49
49
|
appId: appid,
|
50
|
-
partnerId:
|
50
|
+
partnerId: WechatIpay.mch_id,
|
51
51
|
timeStamp: timestamp,
|
52
52
|
nonceStr: noncestr,
|
53
53
|
prepayId: prepay_id,
|
@@ -82,10 +82,10 @@ module WechatPay
|
|
82
82
|
# sub_mchid: 'Your sub mchid',
|
83
83
|
# notify_url: 'the url'
|
84
84
|
# }
|
85
|
-
# result =
|
85
|
+
# result = WechatIpay::Ecommerce.invoke_transactions_in_miniprogram(params).body
|
86
86
|
# # => { prepay_id => 'wx201410272009395522657a690389285100' }
|
87
87
|
# prepay_id = result['prepay_id']
|
88
|
-
#
|
88
|
+
# WechatIpay::Sign.generate_payment_params_from_prepay_id_and_appid(appid, prepay_id)
|
89
89
|
# # => params for invoking the wechat pay in miniprogram
|
90
90
|
# ```
|
91
91
|
def generate_payment_params_from_prepay_id_and_appid(appid, prepay_id)
|
@@ -123,7 +123,7 @@ module WechatPay
|
|
123
123
|
def notification_from_wechat?(timestamp, noncestr, json_body, signature)
|
124
124
|
string = build_callback_string(timestamp, noncestr, json_body)
|
125
125
|
decoded_signature = Base64.strict_decode64(signature)
|
126
|
-
|
126
|
+
WechatIpay.platform_cert.public_key.verify('SHA256', decoded_signature, string)
|
127
127
|
end
|
128
128
|
|
129
129
|
# For signing the sensitive information
|
@@ -134,7 +134,7 @@ module WechatPay
|
|
134
134
|
#
|
135
135
|
# ``` ruby
|
136
136
|
# string = 'Ruby'
|
137
|
-
#
|
137
|
+
# WechatIpay::Sign.sign_important_info(string)
|
138
138
|
# ```
|
139
139
|
#
|
140
140
|
# ``` ruby
|
@@ -142,7 +142,7 @@ module WechatPay
|
|
142
142
|
# "K0MK7g3laREAQ4HIlpIndVmFdz4IyxxiVp42hXFx2CzWRB1fn85ANBxnQXESq91vJ1P9mCt94cHZDoshlEOJRkE1KvcxpBCnG3ghIqiSsLKdLZ3ytO94GBDzCt8nsq+vJKXJbK2XuL9p5h0KYGKZyjt2ydU9Ig6daWTpZH8lAKIsLzPTsaUtScuw/v3M/7t8/4py8N0MOLKbDBDnR5Q+MRHbEWI9nCA3HTAWsSerIIgE7igWnzybxsUzhkV8m49P/Shr2zh6yJAlEnyPLFmQG7GuUaYwDTSLKOWzzPYwxMcucWQha2krC9OlwnZJe6ZWUAI3s4ej4kFRfheOYywRoQ=="
|
143
143
|
# ```
|
144
144
|
def sign_important_info(string)
|
145
|
-
platform_public_key =
|
145
|
+
platform_public_key = WechatIpay.platform_cert.public_key
|
146
146
|
Base64.strict_encode64(platform_public_key.public_encrypt(string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING))
|
147
147
|
end
|
148
148
|
|
@@ -158,7 +158,7 @@ module WechatPay
|
|
158
158
|
# associated_data = body['resource']['associated_data']
|
159
159
|
# nonce = body['resource']['nonce']
|
160
160
|
# ciphertext = body['resource']['ciphertext']
|
161
|
-
# res =
|
161
|
+
# res = WechatIpay::Sign.decrypt_the_encrypt_params(
|
162
162
|
# associated_data: associated_data,
|
163
163
|
# nonce: nonce,
|
164
164
|
# ciphertext: ciphertext
|
@@ -171,7 +171,7 @@ module WechatPay
|
|
171
171
|
# https://contest-server.cs.uchicago.edu/ref/ruby_2_3_1_stdlib/libdoc/openssl/rdoc/OpenSSL/Cipher.html
|
172
172
|
tag_length = 16
|
173
173
|
decipher = OpenSSL::Cipher.new('aes-256-gcm').decrypt
|
174
|
-
decipher.key =
|
174
|
+
decipher.key = WechatIpay.mch_key
|
175
175
|
decipher.iv = nonce
|
176
176
|
signature = Base64.strict_decode64(ciphertext)
|
177
177
|
length = signature.length
|
@@ -192,7 +192,7 @@ module WechatPay
|
|
192
192
|
# method = 'GET'
|
193
193
|
# url = '/v3/certificates'
|
194
194
|
# json_body = ''
|
195
|
-
#
|
195
|
+
# WechatIpay::sign.build_authorization_header(method, url, json_body)
|
196
196
|
# ```
|
197
197
|
#
|
198
198
|
# ``` ruby
|
@@ -206,9 +206,9 @@ module WechatPay
|
|
206
206
|
signature = sign_string(string)
|
207
207
|
|
208
208
|
params = {
|
209
|
-
mchid:
|
209
|
+
mchid: WechatIpay.mch_id,
|
210
210
|
nonce_str: nonce_str,
|
211
|
-
serial_no:
|
211
|
+
serial_no: WechatIpay.apiclient_serial_no,
|
212
212
|
signature: signature,
|
213
213
|
timestamp: timestamp
|
214
214
|
}
|
@@ -219,7 +219,7 @@ module WechatPay
|
|
219
219
|
end
|
220
220
|
|
221
221
|
def sign_string(string)
|
222
|
-
result =
|
222
|
+
result = WechatIpay.apiclient_key.sign('SHA256', string) # 商户私钥的SHA256-RSA2048签名
|
223
223
|
Base64.strict_encode64(result) # Base64处理
|
224
224
|
end
|
225
225
|
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# frozen_string_literal: true
|
4
4
|
|
5
5
|
require 'restclient'
|
6
|
-
require 'wechat-
|
7
|
-
require 'wechat-
|
8
|
-
require 'wechat-
|
6
|
+
require 'wechat-ipay/sign'
|
7
|
+
require 'wechat-ipay/direct' # 直连模式
|
8
|
+
require 'wechat-ipay/ecommerce' # 电商平台
|
9
9
|
|
10
10
|
# # 微信支付
|
11
11
|
#
|
12
12
|
# 设置关键信息
|
13
|
-
module
|
13
|
+
module WechatIpay
|
14
14
|
class << self
|
15
15
|
attr_accessor :app_id, :mch_id, :mch_key
|
16
16
|
attr_reader :apiclient_key, :apiclient_cert, :platform_cert
|
@@ -20,7 +20,7 @@ module WechatPay
|
|
20
20
|
@apiclient_key = OpenSSL::PKey::RSA.new(key)
|
21
21
|
end
|
22
22
|
|
23
|
-
# 设置平台证书,通过接口获取 https://github.com/lanzhiheng/wechat-
|
23
|
+
# 设置平台证书,通过接口获取 https://github.com/lanzhiheng/wechat-ipay/blob/master/lib/wechat-ipay/ecommerce/applyment.rb#L116
|
24
24
|
def platform_cert=(cert)
|
25
25
|
@platform_cert = OpenSSL::X509::Certificate.new(cert)
|
26
26
|
end
|
data/wechat-ipay.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
4
|
|
5
|
-
require 'wechat-
|
5
|
+
require 'wechat-ipay/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = 'wechat-ipay'
|
9
|
-
s.version =
|
9
|
+
s.version = WechatIpay::VERSION
|
10
10
|
s.summary = 'Wechat Pay in api V3'
|
11
11
|
s.description = 'A simple Wechat pay ruby gem in api V3.'
|
12
12
|
s.authors = ['tianlu1677']
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.required_ruby_version = '>= 2.6'
|
19
19
|
s.require_paths = ['lib']
|
20
|
-
s.homepage = 'https://github.com/tianlu1677/wechat-
|
20
|
+
s.homepage = 'https://github.com/tianlu1677/wechat-ipay/'
|
21
21
|
s.license = 'MIT'
|
22
22
|
|
23
23
|
s.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat-ipay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tianlu1677
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -93,23 +93,23 @@ files:
|
|
93
93
|
- Gemfile
|
94
94
|
- README.md
|
95
95
|
- Rakefile
|
96
|
-
- lib/wechat-
|
97
|
-
- lib/wechat-
|
98
|
-
- lib/wechat-
|
99
|
-
- lib/wechat-
|
100
|
-
- lib/wechat-
|
101
|
-
- lib/wechat-
|
102
|
-
- lib/wechat-
|
103
|
-
- lib/wechat-
|
104
|
-
- lib/wechat-
|
105
|
-
- lib/wechat-
|
106
|
-
- lib/wechat-
|
107
|
-
- lib/wechat-
|
108
|
-
- lib/wechat-
|
109
|
-
- lib/wechat-
|
110
|
-
- lib/wechat-
|
96
|
+
- lib/wechat-ipay.rb
|
97
|
+
- lib/wechat-ipay/direct.rb
|
98
|
+
- lib/wechat-ipay/ecommerce.rb
|
99
|
+
- lib/wechat-ipay/ecommerce/applyment.rb
|
100
|
+
- lib/wechat-ipay/ecommerce/balance.rb
|
101
|
+
- lib/wechat-ipay/ecommerce/bill.rb
|
102
|
+
- lib/wechat-ipay/ecommerce/combine_order.rb
|
103
|
+
- lib/wechat-ipay/ecommerce/order.rb
|
104
|
+
- lib/wechat-ipay/ecommerce/profitsharing.rb
|
105
|
+
- lib/wechat-ipay/ecommerce/refund.rb
|
106
|
+
- lib/wechat-ipay/ecommerce/subsidies.rb
|
107
|
+
- lib/wechat-ipay/ecommerce/withdraw.rb
|
108
|
+
- lib/wechat-ipay/helper.rb
|
109
|
+
- lib/wechat-ipay/sign.rb
|
110
|
+
- lib/wechat-ipay/version.rb
|
111
111
|
- wechat-ipay.gemspec
|
112
|
-
homepage: https://github.com/tianlu1677/wechat-
|
112
|
+
homepage: https://github.com/tianlu1677/wechat-ipay/
|
113
113
|
licenses:
|
114
114
|
- MIT
|
115
115
|
metadata: {}
|