PHP程序制作网站短链接API接口,通过多方尝试,终于调试成功,给大家展示下:
header("Access-Control-Allow-Origin:*");
date_default_timezone_set("PRC");
$url = $_GET['url'];
$result = file_get_contents("http://www.mynb8.com/api2/sina?appkey=7054d19939c421f573f04448cd6fc392&long_url=".$url);
$arr = json_decode($result,true);
if ($arr['rs_code']==0) {
header("Content-Type:application/json;charset=UTF-8");
//输出新浪短网址时,改成 $arr['shortUrl']
echo $arr['short_url'];
} else {
header("Content-Type:text/html;charset=UTF-8");
echo $arr['msg'];
}