| 
论坛元老  
 威望94 贡献138 热心值3 金币18536 注册时间2020-8-31
 
 | 
 
 
| 阿里巴巴开放平台 SDK 运行样例。 
 调用阿里巴巴开放平台的API你是不是获取不到访问口令,看一下我的例子吧,原因是后台已经更改,而网站的说明没有更新。
 
 IniFile ini = new IniFile();
 Dictionary sl = new Dictionary();
 sl = ini.GetSectionValues("Setting");
 strAppKey = sl["appKey"].ToString();
 strAccToken = sl["access_token"].ToString();
 strAppSecret = sl["appSecret"].ToString();
 string strTokeyTime = sl["datatime"].ToString();
 string strRefresh_token = sl["refresh_token"].ToString();
 
 //比较令牌保存时间,如果比现在早10个小时以上就更新
 DateTime dt = Convert.ToDateTime(strTokeyTime);
 TimeSpan ts = System.DateTime.Now.Subtract(dt);
 if ((Int16.Parse(ts.Days.ToString()) >= 1) || (decimal.Parse(ts.Hours.ToString()) > 8))
 {
 //超过有效期,重新获取Access_Token
 //利用Refresh_token获取access_token
 Dictionary ls = new Dictionary();
 string urlStr = "https://gw.open.china.alibaba.com/openapi/http/1/system.oauth2/getToken/" + strAppKey;
 Dictionary dc = new Dictionary();
 dc.Add("grant_type", "refresh_token");
 dc.Add("need_refresh_token", "true");
 dc.Add("client_id", strAppKey);
 dc.Add("client_secret", strAppSecret);
 dc.Add("redirect_uri", "http://localhost");
 dc.Add("refresh_token", strRefresh_token);
 WebUtils wu = new WebUtils();
 string tbxToken = wu.DoPost(urlStr, dc);
 Hashtable hs = (Hashtable)PluSoft.Utils.JSON.Decode(tbxToken);
 //保存令牌
 ini.WriteValue("Setting", "access_token", hs["access_token"].ToString());
 ini.WriteValue("Setting", "datatime", System.DateTime.Now.ToString());
 
 strAccToken = hs["access_token"].ToString();
 }
 获取授权的CODE和令牌,分两
 
 | 
 |