09月22日, 2014 4327次
这篇是转载的
包含SDK的版本需要申请API
header("Content-type: text/html; charset=utf-8"); include "TopSdk.php"; //正式环境时需要将该地址设置为:http://gw.api.taobao.com/router/rest //实例化TopClient类 $c = new TopClient; $c->a**ey = "a**ey";//自己改 $c->secretKey = "cccccc"; //自己改 //实例化具体API对应的Request类 $req = new TaobaokeItemsConvertRequest; $req->setFields("click_url,num_iid"); $req->setNumIids("ddd"); //商品ID,自己匹配 $req->setPid(1111); //自己淘客的PID,只有数字,没有mm_ 0 0 这些 //执行API请求并打印结果 $resp = $c->execute($req); echo "result:"; print_r($resp); echo "<br>"; echo "nick:".$req->getNick();
无sdk版本
$a**ey = '1111'; $appSecret = '22222'; //参数数组 $paramArr = array( 'app_key' => $a**ey, 'method' => 'taobao.taobaoke.items.convert', 'format' => 'json', 'v' => '2.0', 'sign_method'=>'md5', 'times**p' => date('Y-m-d H:i:s'), 'fields' => 'click_url,num_iid', 'num_iids' => '1111111111', 'pid' => '2222222222222222222222' ); //生成签名 $sign = createSign($paramArr); //组织参数 $strParam = createStrParam($paramArr); $strParam .= 'sign='.$sign; //访问服务 $url = 'http://gw.api.taobao.com/router/rest?'.$strParam; $result = file_get_contents($url); $result = json_decode($result); echo "json的结构为:"; print_r($result); //签名函数 function createSign ($paramArr) { global $appSecret; $sign = $appSecret; ksort($paramArr); foreach ($paramArr as $key => $val) { if ($key !='' && $val !='') { $sign .= $key.$val; } } $sign.=$appSecret; $sign = strtoupper(md5($sign)); return $sign; } //组参函数 function createStrParam ($paramArr) { $strParam = ''; foreach ($paramArr as $key => $val) { if ($key !='' && $val !='') { $strParam .= $key.'='.urlencode($val).'&'; } } return $strParam; }
目前还可用吗?
可用