`
zzc1684
  • 浏览: 1229175 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

创建淘宝开放平台应用的步骤简单记录

阅读更多

记录一下淘宝开放平台应用开发的步骤。
1,注册成为开发者,创建一个应用,
参照下面的链接如何选择应用
http://open.taobao.com/doc/detail.htm?id=101710
创建应用的时候有一个回调地址url,
回调地址是用来接收TOP(开放平台)返回授权相关数据的,
下面是你的应用使用TOP API的流程:在没有上线之前测试都在所谓的沙箱模式下进行的。
1,以web应用为例,用户访问你的web,你的web应用redirect用户到淘宝的登录认证,比如如下
https://oauth.tbsandbox.com/authorize?response_type=code&client_id=1021738064&redirect_uri=http%3A%2F%2Fdev2dev.sinaapp.com%2Ftaobao%2Fcallback.php&from_site=fuwu
2,用户用淘宝账号登录,redirec用户到回调的url,就是你的应用的一个url
3,一个授权码code会作为参数传给回调的url,你的应用用这个授权码code以post的方式访问淘宝的
https://oauth.tbsandbox.com/token获取token
4,得到token后就可以调用淘宝的API了。
参照下面的链接获取更多关于认证的信息
http://open.taobao.com/doc/detail.htm?spm=0.0.0.0.CSGRVZ&id=118
一下注意点:
1,在测试的时候使用的是沙箱环境的AppKey和AppSecret,淘宝端认证的url也是沙箱环境的tbsandbox。
2,用的登录账户也必须是沙箱环境的,http://www.tbsandbox.com/doc/index.html#taobao_acount
3,淘宝提供的调用示例http://open.taobao.com/doc/detail.htm?spm=0.0.0.0.mtTHeu& id=131  'session_key' => $sessionkey,应该改为'session' => $sessionkey,
下面是回调页面的代码:

 

<?php
function curl($url, $postFields = null)
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_FAILONERROR, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

		if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		}

		if (is_array($postFields) && 0 < count($postFields))
		{
			$postBodyString = "";
			$postMultipart = false;
			foreach ($postFields as $k => $v)
			{
				if("@" != substr($v, 0, 1))//判断是不是文件上传
				{
					$postBodyString .= "$k=" . urlencode($v) . "&"; 
				}
				else//文件上传用multipart/form-data,否则用www-form-urlencoded
				{
					$postMultipart = true;
				}
			}
			unset($k, $v);
			curl_setopt($ch, CURLOPT_POST, true);
			if ($postMultipart)
			{
				curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
			}
			else
			{
				curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
			}
		}
		$reponse = curl_exec($ch);
		
		if (curl_errno($ch))
		{
			throw new Exception(curl_error($ch),0);
		}
		else
		{
			$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
			if (200 !== $httpStatusCode)
			{
				throw new Exception($reponse,$httpStatusCode);
			}
		}
		curl_close($ch);
		return $reponse;
	}
		
header("Content-Type:text/html;charset=UTF-8");
require_once 'util.php';
$appKey = '沙箱环境的appkey';
$appSecret = '沙箱环境的appSecret ';
//$sessionkey= 'test';
$code = $_GET["code"];
<div class="dp-highlighter bg_php"><div class="bar"><div class="tools"><b>[php]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" class="CopyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy</a><a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a><a href="https://code.csdn.net/snippets/195967" target="_blank" title="在CODE上查看代码片" style="text-indent:0;"><img src="https://code.csdn.net/assets/CODE_ico.png" alt="在CODE上查看代码片" style="position:relative;top:1px;left:2px;" height="12" width="12"></a><a href="https://code.csdn.net/snippets/195967/fork" target="_blank" title="派生到我的代码片" style="text-indent:0;"><img src="https://code.csdn.net/assets/ico_fork.svg" alt="派生到我的代码片" style="position:relative;top:2px;left:2px;" height="12" width="12"></a><div style="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 99;"><embed id="ZeroClipboardMovie_2" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" name="ZeroClipboardMovie_2" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&width=0&height=0" wmode="transparent" align="middle" height="0" width="0"></div></div></div><ol class="dp-c" start="1"><li class="alt"><span><span class="comment">//$code&nbsp;=&nbsp;$_GET["top_session"];//prod&nbsp;enc</span><span>&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;" code_snippet_id="195967" snippet_file_name="blog_20140220_1_5824846" name="code" class="php">//$code = $_GET["top_session"];//prod enc</pre>$paramArr = array( 'code' => $code, 'grant_type' => "authorization_code", 'client_id' => $appKey, 'client_secret' => $appSecret, 'redirect_uri' => "http://dev2dev.sinaapp.com/taobao/test.php");//参数数组$url = 'https://oauth.tbsandbox.com/token';<br>
//$url = 'https://oauth.taobao.com/token'; //prod env<br>
echo curl($url,$paramArr); //显示返回信息echo "$code";?>
<pre></pre>
下面是应用调用淘宝API的代码:利用回调页面获取的session tokentest.php<div class="dp-highlighter bg_php"><div class="bar"><div class="tools"><b>[php]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" class="CopyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy</a><a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a><a href="https://code.csdn.net/snippets/195967" target="_blank" title="在CODE上查看代码片" style="text-indent:0;"><img src="https://code.csdn.net/assets/CODE_ico.png" alt="在CODE上查看代码片" style="position:relative;top:1px;left:2px;" height="12" width="12"></a><a href="https://code.csdn.net/snippets/195967/fork" target="_blank" title="派生到我的代码片" style="text-indent:0;"><img src="https://code.csdn.net/assets/ico_fork.svg" alt="派生到我的代码片" style="position:relative;top:2px;left:2px;" height="12" width="12"></a><div style="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 99;"><embed id="ZeroClipboardMovie_3" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" name="ZeroClipboardMovie_3" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&width=0&height=0" wmode="transparent" align="middle" height="0" width="0"></div></div></div><ol class="dp-c" start="1"><li class="alt"><span><span><?php&nbsp;&nbsp;</span></span></li><li class=""><span>header(<span class="string">"Content-Type:text/html;charset=UTF-8"</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="keyword">require_once</span><span>&nbsp;</span><span class="string">'util.php'</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="vars">$appKey</span><span>&nbsp;=&nbsp;</span><span class="string">'沙箱的appkey'</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="vars">$appSecret</span><span>&nbsp;=&nbsp;</span><span class="string">'沙箱的appsecret'</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="vars">$sessionkey</span><span>=&nbsp;</span><span class="string">'6202a275b902c321c324db810764ecbae6ace39da3f702f2074082787'</span><span>;</span><span class="comment">//回调页面得到code后再获取的session&nbsp;token</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="comment">//参数数组</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span><span class="vars">$paramArr</span><span>&nbsp;=&nbsp;</span><span class="keyword">array</span><span>(&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="string">'app_key'</span><span>&nbsp;=>&nbsp;</span><span class="vars">$appKey</span><span>,&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="string">'session'</span><span>&nbsp;=>&nbsp;</span><span class="vars">$sessionkey</span><span>,&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="string">'method'</span><span>&nbsp;=>&nbsp;</span><span class="string">'taobao.user.seller.get'</span><span>,&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="string">'format'</span><span>&nbsp;=>&nbsp;</span><span class="string">'json'</span><span>,&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="string">'v'</span><span>&nbsp;=>&nbsp;</span><span class="string">'2.0'</span><span>,&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="string">'sign_method'</span><span>=></span><span class="string">'md5'</span><span>,&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="string">'timestamp'</span><span>&nbsp;=>&nbsp;</span><span class="func">date</span><span>(</span><span class="string">'Y-m-d&nbsp;H:i:s'</span><span>),&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="string">'fields'</span><span>&nbsp;=>&nbsp;</span><span class="string">'user_id,nick,sex,seller_credit,type,has_more_pic,item_img_num,item_img_size,prop_img_num,prop_img_size,auto_repost,promoted_type,status,alipay_bind,consumer_protection,avatar,liangpin,sign_food_seller_promise,has_shop,is_lightning_consignment,has_sub_stock,is_golden_seller,vip_info,magazine_subscribe,vertical_market,online_gaming'</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>);&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="comment">//生成签名</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span><span class="vars">$sign</span><span>&nbsp;=&nbsp;createSign(</span><span class="vars">$paramArr</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="comment">//组织参数</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span><span class="vars">$strParam</span><span>&nbsp;=&nbsp;createStrParam(</span><span class="vars">$paramArr</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="vars">$strParam</span><span>&nbsp;.=&nbsp;</span><span class="string">'sign='</span><span>.</span><span class="vars">$sign</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="comment">//访问服务</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="vars">$url</span><span>&nbsp;=&nbsp;</span><span class="string">'http://gw.api.tbsandbox.com/router/rest?'</span><span>.</span><span class="vars">$strParam</span><span>;&nbsp;//沙箱环境调用地址&nbsp;&nbsp;</span></span></li><li class=""><span><span class="comment">//$url&nbsp;=&nbsp;'http://gw.api.taobao.com/router/rest?'.$strParam;&nbsp;//prod调用地址</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="vars">$result</span><span>&nbsp;=&nbsp;</span><span class="func">file_get_contents</span><span>(</span><span class="vars">$url</span><span>);&nbsp;&nbsp;</span></span></li><li class=""><span><span class="vars">$result</span><span>&nbsp;=&nbsp;json_decode(</span><span class="vars">$result</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="func">echo</span><span>&nbsp;</span><span class="string">"json的结构为:"</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span>print_r(<span class="vars">$result</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="func">echo</span><span>&nbsp;</span><span class="string">"<br>"</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="func">echo</span><span>&nbsp;</span><span class="string">"用户名称为:"</span><span>.</span><span class="vars">$result</span><span>->user_get_response->user->nick;&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="func">echo</span><span>&nbsp;</span><span class="string">"<br>"</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="func">echo</span><span>&nbsp;</span><span class="string">"买家信用等级为:"</span><span>.</span><span class="vars">$result</span><span>->user_get_response->user->buyer_credit->level;&nbsp;&nbsp;</span></span></li><li class="alt"><span>?>&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;" code_snippet_id="195967" snippet_file_name="blog_20140220_2_186672" name="code" class="php"><?php
header("Content-Type:text/html;charset=UTF-8");
require_once 'util.php';
$appKey = '沙箱的appkey';
$appSecret = '沙箱的appsecret';
$sessionkey= '6202a275b902c321c324db810764ecbae6ace39da3f702f2074082787';//回调页面得到code后再获取的session token
//参数数组
$paramArr = array(
     'app_key' => $appKey,
     'session' => $sessionkey,
     'method' => 'taobao.user.seller.get',
     'format' => 'json',
     'v' => '2.0',
     'sign_method'=>'md5',
     'timestamp' => date('Y-m-d H:i:s'),
     'fields' => 'user_id,nick,sex,seller_credit,type,has_more_pic,item_img_num,item_img_size,prop_img_num,prop_img_size,auto_repost,promoted_type,status,alipay_bind,consumer_protection,avatar,liangpin,sign_food_seller_promise,has_shop,is_lightning_consignment,has_sub_stock,is_golden_seller,vip_info,magazine_subscribe,vertical_market,online_gaming'
);

//生成签名
$sign = createSign($paramArr);
//组织参数
$strParam = createStrParam($paramArr);
$strParam .= 'sign='.$sign;
//访问服务
$url = 'http://gw.api.tbsandbox.com/router/rest?'.$strParam; //沙箱环境调用地址
//$url = 'http://gw.api.taobao.com/router/rest?'.$strParam; //prod调用地址
$result = file_get_contents($url);
$result = json_decode($result);
echo "json的结构为:";
print_r($result);
echo "<br>";
echo "用户名称为:".$result->user_get_response->user->nick;
echo "<br>";
echo "买家信用等级为:".$result->user_get_response->user->buyer_credit->level;
?></pre><br>
util.php
<p></p>
<p></p>
<div class="dp-highlighter bg_php"><div class="bar"><div class="tools"><b>[php]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" class="CopyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy</a><a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a><a href="https://code.csdn.net/snippets/195967" target="_blank" title="在CODE上查看代码片" style="text-indent:0;"><img src="https://code.csdn.net/assets/CODE_ico.png" alt="在CODE上查看代码片" style="position:relative;top:1px;left:2px;" height="12" width="12"></a><a href="https://code.csdn.net/snippets/195967/fork" target="_blank" title="派生到我的代码片" style="text-indent:0;"><img src="https://code.csdn.net/assets/ico_fork.svg" alt="派生到我的代码片" style="position:relative;top:2px;left:2px;" height="12" width="12"></a><div style="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 99;"><embed id="ZeroClipboardMovie_4" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" name="ZeroClipboardMovie_4" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&width=0&height=0" wmode="transparent" align="middle" height="0" width="0"></div></div></div><ol class="dp-c" start="1"><li class="alt"><span><span><?php&nbsp;&nbsp;</span></span></li><li class=""><span><span class="comment">//签名函数</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="keyword">function</span><span>&nbsp;createSign&nbsp;(</span><span class="vars">$paramArr</span><span>)&nbsp;{&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">global</span><span>&nbsp;</span><span class="vars">$appSecret</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vars">$sign</span><span>&nbsp;=&nbsp;</span><span class="vars">$appSecret</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ksort(<span class="vars">$paramArr</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">foreach</span><span>&nbsp;(</span><span class="vars">$paramArr</span><span>&nbsp;</span><span class="keyword">as</span><span>&nbsp;</span><span class="vars">$key</span><span>&nbsp;=>&nbsp;</span><span class="vars">$val</span><span>)&nbsp;{&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span><span>&nbsp;(</span><span class="vars">$key</span><span>&nbsp;!=&nbsp;</span><span class="string">''</span><span>&nbsp;&&&nbsp;</span><span class="vars">$val</span><span>&nbsp;!=&nbsp;</span><span class="string">''</span><span>)&nbsp;{&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vars">$sign</span><span>&nbsp;.=&nbsp;</span><span class="vars">$key</span><span>.</span><span class="vars">$val</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vars">$sign</span><span>.=</span><span class="vars">$appSecret</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vars">$sign</span><span>&nbsp;=&nbsp;</span><span class="func">strtoupper</span><span>(md5(</span><span class="vars">$sign</span><span>));&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="vars">$sign</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="comment">//组参函数</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span><span class="keyword">function</span><span>&nbsp;createStrParam&nbsp;(</span><span class="vars">$paramArr</span><span>)&nbsp;{&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vars">$strParam</span><span>&nbsp;=&nbsp;</span><span class="string">''</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">foreach</span><span>&nbsp;(</span><span class="vars">$paramArr</span><span>&nbsp;</span><span class="keyword">as</span><span>&nbsp;</span><span class="vars">$key</span><span>&nbsp;=>&nbsp;</span><span class="vars">$val</span><span>)&nbsp;{&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span><span>&nbsp;(</span><span class="vars">$key</span><span>&nbsp;!=&nbsp;</span><span class="string">''</span><span>&nbsp;&&&nbsp;</span><span class="vars">$val</span><span>&nbsp;!=&nbsp;</span><span class="string">''</span><span>)&nbsp;{&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vars">$strParam</span><span>&nbsp;.=&nbsp;</span><span class="vars">$key</span><span>.</span><span class="string">'='</span><span>.urlencode(</span><span class="vars">$val</span><span>).</span><span class="string">'&'</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="vars">$strParam</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span>}&nbsp;&nbsp;</span></li><li class="alt"><span>?>&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;" code_snippet_id="195967" snippet_file_name="blog_20140220_3_4439814" name="code" class="php"><?php
//签名函数
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;
}
?></pre>如果想用正式环境测试,需要把appKey,appSecret换成正式环境的。<br>
同时认证后传给应用的回调url的参数是$code = $_GET["top_session"];//prod enc<br>
淘宝的用户认证url也应该换成正式环境的<br>
http://container.api.taobao.com/container?appkey={appkey}<br>
淘宝的token认证url也应该换成正式环境的<br>
$url = 'https://oauth.taobao.com/token'; //prod env<br>
API调用url换成如下<br>
<p>$url = 'http://gw.api.taobao.com/router/rest?'.$strParam; //prod调用地址</p>
<p>用户认证入口</p>
<p><div id="container"><br>
&nbsp;&nbsp; &nbsp;<a href="https://oauth.tbsandbox.com/authorize?response_type=code&client_id=xxxx&redirect_uri=http%3A%2F%2Fdev2dev.sinaapp.com%2Ftaobao%2Fcallback.php&from_site=fuwu">login sandbox</a><br>
&nbsp;&nbsp; &nbsp;<br><br>
&nbsp;&nbsp; &nbsp;<a href="http://container.api.taobao.com/container?appkey=yyy">login prod</a><br>
</div></p>
<p><br>
</p>
<p></p>
<pre></pre>

 

分享到:
评论

相关推荐

    Delphi版本的淘宝接口(TopAPI)开发.rar

    淘宝接口,即Taobao Open Platform API,是淘宝开放平台提供的一系列接口,允许开发者通过这些接口与淘宝平台进行数据交互,实现诸如商品管理、订单处理、用户信息查询等电商功能。 首先,让我们详细了解Delphi如何...

    产品经理的基础工作搭建自己公司开放平台(案例原型带流程).docx

    ### 产品管理之搭建公司开放平台的关键步骤及实践 #### 一、背景介绍 随着互联网技术的发展,越来越多的电商平台及互联网应用公司开始构建自己的开放平台,以吸引更多的外部商户加入,共享平台资源和服务。例如,...

    淘宝/天猫TOP获取Sessionkey解决方案

    Sessionkey是淘宝开放平台(Taobao Open Platform,简称TOP)提供的一个安全认证机制,用于保护应用和淘宝服务器之间的通信数据不被篡改或窃取。在进行任何涉及用户敏感信息的操作时,如读取用户订单、修改商品信息...

    Asp.net 调用淘宝客Top Api接口实例源码

    淘宝客API是淘宝开放平台(Taobao Open Platform, TOP)的一部分,它提供了丰富的接口,涵盖了商品搜索、订单查询、用户信息获取等多个功能。开发者可以通过注册淘宝开发者账号,申请API密钥,然后利用这些接口与淘宝...

    淘宝短信接口API使用jar包

    淘宝短信接口API是淘宝开放平台(Taobao Open Platform, 简称TOP)提供的一项服务,主要用于商家或开发者实现向用户发送短信验证码的功能,增强账户安全性。在Java开发环境中,要使用这个接口,通常需要引入特定的...

    淘宝API与AS3例子

    - **开放平台**:淘宝API是淘宝开放平台(Taobao Open Platform, TOP)的一部分,旨在鼓励开发者创新,提供丰富的电商应用场景。 - **接口分类**:包括商品接口、交易接口、用户接口、店铺接口等,覆盖了电商运营的...

    淘宝SDK开发原文档

    淘宝SDK(Software Development Kit)是淘宝开放平台提供的一套用于帮助开发者进行淘宝应用开发的工具集。这个SDK包含了各种API接口、示例代码、开发指南等资源,使得开发者能够更方便地与淘宝平台进行交互,实现...

    淘宝优站U站自定义导购模板

    淘宝优站,又被称为淘宝U站,是一种基于淘宝开放平台(Taobao Open Platform,简称TOP)的自定义导购服务。U站允许商家或个人开发者创建个性化的购物网站,引导消费者在淘宝内进行购物,以此提升商品销售和用户体验...

    Laravel开发-taobao-sdk .zip

    淘宝API是淘宝开放平台提供的一系列接口,允许开发者获取和操作淘宝平台上的数据,如商品信息、订单状态、用户评价等。这些API通常需要通过OAuth 2.0进行身份验证,并且有严格的调用限制和安全策略。 4. **集成...

    Laravel开发-taobao-top-client

    淘宝顶级客户端(SDK)则是淘宝开放平台(Taobao Open Platform, TOP)为开发者提供的工具包,用于访问淘宝的各种API服务,如商品管理、订单处理、用户信息获取等。通过这个SDK,开发者可以轻松地在自己的应用中集成...

    Laravel开发-oapi-taobao-client

    本项目“Laravel开发-oapi-taobao-client”专注于集成淘宝开放API(OAPI)到Laravel 5.1中,创建一个顶级的客户端SDK,方便开发者轻松地与淘宝平台进行数据交互。 首先,让我们深入理解Laravel 5.1的关键特性。...

    适用于thinkphp5.1 thinkphp6.0的社会化登录扩展.zip

    9. **淘宝登录**:对接淘宝开放平台,让淘宝用户能够在你的网站上一键登录。 三、使用流程 使用"thinkphp-social"扩展通常涉及以下步骤: 1. **安装**:将压缩包解压至项目的扩展目录,然后在ThinkPHP项目配置中...

    Laravel开发-baichuan

    首先,淘宝百川是阿里巴巴集团推出的一套开放平台服务,旨在帮助开发者快速接入淘宝的生态系统,提供包括用户、商品、交易等核心电商功能。其SDK允许开发者便捷地调用这些服务,实现如用户登录、商品管理、订单处理...

    基于PHP的浩天皮卷淘宝客程序无限制版.zip

    2. **淘宝接口集成**:程序通过调用淘宝开放API获取商品信息,展示给用户,包括商品详情、价格、促销信息等。 3. **商品推荐**:根据用户的浏览历史、购买行为,程序可能提供个性化商品推荐,增加销售转化率。 4. ...

    EC第三方登录整合插件

    这通常涉及到获取访问令牌、验证用户身份以及更新或创建网站用户记录的步骤。 4. `bind.php`:这个文件同样与用户绑定操作有关,可能处理用户的登录状态检查、绑定请求以及返回的认证信息处理。 5. `使用说明.txt`...

    基于Android技术的网上商城系统的设计与实现 (2).docx

    Android平台拥有丰富的API接口,允许开发者轻松创建各种类型的应用程序。此外,Android SDK(软件开发工具包)提供了必要的工具和文档,帮助开发者构建高质量的应用程序。由于其开放性和灵活性,Android成为了世界上...

    微信速分销会员分销系统

    - **OpenAPI接口配置**:提供开放接口便于第三方应用接入。 - **第三方登录配置**:支持使用支付宝、微博、QQ等多种方式登录。 - **系统邮箱设置**:配置电子邮件服务以发送通知等信息。 - **短信平台集成**:整合...

Global site tag (gtag.js) - Google Analytics