微信服务号怎样实现异步回复客服消息

By admin, 20 十一月, 2015

为了避免回复超时,微信建议先回复success,再通过客服接口回复。一般情况下,PHP程序返回结果代表程序结束,但是下面的技巧可以让PHP程序返回结果后继续运算。

       

        // 立即返回
        ignore_user_abort(true);
        ob_start();
        // do initial processing here
        echo 'success'; // send the response
        header('Connection: close');
        header('Content-Length: ' . ob_get_length());
        ob_end_flush();
        ob_flush();
        flush();
        
        // 发送客服消息

标签

评论3

Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
验证码
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
请输入"Drupal10"

admin

7 years 10 months 之前

对于Nginx,需要添加以下语句。

header('X-Accel-Buffering: no');

Apache的方法请自行搜索。

请教 (未验证)

5 years 2 months 之前

能否给一份完整的代码,新手不懂