微信公众号扫码/关注时回复模板消息或小程序码

EasyWechat 官方文档

public function callBack()
{
    $app = Factory::officialAccount($config);

    // 消息推送
    $app->server->push(function ($message) use ($app) {
        switch ($message['MsgType']) {
            case 'event':  // 消息类型: 事件
                switch ($message['Event']) {
                    case 'SCAN':  // 事件类型: 扫码
                        $app->customer_service->send([
                            'touser' => $message['FromUserName'],
                            'msgtype' => 'miniprogrampage',
                            'miniprogrampage' => [
                                'title' => '小程序卡片',
                                'appid' => 'wx0d3e3a51fcef8cc3',
                                'pagepath' => 'pages/index/index',
                                'thumb_media_id' => 'ZCn8SlYlsRihPxbRL5cFYQXj5MEUuW2FgqjzsdvuIS0',
                            ],
                        ]);
                        return null;
                    case 'subscribe':  // 事件类型: 关注
                        $app->template_message->send([
                            'touser' => $message['FromUserName'],
                            'template_id' => 'gA-cKPYDKt9t4LTmsAHEIUb8v81ZUHnYeB0ZpsQOrws',
                            'miniprogram' => [
                                'appid' => 'wx0d3e3a51fcef8cc3',
                                'pagepath' => 'pages/index/index',
                            ],
                            'data' => [
                                'first' => '您的测量结果',
                                'keyword1' => '123',
                                'keyword2' => '95',
                                'keyword3' => '65',
                                'keyword4' => '稳定',
                                'remark' => '建议您多吃猪肉',
                            ],
                        ]);
                        return null;
                    default:
                        return null;
                }
            case 'text':
                return '文本消息';
            default:
                return null;
        }
    });

    $response = $app->server->serve();

    // 将响应输出
    $response->send();
    exit();
}