码迷,mamicode.com
首页 > 其他好文 > 详细

淘宝客短网址还原长链接

时间:2016-06-11 15:40:23      阅读:1126      评论:0      收藏:0      [点我收藏+]

标签:

直接上源码,一言不合就上源码

 

<?php
//
淘宝客短网址还原链接 //unescape 转码 function unescape($str) { $ret = ‘‘; $len = strlen($str); for ($i = 0; $i < $len; $i ++) { if ($str[$i] == ‘%‘ && $str[$i + 1] == ‘u‘) { $val = hexdec(substr($str, $i + 2, 4)); if ($val < 0x7f) $ret .= chr($val); else if ($val < 0x800) $ret .= chr(0xc0 | ($val >> 6)) . chr(0x80 | ($val & 0x3f)); else $ret .= chr(0xe0 | ($val >> 12)) . chr(0x80 | (($val >> 6) & 0x3f)) . chr(0x80 | ($val & 0x3f)); $i += 5; } else if ($str[$i] == ‘%‘) { $ret .= urldecode(substr($str, $i, 3)); $i += 2; } else $ret .= $str[$i]; } return $ret; } //使用curl模拟请求返回得到真实url function geturl($clickurl){ $headers = get_headers($clickurl, TRUE); $tu = $headers[‘Location‘]; $eturl = unescape($tu[1]); //获取完整连接 $u = parse_url($eturl); //得到et的连接 $param = $u[‘query‘]; $ref = str_replace(‘tu=‘, ‘‘, $param); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $ref); curl_setopt($ch, CURLOPT_REFERER, $tu[1]); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_NOBODY,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true); curl_setopt($ch, CURLOPT_MAXREDIRS,2); $out = curl_exec($ch); $dd = curl_getinfo($ch); curl_close($ch); $item_url = $dd[‘url‘]; return $item_url; } $res = geturl("http://s.click.taobao.com/xxx"); //这里输入淘宝客短连接 print_r($res);
?>

淘宝客短网址还原长链接

标签:

原文地址:http://www.cnblogs.com/liscookie/p/5575310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!