第一步 定义速卖通api的常量
public String client_id;
public String client_key;
public String site;
第二步 获取登陆的uRL
/**
* getloginurl
* @param redirect_uri
* @return
*/
public String GetLoginUrl(String redirect_uri)
{
String param = (new StringBuilder("client_id=")).append(client_id).append("&site=aliexpress&redirect_uri=").append(redirect_uri).toString();
String param1 = (new StringBuilder("client_id")).append(client_id).append("redirect_uri").append(redirect_uri).append("site").append(site).toString();
String sign = hmac_sha1(param1, client_key).toUpperCase();
return (new StringBuilder("http://gw.api.alibaba.com/auth/authorize.htm?")).append(param).append("&_aop_signature=").append(sign).toString();
}
第三步 获取速卖通 toaken
/**
* 根据店铺名获取token
* @param shopname
* @return
*/
public String gettokenbyshopname(String shopname)
{
String sql= "select FShop_tokenyear,FShop_SysUser from t_smt_shop where fshop_name=‘" + shopname +"‘“
Map mapmain=(Map) Base1.getMapbySQL(sql);
String token = "";
String tokenyear =(String)mapmain.get("FShop_tokenyear");
String ShopName =(String)mapmain.get("FShop_Name");
String FShop_SysUser =(String)mapmain.get("FShop_SysUser");
String rt = GetTokenByTokenYear(tokenyear);
try
{
JSONObject jsonObject = JSONObject.fromObject( rt );
token=jsonObject.get("access_token").toString();
}
catch(Exception ex)
{
String subject= FShop_SysUser+"的速卖通店铺"+ ShopName+"登陆失效请重新登陆";
Base1.sendmail(subject,"","mail"); //todo 修改为32
return "broke";
}
return token;
}
获取到了token后,就可以通过马云提供的各类api管理自己的外贸数据了
参考速卖通api模板
http://gw.api.alibaba.com/dev/doc/api.htm?ns=aliexpress.open
参考