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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d957ce0a1d111a4b89637cbf080700b1ba2e41d
4
- data.tar.gz: 40c563d27c3ded9b0d6d69cd9b15eab345dfb73b
3
+ metadata.gz: 320943ac438d9afbd296d14f4044e9ce8725d63d
4
+ data.tar.gz: 44e5c649b7afabb6d404045e3dbfaf2ea754f591
5
5
  SHA512:
6
- metadata.gz: 7906cf28810660ce05dd94ec1ee021e84f9b5ce435914d52fb00cf0a16ce44f6bc210a992aa015c6f083d4cb611815fee91891e9f47f3ea33c658a016f91e370
7
- data.tar.gz: 108406fd6c981029a42ea7252896d6ae6e0a1067a8b473d9d92cbaa43cd61d1f033d6720eb4ba8f94b7d8b7b84989fe0084132d63e07a79e32d88e478f405ecc
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
 
@@ -2,7 +2,11 @@ require 'alipass/template/content'
2
2
 
3
3
  module Alipass
4
4
  module Template
5
- # REQUIRED_PARAMS = [ :method, :timestamp, :app_id, :version, :sign, :sign_type, :tpl_content]
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] = params[:tpl_content].encode('GBK') if 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] = params[:tpl_params].encode('GBK') if 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)
@@ -1,3 +1,3 @@
1
1
  module Alipass
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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: %Q({"title":"title","begin_at":"2014-11-11 00:11"}),
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
- json = Alipass::Template::Content.add(params)
21
- json['alipay_pass_tpl_add_response']['biz_result']['result'].must_equal 'SUCCESS'
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: 'logo_url',
16
- strip: 'strip_url',
17
- icon: 'icon_url',
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
- json = Alipass::Template.add(tpl_content: params.to_json)
22
- json['alipay_pass_tpl_add_response']['result']['tpl_id'].must_equal tpl_id
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
- def pass_json
35
+ let(:pass_json) do
26
36
  {
27
37
  evoucherInfo: {
28
- goodsId: "",
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: "schemes://com.youyanchu.iphone.showtime",
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: [{key: "number", label: "票号", value: "$number", type: "text"}, {key: "price", label: "金额", value: "$price", type: "text"}],
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: [{altitude: "", longitude: "$longitude", latitude: "$latitude", tel: "$tel", addr: "$address", relevantText: "$scene_name"}]
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: true, canBuy: false, serialNumber: "$serial_number"},
97
+ fileInfo: { formatVersion: "2", canShare: false, canBuy: false, serialNumber: "$serial_number$" },
77
98
 
78
99
  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"},
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.1
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-07-15 00:00:00.000000000 Z
11
+ date: 2014-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client