shadowfax icon indicating copy to clipboard operation
shadowfax copied to clipboard

Laravel-Wechat 客服消息接收异常

Open wilbur-yu opened this issue 3 years ago • 2 comments

接入微信后台的客服api route/api.php

$router->any('wechat/serve', 'WechatMiniCustomerController@serve');

控制器方法

    public function serve() : Response
    {
        $app = $this->getMiniProgram();

        $customerService = $app->customer_service;

        $app->server->push(static function ($message) use ($customerService) {
            if (isset($message['MsgType']) && 'miniprogrampage' === $message['MsgType']) {
                if ('type=map' === $message['PagePath']) {
                    $text = new Text(AirdropConstant::CUSTOMER_INTRO_TEXT);
                    $customerService->message($text)->to($message['FromUserName'])->send();
                }

                $link = new Link(AirdropConstant::APP_INFO[$message['PagePath']]);
                $customerService->message($link)->to($message['FromUserName'])->send();
            }
        });

        return $app->server->serve();
    }

在转发给客服后, 客户端收到消息延迟或者接收不到或者在一段时间后, 会收到好多条. 替换为支持协程的Guzzle Handler后, 也会有这些问题. PHP-FPM下是正常的.

wilbur-yu avatar Jul 27 '20 06:07 wilbur-yu

你可以记下日志,调试一下$message的值,看看你的代码有没有走到if代码块里面。我感觉这个和guzzle没有太大关系,可能是参数的问题

huang-yi avatar Jul 30 '20 08:07 huang-yi

日志正常记录接收到微信端的转发请求,但是转发给微信的请求没有记录到日志中,每次重启服务后,会正常一段时间,之后就开始断断续续的出现接受不到消息的情况

wilbur-yu avatar Aug 01 '20 03:08 wilbur-yu