weixin_rails_middleware 1.3.0 → 1.3.1

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: b0d0b6af708c134cb59378358bbe18334a771f50
4
- data.tar.gz: 5f1a555b56fe4be9a1a80405d58664fe0cbd6e3e
3
+ metadata.gz: f079af9ed5d2cb1eb39c297b00fecdda832e4a1f
4
+ data.tar.gz: a491310af214643839d415dc96a1bc83fea0c245
5
5
  SHA512:
6
- metadata.gz: 0bb09dd78fad486410742f72691f1411ba85197faa672c1f9a599f3cc6aaad85c8f65fd6b62832ba9fa687c466bcbe4b2c711cbf779f68e1837e1046edd5641d
7
- data.tar.gz: 76096e39e64335bb77941cd429120d913a991b509816457d3faf5debc08b14dcbf681b9e8a667c1fff72723480cf89112fac248f382fdbdf6d3e7ba8af6296e1
6
+ metadata.gz: 8edb6d095295516b0ae531706bb34af81486bd04d372b1accfd3a3b2650417ec4509a8daadbed1d607c7b1d041eab35824457a5fc6d1c3d9159bf1d4ca2ccd9e
7
+ data.tar.gz: 6107d9a584ea93dd73592c9e8be7ef8245c910c36f065ebe04eac419c236b2344093023ca66d786cd2c44e724ac7514e7c7c830b7ea9d74d78a31e2e434c29b9
@@ -0,0 +1,15 @@
1
+ ===============================================================================
2
+ ## 如果有任何的疑问,请前往微信开发论坛提问:
3
+
4
+ http://weixin-dev.com
5
+
6
+ ## 微信 Ruby 高级API:
7
+
8
+ https://github.com/lanrion/weixin_authorize
9
+
10
+ ## 企业号相关gem:
11
+
12
+ https://github.com/lanrion/qy_wechat
13
+
14
+ https://github.com/lanrion/qy_wechat_api
15
+
@@ -65,7 +65,12 @@ WeixinRailsMiddleware::WeixinController.class_eval do
65
65
 
66
66
  def response_event_message(options={})
67
67
  event_type = @weixin_message.Event
68
- send("handle_#{event_type.downcase}_event")
68
+ method_name = "handle_#{event_type.downcase}_event"
69
+ if self.respond_to? method_name, true
70
+ send(method_name)
71
+ else
72
+ send("handle_undefined_event")
73
+ end
69
74
  end
70
75
 
71
76
  # 关注公众账号
@@ -127,4 +132,130 @@ WeixinRailsMiddleware::WeixinController.class_eval do
127
132
  Rails.logger.info("回调事件处理")
128
133
  end
129
134
 
