rack-weixin 0.0.4.2 → 0.0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +1 -0
- data/README.md +12 -73
- data/lib/weixin/menu.rb +2 -2
- data/lib/weixin/version.rb +1 -1
- data/rack-weixin.gemspec +2 -1
- metadata +4 -3
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
微信公众平台 开放消息接口 Rack Middleware
|
2
2
|
========================================
|
3
3
|
|
4
|
-
|
4
|
+
[![Build Status](https://travis-ci.org/wolfg1969/rack-weixin.png?branch=master)](https://travis-ci.org/wolfg1969/rack-weixin) [![Gem Version](https://badge.fury.io/rb/rack-weixin.png)](http://badge.fury.io/rb/rack-weixin)
|
5
5
|
|
6
6
|
* 验证微信请求 with 'weixin/middleware'
|
7
7
|
* 解析推送消息 with 'weixin/model'
|
@@ -32,87 +32,24 @@ configure do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
helpers do
|
35
|
-
def text_parse(msg)
|
36
|
-
case msg.Content
|
37
|
-
when '我想听歌'
|
38
|
-
mp3 = Weixin.music(
|
39
|
-
'身骑白马',
|
40
|
-
'徐佳莹首张专辑《LALA创作专辑》的主打歌。这首歌的是由徐佳莹及其老师苏通达共同创作,其最大的特点是改编自台湾的民间剧种歌仔戏。',
|
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
|
-
'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
|
-
)
|
44
|
-
Weixin.music_msg(msg.ToUserName, msg.FromUserName, mp3)
|
45
|
-
else
|
46
|
-
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '这件商品暂时缺货~~')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def image_parse(msg)
|
51
|
-
item = Weixin.item(
|
52
|
-
'发现一个基于sinatra的web框架padrino',
|
53
|
-
'gem install padrino
|
54
|
-
padrino g project myapp -d datamapper -b
|
55
|
-
cd myapp
|
56
|
-
padrino g admin
|
57
|
-
padrino rake dm:migrate seed
|
58
|
-
padrino start',
|
59
|
-
'http://www.padrinorb.com/images/screens.jpg',
|
60
|
-
'http://www.padrinorb.com/'
|
61
|
-
)
|
62
|
-
Weixin.news_msg(msg.ToUserName, msg.FromUserName, [item])
|
63
|
-
end
|
64
|
-
|
65
|
-
def location_parse(msg)
|
66
|
-
"http://maps.googleapis.com/maps/api/geocode/json?latlng=#{msg.Location_X},#{msg.Location_Y}"
|
67
|
-
Weixin.text_msg(msg.ToUserName, msg.FromUserName, "#{msg.Label} 周围没有妹子~")
|
68
|
-
end
|
69
|
-
|
70
|
-
def link_parse(msg)
|
71
|
-
# Mechanize.new.get(msg.Url) # 爬虫
|
72
|
-
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '这件商品暂时缺货~~')
|
73
|
-
end
|
74
|
-
|
75
|
-
def event_parse(msg)
|
76
|
-
case msg.Event
|
77
|
-
when 'subscribe' # 订阅
|
78
|
-
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '欢迎订阅【数字尾巴】~~')
|
79
|
-
when 'unsubscribe' # 退订
|
80
|
-
# 又少了名用户
|
81
|
-
when 'CLICK' # 点击菜单
|
82
|
-
menu_parse(msg)
|
83
|
-
else
|
84
|
-
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '作为一名程序猿,表示压力山大~~')
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def menu_parse(msg)
|
89
|
-
case msg.EventKey
|
90
|
-
when 'profile'
|
91
|
-
# ???
|
92
|
-
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '主人您的个人信息丢失啦~')
|
93
|
-
else
|
94
|
-
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '您想来点什么?')
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
35
|
def msg_router(msg)
|
99
36
|
case msg.MsgType
|
100
37
|
when 'text'
|
101
|
-
|
38
|
+
# text message handler
|
102
39
|
when 'image'
|
103
|
-
|
40
|
+
# image message handler
|
104
41
|
when 'location'
|
105
|
-
|
42
|
+
# location message handler
|
106
43
|
when 'link'
|
107
|
-
|
44
|
+
# link message handler
|
108
45
|
when 'event'
|
109
|
-
|
46
|
+
# event messge handler
|
110
47
|
when 'voice'
|
111
|
-
|
48
|
+
# voice message handler
|
112
49
|
when 'video'
|
113
|
-
|
50
|
+
# video message handler
|
114
51
|
else
|
115
|
-
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '
|
52
|
+
Weixin.text_msg(msg.ToUserName, msg.FromUserName, '未知消息类型')
|
116
53
|
end
|
117
54
|
end
|
118
55
|
end
|
@@ -126,6 +63,8 @@ post '/your_app_root' do
|
|
126
63
|
|
127
64
|
message = request.env[Weixin::Middleware::WEIXIN_MSG]
|
128
65
|
logger.info "原始数据: #{request.env[Weixin::Middleware::WEIXIN_MSG_RAW]}"
|
66
|
+
|
67
|
+
# handle the message according to your business logic
|
129
68
|
msg_router(message) unless message.nil?
|
130
69
|
end
|
131
70
|
```
|
@@ -145,7 +84,7 @@ end
|
|
145
84
|
use Weixin::Middleware, 'your api token', '/your_app_root'
|
146
85
|
|
147
86
|
configure do
|
148
|
-
|
87
|
+
set :wx_id, 'your_weixin_account'
|
149
88
|
end
|
150
89
|
|
151
90
|
|
data/lib/weixin/menu.rb
CHANGED
@@ -45,7 +45,7 @@ module Weixin
|
|
45
45
|
|
46
46
|
def authenticate
|
47
47
|
url = "#{@endpoint}/token"
|
48
|
-
request = Nestful.get url, { grant_type
|
48
|
+
request = Nestful.get url, { :grant_type => 'client_credential', :appid => @api, :secret => @key } rescue nil
|
49
49
|
unless request.nil?
|
50
50
|
auth = MultiJson.load(request.body)
|
51
51
|
unless auth.has_key?('errcode')
|
@@ -57,4 +57,4 @@ module Weixin
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
end
|
60
|
+
end
|
data/lib/weixin/version.rb
CHANGED
data/rack-weixin.gemspec
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.3
|
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:
|
12
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -146,6 +146,7 @@ extensions: []
|
|
146
146
|
extra_rdoc_files: []
|
147
147
|
files:
|
148
148
|
- .gitignore
|
149
|
+
- .travis.yml
|
149
150
|
- Gemfile
|
150
151
|
- Gemfile.lock
|
151
152
|
- README.md
|
@@ -169,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
170
|
requirements:
|
170
171
|
- - ! '>='
|
171
172
|
- !ruby/object:Gem::Version
|
172
|
-
version:
|
173
|
+
version: 1.8.6
|
173
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
175
|
none: false
|
175
176
|
requirements:
|