Skip to content

Commit 123bcb1

Browse files
committed
Merge pull request #80 from zfben/master
update document for after_wechat_response
2 parents 55fcf5d + 6d80653 commit 123bcb1

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

README-CN.md

+16-9
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ default: &default
7979
token: "app_token"
8080
access_token: "/var/tmp/wechat_access_token"
8181
82-
production:
82+
production:
8383
appid: <%= ENV['WECHAT_APPID'] %>
8484
secret: <%= ENV['WECHAT_APP_SECRET'] %>
8585
token: <%= ENV['WECHAT_TOKEN'] %>
8686
access_token: <%= ENV['WECHAT_ACCESS_TOKEN'] %>
8787
88-
development:
88+
development:
8989
<<: *default
9090
91-
test:
91+
test:
9292
<<: *default
9393
```
9494

@@ -149,11 +149,11 @@ Wechat服务器有报道曾出现[RestClient::SSLCertificateNotVerified](http://
149149
```ruby
150150
class WechatFirstController < ActionController::Base
151151
wechat_responder appid: "app1", secret: "secret1", token: "token1", access_token: Rails.root.join("tmp/access_token1")
152-
152+
153153
on :text, with:"help", respond: "help content"
154154
end
155155
```
156-
156+
157157
#### jssdk 支持
158158

159159
jssdk 使用前需通过config接口注入权限验证配置, 所需参数可以通过 signature 方法获取:
@@ -354,7 +354,7 @@ articles:
354354
然后执行命令行
355355

356356
```
357-
$ wechat custom_news oCfEht9oM*********** articles.yml
357+
$ wechat custom_news oCfEht9oM*********** articles.yml
358358
359359
```
360360

@@ -368,7 +368,7 @@ template:
368368
url: "http://weixin.qq.com/download"
369369
topcolor: "#FF0000"
370370
data:
371-
first:
371+
first:
372372
value: "你好,你已报名成功"
373373
color: "#0A0A0A"
374374
keynote1:
@@ -405,7 +405,7 @@ $ wechat template_message oCfEht9oM*********** template.yml
405405
```ruby
406406
class WechatsController < ActionController::Base
407407
wechat_responder
408-
408+
409409
# 默认文字信息responder
410410
on :text do |request, content|
411411
request.reply.text "echo: #{content}" #Just echo
@@ -522,6 +522,13 @@ class WechatsController < ActionController::Base
522522

523523
# 当无任何responder处理用户信息时,使用这个responder处理
524524
on :fallback, respond: 'fallback message'
525+
526+
# 如果你要在微信回复后增加一些操作,可以用 after_wechat_response(req, res)
527+
# private
528+
#
529+
# def after_wechat_response(req, res)
530+
# WechatLog.create req: req, res: res
531+
# end
525532
end
526533
```
527534

@@ -557,7 +564,7 @@ class WechatsController < ActionController::Base
557564
# 当无任何responder处理用户信息时,转发至客服处理。
558565
on :fallback do |message|
559566
message.reply.transfer_customer_service
560-
end
567+
end
561568
end
562569
```
563570

README.md

+19-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ WeChat gem trying to helping Rails developer to integrated [enterprise account](
1717

1818
`wechat` command share the same API in console, so you can interactive with wechat server quickly, without starting up web environment/code.
1919

20-
A responder DSL can used in Rails controller, so giving a event based interface to handler message sent by end user from wechat server.
20+
A responder DSL can used in Rails controller, so giving a event based interface to handler message sent by end user from wechat server.
2121

2222
Wechat provide OAuth2.0 as authentication service and possible to intergrated with devise/other authorization gems, [omniauth-wechat-oauth2](https://github.com/skinnyworm/omniauth-wechat-oauth2) is a good start
2323

@@ -88,16 +88,16 @@ default: &default
8888
token: "app_token"
8989
access_token: "/var/tmp/wechat_access_token"
9090
91-
production:
91+
production:
9292
appid: <%= ENV['WECHAT_APPID'] %>
9393
secret: <%= ENV['WECHAT_APP_SECRET'] %>
9494
token: <%= ENV['WECHAT_TOKEN'] %>
9595
access_token: <%= ENV['WECHAT_ACCESS_TOKEN'] %>
9696
97-
development:
97+
development:
9898
<<: *default
9999
100-
test:
100+
test:
101101
<<: *default
102102
```
103103

@@ -161,11 +161,11 @@ Rare case, you may want to hosting more than one wechat enterprise/public accoun
161161
```ruby
162162
class WechatFirstController < ActionController::Base
163163
wechat_responder appid: "app1", secret: "secret1", token: "token1", access_token: Rails.root.join("tmp/access_token1")
164-
164+
165165
on :text, with:"help", respond: "help content"
166166
end
167167
```
168-
168+
169169
#### JS-SDK helper
170170

171171
JS-SDK enable you control wechat behavior in your web page, but need inject a config with signature methods first, you can obtain those signature hash via below
@@ -182,7 +182,7 @@ wechat gems won't handle any privilege exception. (except token time out, but it
182182

183183
The available API is different between public account and enterprise account, so wechat gems provide different set of command.
184184

185-
Feel safe if you can not read Chinese in the comments, it's keep there in order to copy & find in official document more easier.
185+
Feel safe if you can not read Chinese in the comments, it's keep there in order to copy & find in official document more easier.
186186

187187
#### Public account command line
188188

@@ -367,7 +367,7 @@ articles:
367367
After that, can running command:
368368

369369
```
370-
$ wechat custom_news oCfEht9oM*********** articles.yml
370+
$ wechat custom_news oCfEht9oM*********** articles.yml
371371
372372
```
373373

@@ -381,7 +381,7 @@ template:
381381
url: "http://weixin.qq.com/download"
382382
topcolor: "#FF0000"
383383
data:
384-
first:
384+
first:
385385
value: "Hello, you successfully registed"
386386
color: "#0A0A0A"
387387
keynote1:
@@ -535,10 +535,17 @@ class WechatsController < ActionController::Base
535535

536536
# Any not match above will fail to below
537537
on :fallback, respond: 'fallback message'
538+
539+
# If you need do something after response, you should add after_wechat_response(req, res)
540+
# private
541+
#
542+
# def after_wechat_response(req, res)
543+
# WechatLog.create req: req, res: res
544+
# end
538545
end
539546
```
540547

541-
So the importent statement is only `wechat_responder`, all other is just a DSL:
548+
So the importent statement is only `wechat_responder`, all other is just a DSL:
542549

543550
```
544551
on <message_type> do |message|
@@ -571,13 +578,13 @@ class WechatsController < ActionController::Base
571578
# When no other responder can handle incoming message, will transfer to human customer service.
572579
on :fallback do |message|
573580
message.reply.transfer_customer_service
574-
end
581+
end
575582
end
576583
```
577584

578585
Caution: do not setting default text responder if you want to using [multiply human customer service](http://dkf.qq.com/), other will lead text message can not transfer.
579586

580-
587+
581588
## Known Issue
582589

583590
* Sometime, enterprise account can not receive the menu message due to Tencent server can not resolved the DNS, so using IP as a callback URL more stable, but it's never happen for user sent text message.

0 commit comments

Comments
 (0)