php
              
              
            
          
          <?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' => ''
    ];
    $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;
?>
        上述代码中使用到的token需要前往C1N短网址(c1n.cn)-控制台-我的信息进行查询。
C1N短网址(c1n.cn)还提供了丰富的短链接管理的API接口,只需进行简单的接口调用,就能将稳定好用的短链接系统接入到自己的产品中,极大地降低了开发成本。
