长转短链接再生成二维码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/enjoy_sun_moon/article/details/80900839
/**
 * [bdUrlAPI 调用百度api]
 * @param  [int]    $type [1长转短 0:短转长]
 * @param  [string] $url  [需要转化的url]
 */
function bdUrlAPI($type, $url){
    if($type){
        $baseurl = 'http://dwz.cn/create.php';
    }
    else{
        $baseurl = 'http://dwz.cn/query.php';
    }
    if($type){
        $data=array('url'=>$url);
    }else{
        $data=array('tinyurl'=>$url);
    }
    
    $strRes=https_post($baseurl,$data);

    $arrResponse=json_decode($strRes,true);

    return $arrResponse;
}

    if($arrResponse['status']!=0)
    {
    echo 'ErrorCode: ['.$arrResponse['status'].'] ErrorMsg: ['.iconv('UTF-8','GBK',$arrResponse['err_msg'])."]<br/>";
    return 0;
    }
    if($type)
         return $arrResponse['tinyurl'];
    else
         return $arrResponse['longurl'];
再生成二维码链接  API接口  腾讯接口
 // $url = "http://qr.liantu.com/api.php?&w=200&text=";
    // http://tool.kd128.com/tool/qrcode.html
    $preurl = "http://mobile.qq.com/qrcode?url=";
新浪接口

$key = '1562966081';

$key = '3271760578';

新浪短网址接口的稳定性和跳转速度还是很给力的,现给出其API说明:http://open.weibo.com/wiki/Short_url/shorten

该接口支持两种返回格式:xml和json
对应的URL请求地址为:
xml: http://api.t.sina.com.cn/short_url/shorten.xml?source=*********&url_long=*********************
json: http://api.t.sina.com.cn/short_url/shorten.json?source=********&url_long=********************
请求方式:GET
请求参数:
  source:应用的appkey
  url_long:需要转换的长链接
举个例子:
xml: http://api.t.sina.com.cn/short_url/shorten.xml?source=3271760578&url_long=http://www.douban.com/note/249723561/
返回内容为:
<urls>
     <url>
          <url_short> http://t.cn/zWXySpZ</url_short>
          <url_long> http://www.douban.com/note/249723561/</url_long>
          <type>0</type>
     </url>
</urls>
json: http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=http://www.douban.com/note/249723561/
返回内容为:
[{"url_short":" http://t.cn/zWXySpZ","url_long": http://www.douban.com/note/249723561/","type":0}]

猜你喜欢

转载自blog.csdn.net/enjoy_sun_moon/article/details/80900839
今日推荐