小程序短链接
链接无缝跳转小程序

将原始链接快速转为短链接。
https://c1n.cn/link/shortPOST
{
code: 0,
data: "https://c1n.cn/xxxxx",
msg: "成功"
}
//说明:code为0表示成功,其他情况表示生成失败。
<?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;
?>