tenko / link-sms
Link Group Third-part Sms SDK
v0.1.5
2023-06-09 06:37 UTC
Requires
- php: >=7.4
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^7.6.1
- guzzlehttp/psr7: ^2.5
Requires (Dev)
- phpunit/phpunit: 9.6.*
README
LinkSMS is a third-part SDK for Link Group SMS Service.
Quick Start
- First: Create a config object
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();
Or you can use an anonymous class like this:
$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 []; } };
- If you need to log events, there are also provided interfaces for logging. Here is the usage example:
$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 } };
- And then you can start using it.
$sms = new \LinkSms\SmsService($config[, $log]); // It is not necessary to pass a LogInterface
Usage
- Send message
$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. )
- Get remain
$remain = $sms->getRemain();
- Fetch message
/** @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(); }