allinpay 0.1.0 → 0.1.2
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/.yardopts +1 -0
- data/Gemfile +2 -0
- data/README.md +23 -19
- data/lib/allinpay.rb +0 -1
- data/lib/allinpay/account.rb +21 -16
- data/lib/allinpay/client.rb +37 -0
- data/lib/allinpay/payment.rb +25 -9
- data/lib/allinpay/query.rb +7 -5
- data/lib/allinpay/service.rb +31 -0
- data/lib/allinpay/signature.rb +12 -0
- data/lib/allinpay/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a084b8c15c36cbc55fff5ed3918ec51f191cba20
|
4
|
+
data.tar.gz: bb451c938351c648250923c878570b0aad9d567b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7b87b109da3b588b57c30761664d9c989e189fcf6b3ade61117c315cf78b901d57c8de52aab368a1583c04299a334d0e510e2d6d948895060665d9b02428a49
|
7
|
+
data.tar.gz: 3647485074150a7d673c3f6f4aa951d0e2957dc4fe4d6d41ef8f89d7a2448cfcbc4c9ee0dbd187c14f389da3f9efdec84df1343a3452f7af766a6bb8092f9511
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--plugin activesupport-concern
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,35 +1,39 @@
|
|
1
|
-
|
1
|
+
[](https://badge.fury.io/rb/allinpay)
|
2
2
|
|
3
|
-
|
3
|
+
## 通联支付Ruby接口
|
4
4
|
|
5
|
-
|
5
|
+
### 安装
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
7
|
+
将以下代码添加到 Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
10
|
gem 'allinpay'
|
13
11
|
```
|
14
12
|
|
15
|
-
|
13
|
+
然后执行
|
16
14
|
|
17
15
|
$ bundle
|
18
16
|
|
19
|
-
|
17
|
+
或者直接运行以下命令安装:
|
20
18
|
|
21
19
|
$ gem install allinpay
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
21
|
+
### 使用
|
30
22
|
|
31
|
-
|
23
|
+
在Rails中使用, 需要将以下代码添加到config/initializers/allinpay.rb中
|
32
24
|
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
```ruby
|
26
|
+
require 'allinpay'
|
27
|
+
|
28
|
+
options = {
|
29
|
+
merchant: '商户号',
|
30
|
+
username: '用户名: 商户号 + 02',
|
31
|
+
password: '登录密码',
|
32
|
+
env: '使用环境',
|
33
|
+
private_path: '私钥文件',
|
34
|
+
private_password: '私钥密码',
|
35
|
+
public_path: '公钥文件'
|
36
|
+
}
|
37
|
+
|
38
|
+
$allinpay_client = Allinpay::Client.new(options)
|
39
|
+
```
|
data/lib/allinpay.rb
CHANGED
data/lib/allinpay/account.rb
CHANGED
@@ -1,19 +1,24 @@
|
|
1
|
-
###
|
2
|
-
# 财务接口
|
3
|
-
# 1. 账户充值
|
4
|
-
#
|
5
|
-
###
|
6
|
-
|
7
1
|
module Allinpay
|
2
|
+
# 通联支付 账户查询接口
|
3
|
+
#
|
4
|
+
# 具体文档请查看 http://113.108.182.3:8282/techsp/helper/interapi/tlt/interapi1.html
|
5
|
+
#
|
6
|
+
# @todo
|
7
|
+
# * 添加历史余额查询
|
8
|
+
# * 账户提现
|
8
9
|
module Account
|
9
10
|
extend ActiveSupport::Concern
|
10
11
|
included do
|
11
12
|
|
12
|
-
#
|
13
|
+
# 账户信息查询 交易代码:300000
|
14
|
+
# 查询商户在通联的虚拟账户基本信息
|
15
|
+
#
|
16
|
+
# @param account_number [String] 账户号码
|
13
17
|
#
|
18
|
+
# @return [Hash] (see Allinpay::Client#result_wrap)
|
14
19
|
|
15
20
|
def account(account_number = nil)
|
16
|
-
params = set_infomation('300000',{ REQTIME: timestamps, LEVEL: 9 })
|
21
|
+
params = set_infomation('300000', { REQTIME: timestamps, LEVEL: 9 })
|
17
22
|
params[:ACQUERYREQ] = { ACCTNO: account_number} if account_number
|
18
23
|
res = conn.request(params)
|
19
24
|
return result_wrap(:fail, res, params) if res["INFO"]["RET_CODE"] != "0000"
|
@@ -22,17 +27,17 @@ module Allinpay
|
|
22
27
|
|
23
28
|
# 账户充值接口
|
24
29
|
#
|
25
|
-
#
|
30
|
+
# @param bank_account [String] 银行账户
|
31
|
+
# @param amount [Integer] 充值金额
|
32
|
+
# @param business_code [String] 业务代码 默认 100005
|
33
|
+
# @param options [Hash] 其它
|
34
|
+
# @option options [String] :summary 银行交易2
|
35
|
+
# @option options [String] :remark 商户交易备注
|
26
36
|
#
|
27
|
-
#
|
28
|
-
# amount 充值金额
|
29
|
-
# business_code 业务代码 默认 100005
|
30
|
-
# options
|
31
|
-
# summary 网银交易备注
|
32
|
-
# remark 商户交易备注
|
37
|
+
# @return [Hash] (see Allinpay::Client#result_wrap)
|
33
38
|
|
34
39
|
def charge(bank_account, amount, business_code = '19900', options = {})
|
35
|
-
params = set_infomation('300006',{ REQTIME: timestamps, LEVEL: 9 })
|
40
|
+
params = set_infomation('300006', { REQTIME: timestamps, LEVEL: 9 })
|
36
41
|
charge_info = {
|
37
42
|
BUSINESS_CODE: business_code,
|
38
43
|
BANKACCT: bank_account,
|
data/lib/allinpay/client.rb
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
module Allinpay
|
2
|
+
# 通联支付
|
3
|
+
# @attr merchant [String] 通联支付商户号
|
4
|
+
# @attr username [String] 通联支付用户名
|
5
|
+
# @attr password [String] 通联支付密码
|
6
|
+
# @attr public_path [String] 公共证书位置
|
7
|
+
# @attr private_path [String] 私密证书位置
|
8
|
+
# @attr private_password [String] 私密证书密码
|
9
|
+
# @attr conn [Request] 请求信息
|
10
|
+
|
11
|
+
|
2
12
|
class Client
|
3
13
|
attr_accessor :merchant, :username, :password, :conn
|
4
14
|
|
@@ -6,6 +16,17 @@ module Allinpay
|
|
6
16
|
attr_accessor :private_path, :public_path, :private_password
|
7
17
|
end
|
8
18
|
|
19
|
+
# 初始化通联支付
|
20
|
+
#
|
21
|
+
# @param options [Hash] 交易信息
|
22
|
+
# @option options [String] :merchant 通联支付商户号
|
23
|
+
# @option options [String] :username 通联支付用户名
|
24
|
+
# @option options [String] :password 通联支付密码
|
25
|
+
# @option options [String] :env 设置环境
|
26
|
+
# @option options [String] :public_path 公共证书位置
|
27
|
+
# @option options [String] :private_path 私密证书位置
|
28
|
+
# @option options [String] :private_password 私密证书密码
|
29
|
+
|
9
30
|
def initialize(options)
|
10
31
|
@merchant = options[:merchant]
|
11
32
|
@username = options[:username]
|
@@ -16,6 +37,13 @@ module Allinpay
|
|
16
37
|
|
17
38
|
private
|
18
39
|
|
40
|
+
# 设置基本信息
|
41
|
+
#
|
42
|
+
# @param code [String] 交易代码
|
43
|
+
# @param options [Hash] 其它信息
|
44
|
+
#
|
45
|
+
# return [Hash]
|
46
|
+
|
19
47
|
def set_infomation(code, options = {})
|
20
48
|
info = {
|
21
49
|
TRX_CODE: code,
|
@@ -28,14 +56,23 @@ module Allinpay
|
|
28
56
|
return { INFO: info }
|
29
57
|
end
|
30
58
|
|
59
|
+
# 生成交易序号
|
60
|
+
|
31
61
|
def req_sn
|
32
62
|
merchant + timestamps + rand(1000).to_s.ljust(4, '0')
|
33
63
|
end
|
34
64
|
|
65
|
+
# 生成时间
|
66
|
+
|
35
67
|
def timestamps
|
36
68
|
Time.now.strftime('%Y%m%d%H%M%S')
|
37
69
|
end
|
38
70
|
|
71
|
+
# 将结果重新包装
|
72
|
+
# @param status [String] 返回状态
|
73
|
+
# @param data [String, Hash, Array, nil] 包装数据
|
74
|
+
# @param request [Hash] 请求数据
|
75
|
+
|
39
76
|
def result_wrap(status, data, request = nil)
|
40
77
|
return { "status" => status.to_s, "data" => data, "request" => request }
|
41
78
|
end
|
data/lib/allinpay/payment.rb
CHANGED
@@ -1,16 +1,22 @@
|
|
1
|
-
###
|
2
|
-
# 交易接口
|
3
|
-
# 1. 单笔实时支付
|
4
|
-
#
|
5
|
-
###
|
6
|
-
|
7
|
-
|
8
1
|
module Allinpay
|
2
|
+
# 通联支付 支付接口
|
3
|
+
#
|
4
|
+
# 具体文档请查看 http://113.108.182.3:8282/techsp/helper/interapi/tlt/interapi0.html
|
9
5
|
module Payment
|
10
6
|
extend ActiveSupport::Concern
|
11
7
|
included do
|
12
8
|
|
13
|
-
#
|
9
|
+
# 单笔实时付款 交易代码:100014
|
10
|
+
#
|
11
|
+
# @param tran [Hash] 交易信息
|
12
|
+
# @option tran [String] :bank_code 银行代码,存折必须填写
|
13
|
+
# @option tran [String] :account_number 银行卡或存折号码
|
14
|
+
# @option tran [String] :account_name 银行卡或存折上的所有人姓名
|
15
|
+
# @option tran [String] :account_prop 账号属性 0私人,1公司。不填时,默认为私人0
|
16
|
+
# @param options [Hash] 其它信息 具体参考http://113.108.182.3:8282/techsp/helper/filedetail/tlt/filedetail743.html
|
17
|
+
#
|
18
|
+
# @return [Hash] (see Allinpay::Client#result_wrap)
|
19
|
+
|
14
20
|
def pay(tran, options = {})
|
15
21
|
params = set_infomation('100014')
|
16
22
|
tran_body = {
|
@@ -30,7 +36,17 @@ module Allinpay
|
|
30
36
|
return result_wrap(:success, res, params)
|
31
37
|
end
|
32
38
|
|
33
|
-
#
|
39
|
+
# 批量代付 交易代码:100002
|
40
|
+
#
|
41
|
+
# @param trans [Array<Hash>] 交易信息
|
42
|
+
# @option trans [String] :bank_code 银行代码,存折必须填写
|
43
|
+
# @option trans [String] :account_number 银行卡或存折号码
|
44
|
+
# @option trans [String] :account_name 银行卡或存折上的所有人姓名
|
45
|
+
# @option trans [String] :account_prop 账号属性 0私人,1公司。不填时,默认为私人0
|
46
|
+
# @param options [Hash] 其它信息 具体参考http://113.108.182.3:8282/techsp/helper/filedetail/tlt/filedetail131.html
|
47
|
+
#
|
48
|
+
# @return [Hash] (see Allinpay::Client#result_wrap)
|
49
|
+
|
34
50
|
def batch_pay(trans, options = {})
|
35
51
|
params = set_infomation('100002', {LEVEL: 9})
|
36
52
|
details = []
|
data/lib/allinpay/query.rb
CHANGED
@@ -10,12 +10,14 @@ module Allinpay
|
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
included do
|
12
12
|
|
13
|
-
#
|
13
|
+
# 交易结果查询 交易代码:200004
|
14
14
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# options:
|
15
|
+
# @param sn [String] 要查询的交易流水, 若不填时间必填
|
16
|
+
# @param options [Hash] 其它信息
|
17
|
+
# @option options [String] :type 查询类型, 如果使用0查询,未完成交易将查不到
|
18
|
+
# @option options [String] :status 状态, 如果开始时间和结束时间不为空,该字段生效,不可为空
|
19
|
+
# @option options [String] :start_day 开始时间, 若不填QUERY_SN则必填
|
20
|
+
# @option options [String] :end_day 结束时间, 填了开始时间必填
|
19
21
|
|
20
22
|
def query_batch_pay(sn, options = {})
|
21
23
|
params = set_infomation('200004')
|
data/lib/allinpay/service.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Allinpay
|
2
2
|
module Service
|
3
|
+
# 网关信息处理
|
4
|
+
# @param env [String] 所在环境
|
5
|
+
# @param options [Hash] (see #set_signature_infomation)
|
6
|
+
|
3
7
|
def self.connection(env, options)
|
4
8
|
set_signature_infomation(options)
|
5
9
|
ssl_options = {}
|
@@ -17,6 +21,10 @@ module Allinpay
|
|
17
21
|
end.new(env, ssl_options)
|
18
22
|
end
|
19
23
|
|
24
|
+
# 处理请求
|
25
|
+
# @param params [Hash] 将参数发送服务器
|
26
|
+
#
|
27
|
+
# @return [Hash] 将处理后的结果转换成Hash
|
20
28
|
def request(params)
|
21
29
|
params[:INFO][:SIGNED_MSG] = Signature.generate(parse_xml(params)).unpack('H*').first
|
22
30
|
body = parse_xml(params)
|
@@ -33,18 +41,37 @@ module Allinpay
|
|
33
41
|
|
34
42
|
private
|
35
43
|
|
44
|
+
# 验证服务器返回结果
|
45
|
+
#
|
46
|
+
# @param res [String] 服务返回body信息
|
47
|
+
# @param result [Hash] 返回xml转换后的信息
|
48
|
+
#
|
49
|
+
# return [Boolean] 验证结果
|
50
|
+
|
36
51
|
def verify_signature?(res, result)
|
37
52
|
signed = result["AIPG"]["INFO"]["SIGNED_MSG"]
|
38
53
|
xml_body = res.encode('utf-8', 'gbk').gsub(/<SIGNED_MSG>.*<\/SIGNED_MSG>/, '')
|
39
54
|
Signature.verify?(xml_body.encode('gbk', 'utf-8'), [signed].pack("H*"))
|
40
55
|
end
|
41
56
|
|
57
|
+
# 将数据转换成XML
|
58
|
+
#
|
59
|
+
# @param data [String] 待装换信息
|
60
|
+
# @param indent [Integer] 开始位置, 默认为0
|
61
|
+
#
|
62
|
+
# @return [String] xml信息
|
63
|
+
|
42
64
|
def parse_xml(data, indent = 0)
|
43
65
|
data_xml = data.to_xml(root: 'AIPG', skip_types: true, dasherize: false, indent: indent).sub('UTF-8', 'GBK')
|
44
66
|
data_xml.encode! 'gbk','utf-8'
|
45
67
|
data_xml
|
46
68
|
end
|
47
69
|
|
70
|
+
# 设置支付网关
|
71
|
+
#
|
72
|
+
# @param env [String] 所在环境
|
73
|
+
# @return [String] 网关链接
|
74
|
+
|
48
75
|
def set_gateway_url(env)
|
49
76
|
if env.to_s == "development" || env.to_s == "test"
|
50
77
|
return 'https://113.108.182.3/aipg/ProcessServlet'
|
@@ -53,6 +80,10 @@ module Allinpay
|
|
53
80
|
end
|
54
81
|
end
|
55
82
|
|
83
|
+
# 设置加密信息以及检查证书是否存在
|
84
|
+
#
|
85
|
+
# @param options [Hash](see Allinpay::Client#new)
|
86
|
+
|
56
87
|
def self.set_signature_infomation(options)
|
57
88
|
raise "Allinpay private key not exists" if !File.exists?(options[:private_path])
|
58
89
|
raise "Allinpay public key not exists" if !File.exists?(options[:public_path])
|
data/lib/allinpay/signature.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
|
3
3
|
module Allinpay
|
4
|
+
|
4
5
|
class Signature
|
6
|
+
# 通联支付 参数加密
|
7
|
+
#
|
8
|
+
# @param str [String] 待加密参数
|
9
|
+
#
|
10
|
+
# @return [String] 加密后信息
|
5
11
|
def self.generate(str)
|
6
12
|
private_file = File.open(Allinpay::Client.private_path)
|
7
13
|
private_key= OpenSSL::PKCS12.new(private_file, Allinpay::Client.private_password).key.export
|
@@ -9,6 +15,12 @@ module Allinpay
|
|
9
15
|
rsa.sign("sha1", str.force_encoding("GBK"))
|
10
16
|
end
|
11
17
|
|
18
|
+
# 通联支付 信息验证
|
19
|
+
#
|
20
|
+
# @param str [String] 待加密信息
|
21
|
+
# @param sign [String] 签名
|
22
|
+
#
|
23
|
+
# @return [Boolean] 验证后信息
|
12
24
|
def self.verify?(str, sign)
|
13
25
|
public_file = File.open(Allinpay::Client.public_path)
|
14
26
|
public_key = OpenSSL::X509::Certificate.new(public_file).public_key.export
|
data/lib/allinpay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: allinpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ye.li
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".yardopts"
|
63
64
|
- Gemfile
|
64
65
|
- README.md
|
65
66
|
- Rakefile
|