淘宝客短网址还原长链接
Posted liscookie
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了淘宝客短网址还原长链接相关的知识,希望对你有一定的参考价值。
直接上源码,一言不合就上源码
<?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);
?>
以上是关于淘宝客短网址还原长链接的主要内容,如果未能解决你的问题,请参考以下文章