第一步:php
下載安裝app
https://packagist.org/packages/overtrue/easy-smcomposer
composer require overtrue/easy-sms測試
第二步:ui
在master.php類文件中引入this
require_once __DIR__ . '/../../vendor/autoload.php'; use Overtrue\EasySms\EasySms; use Overtrue\EasySms\Exceptions\InvalidArgumentException; use Overtrue\EasySms\Exceptions\NoGatewayAvailableException;
並在app類中定義屬性,並在構造方法中把EasySms對象賦值給該屬性spa
public $sms;
//雲通信短信驗證碼 $config = [ // HTTP 請求的超時時間(秒) 'timeout' => 5.0, // 默認發送配置 'default' => [ // 網關調用策略,默認:順序調用 'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class, // 默承認用的發送網關 'gateways' => [ 'yuntongxun', ], ], // 可用的網關配置 'gateways' => [ 'errorlog' => [ 'file' => __DIR__ . '/../../data/log/easy-sms.log', ], 'yuntongxun' => [ 'app_id' => 'xxxxx', 'account_sid' => 'xxxxx', 'account_token' => 'xxxxxx', 'is_sub_account' => false, ], ], ]; $this->sms = new EasySms($config);
第三步:視頻
測試地址:http://127.0.0.1/index.php?test-master-test1-send對象
/**
* 榮聯雲短信測試
*/
private function send()
{
// 【小雨xx】您好,我是{1}人事部經理{2},咱們將於{3}在{4}進行{5},收到短信後,請向人事部經理{6}發送短信確認「來」或「不來」並附上本身的姓名,謝謝! template:80463
try {
$r = $this->sms->send(187******, [
'template' => '80463',
'data' => ['小雨xx', '飛天', '2018-07-18', '東郊校區', '視頻會議', '029- '],
]);
print_r($r);
} catch (\Overtrue\EasySms\Exceptions\InvalidArgumentException $e) {
} catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $e) {
}
}
發送成功效果預覽:blog