neotelis_pay 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 911d8cd69f74a88d48f4a196b0299940fe61c708
4
+ data.tar.gz: 738d306dec130f73977e806edc789ea7a21a19e7
5
+ SHA512:
6
+ metadata.gz: a613c346e5d48a9e5c0104f1d48b95119f6d534fba4d95659af2276129aa8702e75bdaa818d4fb7276f9df16b729b9f0fd8ebf39374811348b3b4b19e350e264
7
+ data.tar.gz: d8bc8023e2fb2c13ea355bf2070c5f6d1de806cb8d93ea19986409e73c24acb6302afcb22474561e57895fcea84aab92cf56906300d54ecb3006dfa78451c841
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ hex
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.7
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.7
5
+ before_install: gem install bundler -v 1.15.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tuminfei1981@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in neotelis_pay.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 tarzansos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # NeotelisPay
2
+
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/neotelis_pay`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'neotelis_pay'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install neotelis_pay
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
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.
30
+
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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/neotelis_pay. 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.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the NeotelisPay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/neotelis_pay/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "neotelis_pay"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,69 @@
1
+ require 'uri'
2
+ require 'openssl'
3
+ require 'digest/md5'
4
+ require 'uuid'
5
+
6
+ require "neotelis_pay/version"
7
+ require "neotelis_pay/utils/crypt"
8
+ require "neotelis_pay/utils/des"
9
+ require "neotelis_pay/utils/http_post"
10
+ require "neotelis_pay/service"
11
+ require "neotelis_pay/railtie" if defined?(Rails)
12
+
13
+ module NeotelisPay
14
+ @client_params = {}
15
+ @client_options = {}
16
+ @debug_mode = true
17
+ @version = '1.0.0'
18
+ @input_charset = 'UTF-8'
19
+ @sign_type = 'MD5'
20
+ @dev = 'ruby'
21
+ @request_id = ''
22
+
23
+ #签约申请接口
24
+ SERVICE_TYPE_SIGN_APPLY = 'signApply'
25
+ #签约确认接口
26
+ SERVICE_TYPE_SIGN_CONFIRM = 'signConfirm'
27
+ #签约支付申请接口
28
+ SERVICE_TYPE_PREPAY = 'prepay'
29
+ #签约支付确认接口
30
+ SERVICE_TYPE_PAY_CONFIRM = 'payConfirm'
31
+ #网关支付接口
32
+ SERVICE_TYPE_GATEWAY_PAY = 'gatewayPay'
33
+
34
+
35
+ class<< self
36
+ #merchant_id 商户账号
37
+ #secret_key 加密key
38
+ #merchant_abbr 商户名称
39
+ #product_name 商品名称
40
+ #request_ip 请求地址
41
+ attr_accessor :merchant_id, :merchant_abbr, :product_name, :product_desc, :request_ip, :secret_key, :debug_mode
42
+ attr_reader :api_base_url
43
+
44
+ def api_base_url=(url)
45
+ @api_base_url = url
46
+ end
47
+
48
+ def client_params
49
+ uuid = UUID.new
50
+ @request_id = uuid.generate
51
+ params = {"merchantId" => @merchant_id,
52
+ "requestId" => @request_id,
53
+ "requestTime" => Time.now.strftime("%Y%m%d%H%M%S"),
54
+ "requestIp" => @request_ip}
55
+ @client_params = params
56
+ @client_params
57
+ end
58
+
59
+ def client_options
60
+ options = {"signType" => @sign_type, "version" => @version, "dev" => @dev}
61
+ @client_options = options
62
+ @client_options
63
+ end
64
+
65
+ def debug_mode?
66
+ @debug_mode
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ module NeotelisPay
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load 'rake/neotelis_pay.rake'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ module NeotelisPay
2
+ class Result
3
+ attr_accessor :raw, :msg
4
+
5
+ RESULT_SUCCESS_FLAG = '000000'
6
+
7
+ # 1-快捷支付;
8
+ # 2-代扣;
9
+ # 3-代付;
10
+ # 6-认证支付;
11
+ # 10-微信扫码;
12
+ # 20-支付宝扫码;
13
+ # 11-微信h5支付;
14
+ # 30-QQ钱包扫码;
15
+ # 50-京东扫码;
16
+ ORDER_TYPE_KJ = 1
17
+ ORDER_TYPE_DK = 2
18
+ ORDER_TYPE_DF = 3
19
+ ORDER_TYPE_RZZF = 6
20
+ ORDER_TYPE_WXSM = 10
21
+ ORDER_TYPE_ZFBSM = 20
22
+ ORDER_TYPE_WXH5 = 11
23
+ ORDER_TYPE_QQSM = 30
24
+ ORDER_TYPE_JDSM = 50
25
+
26
+ def initialize(result)
27
+ self.raw = result
28
+ self.msg = JSON.parse(result)
29
+ end
30
+
31
+ def success?
32
+ @msg['returnCode'] == RESULT_SUCCESS_FLAG
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,156 @@
1
+ module NeotelisPay
2
+ class Service
3
+ ########################交易类接口########################
4
+
5
+ # 签约申请接口
6
+ # userToken 用户手机号
7
+ # payerName 持卡人姓名
8
+ # certType 证件类型
9
+ # certNo 证件号
10
+ # bankCardType 银行卡类型
11
+ # bankCardNo 银行卡号
12
+ # cvn2 cvn2
13
+ # useTime 有效期
14
+ def self.post_sign_apply(user_token, payer_name, cert_type, cert_no, bank_card_type, bank_card_no, cvn2, use_time, options={})
15
+ service_name = "signApply"
16
+ input_hash = {"type" => service_name,
17
+ "userToken" => user_token,
18
+ "payerName" => payer_name,
19
+ "certType" => cert_type,
20
+ "certNo" => cert_no,
21
+ "bankCardType" => bank_card_type,
22
+ "bankCardNo" => bank_card_no,
23
+ "cvn2" => cvn2,
24
+ "useTime" => use_time}
25
+ post_params = NeotelisPay.client_params.merge(options).merge(input_hash)
26
+ #调用查询接口
27
+ msg = NeotelisPay::Utils::HttpPost.send_post(service_name, post_params)
28
+ msg
29
+ end
30
+
31
+ # 签约确认接口
32
+ # token 授权码
33
+ # verifyCode 短信验证码
34
+ def self.post_sign_confirm(token, verify_code, options={})
35
+ service_name = "signConfirm"
36
+ input_hash = {"type" => service_name,
37
+ "token" => token,
38
+ "verifyCode" => verify_code}
39
+ post_params = NeotelisPay.client_params.merge(options).merge(input_hash)
40
+ #调用查询接口
41
+ msg = NeotelisPay::Utils::HttpPost.send_post(service_name, post_params)
42
+ msg
43
+ end
44
+
45
+ # 签约支付申请接
46
+ # orderId 商户订单号
47
+ # amount 订单金额
48
+ # currency 币种
49
+ # price 商品单价
50
+ # orderTime 订单日期
51
+ # merAcDate 商户会计日期
52
+ # period 订单有效时间
53
+ # busiPartner 商户业务类型
54
+ # merchantAbbr 商户名称
55
+ # productDesc 商品描述
56
+ # productId 商品编号
57
+ # productName 商品名称
58
+ # productNum 商品数量
59
+ # orderDesc 订单描述
60
+ # userToken 用户手机号
61
+ # payerName 持卡人姓名
62
+ # certType 证件类型
63
+ # certNo 证件号
64
+ # bankCardType 银行卡类型
65
+ # bankCardNo 银行卡号
66
+ # bankNo 银行代码
67
+ # cvn2 CVN2
68
+ # cardExpYear 信用卡有效期年
69
+ # cardExpMonth 信用卡有效期月
70
+ # payType 支付类型
71
+ # notifyUrl 后台通知URL
72
+ # bindId 签约协议号
73
+ # reserved1 保留字段1
74
+ # reserved2 保留字段2
75
+ def self.post_prepay(order_id, amount, currency, product_name, bank_no, notify_url, bind_id, options={})
76
+ service_name = "prepay"
77
+ input_hash = {"type" => service_name,
78
+ "orderId" => order_id,
79
+ "amount" => amount,
80
+ "currency" => currency,
81
+ "orderTime" => Time.now.strftime("%Y%m%d%H%M%S"),
82
+ "merAcDate" => Time.now.strftime("%Y%m%d"),
83
+ "merchantAbbr" => NeotelisPay.merchant_abbr,
84
+ "productName" => NeotelisPay.product_name || product_name,
85
+ "bankNo" => bank_no,
86
+ "notifyUrl" => notify_url,
87
+ "bindId" => bind_id}
88
+ post_params = NeotelisPay.client_params.merge(options).merge(input_hash)
89
+ #调用查询接口
90
+ msg = NeotelisPay::Utils::HttpPost.send_post(service_name, post_params)
91
+ msg
92
+ end
93
+
94
+ # 签约支付确认接口
95
+ # token 授权码
96
+ # verifyCode 短信验证码
97
+ # orderId 商户订单号
98
+ # amount 订单金额
99
+ def self.post_pay_confirm(token, verify_code, order_id, amount, options={})
100
+ service_name = "payConfirm"
101
+ input_hash = {"type" => service_name,
102
+ "token" => token,
103
+ "verifyCode" => verify_code,
104
+ "orderId" => order_id,
105
+ "amount" => amount}
106
+ post_params = NeotelisPay.client_params.merge(options).merge(input_hash)
107
+ #调用查询接口
108
+ msg = NeotelisPay::Utils::HttpPost.send_post(service_name, post_params)
109
+ msg
110
+ end
111
+
112
+ # 网关支付接口
113
+ # bankNo 银行编码
114
+ # orderId 商户订单号
115
+ # amount 订单金额
116
+ # currency 币种
117
+ # orderTime 订单日期
118
+ # productDesc 商品描述
119
+ # productId 商品编号
120
+ # productName 商品名称
121
+ # productNum 商品数量
122
+ # notifyUrl 后台通知URL
123
+ # callbackUrl 前台地址
124
+ # reserved1 保留字段1
125
+ # reserved2 保留字段2
126
+ def self.post_gateway_pay(order_id, amount, currency, product_name, product_desc, bank_no, notify_url, options={})
127
+ service_name = "gatewayPay"
128
+ input_hash = {"type" => service_name,
129
+ "bankNo" => bank_no,
130
+ "orderId" => order_id,
131
+ "amount" => amount,
132
+ "currency" => currency,
133
+ "orderTime" => Time.now.strftime("%Y%m%d%H%M%S"),
134
+ "productName" => NeotelisPay.product_name || product_name,
135
+ "productDesc" => NeotelisPay.product_desc || product_desc,
136
+ "notifyUrl" => notify_url}
137
+ post_params = NeotelisPay.client_params.merge(options).merge(input_hash)
138
+ #调用查询接口
139
+ msg = NeotelisPay::Utils::HttpPost.send_post(service_name, post_params)
140
+ msg
141
+ end
142
+
143
+ ########################查询类接口########################
144
+ def self.query_order(order_type, order_id, options={})
145
+ service_name = "queryOrder"
146
+ input_hash = {"type" => service_name,
147
+ "orderType" => order_type,
148
+ "orderId" => order_id}
149
+ post_params = NeotelisPay.client_params.merge(options).merge(input_hash)
150
+ #调用查询接口
151
+ msg = NeotelisPay::Utils::HttpPost.send_post(service_name, post_params)
152
+ msg
153
+ end
154
+
155
+ end
156
+ end
@@ -0,0 +1,26 @@
1
+ require 'digest/md5'
2
+ module NeotelisPay
3
+ module Utils
4
+ class Crypt
5
+ def self.crypt_md5(source_msg, key)
6
+ k_ipad = Array.new(64, 54)
7
+ k_opad = Array.new(64, 92)
8
+ key_arr = key.unpack('c*')
9
+ for i in 0..(key_arr.size - 1)
10
+ k_ipad[i] = key_arr[i] ^ 54
11
+ k_opad[i] = key_arr[i] ^ 92
12
+ end
13
+ k_ipad_str = k_ipad.pack('c*')
14
+ k_opad_str = k_opad.pack('c*')
15
+
16
+ md1 = ''
17
+ md2 = ''
18
+ #取签名原文和空值进行一次MD5签名
19
+ md1 = Digest::MD5.digest(k_ipad_str + source_msg)
20
+ #取第一次签名后的值和商户秘钥再次MD5签名
21
+ md2 = Digest::MD5.hexdigest(k_opad_str + md1)
22
+ return md1, md2
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,63 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+ module NeotelisPay
4
+ module Utils
5
+ class Des
6
+ ALG = 'DES-ECB'
7
+
8
+ #加密
9
+ def self.encode(str, key)
10
+ #key取固定前8位
11
+ use_key = key[0,8]
12
+ #使用GBK编码
13
+ use_str = str.encode("GBK")
14
+ cipher = OpenSSL::Cipher.new(ALG)
15
+ cipher.encrypt
16
+ cipher.key = use_key
17
+ result = cipher.update(use_str) + cipher.final
18
+ return result.unpack('H*')
19
+ end
20
+
21
+ #解密
22
+ def self.decode(str, key)
23
+ #key取固定前8位
24
+ use_key = key[0,8]
25
+ #
26
+ decode_str = [str].pack('H*')
27
+ des = OpenSSL::Cipher::Cipher.new(ALG)
28
+ des.decrypt
29
+ des.key = use_key
30
+ result = des.update(decode_str) + des.final
31
+ dec_str = result.force_encoding("GBK")
32
+ utf8_str = dec_str.encode("UTF-8")
33
+ return utf8_str
34
+ end
35
+
36
+ #获取需要加密的字段
37
+ def self.des_param_list(service_type)
38
+ des_key_list = []
39
+ case service_type
40
+ when NeotelisPay::SERVICE_TYPE_SIGN_APPLY
41
+ des_key_list << 'userToken'
42
+ des_key_list << 'payerName'
43
+ des_key_list << 'certNo'
44
+ des_key_list << 'bankCardNo'
45
+ when NeotelisPay::SERVICE_TYPE_SIGN_CONFIRM
46
+ des_key_list << 'token'
47
+ des_key_list << 'verifyCode'
48
+ when NeotelisPay::SERVICE_TYPE_PREPAY
49
+ des_key_list << 'userToken'
50
+ des_key_list << 'payerName'
51
+ des_key_list << 'certNo'
52
+ des_key_list << 'bankCardNo'
53
+ when NeotelisPay::SERVICE_TYPE_PAY_CONFIRM
54
+ des_key_list << 'token'
55
+ des_key_list << 'verifyCode'
56
+ when NeotelisPay::SERVICE_TYPE_GATEWAY_PAY
57
+ des_key_list << ''
58
+ end
59
+ return des_key_list
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,80 @@
1
+ require 'logger'
2
+
3
+ module NeotelisPay
4
+ module Utils
5
+ class HttpPost
6
+
7
+ DEFAULT_ERR_MSG = '{"returnCode":"E88888","message":"其他错误!"}'
8
+
9
+ #对参数就行加密
10
+ def self.get_des_params(service_type, params)
11
+ des_key_list = NeotelisPay::Utils::Des.des_param_list(service_type)
12
+ des_key_list.each do |key|
13
+ if params.keys.include?(key)
14
+ params[key] = NeotelisPay::Utils::Des.decode(params[key], NeotelisPay.secret_key)
15
+ end
16
+ end
17
+ return params
18
+ end
19
+
20
+ #生成md5签名
21
+ def self.get_sign_data(params)
22
+ #排序
23
+ data_hash = sorted_hash(params)
24
+ #拼接
25
+ data_arr = []
26
+ data_hash.each do |k,v|
27
+ data_arr << v.to_s
28
+ end
29
+ data_str = data_arr.join('')
30
+ #MD5摘要
31
+ data_md5_1, data_md5_2 = NeotelisPay::Utils::Crypt.crypt_md5(data_str, '')
32
+ data_md5_3, data_md5_4 = NeotelisPay::Utils::Crypt.crypt_md5(data_md5_2, NeotelisPay.secret_key)
33
+ return data_str, data_md5_4
34
+ end
35
+
36
+ #排序
37
+ def self.sorted_hash(in_hash)
38
+ return in_hash.sort{|a,b| a.to_s <=> b.to_s }
39
+ end
40
+
41
+ #发送请求
42
+ def self.send_post(service_type, query_params)
43
+ api_url = ''
44
+
45
+ api_url = NeotelisPay.api_base_url
46
+ #对参数就行加密
47
+ des_params = get_des_params(service_type, query_params)
48
+ #对参数就行排序并签名
49
+ sign_value, sign_data = get_sign_data(des_params)
50
+
51
+ #加签名的查询参数
52
+ func_params = {"transData" => des_params.to_json, "signData" => sign_data}
53
+ func_all_params = func_params.merge(NeotelisPay.client_options)
54
+ conn = Faraday.new(:url => api_url)
55
+
56
+ response = conn.post '', func_all_params
57
+ html_response = response.body
58
+
59
+ if NeotelisPay.debug_mode
60
+ log_file = File.join(Rails.root, "log", "neotelis_pay.log")
61
+ logger = Logger.new(log_file)
62
+ logger.info('--------------NEOTELIS PAY DEBUG--------------')
63
+ logger.info("URL:#{api_url.to_s}")
64
+ logger.info("DES_PARAMS:#{des_params.to_s}")
65
+ logger.info("PARAMS:#{func_all_params.to_s}")
66
+ logger.info("SIGN_STRING:#{sign_value}")
67
+ logger.info("SIGN_DATA:#{sign_data}")
68
+ logger.info("RESPONSE:#{html_response.force_encoding('UTF-8')}")
69
+ end
70
+
71
+ begin
72
+ msg = JSON.parse(html_response)
73
+ rescue JSON::ParserError => e
74
+ msg = JSON.parse(DEFAULT_ERR_MSG)
75
+ end
76
+ msg
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ module NeotelisPay
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'fileutils'
2
+
3
+ namespace :neotelis_pay do
4
+ namespace :init do
5
+ desc "Generate neotelis_pay init file from example"
6
+ task :create do
7
+ source = File.join(Gem.loaded_specs["neotelis_pay"].full_gem_path, "neotelis_pay.rb")
8
+ target = File.join(Rails.root, "config", "initializers", "neotelis_pay.rb")
9
+ FileUtils.cp_r source, target
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "neotelis_pay/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "neotelis_pay"
8
+ spec.version = NeotelisPay::VERSION
9
+ spec.authors = ["tarzansos"]
10
+ spec.email = ["tuminfei1981@gmail.com"]
11
+
12
+ spec.summary = %q{NeotelisPay.}
13
+ spec.description = %q{NeotelisPay.}
14
+ spec.homepage = "https://github.com/tuminfei/neotelis_pay"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "railties", ">= 3.1.0"
25
+ spec.add_dependency "faraday", "~> 0.9.0"
26
+ spec.add_dependency 'uuid', '~> 2.3'
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.15"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "minitest", "~> 5.0"
31
+ end
data/neotelis_pay.rb ADDED
@@ -0,0 +1,31 @@
1
+ ##################TEST##################
2
+ #接口地址
3
+ NeotelisPay.api_base_url = 'http://test.neotelit.com/nft/rest/nft/services'
4
+ #商户账号
5
+ NeotelisPay.merchant_id = '201711291554826020'
6
+ #加密key
7
+ NeotelisPay.secret_key = 'e1af71ed03d26df65ed0b056d3be9fca'
8
+ #商户名称
9
+ NeotelisPay.merchant_abbr = 'OTC.ONE'
10
+ #商品名称
11
+ NeotelisPay.product_name = 'OTC'
12
+ #商品描述
13
+ NeotelisPay.product_desc = 'OTC'
14
+ #请求地址
15
+ NeotelisPay.request_ip = '192.168.0.100'
16
+
17
+ ##################PROD##################
18
+ # #接口地址
19
+ # NeotelisPay.api_base_url = 'http://api.neotelit.com/nft/rest/nft/services'
20
+ # #商户账号
21
+ # NeotelisPay.merchant_id = '201711291554826020'
22
+ # #加密key
23
+ # NeotelisPay.secret_key = 'e1af71ed03d26df65ed0b056d3be9fca'
24
+ # #商户名称
25
+ # NeotelisPay.merchant_abbr = 'OTC.ONE'
26
+ # #商品名称
27
+ # NeotelisPay.product_name = 'OTC'
28
+ #商品描述
29
+ # NeotelisPay.product_desc = 'OTC'
30
+ # #请求地址
31
+ # NeotelisPay.request_ip = '192.168.0.100'
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neotelis_pay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tarzansos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: uuid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ description: NeotelisPay.
98
+ email:
99
+ - tuminfei1981@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".ruby-gemset"
106
+ - ".ruby-version"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - lib/neotelis_pay.rb
116
+ - lib/neotelis_pay/railtie.rb
117
+ - lib/neotelis_pay/result.rb
118
+ - lib/neotelis_pay/service.rb
119
+ - lib/neotelis_pay/utils/crypt.rb
120
+ - lib/neotelis_pay/utils/des.rb
121
+ - lib/neotelis_pay/utils/http_post.rb
122
+ - lib/neotelis_pay/version.rb
123
+ - lib/rake/neotelis_pay.rake
124
+ - neotelis_pay.gemspec
125
+ - neotelis_pay.rb
126
+ homepage: https://github.com/tuminfei/neotelis_pay
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.6.13
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: NeotelisPay.
150
+ test_files: []