135
+ # <xml>
136
+ # <ToUserName><![CDATA[gh_7f083739789a]]></ToUserName>
137
+ # <FromUserName><![CDATA[oia2TjuEGTNoeX76QEjQNrcURxG8]]></FromUserName>
138
+ # <CreateTime>1395658920</CreateTime>
139
+ # <MsgType><![CDATA[event]]></MsgType>
140
+ # <Event><![CDATA[TEMPLATESENDJOBFINISH]]></Event>
141
+ # <MsgID>200163836</MsgID>
142
+ # <Status><![CDATA[success]]></Status>
143
+ # </xml>
144
+ # 推送模板信息回调,通知服务器是否成功推送
145
+ def handle_templatesendjobfinish_event
146
+ Rails.logger.info("回调事件处理")
147
+ end
148
+
149
+ # <xml>
150
+ # <ToUserName><![CDATA[toUser]]></ToUserName>
151
+ # <FromUserName><![CDATA[FromUser]]></FromUserName>
152
+ # <CreateTime>123456789</CreateTime>
153
+ # <MsgType><![CDATA[event]]></MsgType>
154
+ # <Event><![CDATA[card_pass_check]]></Event> //不通过为card_not_pass_check
155
+ # <CardId><![CDATA[cardid]]></CardId>
156
+ # </xml>
157
+ # 卡券审核事件,通知服务器卡券已(未)通过审核
158
+ def handle_card_pass_check_event
159
+ Rails.logger.info("回调事件处理")
160
+ end
161
+
162
+ def handle_card_not_pass_check_event
163
+ Rails.logger.info("回调事件处理")
164
+ end
165
+
166
+ # <xml>
167
+ # <ToUserName><![CDATA[toUser]]></ToUserName>
168
+ # <FromUserName><![CDATA[FromUser]]></FromUserName>
169
+ # <FriendUserName><![CDATA[FriendUser]]></FriendUserName>
170
+ # <CreateTime>123456789</CreateTime>
171
+ # <MsgType><![CDATA[event]]></MsgType>
172
+ # <Event><![CDATA[user_get_card]]></Event>
173
+ # <CardId><![CDATA[cardid]]></CardId>
174
+ # <IsGiveByFriend>1</IsGiveByFriend>
175
+ # <UserCardCode><![CDATA[12312312]]></UserCardCode>
176
+ # <OuterId>0</OuterId>
177
+ # </xml>
178
+ # 卡券领取事件推送
179
+ def handle_user_get_card_event
180
+ Rails.logger.info("回调事件处理")
181
+ end
182
+
183
+ # <xml>
184
+ # <ToUserName><![CDATA[toUser]]></ToUserName>
185
+ # <FromUserName><![CDATA[FromUser]]></FromUserName>
186
+ # <CreateTime>123456789</CreateTime>
187
+ # <MsgType><![CDATA[event]]></MsgType>
188
+ # <Event><![CDATA[user_del_card]]></Event>
189
+ # <CardId><![CDATA[cardid]]></CardId>
190
+ # <UserCardCode><![CDATA[12312312]]></UserCardCode>
191
+ # </xml>
192
+ # 卡券删除事件推送
193
+ def handle_user_del_card_event
194
+ Rails.logger.info("回调事件处理")
195
+ end
196
+
197
+ # <xml>
198
+ # <ToUserName><![CDATA[toUser]]></ToUserName>
199
+ # <FromUserName><![CDATA[FromUser]]></FromUserName>
200
+ # <CreateTime>123456789</CreateTime>
201
+ # <MsgType><![CDATA[event]]></MsgType>
202
+ # <Event><![CDATA[user_consume_card]]></Event>
203
+ # <CardId><![CDATA[cardid]]></CardId>
204
+ # <UserCardCode><![CDATA[12312312]]></UserCardCode>
205
+ # <ConsumeSource><![CDATA[(FROM_API)]]></ConsumeSource>
206
+ # </xml>
207
+ # 卡券核销事件推送
208
+ def handle_user_consume_card_event
209
+ Rails.logger.info("回调事件处理")
210
+ end
211
+
212
+ # <xml>
213
+ # <ToUserName><![CDATA[toUser]]></ToUserName>
214
+ # <FromUserName><![CDATA[FromUser]]></FromUserName>
215
+ # <CreateTime>123456789</CreateTime>
216
+ # <MsgType><![CDATA[event]]></MsgType>
217
+ # <Event><![CDATA[user_view_card]]></Event>
218
+ # <CardId><![CDATA[cardid]]></CardId>
219
+ # <UserCardCode><![CDATA[12312312]]></UserCardCode>
220
+ # </xml>
221
+ # 卡券进入会员卡事件推送
222
+ def handle_user_view_card_event
223
+ Rails.logger.info("回调事件处理")
224
+ end
225
+
226
+ # <xml>
227
+ # <ToUserName><![CDATA[toUser]]></ToUserName>
228
+ # <FromUserName><![CDATA[FromUser]]></FromUserName>
229
+ # <CreateTime>123456789</CreateTime>
230
+ # <MsgType><![CDATA[event]]></MsgType>
231
+ # <Event><![CDATA[user_enter_session_from_card]]></Event>
232
+ # <CardId><![CDATA[cardid]]></CardId>
233
+ # <UserCardCode><![CDATA[12312312]]></UserCardCode>
234
+ # </xml>
235
+ # 从卡券进入公众号会话事件推送
236
+ def handle_user_enter_session_from_card_event
237
+ Rails.logger.info("回调事件处理")
238
+ end
239
+
240
+ # <xml>
241
+ # <ToUserName><![CDATA[toUser]]></ToUserName>
242
+ # <FromUserName><![CDATA[fromUser]]></FromUserName>
243
+ # <CreateTime>1408622107</CreateTime>
244
+ # <MsgType><![CDATA[event]]></MsgType>
245
+ # <Event><![CDATA[poi_check_notify]]></Event>
246
+ # <UniqId><![CDATA[123adb]]></UniqId>
247
+ # <PoiId><![CDATA[123123]]></PoiId>
248
+ # <Result><![CDATA[fail]]></Result>
249
+ # <Msg><![CDATA[xxxxxx]]></Msg>
250
+ # </xml>
251
+ # 门店审核事件推送
252
+ def handle_poi_check_notify_event
253
+ Rails.logger.info("回调事件处理")
254
+ end
255
+
256
+ # 未定义的事件处理
257
+ def handle_undefined_event
258
+ Rails.logger.info("回调事件处理")
259
+ end
260
+
130
261
  end
@@ -30,6 +30,10 @@ module WeixinRailsMiddleware
30
30
  template 'weixin_controller.rb', 'app/decorators/controllers/weixin_rails_middleware/weixin_controller_decorator.rb'
31
31
  end
32
32
 
33
+ def show_readme
34
+ readme "README" if behavior == :invoke
35
+ end
36
+
33
37
  end
34
38
  end
35
39
  end
@@ -21,8 +21,8 @@ module WeixinRailsMiddleware
21
21
  autoload(:SinglePublicAccount, "weixin_rails_middleware/adapter/single_public_account")
22
22
  autoload(:MultiplePublicAccount, "weixin_rails_middleware/adapter/multiple_public_account")
23
23
 
