怎样调用短网址API?

2023-08-13 08:11

生成短网址时:

请求:向http://8of.cc/index.php?m=Index&a=create发送post请求,发送数据包括url=长网址

返回:json格式的数据

1.status!=0 出错,查看err_msg获得错误信息(UTF-8编码)

2.成功,返回生成的短网址 tinyurl字段

显示原网址:

请求:向http://8of.cc/index.php?m=Index&a=query发送post请求,发送数据包括tinyurl=查询的短地址

返回:json格式的数据

1.status!=0 出错,查看err_msg获得错误信息(UTF-8编码)

2.成功,返回原网址 longurl字段

 

示例程序:

 

生成短网址

 

<?php

$ch=curl_init();

curl_setopt($ch,CURLOPT_URL,"http://8of.cc/index.php?m=Index&a=create");

curl_setopt($ch,CURLOPT_POST,true);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

$data=array('url'=>'http://www.pengyong.info');

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";

}

/** tinyurl */

echo$arrResponse['tinyurl']."n";

?>


其他接口使用如上


相关阅读