PHP SDK

安装

使用 Composer 是安装适用于 PHP 的 Unimatrix SDK 的推荐方法,可在 Packagist 上获得。

运行以下命令将 unimtx/uni-sdk 添加为项目依赖:

composer require unimtx/uni-sdk

使用示例

以下示例展示如何使用 Unimatrix PHP SDK 快速调用 Unimatrix 服务。

发送短信

向单个收件人发送短信


use Uni\UniClient;
use Uni\UniException;

// 初始化
$client = new UniClient([
  'accessKeyId' => 'your access key id',
  'accessKeySecret' => 'your access key secret', // 若使用简易验签模式请删除此行
  'endpoint' => 'https://api-cn.unimtx.com' // 设置接入点到中国大陆, 若使用全球节点请移除此行代码
]);

// 发送短信
try {
  $resp = $client->messages->send([
    'to' => '1865800xxxx', // 国际号码以 E.164 格式传入手机号, 如 +861865800xxxx
    'signature' => '合一矩阵', // 请替换为您的短信签名
    'content' => '您的验证码是123456,5分钟内有效。'
  ]);
  var_dump($resp->data);
} catch (UniException $e) {
  print_r($e);
}

使用模版和模版变量发送短信

$client->messages->send([
  'to' => '1865800xxxx',
  'signature' => '合一矩阵',
  'templateId' => 'pub_verif_ttl2',
  'templateData' => [
    'code' => '123456',
    'ttl' => '5'
  ]
]);