Created
June 23, 2009 09:56
-
-
Save quake/134460 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# orig http://open.taobao.com/demo/RubyDemo.rb | |
#此DEMO的功能:查询手机类的淘客商品 | |
require 'digest/md5' | |
require 'open-uri' | |
require 'cgi' | |
#组装参数 | |
param_array = { | |
#组装协议参数 | |
'app_key'=>'test', | |
'method'=>'taobao.taobaoke.items.get', | |
'format'=>'xml', | |
'v'=>'1.0', | |
'timestamp'=>Time.now.strftime("%Y-%m-%d %H:%M:%S"), | |
#组装应用参数 | |
'fields'=>'iid,title,nick,pic_url,price,click_url', | |
'pid' => 'mm_5410_0_0', | |
'cid' => '1512', | |
'page_no' => '1', | |
'page_size' => '6' | |
} | |
#生成签名 | |
def sign(param,sercetCode) | |
Digest::MD5.hexdigest(([sercetCode] + param.sort.flatten).join).upcase | |
end | |
param_array['sign'] = sign(param_array,'test') | |
url = 'http://gw.sandbox.taobao.com/router/rest?' | |
#构建参数 | |
url = url + param_array.map{|p| "#{p[0]}=#{CGI.escape p[1]}"}.join('&') | |
open(url) do |http| | |
p http.read | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment