近期整理的php调用折淘客API

整合了淘口令解析转链、itemId解析转链、淘宝短链接

对于淘宝联盟官方API无权限调用的朋友可能会有帮助哦。

代码如下:

<?php
header("Content-Type: text/json;");
class zhetaoke
{
const sid = 27214; // 改成你的陶宝sid
const appkey = 'zhetaoke.com 里面申请的 appkey';
const pid = '改成你的pid';
const host = 'https://api.zhetaoke.com:10001/';
public function parse_tkl($tkl, $signurl=4)
{
    $sid = self::sid;
    $appkey = self::appkey;
    $pid = self::pid;
    $host = self::host;
    $tkl = urlencode($tkl);
    $url = "{$host}api/open_gaoyongzhuanlian_tkl.ashx?appkey={$appkey}&sid={$sid}&pid={$pid}&tkl={$tkl}=&signurl={$signurl}";
    return $this->get_url_info($url);
}
public function parse_itemId($id, $signurl=4)
{
    $sid = self::sid;
    $appkey = self::appkey;
    $pid = self::pid;
    $host = self::host;
    $url = "{$host}api/open_gaoyongzhuanlian.ashx?appkey={$appkey}&sid={$sid}&pid={$pid}&num_iid={$id}&signurl={$signurl}";
    return $this->get_url_info($url);
}
public function short_url($longurl)
{
    $sid = self::sid;
    $appkey = self::appkey;
    $host = self::host;
    $content = urlencode($longurl);
    $url = "{$host}api/open_shorturl_taobao_get.ashx?appkey={$appkey}&sid={$sid}&content={$content}";
    return json_decode($this->curl_get($url));
}
private function get_url_info($url)
{
    $getUrl = $this->curl_get($url);
    $getInfo = json_decode($getUrl)->tbk_privilege_get_response->result->data;
    // return $getInfo;
    switch ($getInfo->coupon_type)
    {//1 公开券,2 私有券,3 妈妈券
        case 1:
            $coupon_type = '公开券';
            break;
        case 2:
            $coupon_type = '私有券';
            break;
        case 3:
            $coupon_type = '妈妈券';
            break;
        default:
            $coupon_type = '暂无优惠券';
            break;
    }
    if($getInfo->zk_final_price >= $getInfo->coupon_startfee && !empty($getInfo->coupon_type))
    {
        $actualPrice = $getInfo->zk_final_price - $getInfo->coupon_amount;
    }else{
        $actualPrice = $getInfo->zk_final_price;
    }
    $returnCash = number_format($actualPrice * ($getInfo->max_commission_rate / 100), 2, '.', ',');
    $getInfo = (object) array(
        'item_id' => $getInfo->item_id,
        'title' => $getInfo->title,
        'item_url' => $getInfo->item_url,
        'coupon_click_url' => $getInfo->coupon_click_url,
        'coupon_start_time' => $getInfo->coupon_start_time,
        'coupon_end_time' => $getInfo->coupon_end_time,
        'coupon_info' => $getInfo->coupon_info,
        'coupon_startfee' => $getInfo->coupon_startfee,
        'coupon_amount' => $getInfo->coupon_amount,
        'coupon_total_count' => $getInfo->coupon_total_count,
        'coupon_remain_count' => $getInfo->coupon_remain_count,
        'coupon_type' => $coupon_type,
        'max_commission_rate' => $getInfo->max_commission_rate,
        'pict_url' => $getInfo->pict_url,
        'small_images' => $getInfo->small_images,
        'volume' => $getInfo->volume,
        'zk_final_price' => $getInfo->zk_final_price,
        'actual_price' => $actualPrice,
        'return_cash' => $returnCash,
        'tkl' => $getInfo->tkl
        );
    return $getInfo;
}
private function curl_get($url, $post='')
{
    $ch = curl_init();
    $options = array(
        CURLOPT_URL => $url,
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTPHEADER => array(
            'Referer: '.$url,
            'User-Agent: '.$_SERVER['HTTP_USER_AGENT']
        ),
        CURLOPT_ENCODING => "gzip",
        CURLOPT_FOLLOWLOCATION => 0,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_RETURNTRANSFER => 1
    );
    curl_setopt_array($ch, $options);
    if($post == true) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}
}
$tb = new zhetaoke;

print_r($tb->parse_tkl('付致这行话₤J1vh1RnfrDB₤转移至τаo宝аρρ【2020新款男夏季ins简约短袖t恤潮牌宽松百搭潮流原宿风丅五分袖男】;或https://m.tb.cn/h.V59YCis?sm=e970ca 点几链街,再选择瀏lan嘂..dakai')); // 淘口令方法 转链

print_r($tb->parse_itemId(596085599238)); // itemId方法 转链

print_r($tb->short_url('https://uland.taobao.com/coupon/edetail?e=J2t0TZ0irKgGQASttHIRqZvzbkJZTWYwAdzdZUKt9IxPCFlCNXc9C4I4Kh29whdPLIWKdvDf2uErsg7RWzKxHbtLudRyr0RwSEyvAL3v9LJ0qM9k%2FRdcGrCSyLFw4qsuJ47rYvIjaE20%2Bc5Gzwi6gW5us6IkMHWUSn4qX%2BrddxhK0SfgjMBZ%2BNl4X1VWjKahZ9F0GokUeXA8X7gTGyneaw%3D%3D&traceId=0b0baf5915853781295051670e&union_lens=lensId:0b0175f0_0d90_1711fe67680_78b3&xId=5dnVNeTnjIwEGp2i63KasVhOOA7QssnGpBycqXIOnv0zV3FQXtbfuqXoFjkE8kvoXvCbrEBXC3HlruMwtK3HLK')); // 调用,生成淘宝短链接
?>

请输入图片描述

API信息获取地址:

sid和appkey获取地址:http://www.zhetaoke.com/user/open/open_appkey.aspx

pid获取地址:https://pub.alimama.com/myunion.htm

文章目录