PHPackages                             huacaizhi/short-url - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. huacaizhi/short-url

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

huacaizhi/short-url
===================

Generate Short Url

v0.3.0(6y ago)113MITPHPPHP &gt;=5.4CI failing

Since Dec 19Pushed 6y agoCompare

[ Source](https://github.com/huacaizhi/short-url)[ Packagist](https://packagist.org/packages/huacaizhi/short-url)[ RSS](/packages/huacaizhi-short-url/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (4)Used By (0)

ShortUrl
========

[](#shorturl)

**ShortUrl** 是一个尽可能聚合市面上提供短链接服务应用的 `PHP` 包。

安装
--

[](#安装)

1. 环境要求:

    - php &gt;= 5.5
    - cURL extension
2. 如果您通过 `composer` 管理您的项目依赖，可以在您的项目根目录运行：

    ```
     $ composer require huacaizhi/short-url

    ```

    或者在您的 `composer.json` 中声明对 `huacaizhi/short-url` for PHP的依赖：

    ```
     "require": {
         "huacaizhi/short-url": "0.2.0"
     }

    ```

    然后通过 `composer install` 安装依赖。`composer` 安装完成后，在您的 `PHP` 代码中引入依赖即可：

    ```
     require_once __DIR__ . '/vendor/autoload.php';

    ```
3. 下载`SDK`源码，在您的代码中引入SDK目录下的 `autoload.php` 文件：

    ```
     require_once '/path/to/shorturl/autoload.php';

    ```

用法
--

[](#用法)

1.创建短链接

```
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);
```

2.创建短链接并设置有效期

```
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);
```

3.还原短链接

```
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);
```

常用的短网址服务商
---------

[](#常用的短网址服务商)

>  (百度短网址) - 已支持

> > 百度短链接:

> > `token` 获取地址:

>  - 已支持

> > 麦云短链接:

>

>

>

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

3

Last Release

2331d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.5

v0.2.0PHP &gt;=5.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7012529?v=4)[huacaizhi](/maintainers/huacaizhi)[@huacaizhi](https://github.com/huacaizhi)

---

Tags

short url

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/huacaizhi-short-url/health.svg)

```
[![Health](https://phpackages.com/badges/huacaizhi-short-url/health.svg)](https://phpackages.com/packages/huacaizhi-short-url)
```

###  Alternatives

[yourls/yourls

Your Own URL Shortener

11.9k27.7k1](/packages/yourls-yourls)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
