<?php

namespace crmeb\services\async\task;

use crmeb\repositories\ShortLetterRepositories;

/**
 * 异步发短信
 */
class AsyncSms extends Task {

    const CMD = 'sms';

    protected static function getCmd()
    {
        return self::CMD;
    }

    public static function exec(array $task)
    {
        if (!self::checkTask($task)) {
            return false;
        }

        $params = $task['params'];

        return ShortLetterRepositories::send(true, $params['phone'], $params['data'], $params['template']);
    }

    public static function push(string $phone, array $data, string $template)
    {
        return self::put([
            'phone' => $phone,
            'data'  => $data,
            'template' => $template,
        ]);
    }
}