PHP code example of larva / laravel-aliyun

1. Go to this page and download the library: Download larva/laravel-aliyun 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/ */

    

larva / laravel-aliyun example snippets


return [
    'default' => [
        'type' => 'access_key',
        'region' => 'cn-beijing',
        'access_id' => env('ALIBABA_CLOUD_ACCESS_KEY_ID'),
        'access_key' => env('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
        'connect_timeout' => 5,
        'timeout' => 10,
        'proxy' => null,
    ],

    // 额外账号(配置会与 default 合并)
    'secondary' => [
        'type' => 'access_key',
        'access_id' => env('ALIYUN_SECONDARY_ACCESS_KEY_ID'),
        'access_key' => env('ALIYUN_SECONDARY_ACCESS_KEY_SECRET'),
        'region' => 'cn-shanghai',
    ],
];

use Larva\Aliyun\AliyunHelper;

// 发送短信
AliyunHelper::sendSms(
    phoneNumbers: '13800138000',           // string|array 手机号
    templateCode: 'SMS_123456789',         // 模板Code
    templateParam: ['code' => '1234'],     // array|string 模板参数
    signName: '阿里云',                    // 签名
    smsUpExtendCode: null,                 // 选填,上行短信扩展码
    outId: null,                           // 选填,外部流水号
);

use Larva\Aliyun\Jobs\Cdn\PushObjectCacheJob;
use Larva\Aliyun\Jobs\Cdn\RefreshObjectCachesJob;

// 预热缓存(将源站内容预热到 L2 缓存节点)
PushObjectCacheJob::dispatch(['https://example.com/page1', 'https://example.com/page2'], 'domestic');
// $area: domestic(国内)| overseas(海外)

// 刷新缓存
RefreshObjectCachesJob::dispatch('https://example.com/page1', 'File');
// $objectType: File(文件)| Directory(目录)

use Larva\Aliyun\Jobs\Dns\DeleteDomainRecord;
use Larva\Aliyun\Jobs\Dns\DeleteSubDomainRecordsJob;
use Larva\Aliyun\Jobs\Dns\UpdateDomainRecordJob;

// 删除解析记录
DeleteDomainRecord::dispatch('recordId');

// 删除主机记录的所有解析
DeleteSubDomainRecordsJob::dispatch('example.com', 'www');

// 修改解析记录
UpdateDomainRecordJob::dispatch(
    recordId: 'recordId',
    rr: 'www',
    type: 'A',
    value: '192.168.1.1',
    ttl: 600,         // 选填,默认 600
    line: 'default',  // 选填,默认 default
);

use Larva\Aliyun\LiveHelper;
use Larva\Aliyun\Jobs\Live\StreamsNotifySetJob;
use Larva\Aliyun\Jobs\Live\StreamNotifyDeleteJob;

// 设置直播推流回调(同步)
LiveHelper::setLiveStreamsNotifyUrlConfig('push.example.com', 'https://example.com/callback');

// 删除流回调配置(同步)
LiveHelper::deleteLiveStreamsNotifyUrlConfig('push.example.com');

// 禁止推流(同步)
LiveHelper::forbidLiveStream('app', 'push.example.com', 'streamName');

// 恢复推流(同步)
LiveHelper::resumeLiveStream('app', 'push.example.com', 'streamName');

// 设置直播推流回调(异步队列)
StreamsNotifySetJob::dispatch('push.example.com', 'https://example.com/callback');

// 删除流回调配置(异步队列)
StreamNotifyDeleteJob::dispatch('push.example.com');

use Larva\Aliyun\AliyunHelper;

// 宽带提速预检查
AliyunHelper::SnsuBandPreCheck('192.168.1.1', 80);
bash
php artisan vendor:publish --tag="aliyun-config"