Comments (18)
微信不能发送空消息吧?
from weixin_rails_middleware.
2、微信服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次。假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试
如果确实要避免,消息为空的时候,返回一个 nil 即:reply_text_message(nil)
.
from weixin_rails_middleware.
假如服务器无法保证在五秒内处理并回复,必须做出下述回复,这样微信服务器才不会对此作任何处理,并且不会发起重试(这种情况下,可以使用客服消息接口进行异步回复),否则,将出现严重的错误提示。详见下面说明:
1、直接回复空串(指字节长度为0的空字符串,而不是XML结构体中content字段的内容为空)
2、直接回复success
微信官方的说明,就是接口至少返回空串,才能避免报错。
from weixin_rails_middleware.
你试一下。
from weixin_rails_middleware.
你的
def reply_text_message(from=nil, to=nil, content)
message = TextReplyMessage.new
message.FromUserName = from || @weixin_message.ToUserName
message.ToUserName = to || @weixin_message.FromUserName
message.Content = content
encrypt_message message.to_xml
end
把这个写死了。能不能写个统一接口只要收到请求,至少返回success,或者0字节字符串。多谢
from weixin_rails_middleware.
你试过 reply_text_message(nil)
吗?
from weixin_rails_middleware.
试过,不行的。因为你那只是设置 message.Content = nil
from weixin_rails_middleware.
我是可以的哦。
from weixin_rails_middleware.
自动回复功能,是一个很常见的功能,如果这个需求都无法满足的话,这个issue应该早有人报了。
from weixin_rails_middleware.
不报service unavailable 么? 如果是这样,那我再看下。
from weixin_rails_middleware.
你的需求是,微信用户发送关键字过来,如果你的数据库没有找到针对这个关键字设置的回复内容,则不回复。即:message = @weixin_public_account.find_autoreply_by(@keyword)
,为了排除其他非此gem的错误,先将非weixin_rails_middleware生成的代码去除,然后再直接 reply_text_message(nil)
,你会发现,你在公众号上发任何文本消息,都不会有回应。
from weixin_rails_middleware.
ok, 多谢
from weixin_rails_middleware.
def response_text_message(options={})
# message = @weixin_public_account.find_autoreply_by(@keyword)
reply_text_message(nil)
end
我的微信账号里返回的是 Official account services unavailable. Try again lager
from weixin_rails_middleware.
http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index
from weixin_rails_middleware.
我也是这样,reply_text_message(nil) 一直提示 该公众号暂时无法提供服务,请稍后再试.
from weixin_rails_middleware.
@elele 可否把你的账号上传一下?
from weixin_rails_middleware.
@lanrion 什么账号? 我临时修改了一下
def reply
if @Keyword && @weixin_message.MsgType == 'text' && @keyword.to_s != '1'
return render :text => ''
end
render xml: send("response_#{@weixin_message.MsgType}_message", {})
end
因为自动回复都是返回 xml 结构的数据,不需要回复的地方,微信官方说明
1、直接回复空串(指字节长度为0的空字符串,而不是XML结构体中content字段的内容为空)
2、直接回复success
还是有很多的回调处理会出现 该公众号暂时无法提供服务,请稍后再试 这样的提示
比如扫描二维码关注,自动发送模版消息等. 希望能加上一个不回复的功能.
from weixin_rails_middleware.
@lanrion
我直接改成这样了:
def reply
if (response = send("response_#{@weixin_message.MsgType}_message", {})).nil?
render text: ''
else
render xml: response
end
end
from weixin_rails_middleware.
Related Issues (20)
- 公众平台消息体签名及加解密方案 HOT 1
- 重复的 `private` ? HOT 3
- weixin_token_string 验证失败 HOT 2
- 转发多客服消息 HOT 3
- 小视频消息 HOT 2
- 对weixin_rails_middleware Rspec测试的时候, WeixinRailsMiddleware::WeixinController#default_url_options 报错 HOT 3
- 取消关注 报错 NoMethodError (undefined method `empty?' for true:TrueClass): HOT 10
- reply_transfer_customer_service_message 未提供指定客服参数 HOT 1
- 要对不同微信回复消息XML结构要实现到自动匹配
- 如何在weixin_controller_decorator.rb文件以外使用reply方法 HOT 2
- Rails 5 貌似不支持。 HOT 4
- 貌似 rails 5 开始不鼓励使用 before_filter 了 HOT 2
- 无法看到log HOT 3
- Rails5.1 貌似会取消这个 before_filter HOT 3
- 版本 1.3.2,初始配置校验,报MissTemplate错误 HOT 10
- Filter chain halted as :check_weixin_legality rendered or redirected HOT 3
- message.to_xml的class是Nokogiri::XML::Element Prpcrypt.encrypt加密的时候会undefined method `force_encoding' for #<Nokogiri::XML::Document HOT 1
- Weixin signature NotMatch HOT 4
- NameError: uninitialized constant HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from weixin_rails_middleware.