<?php

namespace app\controller;

use support\Request;
use Webman\Container;
use Webman\Push\Api;

class IndexController
{
    public function index(Request $request)
    {
        return json(['code' => 0, 'msg' => 'ok']);

    }

    public function view(Request $request)
    {
        return view('index/view', ['name' => 'webman']);
    }

    public function json(Request $request)
    {
        return json(['code' => 0, 'msg' => 'ok']);
    }

    public function push(Request $request){
        $parmas=$request->get('name');
        $api = new Api(
            // webman下可以直接使用config获取配置，非webman环境需要手动写入相应配置
            'http://127.0.0.1:3232',
            config('plugin.webman.push.app.app_key'),
            config('plugin.webman.push.app.app_secret')
        );
        // 给订阅 user-1 的所有客户端推送 message 事件的消息
        $api->trigger('user-1', 'message', [
            'from_uid' => 1,
            'content'  => $parmas
        ]);
        return json(['code' => 0, 'msg' => 'ok']);
    }
}
