PHP code example of sxqibo / fast-sms
1. Go to this page and download the library: Download sxqibo/fast-sms 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/ */
sxqibo / fast-sms example snippets
use Sxqibo\Sms\SmsFactory;
use Sxqibo\Sms\SmsInterface;
public function __construct()
{
// 从数据库中读取的短信供应商
// 这个值是文档中 [说明] 部分的值
$provider = 'aliyun_new';
// 从数据库中读取的短信配置
$config = [
'version' => '2017-05-25',
'host' => 'dysmsapi.aliyuncs.com',
'scheme' => 'http',
'region_id' => 'cn-hangzhou',
'access_key' => 'aaa',
'access_secret' => 'bbb',
'sign_name' => 'ccc',
'actions' => [
'smsVerify' => [
'actions_name' => '验证码短信',
'template_id' => 'SMS_264200953',
],
'login' => [
'actions_name' => '登录验证',
'template_id' => 'SMS_53115057',
],
'changePassword' => [
'actions_name' => '修改密码',
'template_id' => 'SMS_53115053',
],
'changeUserinfo' => [
'actions_name' => '变更信息',
'template_id' => 'SMS_53115052',
],
],
];;
$this->sms = SmsFactory::getSmsObject($provider, $config);
}
public function sendSms($mobile, $template, $param)
{
return $this->sms->send($template, $mobile, $param);
}
}
$smsSend = new SmsSend();
// 参数1是手机号
// 参数二是模版,有的短信可能没有模版,传空即可,注意这个模版在 $config 中配置过的
// 第三个参数是模版对应的内容,注意有的短信没有模板,可以直接把短信内容(字符串)包装到数组中即可,如['123456']
$data = $smsSend->sendSms('15000000001', 'smsVerify', ['code' => '123456']);
var_dump($data);