Java调⽤淘宝APIdemo源代码
/**
*
*/
;
ption;
oder;
tException;
rvlet;
rvletRequest;
rvletRespon;
;
tory;
ApiException;
JsonRestClient;
RestClient;
etRespon;
nSaleGetRequest;
/**
*@version2008-10-29
*@author
*
*/
publicclassMainServletextendsHttpServlet{
privatestaticfinaltransientLoglog=LogFactory
.getLog();
/**
*
*/
privatestaticfinallongrialVersionUID=8839274L;
@Override
protectedvoiddoPost(HttpServletRequestreq,HttpServletResponresp)
throwsServletException,IOException{
Stringappkey=ameter("appkey");
Stringcret=ameter("cret");
if(gEnabled()){
(appkey+":"+cret);
}
if(appkey!=null&&cret!=null){
try{
//⽣成客户端实例
TaobaoRestClientclient=newTaobaoJsonRestClient(appkey,cret);
//淘宝卖家的出售的商品列表
ItemsOnSaleGetRequesttbReq=newItemsOnSaleGetRequest()
.withFields("iid,title,price,list_time,num")
.withPageNo(1)
.withPageSize(20);
//uappkeyasssion_id
ItemsGetRespontbRsp=nSaleGet(tbReq,appkey);//搜索单个商品信息的Request请求
if(gEnabled()){
(y());
}
//如果接⼝调⽤成功
if(!ess()){
if(rect()){
ribute("url",
irectUrl(URLEncoder
.encode
(uestURL()
.append('?')
.append("appkey=")
.append(appkey)
.append("&cret=")
.append(cret)
.toString(),"utf-8")
)
);
}el{
ribute("msg",());
}
}el{
ribute("items",ms());
}
}catch(TaobaoApiExceptione){
thrownewServletException(e);
}
}
uestDispatcher("").forward(req,resp);
}
@Override
protectedvoiddoGet(HttpServletRequestreq,HttpServletResponresp)
throwsServletException,IOException{
doPost(req,resp);
}
}
本文发布于:2022-12-11 05:29:55,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/88/83746.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |