rack-weixin 0.0.4.1 → 0.0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +6 -4
- data/README.md +31 -11
- data/lib/rack-weixin.rb +4 -10
- data/lib/weixin/model.rb +0 -2
- data/lib/weixin/version.rb +1 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rack-weixin (0.0.
|
4
|
+
rack-weixin (0.0.4.2)
|
5
|
+
multi_json (>= 1.7.9)
|
5
6
|
multi_xml (>= 0.5.2)
|
7
|
+
nestful
|
6
8
|
rack
|
7
9
|
roxml
|
8
10
|
|
9
11
|
GEM
|
10
|
-
remote: http://rubygems.org/
|
11
12
|
remote: http://ruby.taobao.org/
|
12
13
|
specs:
|
13
14
|
activesupport (3.2.12)
|
14
15
|
i18n (~> 0.6)
|
15
16
|
multi_json (~> 1.0)
|
16
17
|
diff-lcs (1.1.3)
|
17
|
-
i18n (0.6.
|
18
|
-
multi_json (1.
|
18
|
+
i18n (0.6.5)
|
19
|
+
multi_json (1.8.2)
|
19
20
|
multi_xml (0.5.3)
|
21
|
+
nestful (1.0.7)
|
20
22
|
nokogiri (1.5.6)
|
21
23
|
rack (1.5.2)
|
22
24
|
rack-test (0.6.2)
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
微信公众平台 开放消息接口 Rack Middleware
|
2
2
|
========================================
|
3
3
|
|
4
|
-
Latest version: v0.4.
|
4
|
+
Latest version: v0.0.4.2, supports subscribe/unsubscribe event
|
5
5
|
|
6
6
|
* 验证微信请求 with 'weixin/middleware'
|
7
7
|
* 解析推送消息 with 'weixin/model'
|
@@ -41,9 +41,9 @@ helpers do
|
|
41
41
|
'http://nj.baidupcs.com/file/9cbb087ece3da309a31e05a7e14003c9?xcode=70d27743259294de1c42dff2d4720c05d4c19cd5e52a44f7&fid=204864837-250528-3177081425&time=1376666534&sign=FDTAXER-DCb740ccc5511e5e8fedcff06b081203-9NqxJyKhTJYx34SlHyPnK7%2B83vY%3D&to=nb&fm=B,B,T&expires=8h&rt=sh&r=756751042&logid=2171432620&sh=1&fn=%E8%BA%AB%E9%AA%91%E7%99%BD%E9%A9%AC.mp3',
|
42
42
|
'http://nj.baidupcs.com/file/9cbb087ece3da309a31e05a7e14003c9?xcode=c59d095c8566efe4d948c3846269e02ed4c19cd5e52a44f7&fid=204864837-250528-3177081425&time=1376666631&sign=FDTAXER-DCb740ccc5511e5e8fedcff06b081203-yAO3TLeuAQ867emfUs0dYKgMtSE%3D&to=nb&fm=B,B,T&expires=8h&rt=sh&r=897038653&logid=4061975287&sh=1&fn=%E8%BA%AB%E9%AA%91%E7%99%BD%E9%A9%AC.mp3'
|
43
43
|
)
|
44
|
-
Weixin.music_msg(msg.
|
44
|
+
Weixin.music_msg(msg.ToUserName, msg.FromUserName, mp3)
|
45
45
|
else
|
46
|
-
Weixin.text_msg(msg.
|
46
|
+
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '这件商品暂时缺货~~')
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -59,29 +59,29 @@ helpers do
|
|
59
59
|
'http://www.padrinorb.com/images/screens.jpg',
|
60
60
|
'http://www.padrinorb.com/'
|
61
61
|
)
|
62
|
-
Weixin.news_msg(
|
62
|
+
Weixin.news_msg(msg.ToUserName, msg.FromUserName, [item])
|
63
63
|
end
|
64
64
|
|
65
65
|
def location_parse(msg)
|
66
66
|
"http://maps.googleapis.com/maps/api/geocode/json?latlng=#{msg.Location_X},#{msg.Location_Y}"
|
67
|
-
Weixin.text_msg(msg.
|
67
|
+
Weixin.text_msg(msg.ToUserName, msg.FromUserName, "#{msg.Label} 周围没有妹子~")
|
68
68
|
end
|
69
69
|
|
70
70
|
def link_parse(msg)
|
71
71
|
# Mechanize.new.get(msg.Url) # 爬虫
|
72
|
-
Weixin.text_msg(msg.
|
72
|
+
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '这件商品暂时缺货~~')
|
73
73
|
end
|
74
74
|
|
75
75
|
def event_parse(msg)
|
76
76
|
case msg.Event
|
77
77
|
when 'subscribe' # 订阅
|
78
|
-
Weixin.text_msg(msg.
|
78
|
+
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '欢迎订阅【数字尾巴】~~')
|
79
79
|
when 'unsubscribe' # 退订
|
80
80
|
# 又少了名用户
|
81
81
|
when 'CLICK' # 点击菜单
|
82
82
|
menu_parse(msg)
|
83
83
|
else
|
84
|
-
Weixin.text_msg(msg.
|
84
|
+
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '作为一名程序猿,表示压力山大~~')
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -89,9 +89,9 @@ helpers do
|
|
89
89
|
case msg.EventKey
|
90
90
|
when 'profile'
|
91
91
|
# ???
|
92
|
-
Weixin.text_msg(msg.
|
92
|
+
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '主人您的个人信息丢失啦~')
|
93
93
|
else
|
94
|
-
Weixin.text_msg(msg.
|
94
|
+
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '您想来点什么?')
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -112,7 +112,7 @@ helpers do
|
|
112
112
|
when 'video'
|
113
113
|
video_parse(msg)
|
114
114
|
else
|
115
|
-
Weixin.text_msg(msg.
|
115
|
+
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '作为一名程序猿,表示压力山大~~')
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
@@ -130,6 +130,26 @@ post '/your_app_root' do
|
|
130
130
|
end
|
131
131
|
```
|
132
132
|
|
133
|
+
### Padrino下使用
|
134
|
+
在`Gemfile`里加入:
|
135
|
+
|
136
|
+
gem 'rack-weixin'
|
137
|
+
|
138
|
+
在`config/apps.rb`关闭以下两个:
|
139
|
+
|
140
|
+
set :protection, false
|
141
|
+
set :protect_from_csrf, false
|
142
|
+
|
143
|
+
在`app.rb`里加入:
|
144
|
+
|
145
|
+
use Weixin::Middleware, 'your api token', '/your_app_root'
|
146
|
+
|
147
|
+
configure do
|
148
|
+
set :wx_id, 'your_weixin_account'
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
|
133
153
|
TODO
|
134
154
|
----
|
135
155
|
|
data/lib/rack-weixin.rb
CHANGED
@@ -2,16 +2,10 @@
|
|
2
2
|
require 'weixin/version'
|
3
3
|
require 'weixin/middleware'
|
4
4
|
require 'weixin/menu'
|
5
|
+
require 'weixin/model'
|
5
6
|
|
6
7
|
module Weixin
|
7
|
-
|
8
|
-
autoload :Music, 'weixin/model'
|
9
|
-
autoload :Item, 'weixin/model'
|
10
|
-
|
11
|
-
autoload :TextReplyMessage, 'weixin/model'
|
12
|
-
autoload :MusicReplyMessage, 'weixin/model'
|
13
|
-
autoload :NewsReplyMessage, 'weixin/model'
|
14
|
-
|
8
|
+
|
15
9
|
extend self
|
16
10
|
|
17
11
|
def music(title, desc, music_url, hq_music_url)
|
@@ -32,7 +26,7 @@ module Weixin
|
|
32
26
|
item
|
33
27
|
end
|
34
28
|
|
35
|
-
def text_msg(from, to, content
|
29
|
+
def text_msg(from, to, content)
|
36
30
|
msg = TextReplyMessage.new
|
37
31
|
msg.ToUserName = to
|
38
32
|
msg.FromUserName = from
|
@@ -56,4 +50,4 @@ module Weixin
|
|
56
50
|
msg.ArticleCount = items.count
|
57
51
|
msg.to_xml
|
58
52
|
end
|
59
|
-
end
|
53
|
+
end
|
data/lib/weixin/model.rb
CHANGED
@@ -166,11 +166,9 @@ module Weixin
|
|
166
166
|
xml_accessor :FromUserName, :cdata => true
|
167
167
|
xml_reader :CreateTime, :as => Integer
|
168
168
|
xml_reader :MsgType, :cdata => true
|
169
|
-
xml_accessor :FuncFlag, :as => Integer
|
170
169
|
|
171
170
|
def initialize
|
172
171
|
@CreateTime = Time.now.to_i
|
173
|
-
@FuncFlag = 0
|
174
172
|
end
|
175
173
|
|
176
174
|
def to_xml
|
data/lib/weixin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-weixin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.4.
|
4
|
+
version: 0.0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|