PHP code example of life2016 / aliyun-dysms-php-sdk
1. Go to this page and download the library: Download life2016/aliyun-dysms-php-sdk 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/ */
life2016 / aliyun-dysms-php-sdk example snippets
//在common\config\params.php配置文件中定义配置信息
return [
......
'smsAppKey'=>'LTAIKG534543523',
'smsAppSecret'=>'1kqm43254546tgfdgfdfsrffgttetretI',
......
];
$response = Sms::getInstance()->sendSms($phone, $signName, $templateCode, $code);
$phone ,短信接收号码。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式;
$signName,短信签名;
$templateCode 短信模板ID
$code 验证码
$outId 可选,设置流水号,未传参,默认YmdHis . time()
$upExtendCode 选填,上行短信扩展码(扩展码字段控制在7位或以下,无特殊需求用户请忽略此字段)
$list = Sms::getInstance()->querySendDetails($phone, $date, $pageSize, $pageNo);
$phone 手机号
$date 年月日, 短信发送日期格式yyyyMMdd,支持最近30天记录查询
$pageSize 当前页码 页大小Max=50
$pageNo 当前页码
$bizId 选填,发送流水号,从调用发送接口返回值中获取
echo "消息接口查阅短信状态报告返回结果:\n";
MsgDemo::receiveMsg(
// 消息类型,SmsReport: 短信状态报告
"SmsReport",
// 在云通信页面开通相应业务消息后,就能在页面上获得对应的queueName
"Alicom-Queue-xxxxxxxx-SmsReport",
/**
* 回调
* @param stdClass $message 消息数据
* @return bool 返回true,则工具类自动删除已拉取的消息。返回false,消息不删除可以下次获取
*/
function ($message) {
print_r($message);
return false;
}
);
echo "消息接口查阅短信服务上行返回结果:\n";
MsgDemo::receiveMsg(
// 消息类型,SmsUp: 短信服务上行
"SmsUp",
// 在云通信页面开通相应业务消息后,就能在页面上获得对应的queueName
"Alicom-Queue-xxxxxxxx-SmsUp",
/**
* 回调
* @param stdClass $message 消息数据
* @return bool 返回true,则工具类自动删除已拉取的消息。返回false,消息不删除可以下次获取
*/
function ($message) {
print_r($message);
return false;
}
);
json
{
"fe2016/aliyun-dysms-php-sdk": "*"
}
}