生成短网址时:
请求:向http://96114.co/index.php?m=Index&a=newurl 发送post请求,发送数据包括url=长网址
返回:json格式的数据
1.status!=0 出错,查看err_msg获得错误信息(UTF-8编码)
2.成功,返回生成的短网址 tinyurl字段
生成短网址示例程序:
<?php
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"http://96114.co/index.php?m=Index&a=newurl"); /*create*/
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$data=array('url'=>'https://tuwen.18660.cn/z/?id=59', 'user_id'=>1025, 'api_key'=>'smncbd7b31a68d23f0d5579d7e4525c86a130' ); /*用户ID和API秘钥需要登录后查看*/
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$strRes=curl_exec($ch);
curl_close($ch);
$arrResponse=json_decode($strRes,true);
if($arrResponse['status']!=0)
{
/**错误处理*/
echo iconv('UTF-8','GBK',$arrResponse['err_msg'])." n ";
}else
{ /** tinyurl */
echo $arrResponse['tinyurl']." n ";
}
?>
显示原网址:
请求:向http://96114.co/index.php?m=Index&a=goback 发送post请求,发送数据包括url=查询的短地址
返回:json格式的数据
1.status!=0 出错,查看err_msg获得错误信息(UTF-8编码)
2.成功,返回原网址 longurl字段
短网址查询原来的长网址示例程序:
<?php
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"http://96114.co/index.php?m=Index&a=query"); /*类reurl*/
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$data=array('url'=>'http://96114.co/zhl');
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$strRes=curl_exec($ch);
curl_close($ch);
$arrResponse=json_decode($strRes,true);
if($arrResponse['status']!=0)
{
/**错误处理*/
echo iconv('UTF-8','GBK',$arrResponse['err_msg'])." n ";
}else
{ /** longurl */
echo $arrResponse['longurl']." n ";
}
?>
© 2023兰山区浩瀚日用商行 https://96114.co 自家用短网址 QQ群1137412295