创建短链

接口说明

将原始链接快速转为短链接。

接口地址

https://c1n.cn/link/short

请求方式

POST

请求头:Headers

请求参数:Form 表单

响应数据:JSON格式

{
    code: 0,
    data: "https://c1n.cn/xxxxx",
    msg: "成功"
}
//说明:code为0表示成功,其他情况表示生成失败。

SDK DEMO

           
<?php
function short_url($long_url)
{
    $headers = [
        'Content-Type: application/x-www-form-urlencoded',
        'token: your_token'  // 替换为您的token
    ];
    $data = [
        'url' => $long_url,
        'key' => '',
        'remark' => '',
        'expiryDate' => '',
        'domainName' => ''
    ];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://c1n.cn/link/short');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
    $response_data = json_decode($response, true);
    if ($response_data['code'] == 0) {
        return $response_data['data'];
    }
    echo $response_data['msg'];
}
// 请确保您的PHP环境中已经安装了cURL库
$res = short_url('https://example.com');  // 替换为您要生成短链接的原始网址
echo $res; 
?>