<?php


namespace App\Console\Commands\Push;


use App\Consts\PushConst;
use App\Libs\Push\OPPOPush\OPPOPushCommon;
use Illuminate\Console\Command;
use GuzzleHttp\Exception\GuzzleException;

class OppoPushTest extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'push:oppo:test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @throws GuzzleException
     */
    public function handle()
    {
        // 配置
        $regId = 'CN_83427bab875a0a40e4da3eeb2055f331';
        [$appKey, $masterSecret] = ['354f2fba4c834e94a206fca247f132a0', 'ba2d9968c45b489da75e6bde7147b32a'];

        // 初始化
        $instance = new OPPOPushCommon($appKey, $masterSecret);

        // 查询APP当天发送量的状态
        $res = $instance->fetchPushPermit();
        dd($res);

        // 标签相关
        $tag  = PushConst::TOPIC_ALL;
        $res1 = $instance->addTags($tag, '全部用户');
        $res2 = $instance->subscribeTags($regId, $tag);
        $res3 = $instance->getAllTags($regId);
        dd($res1, $res2, $res3);

        // 发送消息
        $messageId = $instance->getMessageId('我是标题11', '我是内容11', '/');
        $res4      = $instance->broadCastRegIds($messageId, [$regId]);
        dd($messageId, $res4);

    }
}
