geee_pay 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cacbe0b1d32942e528058c590c7116067385377d
4
+ data.tar.gz: d2fe88fc9e2a79ebcf78025fdfd2066d66882e43
5
+ SHA512:
6
+ metadata.gz: 3bc6580e8b97c679bd56f77748d09aa4c086ce5d11fa1acc1f26abf9ed9a87995fcee2a3c477bfe22a42f5282581d372dd9c7a0d518e45471a122cfeb9e63f19
7
+ data.tar.gz: e5e9a525d3afb1dd1e2e1cf8d04e937db13b013303859a43d25f52f20418e89303e907a861a9b5a02dccc1cd2d353b12d8b387874841d884322694d3e8380ecf
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/.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.4
@@ -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 geee_pay.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Terry
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
+ # GeeePay
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/geee_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 'geee_pay'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install geee_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]/geee_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 GeeePay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/geee_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
@@ -0,0 +1,32 @@
1
+ module GeeePay
2
+ class NotifyController < ::ActionController::Base
3
+ if _process_action_callbacks.any?{|a| a.filter == :verify_authenticity_token}
4
+ # ActionController::Base no longer protects from forgery in Rails 5
5
+ skip_before_filter :verify_authenticity_token
6
+ end
7
+
8
+ layout false
9
+
10
+ def index
11
+ notice = GeeePay::Notice.new
12
+ notice.version_id = params[:versionId]
13
+ notice.trans_type = params[:transType]
14
+ notice.asyn_notify_url = params[:asynNotifyUrl]
15
+ notice.syn_notify_url = params[:synNotifyUrl]
16
+ notice.mer_id = params[:merId]
17
+ notice.order_amount = params[:orderAmount]
18
+ notice.prd_ord_no = params[:prdOrdNo]
19
+ notice.order_status = params[:orderStatus]
20
+ notice.pay_id = params[:payId]
21
+ notice.pay_time = params[:payTime]
22
+ notice.sign_type = params[:signType]
23
+ notice.mer_param = params[:merParam]
24
+ notice.sign_data = params[:signData]
25
+ if notice.save
26
+ render text: 'SUCCESS'
27
+ else
28
+ render text: 'FAIL'
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ module GeeePay
2
+ class Notice < ActiveRecord::Base
3
+ end
4
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "geee_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
data/geee_pay.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "geee_pay/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "geee_pay"
8
+ spec.version = GeeePay::VERSION
9
+ spec.authors = ["Terry.Tu"]
10
+ spec.email = ["tuminfei1981@gmail.com"]
11
+
12
+ spec.summary = %q{Geee Pay.}
13
+ spec.description = %q{Geee Pay.}
14
+ spec.homepage = "https://github.com/tuminfei/geee_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 "faraday", "~> 0.9.0"
25
+ spec.add_dependency "railties", ">= 3.1.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.15"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest", "~> 5.0"
30
+ end
data/geee_pay.rb ADDED
@@ -0,0 +1,15 @@
1
+ ##################TEST##################
2
+ # 接口地址
3
+ GeeePay.api_base_url = 'http://geeepay.com:8080/payment'
4
+ # 商户账号
5
+ GeeePay.mer_id = '201711291554826020'
6
+ # 商户key
7
+ GeeePay.mer_key = 'e1af71ed03d26df65ed0b056d3be9fca'
8
+
9
+ ##################PROD##################
10
+ # # 接口地址
11
+ # GeeePay.api_base_url = 'http://geeepay.com:8080/payment'
12
+ # # 商户账号
13
+ # GeeePay.mer_id = '201711291554826020'
14
+ # # 商户key
15
+ # GeeePay.mer_key = 'e1af71ed03d26df65ed0b056d3be9fca'
@@ -0,0 +1,12 @@
1
+ module GeeePay
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace GeeePay
4
+
5
+ initializer 'GeeePay', group: :all do |app|
6
+ Rails.application.routes.prepend do
7
+ mount GeeePay::Engine, at: '/api/geee_pay'
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,8 @@
1
+ #encoding: utf-8
2
+ module GeeePay
3
+ class Railtie < Rails::Railtie
4
+ rake_tasks do
5
+ load 'rake/geee_pay.rake'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,43 @@
1
+ module GeeePay
2
+ class Result
3
+ attr_accessor :raw, :msg
4
+
5
+ RESULT_SUCCESS_FLAG = '1'
6
+
7
+
8
+ # 网关支付-银行编码
9
+ BANK_CODE_MAP = {
10
+ '102' => '工商银行',
11
+ '103' => '农业银行',
12
+ '104' => '中国银行',
13
+ '105' => '建设银行',
14
+ '203' => '农业发展银行',
15
+ '301' => '交通银行',
16
+ '302' => '中信银行',
17
+ '303' => '光大银行',
18
+ '304' => '华夏银行',
19
+ '305' => '民生银行',
20
+ '306' => '广发银行',
21
+ '307' => '平安银行',
22
+ '308' => '招商银行',
23
+ '309' => '兴业银行',
24
+ '310' => '浦发银行',
25
+ '313' => '北京银行',
26
+ '315' => '恒丰银行',
27
+ '316' => '浙商银行',
28
+ '318' => '渤海银行',
29
+ '325' => '上海银行',
30
+ '403' => '邮储银行',
31
+ '440' => '徽商银行'
32
+ }
33
+
34
+ def initialize(result)
35
+ self.raw = result.to_s
36
+ self.msg = result
37
+ end
38
+
39
+ def success?
40
+ @msg['returnCode'] == RESULT_SUCCESS_FLAG
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,166 @@
1
+ module GeeePay
2
+ class Service
3
+ ########################交易类接口########################
4
+
5
+ # 扫码支付申请
6
+ # orderAmount 订单金额
7
+ # orderDate 订单日期
8
+ # currency 货币类型
9
+ # asynNotifyUrl 异步通知 URL
10
+ # synNotifyUrl 同步返回 URL
11
+ # prdOrdNo 商户订单号
12
+ # payMode 支付方式
13
+ # receivableType 到账类型
14
+ # prdAmt 商品价格
15
+ # prdDisUrl 商品展示网址
16
+ # prdName 商品名称
17
+ # prdShortName 商品简称
18
+ # prdDesc 商品描述
19
+ # merParam 扩展参数
20
+ def self.post_scan_pay_apply(order_amount, order_date, currency, asyn_notify_url, syn_notify_url,
21
+ prd_ord_no, pay_mode, receivable_type, prd_amt, prd_name, prd_dis_url='', prd_short_name='', prd_desc='', mer_param='', options={})
22
+ service_name = GeeePay::SERVICE_SCAN_PAY_APPLY
23
+ input_hash = {"orderAmount" => order_amount,
24
+ "orderDate" => order_date,
25
+ "currency" => currency,
26
+ "asynNotifyUrl" => asyn_notify_url,
27
+ "synNotifyUrl" => syn_notify_url,
28
+ "prdOrdNo" => prd_ord_no,
29
+ "payMode" => pay_mode,
30
+ "receivableType" => receivable_type,
31
+ "prdAmt" => prd_amt,
32
+ "prdName" => prd_name,
33
+ "prdDisUrl" => prd_dis_url,
34
+ "prdShortName" => prd_short_name,
35
+ "prdDesc" => prd_desc,
36
+ "merParam" => mer_param}
37
+ post_params = GeeePay.client_params.merge(options).merge(input_hash)
38
+ #调用查询接口
39
+ msg = GeeePay::Utils::HttpPost.send_post(service_name, post_params, GeeePay.mer_key)
40
+ msg
41
+ end
42
+
43
+ # 提现申请
44
+ # orderAmount 订单金额
45
+ # orderDate 订单日期
46
+ # currency 货币类型]
47
+ # asynNotifyUrl 异步通知 URL
48
+ # prdOrdNo 商户订单号
49
+ # receivableType 到账类型
50
+ # isCompay 对公对私标识
51
+ # phoneNo 手机号
52
+ # customerName 账户名
53
+ # cerdType 证件类型
54
+ # cerdId 证件号
55
+ # accBankNo 开户行号
56
+ # accBankName 开户行名称
57
+ # acctNo 银行账号
58
+ # rcvBranchName 开户行联行名称
59
+ # rcvBranchCode 开户行联行行号
60
+ # outaccounttype 出账类型
61
+ # bankBranch 支行名称
62
+ # provinceName 省份
63
+ # cityname 城市
64
+ # note 摘要
65
+ def self.post_withdraw_apply(order_amount, order_date, currency, asyn_notify_url, prd_ord_no, pay_mode,
66
+ receivable_type, is_compay, phone_no, customer_name, cerd_id, acc_bank_no, acc_bank_name, acct_no,
67
+ rcv_branch_code, bank_branch, province_name, city_name, cerd_type='', rcv_branch_name='', out_account_type='', note='', options={})
68
+ service_name = GeeePay::SERVICE_WITHDRAW_APPLY
69
+ input_hash = {"orderAmount" => order_amount,
70
+ "orderDate" => order_date,
71
+ "currency" => currency,
72
+ "asynNotifyUrl" => asyn_notify_url,
73
+ "prdOrdNo" => prd_ord_no,
74
+ "payMode" => pay_mode,
75
+ "receivableType" => receivable_type,
76
+ "isCompay" => is_compay,
77
+ "phoneNo" => phone_no,
78
+ "customerName" => customer_name,
79
+ "cerdId" => cerd_id,
80
+ "accBankNo" => acc_bank_no,
81
+ "accBankName" => acc_bank_name,
82
+ "acctNo" => acct_no,
83
+ "rcvBranchCode" => rcv_branch_code,
84
+ "bankBranch" => bank_branch,
85
+ "provinceName" => province_name,
86
+ "cityname" => city_name,
87
+ "cerdType" => cerd_type,
88
+ "rcvBranchName" => rcv_branch_name,
89
+ "outaccounttype" => out_account_type,
90
+ "note" => note}
91
+ post_params = GeeePay.client_params.merge(options).merge(input_hash)
92
+ #调用查询接口
93
+ msg = GeeePay::Utils::HttpPost.send_post(service_name, post_params, GeeePay.mer_key)
94
+ msg
95
+ end
96
+
97
+ # 网银支付申请
98
+ # orderAmount 订单金额
99
+ # orderDate 订单日期
100
+ # currency 货币类型
101
+ # accountType 银行卡种类
102
+ # asynNotifyUrl 异步通知 URL
103
+ # synNotifyUrl 同步返回 URL
104
+ # prdOrdNo 商户订单号
105
+ # payMode 支付方式
106
+ # tranChannel 银行编码
107
+ # receivableType 到账类型
108
+ # prdAmt 商品价格
109
+ # prdDisUrl 商品展示网址
110
+ # prdName 商品名称
111
+ # pnum 商品数量
112
+ # prdShortName 商品简称
113
+ # prdDesc 商品描述
114
+ # merParam 扩展参数
115
+ def self.post_pay_apply(order_amount, order_date, currency, account_type, asyn_notify_url, syn_notify_url, bank_card_no,
116
+ prd_ord_no, pay_mode, tran_channel, receivable_type, prd_amt, prd_name, pnum, prd_dis_url='', prd_short_name='', prd_desc='', mer_param='', options={})
117
+ service_name = GeeePay::SERVICE_PAY_APPLY
118
+ input_hash = {"orderAmount" => order_amount,
119
+ "orderDate" => order_date,
120
+ "currency" => currency,
121
+ "accountType" => account_type,
122
+ "asynNotifyUrl" => asyn_notify_url,
123
+ "synNotifyUrl" => syn_notify_url,
124
+ "bankCardNo" => bank_card_no,
125
+ "prdOrdNo" => prd_ord_no,
126
+ "payMode" => pay_mode,
127
+ "tranChannel" => tran_channel,
128
+ "receivableType" => receivable_type,
129
+ "prdAmt" => prd_amt,
130
+ "prdName" => prd_name,
131
+ "pnum" => pnum,
132
+ "prdDisUrl" => prd_dis_url,
133
+ "prdShortName" => prd_short_name,
134
+ "prdDesc" => prd_desc,
135
+ "merParam" => mer_param}
136
+ post_params = GeeePay.client_params.merge(options).merge(input_hash)
137
+ # 调用查询接口
138
+ msg, html_content = GeeePay::Utils::HttpPost.send_post(service_name, post_params, GeeePay.mer_key)
139
+ # 网银支付接口接口竟然返回html, O !!! M !!! G !!!
140
+ html_content
141
+ end
142
+
143
+ ########################查询类接口########################
144
+
145
+ # 订单状态查询
146
+ # prdOrdNo 商户订单号
147
+ def self.query_order_status(prd_ord_No, options={})
148
+ service_name = GeeePay::SERVICE_ORDER_QUERY
149
+ input_hash = {"prdOrdNo" => prd_ord_No}
150
+ post_params = GeeePay.client_query_params.merge(options).merge(input_hash)
151
+ # 调用查询接口
152
+ msg = GeeePay::Utils::HttpPost.send_post(service_name, post_params, GeeePay.mer_key)
153
+ msg
154
+ end
155
+
156
+ # 帐户余额查询
157
+ def self.query_mer_balance(options={})
158
+ service_name = GeeePay::SERVICE_BALANCE_QUERY
159
+ post_params = GeeePay.client_query_params.merge(options)
160
+ #调用查询接口
161
+ msg = GeeePay::Utils::HttpPost.send_post(service_name, post_params, GeeePay.mer_key)
162
+ msg
163
+ end
164
+
165
+ end
166
+ end
@@ -0,0 +1,46 @@
1
+ require 'logger'
2
+
3
+ module GeeePay
4
+ module Utils
5
+ class HttpPost
6
+
7
+ DEFAULT_ERR_MSG = '{"code":"0","desc":"其他错误!"}'
8
+
9
+ #发送请求
10
+ def self.send_post(service_type, query_params, key)
11
+ api_url = "#{GeeePay.api_base_url}/#{service_type}"
12
+ # 对参数就行排序并签名
13
+ sign_data, sign_str = GeeePay::Utils::Md5.sign(query_params, key)
14
+
15
+ # 加签名的查询参数
16
+ func_params = {"signData" => sign_data}
17
+
18
+ func_all_params = query_params.merge(func_params)
19
+ conn = Faraday.new(:url => api_url)
20
+
21
+ response = conn.post '', func_all_params
22
+ html_response = response.body
23
+ html_content = ''
24
+
25
+ if GeeePay.debug_mode
26
+ log_file = File.join(Rails.root, "log", "geee_pay.log")
27
+ logger = Logger.new(log_file)
28
+ logger.info('--------------GEEE PAY DEBUG--------------')
29
+ logger.info("URL:#{api_url.to_s}")
30
+ logger.info("PARAMS:#{func_all_params.to_s}")
31
+ logger.info("SIGN_STR:#{sign_str}")
32
+ logger.info("SIGN_DATA:#{sign_data}")
33
+ logger.info("RESPONSE:#{html_response.force_encoding('UTF-8')}")
34
+ end
35
+
36
+ begin
37
+ msg = JSON.parse(html_response)
38
+ rescue JSON::ParserError => e
39
+ html_content = html_response
40
+ msg = JSON.parse(DEFAULT_ERR_MSG)
41
+ end
42
+ return msg, html_content
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,38 @@
1
+ require 'digest/md5'
2
+
3
+ module GeeePay
4
+ module Utils
5
+ class Md5
6
+ # 生成md5签名
7
+ def self.sign(params, key)
8
+ # 删除空值
9
+ nonull_params = params.delete_if {|key, value| value.nil? or value == ''}
10
+ # 排序
11
+ data_hash = sorted_hash(nonull_params)
12
+ # 拼接
13
+ data_arr = []
14
+ data_hash.each do |k,v|
15
+ data_arr << "#{k.to_s}=#{v.to_s}"
16
+ end
17
+ data_arr << "key=#{key}"
18
+ data_str = data_arr.join('&')
19
+ return crypt_md5(data_str), data_str
20
+ end
21
+
22
+ # 排序
23
+ def self.sorted_hash(in_hash)
24
+ return in_hash.sort{|a,b| a.to_s <=> b.to_s }
25
+ end
26
+
27
+ def self.crypt_md5(msg, input_charset='utf-8')
28
+ if input_charset == 'utf-8'
29
+ sign_msg = msg
30
+ else
31
+ sign_msg = msg.encode('utf-8', input_charset)
32
+ end
33
+
34
+ return Digest::MD5.hexdigest sign_msg
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module GeeePay
2
+ VERSION = "0.1.0"
3
+ end
data/lib/geee_pay.rb ADDED
@@ -0,0 +1,61 @@
1
+ require 'digest/md5'
2
+
3
+ require "geee_pay/version"
4
+ require "geee_pay/engine"
5
+ require "geee_pay/utils/md5"
6
+ require "geee_pay/utils/http_post"
7
+ require "geee_pay/service"
8
+ require "geee_pay/result"
9
+ require "geee_pay/railtie" if defined?(Rails)
10
+
11
+ module GeeePay
12
+ @client_params = {}
13
+ @client_query_params = {}
14
+ @debug_mode = true
15
+ @version = '1.0'
16
+ @trans_type = '008'
17
+ @input_charset = 'UTF-8'
18
+ @sign_type = 'MD5'
19
+
20
+ # 扫码支付申请-接口
21
+ SERVICE_SCAN_PAY_APPLY = 'ScanPayApply.do'
22
+ # 提现申请-接口
23
+ SERVICE_WITHDRAW_APPLY = 'WithdrawApply.do'
24
+ # 网银支付申请-接口
25
+ SERVICE_PAY_APPLY = 'PayApply.do'
26
+ # 订单状态查询-接口
27
+ SERVICE_ORDER_QUERY = 'OrderStatusQuery.do'
28
+ # 帐户余额查询-接口
29
+ SERVICE_BALANCE_QUERY = 'QueryMerBalance.do'
30
+
31
+ class<< self
32
+ # mer_id 商户账号
33
+ # mer_key 加密key
34
+ attr_accessor :mer_id, :mer_key, :debug_mode
35
+ attr_reader :api_base_url
36
+
37
+ def api_base_url=(url)
38
+ @api_base_url = url
39
+ end
40
+
41
+ def client_params
42
+ params = {"versionId" => @version,
43
+ "merId" => @mer_id,
44
+ "transType" => @trans_type,
45
+ "signType" => @sign_type}
46
+ @client_params = params
47
+ @client_params
48
+ end
49
+
50
+ def client_query_params
51
+ params = {"merId" => @mer_id,
52
+ "signType" => @sign_type}
53
+ @client_query_params = params
54
+ @client_query_params
55
+ end
56
+
57
+ def debug_mode?
58
+ @debug_mode
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ class GeeePay::MigrationGenerator < ::Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ desc 'Installs GeeePay migration file.'
7
+
8
+ def install
9
+ migration_template 'migration.rb', 'db/migrate/create_geee_pay_notices.rb'
10
+ end
11
+
12
+ def self.next_migration_number(dirname)
13
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ class CreateSuningPayNotices < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :geee_pay_notices do |t|
4
+ t.string :version_id
5
+ t.string :trans_type
6
+ t.string :asyn_notify_url
7
+ t.string :syn_notify_url
8
+ t.string :mer_id
9
+ t.string :order_amount
10
+ t.string :prd_ord_no
11
+ t.string :order_status
12
+ t.string :pay_id
13
+ t.string :pay_time
14
+ t.string :sign_type
15
+ t.string :mer_param
16
+ t.string :sign_data
17
+ t.timestamps
18
+ end
19
+ end
20
+
21
+ def self.down
22
+ drop_table :geee_pay_notices
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require 'fileutils'
2
+
3
+ namespace :geee_pay do
4
+ namespace :init do
5
+ desc "Generate geee_pay init file from example"
6
+ task :create do
7
+ source = File.join(Gem.loaded_specs["geee_pay"].full_gem_path, "geee_pay.rb")
8
+ target = File.join(Rails.root, "config", "initializers", "geee_pay.rb")
9
+ FileUtils.cp_r source, target
10
+ end
11
+
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geee_pay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Terry.Tu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Geee Pay.
84
+ email:
85
+ - tuminfei1981@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - app/controllers/notify_controller.rb
98
+ - app/models/geee_pay/notice.rb
99
+ - bin/console
100
+ - bin/setup
101
+ - geee_pay.gemspec
102
+ - geee_pay.rb
103
+ - lib/geee_pay.rb
104
+ - lib/geee_pay/engine.rb
105
+ - lib/geee_pay/railtie.rb
106
+ - lib/geee_pay/result.rb
107
+ - lib/geee_pay/service.rb
108
+ - lib/geee_pay/utils/http_post.rb
109
+ - lib/geee_pay/utils/md5.rb
110
+ - lib/geee_pay/version.rb
111
+ - lib/generators/geee_pay/migration_generator.rb
112
+ - lib/generators/geee_pay/templates/migration.rb
113
+ - lib/rake/geee_pay.rake
114
+ homepage: https://github.com/tuminfei/geee_pay
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.6.13
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Geee Pay.
138
+ test_files: []