Giter Site home page Giter Site logo

Comments (18)

lanrion avatar lanrion commented on May 24, 2024

微信不能发送空消息吧?

from weixin_rails_middleware.

lanrion avatar lanrion commented on May 24, 2024

2、微信服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次。假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试

如果确实要避免,消息为空的时候,返回一个 nil 即:reply_text_message(nil).

from weixin_rails_middleware.

Wangjiaji007 avatar Wangjiaji007 commented on May 24, 2024

假如服务器无法保证在五秒内处理并回复,必须做出下述回复,这样微信服务器才不会对此作任何处理,并且不会发起重试(这种情况下,可以使用客服消息接口进行异步回复),否则,将出现严重的错误提示。详见下面说明:

1、直接回复空串(指字节长度为0的空字符串,而不是XML结构体中content字段的内容为空)
2、直接回复success

微信官方的说明,就是接口至少返回空串,才能避免报错。

from weixin_rails_middleware.

lanrion avatar lanrion commented on May 24, 2024

你试一下。

from weixin_rails_middleware.

Wangjiaji007 avatar Wangjiaji007 commented on May 24, 2024

你的

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.

lanrion avatar lanrion commented on May 24, 2024

你试过 reply_text_message(nil) 吗?

from weixin_rails_middleware.

Wangjiaji007 avatar Wangjiaji007 commented on May 24, 2024

试过,不行的。因为你那只是设置 message.Content = nil

from weixin_rails_middleware.

lanrion avatar lanrion commented on May 24, 2024

我是可以的哦。

from weixin_rails_middleware.

lanrion avatar lanrion commented on May 24, 2024

自动回复功能,是一个很常见的功能,如果这个需求都无法满足的话,这个issue应该早有人报了。

from weixin_rails_middleware.

Wangjiaji007 avatar Wangjiaji007 commented on May 24, 2024

不报service unavailable 么? 如果是这样,那我再看下。

from weixin_rails_middleware.

lanrion avatar lanrion commented on May 24, 2024

你的需求是,微信用户发送关键字过来,如果你的数据库没有找到针对这个关键字设置的回复内容,则不回复。即:message = @weixin_public_account.find_autoreply_by(@keyword),为了排除其他非此gem的错误,先将weixin_rails_middleware生成的代码去除,然后再直接 reply_text_message(nil),你会发现,你在公众号上发任何文本消息,都不会有回应。

from weixin_rails_middleware.

Wangjiaji007 avatar Wangjiaji007 commented on May 24, 2024

ok, 多谢

from weixin_rails_middleware.

Wangjiaji007 avatar Wangjiaji007 commented on May 24, 2024
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.

lanrion avatar lanrion commented on May 24, 2024

http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index

from weixin_rails_middleware.

elele avatar elele commented on May 24, 2024

我也是这样,reply_text_message(nil) 一直提示 该公众号暂时无法提供服务,请稍后再试.

from weixin_rails_middleware.

lanrion avatar lanrion commented on May 24, 2024

@elele 可否把你的账号上传一下?

from weixin_rails_middleware.

elele avatar elele commented on May 24, 2024

@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.

smoothdvd avatar smoothdvd commented on May 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.