24
- DEFAULT_TOKEN_COLUMN_NAME = "weixin_token".freeze
25
- DEFAULT_WEIXIN_SECRET_KEY = "weixin_secret_key".freeze
24
+ DEFAULT_TOKEN_COLUMN_NAME = "weixin_token"
25
+ DEFAULT_WEIXIN_SECRET_KEY = "weixin_secret_key"
26
26
 
27
27
  end
28
28
 
@@ -105,8 +105,22 @@ module WeixinRailsMiddleware
105
105
  encrypt_message message.to_xml
106
106
  end
107
107
 
108
- def reply_transfer_customer_service_message(from=nil, to=nil)
109
- message = TransferCustomerServiceReplyMessage.new
108
+ # 指定会话接入的客服账号
109
+ def generate_kf_trans_info(kf_account)
110
+ trans_info = KfTransInfo.new
111
+ trans_info.KfAccount = kf_account
112
+ trans_info
113
+ end
114
+
115
+ # 消息转发到多客服
116
+ # 消息转发到指定客服
117
+ def reply_transfer_customer_service_message(from=nil, to=nil, kf_account=nil)
118
+ if kf_account.blank?
119
+ message = TransferCustomerServiceReplyMessage.new
120
+ else
121
+ message = TransferCustomerServiceWithTransInfoReplyMessage.new
122
+ message.TransInfo = generate_kf_trans_info(kf_account)
123
+ end
110
124
  message.FromUserName = from || @weixin_message.ToUserName
111
125
  message.ToUserName = to || @weixin_message.FromUserName
112
126
  encrypt_message message.to_xml
@@ -39,6 +39,8 @@ module WeixinRailsMiddleware
39
39
  VoiceMessage.new(hash)
40
40
  when 'video'
41
41
  VideoMessage.new(hash)
42
+ when 'shortvideo'
43
+ ShortVideo.new(hash)
42
44
  else
43
45
  raise ArgumentError, 'Unknown Weixin Message'
44
46
  end
@@ -155,4 +157,25 @@ module WeixinRailsMiddleware
155
157
  end
156
158
  end
157
159
 
160
+ # <xml>
161
+ # <ToUserName><![CDATA[toUser]]></ToUserName>
162
+ # <FromUserName><![CDATA[fromUser]]></FromUserName>
163
+ # <CreateTime>1357290913</CreateTime>
164
+ # <MsgType><![CDATA[shortvideo]]></MsgType>
165
+ # <MediaId><![CDATA[media_id]]></MediaId>
166
+ # <ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>
167
+ # <MsgId>1234567890123456</MsgId>
168
+ # </xml>
169
+
170
+ class ShortVideo < Message
171
+
172
+ def MediaId
173
+ @source.MediaId
174
+ end
175
+
176
+ def ThumbMediaId
177
+ @source.ThumbMediaId
178
+ end
179
+ end
180
+
158
181
  end
@@ -192,4 +192,27 @@ module WeixinRailsMiddleware
192
192
  end
193
193
  end
194
194
 
195
+ # 指定会话接入的客服账号
196
+ class KfTransInfo
197
+ include ROXML
198
+ xml_accessor :KfAccount, :cdata => true
199
+ end
200
+
201
+ # <xml>
202
+ # <ToUserName><![CDATA[touser]]></ToUserName>
203
+ # <FromUserName><![CDATA[fromuser]]></FromUserName>
204
+ # <CreateTime>1399197672</CreateTime>
205
+ # <MsgType><![CDATA[transfer_customer_service]]></MsgType>
206
+ # <TransInfo>
207
+ # <KfAccount>test1@test</KfAccount>
208
+ # </TransInfo>
209
+ # </xml>
210
+ class TransferCustomerServiceWithTransInfoReplyMessage < ReplyMessage
211
+ xml_accessor :TransInfo, :as => KfTransInfo
212
+ def initialize
213
+ super
214
+ @MsgType = 'transfer_customer_service'
215
+ end
216
+ end
217
+
195
218
  end
@@ -1,3 +1,3 @@
1
1
  module WeixinRailsMiddleware
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weixin_rails_middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - lanrion
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-02 00:00:00.000000000 Z
11
+ date: 2015-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -91,6 +91,7 @@ files:
91
91
  - Rakefile
92
92
  - app/controllers/weixin_rails_middleware/weixin_controller.rb
93
93
  - config/routes.rb
94
+ - lib/generators/templates/README
94
95
  - lib/generators/templates/add_encrypt_message_config_migration.rb
95
96
  - lib/generators/templates/add_weixin_secret_key_and_weixin_token_migration.rb
96
97
  - lib/generators/templates/install_weixin_rails_middleware.rb
@@ -132,9 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  version: '0'
133
134
  requirements: []
134
135
  rubyforge_project:
135
- rubygems_version: 2.2.2
136
+ rubygems_version: 2.4.5.1
136
137
  signing_key:
137
138
  specification_version: 4
138
139
  summary: weixin_rails_middleware for integration weixin
139
140
  test_files: []
140
- has_rdoc: