├── README.md ├── composer.json └── src └── DljBiz.php /README.md: -------------------------------------------------------------------------------- 1 | > 由于短链服务经常被滥用,没有能力监管,已暂时关闭,敬请谅解! 2 | 3 | 4 | # dlj.biz-php 5 | [dlj.biz](https://dlj.biz) 短链接 API 扩展包 6 | 7 | 8 | ## 安装 9 | 10 | > composer require lunzi/dlj 11 | 12 | ## 使用 13 | 14 | ### 短链接生成 15 | 16 | ~~~ 17 | use lunzi\DljBiz; 18 | 19 | DljBiz::create("长链接"); 20 | 21 | // 示例 22 | DljBiz::create("https://newphper.com/tool/layuitheme.html"); 23 | 24 | ~~~ 25 | 26 | ### 短链接还原 27 | 28 | ~~~ 29 | use lunzi\DljBiz; 30 | 31 | DljBiz::create("长链接"); 32 | 33 | // 示例 34 | DljBiz::query("https://dlj.biz/2Bw"); 35 | 36 | ~~~ 37 | 38 | ## 返回示例(数组) 39 | 40 | ~~~ 41 | 42 | array(4) { 43 | 'Code' => int(0) 44 | 'ShortUrl' => string(19) "https://dlj.biz/2Bw" 45 | 'LongUrl' => string(41) "https://newphper.com/tool/layuitheme.html" 46 | 'ErrMsg' => string(0) "" 47 | } 48 | 49 | ~~~ 50 | 51 | 详细文档见(https://dlj.biz/doc) 52 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lunzi/dlj", 3 | "description": "api package for dlj.biz", 4 | "authors": [ 5 | { 6 | "name": "lunzi", 7 | "email": "service@newphper.com" 8 | } 9 | ], 10 | "license": "Apache-2.0", 11 | "autoload": { 12 | "psr-4": { 13 | "lunzi\\": "src" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/DljBiz.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace lunzi; 13 | 14 | 15 | class DljBiz 16 | { 17 | const HOST = 'https://dlj.biz'; 18 | 19 | /** 20 | * 网址缩短接口 21 | * @param $long_url 22 | * @return bool|string 23 | */ 24 | public static function create($long_url) 25 | { 26 | $path = '/api/create'; 27 | 28 | $bodys = array('url'=>$long_url); 29 | 30 | return self::req($path,$bodys); 31 | } 32 | 33 | /** 34 | * 网址还原接口 35 | * @param $short_url 36 | * @return bool|string 37 | */ 38 | public static function query($short_url) 39 | { 40 | $path = '/api/query'; 41 | 42 | // 短网址 43 | $bodys = array('shortUrl'=>$short_url); 44 | 45 | return self::req($path,$bodys); 46 | } 47 | 48 | /** 49 | * 请求函数 50 | * @param $path 51 | * @param $bodys 52 | * @return bool|string 53 | */ 54 | protected static function req($path,$bodys) 55 | { 56 | $content_type = 'application/json'; 57 | // 创建连接 58 | $curl = curl_init(self::HOST . $path); 59 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); 60 | curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:'.$content_type)); 61 | curl_setopt($curl, CURLOPT_FAILONERROR, false); 62 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 63 | curl_setopt($curl, CURLOPT_HEADER, false); 64 | curl_setopt($curl, CURLOPT_POST, true); 65 | curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($bodys)); 66 | 67 | // 发送请求 68 | $response = curl_exec($curl); 69 | curl_close($curl); 70 | 71 | return json_decode($response,1); 72 | } 73 | 74 | } --------------------------------------------------------------------------------