Skip to content

Laravel-Wechat 客服消息接收异常 #40

@wilbur-yu

Description

@wilbur-yu

接入微信后台的客服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下是正常的.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions