static void Main(string[] args) { Console.WriteLine("Example starting...."); //create the connection information for accessing API server ClientPolicy clientPolicy = new ClientPolicy(); clientPolicy.AppKey = ""; clientPolicy.SecretKey = ""; String refreshToken = "ecc43432-87f9-4bd6-b8c0-5a741820c5a2"; //create an object for handling API request SyncAPIClient instance = new SyncAPIClient(clientPolicy); //create the API request, here the simple example is retrieve some information from API server. ExampleFamilyGetParam exampleFamilyGetParam = new ExampleFamilyGetParam(); exampleFamilyGetParam.setFamilyNumber(1); //call the API server with request ExampleFamilyGetResult exampleFamilyGetResult = instance.send <ExampleFamilyGetResult>(exampleFamilyGetParam); //get the result from API server. ExampleFamily exampleFamily = exampleFamilyGetResult.getResult(); Console.WriteLine("exampleFamilyGet:" + exampleFamily.getFather() + " and the name of father is " + exampleFamily.getFather().getName() + ", the birthday of fanther is " + exampleFamily.getFather().getBirthday()); }
public void Alibaba_GetToken() { SyncAPIClient client = new SyncAPIClient("3259943", "t6MpyARzzv"); var token = client.getToken("a448afd8-ef2c-4e51-9b2c-a640e8551a81"); Console.WriteLine(token.getAccess_token()); Assert.True(true); }
public GoodRequest(string alistr) { ClientPolicy clientPolicy = new ClientPolicy(); clientPolicy.AppKey = "4291F75C-A7B9-4DB3-AADC-234490550B14"; instance = new SyncAPIClient(clientPolicy); //解析规格 dspec = new DeserialSpec(instance, alistr); this.alistr = alistr; }
/// <summary> /// 使用 refresh token 来重新刷一个新的 access Token /// </summary> /// <param name="token">Token.</param> public virtual void RefreshAccessToken(AccessToken token) { /* * { * "access_token": "76dee230-a91b-4178-aa25-83855bb7808b", * "aliId": "3305067292", * "resource_owner": "ericzhongxu", * "expires_in": "35999", * "memberId": "b2b-3305067292666fa" * } */ try { SyncAPIClient client = new SyncAPIClient(token.App_Key, token.App_Secret); var oldAccessToken = token.Access_Token; var newToken = client.refreshToken(token.Refresh_Token); token.Access_Token = newToken.getAccess_token(); token.AliId = newToken.getAliId().ToString(); token.Resource_Owner = newToken.getResource_owner(); token.Expires_In = DateTime.Now.AddSeconds(double.Parse(newToken.getExpires_in().ToString())); // token.Expires_In = newToken.getExpires_time(); token.MemberId = newToken.getMemberId(); token.Status = (int)CallbackMessageStatus.Success; token.Comment = "Success. " + JsonConvert.SerializeObject(newToken); Console.WriteLine(string.Format( "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", token.Id, token.App_Key, token.App_Secret, oldAccessToken, token.Access_Token, token.AliId, token.Resource_Owner, token.MemberId, token.Expires_In.ToString("yyyy-MM-dd HH:mm:ss"))); } catch (Exception err) { token.Status = (int)CallbackMessageStatus.Failed; token.Comment = err.ToString(); // Notice to admin // Error code : 210 string tokenJson = JsonConvert.SerializeObject(token); emailManager.SendMail("[XTOPMS] 刷新 AccessToken 时出现异常 (Error 210)", tokenJson + "\r\n\r\n" + err.ToString(), false); } accessTokenRepository.Update(token); }
public ActionResult Index() { ClientPolicy clientPolicy = new ClientPolicy(); clientPolicy.AppKey = "9769930"; clientPolicy.SecretKey = "RkBsy8k9v5h"; SyncAPIClient instance = new SyncAPIClient(clientPolicy); Model.CategoryGetParam categoryGetParam = new Model.CategoryGetParam(); categoryGetParam.setCategoryID(2); categoryGetParam.setWebSite("1688"); string category = instance.sendJson(categoryGetParam); return(View()); }
public virtual async Task <PushQueryMessageListResult> PushQueryMessageList() { CurrentUnitOfWork.DisableFilter(AbpDataFilters.SoftDelete); AccessToken token = await this.Repository.GetAsync(6526667356666593280); SyncAPIClient client = new SyncAPIClient(token.App_Key, token.App_Secret); PushQueryMessageListParam param = new PushQueryMessageListParam(); RequestPolicy oauthPolicy = new RequestPolicy(); oauthPolicy.UseHttps = true; PushQueryMessageListResult response = client.execute <PushQueryMessageListResult>(param, token.Access_Token); return(null); }
// Testing Method public void GetSellerTradeView() { SyncAPIClient client = new SyncAPIClient("3259943", "t6MpyARzzv"); AlibabaTradeGetSellerOrderListParam param = new AlibabaTradeGetSellerOrderListParam(); string accessToken = "aa200987-fcec-48d9-9521-967d3ce2eea2"; RequestPolicy oauthPolicy = new RequestPolicy(); oauthPolicy.UseHttps = true; AlibabaTradeGetSellerOrderListResult result = client.execute <AlibabaTradeGetSellerOrderListResult>(param, accessToken); Console.Write(result.getTotalRecord()); }
public IList <AlibabaOpenplatformTradeModelTradeInfo> GetModificationTradeInfos( IAccessToken token, DateTime modifyStart, DateTime modifyEnd) { string accessToken = token.Access_Token; SyncAPIClient client = new SyncAPIClient(token.App_Key, token.App_Secret); int maxPageSize = 20; // Alibaba only support 20 int currentPage = 1; long totalCount = 0; // Save all trade into this collection. IList <AlibabaOpenplatformTradeModelTradeInfo> data = new List <AlibabaOpenplatformTradeModelTradeInfo>(); // 先计算一次,拿到总数后,再做循环处理 do { Console.WriteLine("Page " + currentPage.ToString()); AlibabaTradeGetSellerOrderListParam param = new AlibabaTradeGetSellerOrderListParam(); // 设置查询条件,查询前一在的数据 param.setModifyStartTime(modifyStart); param.setModifyEndTime(modifyEnd); // 分页计算 param.setPageSize(maxPageSize); param.setPage(currentPage); RequestPolicy oauthPolicy = new RequestPolicy(); oauthPolicy.UseHttps = true; AlibabaTradeGetSellerOrderListResult result = client.execute <AlibabaTradeGetSellerOrderListResult>(param, accessToken); totalCount = result.getTotalRecord().Value; AlibabaOpenplatformTradeModelTradeInfo[] orders = result.getResult(); foreach (var ord in orders) { data.Add(ord); } currentPage++; }while (currentPage * 1.0 <= (totalCount * 1.0 / maxPageSize)); // 没有超出分页,继续执行 Console.WriteLine("Alibaba Order Count : " + data.Count); Console.WriteLine("Pull Order Count : " + data.Count); return(data); }
/// <summary> /// 使用 code 去刷新新的 Access Token & Refresh Token 信息 /// </summary> /// <param name="token">Token.</param> /// <param name="code">Code.</param> public virtual void InitializeToken(AccessToken token, string code) { /* * { * "access_token": "3f611def-9f31-4f21-a95c-0ca1b0922309", * "aliId": "3305067292", * "refresh_token": "14f0af01-0664-4fa0-a34f-5c0f815247f9", * "resource_owner": "ericzhongxu", * "expires_in": "35999", * "refresh_token_timeout": "20191014003220000+0800", * "memberId": "b2b-3305067292666fa" * } */ SyncAPIClient client = new SyncAPIClient(token.App_Key, token.App_Secret); var newToken = client.getToken(code); newToken.setExpires_in(newToken.getExpires_in()); token.Access_Token = newToken.getAccess_token(); token.AliId = newToken.getAliId().ToString(); token.Refresh_Token = newToken.getRefresh_token(); token.Resource_Owner = newToken.getResource_owner(); token.Expires_In = newToken.getExpires_time(); token.Refresh_Token_Timeout = TransformDateTime(newToken.getRefresh_token_timeout()); token.MemberId = newToken.getMemberId(); accessTokenRepository.Update(token); Console.WriteLine(string.Format( "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", token.Id, token.App_Key, token.App_Secret, code, token.Access_Token, token.AliId, token.Resource_Owner, token.MemberId, token.Expires_In.ToString("yyyy-MM-dd HH:mm:ss"))); }
public AlibabaOpenplatformTradeModelTradeInfo GetTradeInfor(string appKey, string memberId, long orderId) { var token = accessTokenRepository.Single( t => t.App_Key == appKey && t.MemberId == memberId && t.IsActive == true && t.IsDeleted == false); SyncAPIClient client = new SyncAPIClient(token.App_Key, token.App_Secret); // SyncAPIClient client = new SyncAPIClient("3259943", "t6MpyARzzv"); AlibabaTradeGetSellerViewParam param = new AlibabaTradeGetSellerViewParam(); RequestPolicy oauthPolicy = new RequestPolicy(); oauthPolicy.UseHttps = true; param.setOrderId(orderId); AlibabaTradeGetSellerViewResult response = client.execute <AlibabaTradeGetSellerViewResult>(param, token.Access_Token); return(response.getResult()); }
/// <summary> /// Refreshs the refresh token. /// </summary> /// <param name="token">Token.</param> public virtual void RefreshRefreshToken(AccessToken token) { /* * { * "error_description": "refreshToken is too long to expire with expireTime 20191014003220000+0800", * "error": "invalid_request" * } */ try { SyncAPIClient client = new SyncAPIClient(token.App_Key, token.App_Secret); var newToken = client.refreshRefreshToken(token.Access_Token, token.Refresh_Token); token.Access_Token = newToken.getAccess_token(); token.Expires_In = newToken.getExpires_time(); token.Refresh_Token = newToken.getRefresh_token(); token.Refresh_Token_Timeout = TransformDateTime(newToken.getRefresh_token_timeout()); token.AliId = newToken.getAliId().ToString(); token.Resource_Owner = newToken.getResource_owner(); token.MemberId = newToken.getMemberId(); token.Status = (int)CallbackMessageStatus.Success; token.Comment = "Success. " + JsonConvert.SerializeObject(newToken); } catch (Exception err) { token.Status = (int)CallbackMessageStatus.Failed; token.Comment = err.ToString(); // Notice to admin // Error code : 200 string body = ""; try { OceanException oceanException = err as OceanException; body = @" Hi admin, There are some error when executte refresh 'Refresh-Token' background job. "; body += @" Error Code: " + oceanException.getError_code(); body += @" Error Message: " + oceanException.getError_message(); body += @" Detail: " + oceanException.ToString(); } finally { body += "\r\nError: " + err.ToString(); } // string body = @" //Hi admin, //There are some error when executte refresh 'Refresh-Token' background job. //"; // body += @" //Error Code: " + err.getError_code(); // body += @" //Error Message: " + err.getError_message(); // body += @" //Detail: " + err.ToString(); emailManager.SendMail("[XTOPMS] 刷新 RefreshToken 时出现异常 (Error 200)", body, false); } accessTokenRepository.Update(token); }