yiiviet / yii2-esms
支持集成 eSMS 服务。
1.0.3
2018-11-12 15:26 UTC
Requires
- vxm/yii2-gateway-clients: ~2.0.0
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-09-23 07:34:18 UTC
README
Yii2 扩展,帮助您集成 eSMS 服务。
如果您经常构建与 sms
或 voice call
相关的系统,那么 eSMS 可能是您不陌生的合作伙伴,此扩展可以帮助您将 eSMS 的服务集成到您的系统中。
要求
安装
如果您对 composer
这个概念比较陌生,请点击 此处 了解它。
composer require "yiiviet/yii2-esms"
或者
"yiiviet/yii2-esms": "*"
在 composer.json 文件中的 require
部分添加以下内容。
配置
安装完成后,请进入 config
文件夹,打开 web.php
文件,并在 components
中添加以下配置。
'components' => [ 'eSMS' => [ 'class' => 'yiiviet\esms\Gateway', 'client' => [ 'apiKey' => 'API key ban dang ky tai eSMS (phan quan ly api)', 'secretKey' => 'Secret key ban dang ky tai eSMS (phan quan ly api)' ] ] ]
配置完成后,您就可以立即通过以下语法与 eSMS
进行交互: Yii::$app->eSMS
。
基本使用
1. 发送短信的方法
$result = Yii::$app->eSMS->sendSMS([ 'Phone' => '0909113911', 'Content' => 'Hi Mr.Minh' ]); if ($result->isOk) { Yii::info('Send sms to Mr.Minh success! SMSID: ' . $result->SMSID); } else { Yii::warning($result->message); }
2. 发送语音通话的方法
Yii::$app->eSMS->sendVoice([ 'Phone' => '0909113911', 'ApiCode' => 'xxxxxxxxxxx', // Liên hệ kỹ thuật eSMS cấp 'ApiPass' => 'xxxxxxxxxxx' ]); if ($result->isOk) { Yii::info('Send voice call to Mr.Minh success! SMSID: ' . $result->SMSID); } else { Yii::warning($result->message); }
3. 检查账户余额的方法
$result = Yii::$app->eSMS->getBalance(); if ($result->isOk) { Yii::info('Balance of account: ' . $result->Balance); } else { Yii::warning($result->message); }
4. 检查已发送短信的状态
$result = Yii::$app->eSMS->getSendStatus($SMSID); if ($result->isOk) { Yii::info('Sent: ' . $result->SentSuccess); } else { Yii::warning($result->message); }
$SMSID
将在发送短信或语音通话的结果中返回,因此发送短信后,您应保存$SMSID
。
5. 检查已发送短信的详细状态(显示每个电话号码的详细信息)
$result = Yii::$app->eSMS->getReceiverStatus($SMSID); if ($result->isOk) { Yii::info('Sent: ' . var_export($result->ReceiverList, true)); } else { Yii::warning($result->message); }
$SMSID
将在发送短信或语音通话的结果中返回,因此发送短信后,您应保存$SMSID
。
高级使用
如果您想了解更多关于在发送短信或语音通话时创建命令的组件,或 eSMS 返回的结果组件,请参阅 此处 的 eSMS 文档。eSMS 文档中的组件名称与扩展中的组件名称(属性、元素键)一致。