PHP code example of achais / shorturl

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

    

achais / shorturl example snippets


use Achais\ShortUrl\ShortUrl;

$config = [
    // HTTP 请求的超时时间(秒)
    'timeout' => 5.0,

    // 默认使用配置
    'default' => [
        // 网关调用策略,默认:顺序调用
        'strategy' => \Achais\ShortUrl\Strategies\OrderStrategy::class,

        // 默认可用的发送网关
        'gateways' => [
            'baidu',
        ],
    ],

    // 可用的网关配置
    'gateways' => [
        'baidu' => [
            'token' => '44712d2fdaaa48d0a717866e9a******',
        ],
        'weibo' => [
            'source' => '1771******',
        ],
        //...
    ],
];

$shortUrl = new ShortUrl($config);

// 长链接 -> 短链接
$long_url = 'https://www.achais.com';
$result = $shortUrl->shorten($long_url);
print_r($result);

// 短链接 -> 长链接
$short_url = 'https://dwz.cn/ZzVmHQZa';
$result = $shortUrl->expand($short_url);
var_dump($result);

'baidu' => [
    'token' => ''
],

'weibo' => [
    'source' => ''
],