alipass 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/alipass/template.rb +8 -5
- data/lib/alipass/template/content.rb +2 -5
- data/lib/alipass/version.rb +1 -1
- data/spec/alipass/template/content_spec.rb +45 -7
- data/spec/alipass/template_spec.rb +60 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 320943ac438d9afbd296d14f4044e9ce8725d63d
|
4
|
+
data.tar.gz: 44e5c649b7afabb6d404045e3dbfaf2ea754f591
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7de3047c33a9f37538a464eac3a3581141f3157f0888a810ca96ac9bdd047dcac791342de32c3c21506bb225ab141f4ccdca1dcee3740251a61e9c925f1d551b
|
7
|
+
data.tar.gz: ec8e28fb745ba6d4dcf0d2944b69870aa29a10eae7ff7a40c55e9c1740fe540ef0e94a30a875aa104c66e8b9039b6ea259182d70a4b2cb99fdbcf8edc99aec72
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ Alipass::Template.add(
|
|
34
34
|
)
|
35
35
|
```
|
36
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)
|
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
38
|
|
39
39
|
### 模版方式添加卡券
|
40
40
|
|
@@ -50,6 +50,7 @@ Alipass::Template::Content.add(
|
|
50
50
|
### Run test
|
51
51
|
|
52
52
|
```
|
53
|
+
# Edit spec/spec_helper.rb
|
53
54
|
rake test
|
54
55
|
```
|
55
56
|
|
data/lib/alipass/template.rb
CHANGED
@@ -2,7 +2,11 @@ require 'alipass/template/content'
|
|
2
2
|
|
3
3
|
module Alipass
|
4
4
|
module Template
|
5
|
-
|
5
|
+
|
6
|
+
# REQUIRED_PARAMS = [
|
7
|
+
# :method, :timestamp, :app_id, :version, :sign, :sign_type,
|
8
|
+
# :tpl_content, :unique_id
|
9
|
+
# ]
|
6
10
|
|
7
11
|
def self.add(params)
|
8
12
|
gateway = 'https://openapi.alipay.com/gateway.do'
|
@@ -12,13 +16,12 @@ module Alipass
|
|
12
16
|
format: 'json',
|
13
17
|
app_id: Alipass.app_id,
|
14
18
|
version: '1.0',
|
19
|
+
unique_id: SecureRandom.hex,
|
15
20
|
sign_type: 'RSA'
|
16
21
|
}.merge(params)
|
17
22
|
|
18
|
-
params[:tpl_content]
|
19
|
-
|
20
|
-
sign = Sign.generate(params)
|
21
|
-
params.merge!(sign: sign)
|
23
|
+
params[:tpl_content].encode!('GBK', { invalid: :replace, undef: :replace, replace: '' })
|
24
|
+
params[:sign] = Sign.generate(params)
|
22
25
|
|
23
26
|
RestClient.post(gateway, params) do |response|
|
24
27
|
JSON.parse(response.body)
|
@@ -10,7 +10,6 @@ module Alipass
|
|
10
10
|
# :tpl_id, :tpl_params, :recognition_type, :recognition_info
|
11
11
|
# ]
|
12
12
|
|
13
|
-
# tpl_id, tpl_params, recognition_type, recognition_info
|
14
13
|
def self.add(params)
|
15
14
|
gateway = 'https://openapi.alipay.com/gateway.do'
|
16
15
|
params = {
|
@@ -22,10 +21,8 @@ module Alipass
|
|
22
21
|
version: '1.0'
|
23
22
|
}.merge(params)
|
24
23
|
|
25
|
-
params[:tpl_params]
|
26
|
-
|
27
|
-
sign = Sign.generate(params)
|
28
|
-
params.merge!(sign: sign)
|
24
|
+
params[:tpl_params].encode!('GBK', { invalid: :replace, undef: :replace, replace: '' })
|
25
|
+
params[:sign] = Sign.generate(params)
|
29
26
|
|
30
27
|
RestClient.post(gateway, params) do |response|
|
31
28
|
JSON.parse(response.body)
|
data/lib/alipass/version.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
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
4
|
before do
|
9
5
|
FakeWeb.register_uri(:post, 'https://openapi.alipay.com/gateway.do', body: body)
|
10
6
|
end
|
@@ -12,12 +8,54 @@ describe Alipass::Template::Content do
|
|
12
8
|
it ".add" do
|
13
9
|
params = {
|
14
10
|
tpl_id: 'tpl_id',
|
15
|
-
tpl_params:
|
11
|
+
tpl_params: tpl_params.to_json,
|
16
12
|
recognition_type: '1',
|
17
13
|
recognition_info: %Q({"partner_id":"partner_id","out_trade_no":"out_trade_no"})
|
18
14
|
}
|
19
15
|
|
20
|
-
|
21
|
-
|
16
|
+
response = Alipass::Template::Content.add(params)
|
17
|
+
biz_result = response['alipay_pass_tpl_content_add_response']['biz_result']
|
18
|
+
biz_result.must_be_kind_of String
|
19
|
+
|
20
|
+
json = JSON.parse(biz_result)
|
21
|
+
json['passId'].wont_be_empty
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:body) do
|
25
|
+
{
|
26
|
+
alipay_pass_tpl_content_add_response: {
|
27
|
+
biz_result: '{"passId":"passId","serialNumber":"serialNumber","result":"SUCCESS"}',
|
28
|
+
error_code: "SUCCESS",
|
29
|
+
success: true
|
30
|
+
},
|
31
|
+
sign: "sign"
|
32
|
+
}.to_json
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:tpl_params) do
|
36
|
+
{
|
37
|
+
title: 'title',
|
38
|
+
begin_at: '2014-07-16 20:20:00',
|
39
|
+
end_at: '2014-07-17 23:20:00',
|
40
|
+
begin_at_date: "2014-07-15",
|
41
|
+
begin_at_time: "20:20",
|
42
|
+
scene: '场地名',
|
43
|
+
number: '110',
|
44
|
+
price: '0.02',
|
45
|
+
longitude: '116.407413',
|
46
|
+
latitude: '39.904214',
|
47
|
+
tel: '123456',
|
48
|
+
address: '场地名',
|
49
|
+
scene_name: 'SD',
|
50
|
+
qr_value: '123|321|123',
|
51
|
+
qr_tips: '刷这里啊',
|
52
|
+
app_tips: '启动 APP',
|
53
|
+
perf_url: 'http://youyanchu.com',
|
54
|
+
web_tips: '打开网页',
|
55
|
+
serial_number: 'serial_number',
|
56
|
+
channel_id: Alipass.app_id,
|
57
|
+
web_service_url: 'http://youyanchu.com',
|
58
|
+
background_color: 'rgb(165,22,40)'
|
59
|
+
}
|
22
60
|
end
|
23
61
|
end
|
@@ -1,42 +1,51 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
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
4
|
before do
|
10
5
|
FakeWeb.register_uri(:post, 'https://openapi.alipay.com/gateway.do', body: body)
|
11
6
|
end
|
12
7
|
|
13
8
|
it ".add" do
|
14
9
|
params = {
|
15
|
-
logo: '
|
16
|
-
strip: '
|
17
|
-
icon: '
|
10
|
+
logo: 'http://dn-dev.qbox.me/test/alipass-logo-test.png',
|
11
|
+
strip: '',
|
12
|
+
icon: '',
|
18
13
|
content: pass_json
|
19
14
|
}
|
20
15
|
|
21
|
-
|
22
|
-
|
16
|
+
response = Alipass::Template.add(tpl_content: params.to_json)
|
17
|
+
result = response['alipay_pass_tpl_add_response']['result']
|
18
|
+
result.must_be_kind_of String
|
19
|
+
|
20
|
+
json = JSON.parse(result)
|
21
|
+
json['tpl_id'].wont_be_empty
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:body) do
|
25
|
+
{
|
26
|
+
alipay_pass_tpl_add_response: {
|
27
|
+
result: '{"tpl_id":"tpl_id","tpl_params":["title", "begin_at"]}',
|
28
|
+
error_code: "SUCCESS",
|
29
|
+
success: true
|
30
|
+
},
|
31
|
+
sign: "sign"
|
32
|
+
}.to_json
|
23
33
|
end
|
24
34
|
|
25
|
-
|
35
|
+
let(:pass_json) do
|
26
36
|
{
|
27
37
|
evoucherInfo: {
|
28
|
-
|
29
|
-
title: "$title",
|
38
|
+
title: "$title$",
|
30
39
|
type: "eventTicket",
|
31
40
|
product: "movie",
|
32
|
-
startDate: "$begin_at",
|
33
|
-
endDate: "$end_at",
|
41
|
+
startDate: "$begin_at$",
|
42
|
+
endDate: "$end_at$",
|
34
43
|
operation: [
|
35
44
|
{
|
36
45
|
format: "qrcode",
|
37
|
-
message: "$qr_value",
|
46
|
+
message: "$qr_value$",
|
38
47
|
messageEncoding: "utf-8",
|
39
|
-
altText: "$qr_tips"
|
48
|
+
altText: "$qr_tips$"
|
40
49
|
},
|
41
50
|
{
|
42
51
|
message: {
|
@@ -44,39 +53,58 @@ describe Alipass::Template do
|
|
44
53
|
android_launch: "schemes://com.youyanchu.android",
|
45
54
|
android_download: "http://youyanchu.com/l/app/android",
|
46
55
|
ios_appid: "com.youyanchu.iphone.showtime",
|
47
|
-
ios_launch: "
|
56
|
+
ios_launch: "youyanchuiphone://",
|
48
57
|
ios_download: "http://youyanchu.com/l/app/ios"
|
49
58
|
},
|
50
59
|
format: "app",
|
51
60
|
messageEncoding: "utf-8",
|
52
|
-
altText: "$app_tips"
|
61
|
+
altText: "$app_tips$"
|
53
62
|
},
|
54
63
|
{
|
55
64
|
format: "url",
|
56
|
-
message: "$perf_url",
|
65
|
+
message: "$perf_url$",
|
57
66
|
messageEncoding: "utf-8",
|
58
|
-
altText: "$web_tips"
|
67
|
+
altText: "$web_tips$"
|
59
68
|
}
|
60
69
|
],
|
61
70
|
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: [
|
71
|
+
logoText: "$title$",
|
72
|
+
headFields: [{ key: "begin_at_date", label: "日期", value: "$begin_at_date$", type: "text" }],
|
73
|
+
primaryFields: [{ key: "begin_at_time", label: "演出时间", value: "$begin_at_time$", type: "text" }],
|
74
|
+
secondaryFields: [{ key: "scene", label: "场地", value: "$scene$", type: "map" }],
|
75
|
+
auxiliaryFields: [
|
76
|
+
{ key: "number", label: "票号", value: "$number$", type: "text" },
|
77
|
+
{ key: "price", label: "金额", value: "$price$", type: "text" }
|
78
|
+
],
|
67
79
|
backFields: []
|
68
80
|
},
|
69
|
-
locations: [
|
81
|
+
locations: [
|
82
|
+
{
|
83
|
+
altitude: "",
|
84
|
+
longitude: "$longitude$",
|
85
|
+
latitude: "$latitude$",
|
86
|
+
tel: "$tel$",
|
87
|
+
addr: "$address$",
|
88
|
+
relevantText: "$scene_name$"
|
89
|
+
}
|
90
|
+
]
|
70
91
|
}, # evoucherInfo
|
71
92
|
|
72
|
-
merchant: {mname: "xxx有限公司", mtel: "123456789", minfo: ""},
|
73
|
-
platform: {channelID: "$channel_id", webServiceUrl: "$web_service_url"},
|
74
|
-
style: {backgroundColor: "$background_color"},
|
93
|
+
merchant: { mname: "xxx有限公司", mtel: "123456789", minfo: "" },
|
94
|
+
platform: { channelID: "$channel_id$", webServiceUrl: "$web_service_url$" },
|
95
|
+
style: { backgroundColor: "$background_color$" },
|
75
96
|
|
76
|
-
fileInfo: {formatVersion: "2", canShare:
|
97
|
+
fileInfo: { formatVersion: "2", canShare: false, canBuy: false, serialNumber: "$serial_number$" },
|
77
98
|
|
78
99
|
appInfo: {
|
79
|
-
app: {
|
100
|
+
app: {
|
101
|
+
android_appid: "com.youyanchu.android",
|
102
|
+
android_launch: "schemes://com.youyanchu.android",
|
103
|
+
android_download: "http://youyanchu.com/l/app/android",
|
104
|
+
ios_appid: "com.youyanchu.iphone.showtime",
|
105
|
+
ios_launch: "youyanchuiphone://",
|
106
|
+
ios_download: "http://youyanchu.com/l/app/ios"
|
107
|
+
},
|
80
108
|
label: "有演出",
|
81
109
|
message: "音乐演出神器"
|
82
110
|
},
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alipass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HungYuHei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|