alipass 0.0.1
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +9 -0
- data/alipass.gemspec +26 -0
- data/lib/alipass.rb +10 -0
- data/lib/alipass/sign.rb +12 -0
- data/lib/alipass/template.rb +29 -0
- data/lib/alipass/template/content.rb +37 -0
- data/lib/alipass/version.rb +3 -0
- data/spec/alipass/template/content_spec.rb +23 -0
- data/spec/alipass/template_spec.rb +89 -0
- data/spec/spec_helper.rb +7 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0d957ce0a1d111a4b89637cbf080700b1ba2e41d
|
4
|
+
data.tar.gz: 40c563d27c3ded9b0d6d69cd9b15eab345dfb73b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7906cf28810660ce05dd94ec1ee021e84f9b5ce435914d52fb00cf0a16ce44f6bc210a992aa015c6f083d4cb611815fee91891e9f47f3ea33c658a016f91e370
|
7
|
+
data.tar.gz: 108406fd6c981029a42ea7252896d6ae6e0a1067a8b473d9d92cbaa43cd61d1f033d6720eb4ba8f94b7d8b7b84989fe0084132d63e07a79e32d88e478f405ecc
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 HungYuHei
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Alipass
|
2
|
+
|
3
|
+
支付宝卡券 https://alipass.alipay.com/index.htm
|
4
|
+
[官方文档](https://openhome.alipay.com/doc/docIndex.htm?url=https://openhome.alipay.com/doc/viewKbDoc.htm?key=236698&type=cat)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'alipass'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install alipass
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Config
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Alipass.app_id = 'APP_ID'
|
26
|
+
Alipass.private_key_file = '/PATH/TO/YOUR/RSA/PRIVATE_KEY_FILE'
|
27
|
+
```
|
28
|
+
|
29
|
+
### 新建模版
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Alipass::Template.add(
|
33
|
+
tpl_content: "" # 支付宝pass模版内容
|
34
|
+
)
|
35
|
+
```
|
36
|
+
|
37
|
+
`tpl_content` 参数比较复杂,请参考[测试代码](https://github.com/HungYuHei/alipass/blob/master/spec/alipass/template_spec.rb)和[数据格式说明](https://openhome.alipay.com/doc/docIndex.htm?url=https://openhome.alipay.com/doc/viewKbDoc.htm?key=236698_261970&type=info)
|
38
|
+
|
39
|
+
### 模版方式添加卡券
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Alipass::Template::Content.add(
|
43
|
+
tpl_id: 'tpl_id',
|
44
|
+
tpl_params: %Q({"title":"title","begin_at":"2014-11-11 00:11"}),
|
45
|
+
recognition_type: '1',
|
46
|
+
recognition_info: %Q({"partner_id":"partner_id","out_trade_no":"out_trade_no"})
|
47
|
+
)
|
48
|
+
```
|
49
|
+
|
50
|
+
### Run test
|
51
|
+
|
52
|
+
```
|
53
|
+
rake test
|
54
|
+
```
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/alipass.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'alipass/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "alipass"
|
8
|
+
spec.version = Alipass::VERSION
|
9
|
+
spec.authors = ["HungYuHei"]
|
10
|
+
spec.email = ["kongruxi@gmail.com"]
|
11
|
+
spec.summary = "支付宝卡券"
|
12
|
+
spec.description = "支付宝卡券"
|
13
|
+
spec.homepage = "https://github.com/HungYuHei/alipass"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rest-client", "~> 1.6.7"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "fakeweb", "~> 1.3"
|
26
|
+
end
|
data/lib/alipass.rb
ADDED
data/lib/alipass/sign.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Alipass
|
4
|
+
module Sign
|
5
|
+
def self.generate(params)
|
6
|
+
private_key = OpenSSL::PKey::RSA.new(File.read(Alipass.private_key_file))
|
7
|
+
digest = OpenSSL::Digest::SHA1.new
|
8
|
+
to_sign = params.sort.map { |item| item.join('=') }.join('&')
|
9
|
+
Base64.encode64(private_key.sign(digest, to_sign))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'alipass/template/content'
|
2
|
+
|
3
|
+
module Alipass
|
4
|
+
module Template
|
5
|
+
# REQUIRED_PARAMS = [ :method, :timestamp, :app_id, :version, :sign, :sign_type, :tpl_content]
|
6
|
+
|
7
|
+
def self.add(params)
|
8
|
+
gateway = 'https://openapi.alipay.com/gateway.do'
|
9
|
+
params = {
|
10
|
+
method: 'alipay.pass.tpl.add',
|
11
|
+
timestamp: Time.now.strftime('%F %T'),
|
12
|
+
format: 'json',
|
13
|
+
app_id: Alipass.app_id,
|
14
|
+
version: '1.0',
|
15
|
+
sign_type: 'RSA'
|
16
|
+
}.merge(params)
|
17
|
+
|
18
|
+
params[:tpl_content] = params[:tpl_content].encode('GBK') if params[:tpl_content]
|
19
|
+
|
20
|
+
sign = Sign.generate(params)
|
21
|
+
params.merge!(sign: sign)
|
22
|
+
|
23
|
+
RestClient.post(gateway, params) do |response|
|
24
|
+
JSON.parse(response.body)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest_client'
|
3
|
+
|
4
|
+
module Alipass
|
5
|
+
module Template
|
6
|
+
module Content
|
7
|
+
|
8
|
+
# REQUIRED_PARAMS = [
|
9
|
+
# :method, :timestamp, :app_id, :version, :sign, :sign_type,
|
10
|
+
# :tpl_id, :tpl_params, :recognition_type, :recognition_info
|
11
|
+
# ]
|
12
|
+
|
13
|
+
# tpl_id, tpl_params, recognition_type, recognition_info
|
14
|
+
def self.add(params)
|
15
|
+
gateway = 'https://openapi.alipay.com/gateway.do'
|
16
|
+
params = {
|
17
|
+
method: 'alipay.pass.tpl.content.add',
|
18
|
+
timestamp: Time.now.strftime('%F %T'),
|
19
|
+
format: 'json',
|
20
|
+
app_id: Alipass.app_id,
|
21
|
+
sign_type: 'RSA',
|
22
|
+
version: '1.0'
|
23
|
+
}.merge(params)
|
24
|
+
|
25
|
+
params[:tpl_params] = params[:tpl_params].encode('GBK') if params[:tpl_params]
|
26
|
+
|
27
|
+
sign = Sign.generate(params)
|
28
|
+
params.merge!(sign: sign)
|
29
|
+
|
30
|
+
RestClient.post(gateway, params) do |response|
|
31
|
+
JSON.parse(response.body)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alipass::Template::Content do
|
4
|
+
let(:body) do
|
5
|
+
%Q({"alipay_pass_tpl_add_response":{"success":"T","error_code":"SUCCESS","biz_result":{"serialNumber":"123555123","passId":"32770","result":"SUCCESS"}}})
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
FakeWeb.register_uri(:post, 'https://openapi.alipay.com/gateway.do', body: body)
|
10
|
+
end
|
11
|
+
|
12
|
+
it ".add" do
|
13
|
+
params = {
|
14
|
+
tpl_id: 'tpl_id',
|
15
|
+
tpl_params: %Q({"title":"title","begin_at":"2014-11-11 00:11"}),
|
16
|
+
recognition_type: '1',
|
17
|
+
recognition_info: %Q({"partner_id":"partner_id","out_trade_no":"out_trade_no"})
|
18
|
+
}
|
19
|
+
|
20
|
+
json = Alipass::Template::Content.add(params)
|
21
|
+
json['alipay_pass_tpl_add_response']['biz_result']['result'].must_equal 'SUCCESS'
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alipass::Template do
|
4
|
+
let(:tpl_id) { 'test_tpl_id' }
|
5
|
+
let(:body) do
|
6
|
+
%Q({"alipay_pass_tpl_add_response":{"error_code":"SUCCESS", "result":{"tpl_id":"#{tpl_id}","tpl_params":[]}, "success":true}, "sign":"sign"})
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
FakeWeb.register_uri(:post, 'https://openapi.alipay.com/gateway.do', body: body)
|
11
|
+
end
|
12
|
+
|
13
|
+
it ".add" do
|
14
|
+
params = {
|
15
|
+
logo: 'logo_url',
|
16
|
+
strip: 'strip_url',
|
17
|
+
icon: 'icon_url',
|
18
|
+
content: pass_json
|
19
|
+
}
|
20
|
+
|
21
|
+
json = Alipass::Template.add(tpl_content: params.to_json)
|
22
|
+
json['alipay_pass_tpl_add_response']['result']['tpl_id'].must_equal tpl_id
|
23
|
+
end
|
24
|
+
|
25
|
+
def pass_json
|
26
|
+
{
|
27
|
+
evoucherInfo: {
|
28
|
+
goodsId: "",
|
29
|
+
title: "$title",
|
30
|
+
type: "eventTicket",
|
31
|
+
product: "movie",
|
32
|
+
startDate: "$begin_at",
|
33
|
+
endDate: "$end_at",
|
34
|
+
operation: [
|
35
|
+
{
|
36
|
+
format: "qrcode",
|
37
|
+
message: "$qr_value",
|
38
|
+
messageEncoding: "utf-8",
|
39
|
+
altText: "$qr_tips"
|
40
|
+
},
|
41
|
+
{
|
42
|
+
message: {
|
43
|
+
android_appid: "com.youyanchu.android",
|
44
|
+
android_launch: "schemes://com.youyanchu.android",
|
45
|
+
android_download: "http://youyanchu.com/l/app/android",
|
46
|
+
ios_appid: "com.youyanchu.iphone.showtime",
|
47
|
+
ios_launch: "schemes://com.youyanchu.iphone.showtime",
|
48
|
+
ios_download: "http://youyanchu.com/l/app/ios"
|
49
|
+
},
|
50
|
+
format: "app",
|
51
|
+
messageEncoding: "utf-8",
|
52
|
+
altText: "$app_tips"
|
53
|
+
},
|
54
|
+
{
|
55
|
+
format: "url",
|
56
|
+
message: "$perf_url",
|
57
|
+
messageEncoding: "utf-8",
|
58
|
+
altText: "$web_tips"
|
59
|
+
}
|
60
|
+
],
|
61
|
+
einfo: {
|
62
|
+
logoText: "$title",
|
63
|
+
headFields: [{key: "begin_at_date", label: "日期", value: "$begin_at_date", type: "text"}],
|
64
|
+
primaryFields: [{key: "begin_at_time", label: "演出时间", value: "$begin_at_time", type: "text"}],
|
65
|
+
secondaryFields: [{key: "scene", label: "场地", value: "$scene", type: "map"}],
|
66
|
+
auxiliaryFields: [{key: "number", label: "票号", value: "$number", type: "text"}, {key: "price", label: "金额", value: "$price", type: "text"}],
|
67
|
+
backFields: []
|
68
|
+
},
|
69
|
+
locations: [{altitude: "", longitude: "$longitude", latitude: "$latitude", tel: "$tel", addr: "$address", relevantText: "$scene_name"}]
|
70
|
+
}, # evoucherInfo
|
71
|
+
|
72
|
+
merchant: {mname: "xxx有限公司", mtel: "123456789", minfo: ""},
|
73
|
+
platform: {channelID: "$channel_id", webServiceUrl: "$web_service_url"},
|
74
|
+
style: {backgroundColor: "$background_color"},
|
75
|
+
|
76
|
+
fileInfo: {formatVersion: "2", canShare: true, canBuy: false, serialNumber: "$serial_number"},
|
77
|
+
|
78
|
+
appInfo: {
|
79
|
+
app: {android_appid: "com.youyanchu.android", android_launch: "schemes://com.youyanchu.android", android_download: "http://youyanchu.com/l/app/android", ios_appid: "com.youyanchu.iphone.showtime", ios_launch: "schemes://com.youyanchu.iphone.showtime", ios_download: "http://youyanchu.com/l/app/ios"},
|
80
|
+
label: "有演出",
|
81
|
+
message: "音乐演出神器"
|
82
|
+
},
|
83
|
+
|
84
|
+
source: "alipassprod",
|
85
|
+
alipayVerify: []
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alipass
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- HungYuHei
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fakeweb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
description: "支付宝卡券"
|
70
|
+
email:
|
71
|
+
- kongruxi@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- alipass.gemspec
|
82
|
+
- lib/alipass.rb
|
83
|
+
- lib/alipass/sign.rb
|
84
|
+
- lib/alipass/template.rb
|
85
|
+
- lib/alipass/template/content.rb
|
86
|
+
- lib/alipass/version.rb
|
87
|
+
- spec/alipass/template/content_spec.rb
|
88
|
+
- spec/alipass/template_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: https://github.com/HungYuHei/alipass
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.2.2
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: "支付宝卡券"
|
114
|
+
test_files:
|
115
|
+
- spec/alipass/template/content_spec.rb
|
116
|
+
- spec/alipass/template_spec.rb
|
117
|
+
- spec/spec_helper.rb
|