PHP code example of mindertech / laravel-aliyun-dysms
1. Go to this page and download the library: Download mindertech/laravel-aliyun-dysms 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/ */
mindertech / laravel-aliyun-dysms example snippets
return [
'access_key_id' => '',
'access_key_secret' => '',
'sign' => '',
'log' => false,
'sms-report-queue' => '',
'sms-up-queue' => '',
//以下配置暂时无需替换
'product' => 'Dysmsapi',
'domain' => 'dysmsapi.aliyuncs.com',
'region' => 'cn-hangzhou',
'end_point_name' => 'cn-hangzhou',
'mns' => [
'account_id' => '1943695596114318',
'product' => 'Dybaseapi',
'domain' => 'dybaseapi.aliyuncs.com',
'wait_seconds' => 3
],
];
try {
$bizId = SendSms::to('SMS_123456', '18688886666', [
'code' => mt_rand(1000, 9999)
]);
} catch(\Exception $e) {
echo $e->getMessage();
}
$page = 1;
$pageSize = 1;
$bizId = null;
$result = QuerySms::search('18688886666', '20180516', $page, $pageSize, $bizId);
try {
$bizId = SendSmsBatch::to(
'SMS_123456',
[
'18688886666',
'18666666666'
],
[
'sign-1', 'sign-2'
],
[
[
'code' => mt_rand(1000, 9999)
],
[
'code' => mt_rand(1000, 9999)
]
]
);
} catch (\Exception $e) {
echo $e->getMessage();
}
/**
* 回调
* @param stdClass $message 消息数据
* @return bool 返回true,则工具类自动删除已拉取的消息。返回false,消息不删除可以下次获取
*/
SmsQueue::up(function($message) {
/*
{
"dest_code": "2199787"
"send_time": "2018-05-16 18:05:13"
"sign_name": "signname"
"sp_id": null
"sequence_id": 531571249
"phone_number": "18688886666"
"content": "回复测试"
}
*/
print_r($message);
return true;
});
/**
* 回调
* @param stdClass $message 消息数据
* @return bool 返回true,则工具类自动删除已拉取的消息。返回false,消息不删除可以下次获取
*/
SmsQueue::report(function($message) {
/*
{
"send_time": "2018-05-16 14:18:57"
"report_time": "2018-05-16 14:19:02"
"success": true
"err_msg": "用户接收成功"
"err_code": "DELIVERED"
"phone_number": "18688886666"
"sms_size": "1"
"biz_id": "48490846451537371^0"
"out_id": null
}
*/
print_r($message);
return true;
});
try {
$bizId = SendSms::setRuntimeConfig([
'access_key_id' => 'id',
'access_key_secret' => 'key'
])->to('SMS_123456', '18688886666', [
'code' => mt_rand(1000, 9999)
]);
} catch(\Exception $e) {
echo $e->getMessage();
}
shell
php artisan vendor:publish --provider=Mindertech\Dysms\MindertechDysmsServiceProvider