PHP code example of huacaizhi / short-url

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

    

huacaizhi / short-url example snippets


use HuaCaiZhi\ShortUrlPackage\Driver\BaiDuDriver;
use HuaCaiZhi\ShortUrlPackage\Service\ShortUrlService;

//PHP_VERSION >=5.5
$shortUrl = new ShortUrlService();
$result = $shortUrl->service(BaiDuDriver::class)
    ->boot(array(
        'token' => 'xxxx',
        'long_url' => 'http://www.baidu.com',
    ));
var_dump($result);


//PHP_VERSION >=5.4
$shortUrl = new ShortUrlService();
$result = $shortUrl->service((new BaiDuDriver()))
    ->boot(array(
        'token' => 'xxxx',
        'long_url' => 'http://www.baidu.com',
    ));
var_dump($result);

use HuaCaiZhi\ShortUrlPackage\Driver\BaiDuDriver;
use HuaCaiZhi\ShortUrlPackage\Service\ShortUrlService;

//百度短链接目前支持两种:1年有效(1-year)和长期有效:默认(long-term)
$shortUrl = new ShortUrlService();
$result = $shortUrl->service(BaiDuDriver::class)
    ->boot(array(
        'token' => 'xxxx',
        'long_url' => 'http://www.baidu.com',
        'expire' => '1-year',
    ));
var_dump($result);

use HuaCaiZhi\ShortUrlPackage\Driver\BaiDuDriver;
use HuaCaiZhi\ShortUrlPackage\Service\ShortUrlService;

$shortUrl = new ShortUrlService();
$result = $shortUrl->service(BaiDuDriver::class)
    ->boot(array(
        'token' => 'xxxx',
        'short_url' => 'https://dwz.cn/VQDLmcaR'
    ),BaiDuDriver::TO_QUERY);
var_dump($result);