PHP code example of tenko / link-sms

1. Go to this page and download the library: Download tenko/link-sms library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tenko / link-sms example snippets


class Config implements \LinkSms\Library\ConfigInterface {
    public function getBaseUrl(): string
    {
        return 'https://sdk3.028lk.com:9988';
    }

    public function getCorpId(): string
    {
        return '[CORP_ID]';
    }

    public function getPassword(): string
    {
        return '[PASSWORD]';
    }

    public function getHeaders(): array
    {
        return [];
    }

    public function getGuzzleConfig(): array
    {
        return [];
    }
}

$config = new Config();

$config = new class implements \LinkSms\Library\ConfigInterface {
    public function getBaseUrl(): string
    {
        return 'https://sdk3.028lk.com:9988';
    }

    public function getCorpId(): string
    {
        return '[CORP_ID]';
    }

    public function getPassword(): string
    {
        return '[PASSWORD]';
    }

    public function getHeaders(): array
    {
        return [];
    }

    public function getGuzzleConfig(): array
    {
        return [];
    }
};

$log = new class implements \LinkSms\Library\LogInterface {
    public function info(string $message, array $data = [])
    {
        // TODO write info
    }

    public function warning(string $message, array $data = [])
    {
        // TODO write warning
    }

    public function error(string $message, array $data = [])
    {
        // TODO write error
    }
};

$sms = new \LinkSms\SmsService($config[, $log]); // It is not necessary to pass a LogInterface

$sms->sendMessage(
    ['13800008888'],
    'content 【Sign】',
    '', // Cell, must be a numeric string,
    new DateTimeImmutable('2024-01-01 08:00') // It is not necessary unless you need to schedule the sending of text messages.
)

$remain = $sms->getRemain();

/** @var array<\LinkSms\Library\Message> $messages */
$messages = $sms->fetchMessage();

foreach ($messages as $message) {
    $mobile = $message->getMobile();
    
    $content = $message->getContent();
    
    /** @var DateTimeImmutable $sendTime */
    $sendTime = $message->getSendTime();
    $sendTimestamp = $sendTime->getTimestamp();
    
    $cell = $message->getCell();
}