PHP code example of codepower / sms-mitake

1. Go to this page and download the library: Download codepower/sms-mitake 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/ */

    

codepower / sms-mitake example snippets


use CodePower\Mitake\Client;
use CodePower\Mitake\Credentials;
use CodePower\Mitake\Message;

$client = new Client(new Credentials('username', 'password'));

$result = $client->send(new Message(to: '0912345678', body: 'Hello 你好'));

$result->msgId;                 // Mitake message serial, e.g. "0000000013"
$result->isAccepted();          // true if accepted
$result->statusCode->code;      // raw status code
$result->accountPoint;          // remaining credit after this send

$client->send(new Message(
    to: '0912345678',
    body: 'See you tomorrow',
    deliverAt: new DateTimeImmutable('2026-06-02 09:00:00'),
    validUntil: new DateTimeImmutable('2026-06-02 12:00:00'),
    callbackUrl: 'https://example.com/mitake/callback',
    clientId: 'order-4821',
));

$results = $client->sendBulk([
    new Message('0912345678', 'Hi A', clientId: 'a'),
    new Message('0987654321', 'Hi B', clientId: 'b'),
]);

$seg = (new Message('0912345678', 'Hello 你好'))->segmentation();

$seg->encoding;      // SmsEncoding::Ucs2 (a Chinese char forces UCS-2)
$seg->length;        // billed unit count
$seg->segments;      // number of SMS parts
$seg->isMultipart(); // true if more than one part
$seg->remaining;     // free units left in the last part

// Or measure any string directly:
\CodePower\Mitake\Segmentation::measure('plain ascii')->encoding; // SmsEncoding::Gsm7

$statuses = $client->queryStatus(['0000000013', '0000000014']);
foreach ($statuses as $status) {
    $status->statusCode->isDelivered();
    $status->statusTime;   // DateTimeImmutable|null
}

$balance = $client->queryBalance();   // $balance->points

foreach ($client->cancel(['0000000013']) as $cancel) {
    $cancel->isCancelled();   // true when status code is 9
}

use CodePower\Mitake\Callback\DeliveryReceipt;

$receipt = DeliveryReceipt::fromArray($_GET);

$receipt->msgId;
$receipt->isDelivered();
$receipt->isFinal();

header('Content-Type: text/plain');
echo $receipt->acknowledge();   // "magicid=sms_gateway_rpack\nmsgid=...\n"