Skip to content

Instantly share code, notes, and snippets.

@pzzrudlf
Created November 9, 2016 09:21
Show Gist options
  • Save pzzrudlf/ae9098ae3e9ed48f689e9cd046aa9c7e to your computer and use it in GitHub Desktop.
Save pzzrudlf/ae9098ae3e9ed48f689e9cd046aa9c7e to your computer and use it in GitHub Desktop.
<?php
/**
*将参与淘客计划的商品id转换为淘客链接
*
*$param version 0.1
*
*$author pzzrulf <[email protected]>
*
*/
function get_word($html,$star,$end){
$wd = null;
$pat = '/'.$star.'(.*?)'.$end.'/s';
if(!preg_match_all($pat, $html, $mat)) {
}else{
$wd= $mat[1][0];
}
return $wd;
}
function convertTbkUrl($num_id, $pid, $cookie)
{
$zym_19 = $cookie;
$zym_20 = array(' ',' ','' . "\xa" . '','' . "\xd" . '','' . "\x9" . '');
$zym_24 = array("","","","","");
$zym_19 = str_replace($zym_20, $zym_24, $zym_19);
$zym_23 = get_word($zym_19,'_tb_token_=',';');
$zym_22 = get_word($zym_19,'t=',';');
$zym_21 = get_word($zym_19,'cna=',';');
$zym_13 = get_word($zym_19,'l=',';');
$zym_12 = get_word($zym_19,'mm-guidance3',';');
$zym_5 = get_word($zym_19,'_umdata=',';');
$zym_4 = get_word($zym_19,'cookie2=',';');
$zym_3 = get_word($zym_19,'cookie32=',';');
$zym_1 = get_word($zym_19,'cookie31=',';');
$zym_2 = get_word($zym_19,'alimamapwag=',';');
$zym_6 = get_word($zym_19,'login=',';');
$zym_7 = get_word($zym_19,'alimamapw=',';');
$zym_11 = 't='.$zym_22.';cna='.$zym_21.';l='.$zym_13.';mm-guidance3='.$zym_12.';_umdata='.$zym_5.';cookie2='.$zym_4.';_tb_token_='.$zym_23.';v=0;cookie32='.$zym_3.';cookie31='.$zym_1.';alimamapwag='.$zym_2.';login='.$zym_6.';alimamapw='.$zym_7;
$zym_10 =microtime(true)*1000;
$zym_10 = explode('.', $zym_10);
$zym_29 = $pid;
$zym_27 = explode('_',$zym_29);
$zym_28 = $zym_27[2];
$zym_32 = $zym_27[3];
// $zym_31 = get_client_ip();
$zym_31 = "127.0.0.1";
$zym_30 = '50_'.$zym_31.'_15881_1468693605455';
$zym_33 = 'http://pub.alimama.com/common/code/getAuctionCode.json?auctionid='.$num_id.'&adzoneid='.$zym_32.'&siteid='.$zym_28.'&t='.$zym_10[0].'&pvid='.$zym_30.'&_tb_token_='.$zym_23.'&_input_charset=utf-8';
// print_r($zym_33);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $zym_33);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.alimama.com/index.htm');
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Cookie:{'.$zym_11.'}', ));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$rs = curl_exec($ch);
curl_close($ch);
return json_decode($rs,true);
}
/**
*这是加入淘客计划的商品id
*/
$num_id = isset($_GET['id'])?($_GET['id']):'537154174717';
$url = "http://item.taobao.com/item.htm?id=".$num_id;
/**
*这是你的pid
*/
$pid = "mm_xxxxx_xxxxx_xxxxx";
/**
*这是你的阿里妈妈的cookie
*/
$cookie = "";
$data = (convertTbkUrl($num_id, $pid, $cookie));
if ($data) {
$url = $data['data']['shortLinkUrl'];
header("Location: $url");exit(0);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<div style=" margin:0 auto; text-align:center; padding:50px 0">
<div id="show"></div>
</div>
<script language="javascript">
function get_et()
{
var s = new Date(),
l = +s / 1000 | 0,
r = s.getTimezoneOffset() * 60,
p = l + r,
m = p + (3600 * 8),
q = m.toString().substr(2, 8).split(""),
o = [6, 3, 7, 1, 5, 2, 0, 4],
n = [];
for (var k = 0; k < o.length; k++) {
n.push(q[o[k]])
}
n[2] = 9 - n[2];
n[4] = 9 - n[4];
n[5] = 9 - n[5];
return n.join("")
}
function setCookie(j, k)
{
document.cookie = j + "=" + encodeURIComponent(k.toString()) + "; path=/"
}
function getCookie(l)
{
var m = (" " + document.cookie).split(";"),
j = "";
for (var k = 0; k < m.length; k++) {
if (m[k].indexOf(" " + l + "=") === 0) {
j = decodeURIComponent(m[k].split("=")[1].toString());
break
}
}
return j
}
function get_pgid()
{
var l = "",
k = "",
n,
o,
t,
u,
s = location,
m = "",
q = Math;
function r(x, z) {
var y = "",
v = 1,
w;
v = Math.floor(x.length / z);
if (v == 1) {
y = x.substr(0, z)
} else {
for (w = 0; w < z; w++) {
y += x.substr(w * v, 1)
}
}
return y
}
n = (" " + document.cookie).split(";");
for (o = 0; o < n.length; o++) {
if (n[o].indexOf(" cna=") === 0) {
k = n[o].substr(5, 24);
break
}
}
if (k === "") {
cu = (s.search.length > 9) ? s.search: ((s.pathname.length > 9) ? s.pathname: s.href).substr(1);
n = document.cookie.split(";");
for (o = 0; o < n.length; o++) {
if (n[o].split("=").length > 1) {
m += n[o].split("=")[1]
}
}
if (m.length < 16) {
m += "abcdef0123456789"
}
k = r(cu, 8) + r(m, 16)
}
for (o = 1; o <= 32; o++) {
t = q.floor(q.random() * 16);
if (k && o <= k.length) {
u = k.charCodeAt(o - 1);
t = (t + u) % 16
}
l += t.toString(16)
}
setCookie('amvid', l);
var p = getCookie('amvid');
if (p) {
return p
}
return l
}
var click_url = "http://item.taobao.com/item.htm?id=<?=$num_id;?>";
var itemid = "itemid=<?=$num_id;?>";
/**
*这是你的pid
*/
var pid = 'mm_xxxxx_xxxxx_xxxxx';
var wt = '0';
var ti = '625';
var tl = '230x45';
var rd = '1';
var ct = encodeURIComponent(itemid);
var st = '2';
/**
*这是你的网站域名
*/
var rf = encodeURIComponent("http://coubei.me");
var et = get_et();
console.log(et);
var pgid = get_pgid();
// console.log(pgid);
var v = '2.0';
$(function(){
var dd = 'pid='+pid+'&wt='+wt+'&ti='+ti+'&tl='+tl+'&rd='+rd+'&ct='+ct+'&st='+st+'&rf='+rf+'&et='+et+'&pgid='+pgid+'&v='+v;
console.log(dd);
$.ajax({
url: 'http://g.click.taobao.com/display?cb=?',
type: 'GET',
dataType: 'jsonp',
jsonp: 'cb',
data: dd,
success: function(msg) {
if(msg.code == 200)
{
console.log(msg.data.items[0].ds_item_click);
// alert(msg.data.items[0].ds_item_click);debugger;
document.location.href = msg.data.items[0].ds_item_click;
}
else
{
debugger;document.location.href = click_url;
}
},
error: function(msg){
debugger;document.location.href = click_url;
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment