new_alipay 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: 5aab313870916203fa6f44f249aa0a2046f9c753
4
+ data.tar.gz: 9c7b79ab9cac499ddc68fea2dc4948d35921ee3b
5
+ SHA512:
6
+ metadata.gz: fcd47aaba0b36968f9ed7e47fd785ae47568c09171fb9198b24f9ef875f9e71c161d2af6e1831a73f26aa8feb4db6081ba1c3ddc39a20535fce7792b91afc87b
7
+ data.tar.gz: 1182d94d9648398a6747316bf398ac11e247216c9ee9c6af0d5b173b4a61a18039588cf3c7a288ba1bf74e787715e00747003d5bd7d86a276f7f52a10efaf447
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ /config/
12
+ /.idea/
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalisation:
26
+ /.bundle/
27
+ /vendor/bundle
28
+ /lib/bundler/man/
29
+
30
+ # for a library or gem, you might want to ignore these files since the code is
31
+ # intended to run in multiple environments; otherwise, check them in:
32
+ # Gemfile.lock
33
+ # .ruby-version
34
+ # .ruby-gemset
35
+
36
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
37
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in new_alipay.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,115 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ new_alipay (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionmailer (3.2.21)
10
+ actionpack (= 3.2.21)
11
+ mail (~> 2.5.4)
12
+ actionpack (3.2.21)
13
+ activemodel (= 3.2.21)
14
+ activesupport (= 3.2.21)
15
+ builder (~> 3.0.0)
16
+ erubis (~> 2.7.0)
17
+ journey (~> 1.0.4)
18
+ rack (~> 1.4.5)
19
+ rack-cache (~> 1.2)
20
+ rack-test (~> 0.6.1)
21
+ sprockets (~> 2.2.1)
22
+ activemodel (3.2.21)
23
+ activesupport (= 3.2.21)
24
+ builder (~> 3.0.0)
25
+ activerecord (3.2.21)
26
+ activemodel (= 3.2.21)
27
+ activesupport (= 3.2.21)
28
+ arel (~> 3.0.2)
29
+ tzinfo (~> 0.3.29)
30
+ activeresource (3.2.21)
31
+ activemodel (= 3.2.21)
32
+ activesupport (= 3.2.21)
33
+ activesupport (3.2.21)
34
+ i18n (~> 0.6, >= 0.6.4)
35
+ multi_json (~> 1.0)
36
+ arel (3.0.3)
37
+ builder (3.0.4)
38
+ diff-lcs (1.2.5)
39
+ erubis (2.7.0)
40
+ faraday (0.9.1)
41
+ multipart-post (>= 1.2, < 3)
42
+ hike (1.2.3)
43
+ i18n (0.7.0)
44
+ journey (1.0.4)
45
+ json (1.8.3)
46
+ mail (2.5.4)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.25.1)
50
+ multi_json (1.11.1)
51
+ multipart-post (2.0.0)
52
+ polyglot (0.3.5)
53
+ rack (1.4.5)
54
+ rack-cache (1.2)
55
+ rack (>= 0.4)
56
+ rack-ssl (1.3.4)
57
+ rack
58
+ rack-test (0.6.3)
59
+ rack (>= 1.0)
60
+ rails (3.2.21)
61
+ actionmailer (= 3.2.21)
62
+ actionpack (= 3.2.21)
63
+ activerecord (= 3.2.21)
64
+ activeresource (= 3.2.21)
65
+ activesupport (= 3.2.21)
66
+ bundler (~> 1.0)
67
+ railties (= 3.2.21)
68
+ railties (3.2.21)
69
+ actionpack (= 3.2.21)
70
+ activesupport (= 3.2.21)
71
+ rack-ssl (~> 1.3.2)
72
+ rake (>= 0.8.7)
73
+ rdoc (~> 3.4)
74
+ thor (>= 0.14.6, < 2.0)
75
+ rake (10.1.1)
76
+ rdoc (3.12.2)
77
+ json (~> 1.4)
78
+ rspec (3.3.0)
79
+ rspec-core (~> 3.3.0)
80
+ rspec-expectations (~> 3.3.0)
81
+ rspec-mocks (~> 3.3.0)
82
+ rspec-core (3.3.0)
83
+ rspec-support (~> 3.3.0)
84
+ rspec-expectations (3.3.0)
85
+ diff-lcs (>= 1.2.0, < 2.0)
86
+ rspec-support (~> 3.3.0)
87
+ rspec-mocks (3.3.0)
88
+ diff-lcs (>= 1.2.0, < 2.0)
89
+ rspec-support (~> 3.3.0)
90
+ rspec-support (3.3.0)
91
+ sprockets (2.2.3)
92
+ hike (~> 1.2)
93
+ multi_json (~> 1.0)
94
+ rack (~> 1.0)
95
+ tilt (~> 1.1, != 1.3.0)
96
+ thor (0.19.1)
97
+ tilt (1.4.1)
98
+ treetop (1.4.15)
99
+ polyglot
100
+ polyglot (>= 0.3.1)
101
+ tzinfo (0.3.44)
102
+
103
+ PLATFORMS
104
+ ruby
105
+
106
+ DEPENDENCIES
107
+ bundler (~> 1.9)
108
+ faraday (~> 0.9)
109
+ new_alipay!
110
+ rails (~> 3.2)
111
+ rake (~> 10.0)
112
+ rspec (~> 3.2)
113
+
114
+ BUNDLED WITH
115
+ 1.10.3
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 木卯溪
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # NewAlipay
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/new_alipay`. 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 'new_alipay'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install new_alipay
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 `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` to 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
+ 1. Fork it ( https://github.com/[my-github-username]/new_alipay/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "new_alipay"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module NewAlipay
2
+ VERSION = "0.1.0"
3
+ end
data/lib/new_alipay.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'rails'
2
+ require "new_alipay/version"
3
+ require "faraday"
4
+ require 'openssl'
5
+ require 'base64'
6
+
7
+ module NewAlipay
8
+ class << self
9
+ attr_accessor :seller_email, :partner, :key
10
+ end
11
+ module_function
12
+
13
+ #移动支付:创建支付订单
14
+ def mobile_trade_create(config)
15
+ parameters = {
16
+ "partner" => "\"#{self.partner}\"",
17
+ "seller_id" => "\"#{self.seller_email}\"",
18
+ "out_trade_no" => "\"#{config[:out_trade_no]}\"",
19
+ "subject" => "\"#{config[:subject]}\"",
20
+ "body" => "\"#{config[:body]}\"",
21
+ "total_fee" => "\"#{config[:total_fee]}\"",
22
+ "notify_url" => "\"#{config[:notify_url]}\"",
23
+ "service" => "\"mobile.securitypay.pay\"",
24
+ "payment_type" => "1",
25
+ "_input_charset" => "\"utf-8\"",
26
+ "it_b_pay" => "30m",
27
+ "return_url" => "\"m.alipay.com\""
28
+ }
29
+ signing_str = parameters.inject([]) { |memo, (key, v)| memo << "#{key}=#{v}"; memo }.join("&")
30
+ rsa_sign(signing_str)
31
+ end
32
+
33
+ #rsa签名
34
+ def rsa_sign(signing_str)
35
+ #读取私钥文件
36
+ private_key_content = File.read(Rails.root ? File.join(Rails.root, "config", "alipay/quick/key/rsa_private_key.pem") : './config/alipay/quick/key/rsa_private_key.pem')
37
+
38
+ p private_key_content
39
+ private_key = OpenSSL::PKey::RSA.new private_key_content
40
+ digest = OpenSSL::Digest::SHA1.new
41
+ sign = Base64::encode64(private_key.sign(digest, signing_str))
42
+ signing_str+= "&sign=\"#{url_encode(sign)}\""
43
+ signing_str+ "&sign_type=\"RSA\""
44
+ end
45
+
46
+ def url_encode(s)
47
+ URI.escape(s.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
48
+ end
49
+
50
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'new_alipay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "new_alipay"
8
+ spec.version = NewAlipay::VERSION
9
+ spec.authors = ["saxer"]
10
+ spec.email = ["15201280641@qq.com"]
11
+
12
+ spec.summary = %q{支付宝支付}
13
+ spec.description = %q{支付宝移动支付}
14
+ spec.homepage = "https://github.com/mumaoxi/new_alipay"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|config)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.9"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "faraday", "~> 0.9"
32
+ spec.add_development_dependency "rspec", "~> 3.2"
33
+ spec.add_development_dependency "rails", "~> 3.2"
34
+ end
data/rsa.php ADDED
@@ -0,0 +1,32 @@
1
+ <?php
2
+
3
+ $seller_id = "13366655137";
4
+ $partner = "2088702240557723";
5
+ $key = "5ze1yn7tv8ytfx0pb1r7spdnnahjksbg";
6
+
7
+ $data.= "&partner=\"$partner\"";
8
+ $data.= "&notify_url=\"".urlencode("http://test.api.miliani.com/")."\"";
9
+ $data.= "&service=\"mobile.securitypay.pay\"";
10
+ $data.= "&_input_charset=\"UTF-8\"";
11
+ $data.= "&payment_type=\"1\"";
12
+ $data.= "&seller_id=\"$seller_id\"";
13
+ $data.= "&it_b_pay=\"3h\"";
14
+
15
+ //读取私钥文件
16
+ $priKey = file_get_contents("config/alipay/quick/key/rsa_private_key.pem");
17
+
18
+ //转换为openssl密钥,必须是没有经过pkcs8转换的私钥
19
+ $res = openssl_get_privatekey($priKey);
20
+
21
+ //调用openssl内置签名方法,生成签名$sign
22
+ openssl_sign($data, $sign, $res);
23
+
24
+ //释放资源
25
+ openssl_free_key($res);
26
+
27
+ //base64编码
28
+ $sign = base64_encode($sign);
29
+
30
+ $data.= "&sign=\"".urlencode($sign)."\"";
31
+ $data.= "&sign_type=\"RSA\"";
32
+ ?>
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: new_alipay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - saxer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ description: 支付宝移动支付
84
+ email:
85
+ - 15201280641@qq.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/new_alipay.rb
100
+ - lib/new_alipay/version.rb
101
+ - new_alipay.gemspec
102
+ - rsa.php
103
+ homepage: https://github.com/mumaoxi/new_alipay
104
+ licenses: []
105
+ metadata:
106
+ allowed_push_host: https://rubygems.org
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.6
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: 支付宝支付
127
+ test_files: []