项目作者: CurlyBraceTT

项目描述 :
Aliexpress Api high level C# client
高级语言: C#
项目地址: git://github.com/CurlyBraceTT/Aliexpress.Api.git
创建时间: 2017-04-15T14:20:40Z
项目社区:https://github.com/CurlyBraceTT/Aliexpress.Api

开源协议:MIT License

下载


Aliexpress.Api

Aliexpress Api high level client written on C#

About

  • Build on Asp.net core 2.0
  • Wraps all results into strong-typed models
  • Parses API exceptions
  • Tests included
  • Service Collection extension for easy integration

Getting started

To add client into dependency injection services:

  1. public void ConfigureServices(IServiceCollection services)
  2. {
  3. services.AddAliClient(settings =>
  4. {
  5. settings.AppKey = "YOURAPPKEY";
  6. });
  7. }

Then client will be injected, for example simple MVC Controller:

  1. [Route("api/[controller]")]
  2. public class AliController : Controller
  3. {
  4. private readonly IAliexpressApiClient _aliClient;
  5. public AliController(IAliexpressApiClient aliClient)
  6. {
  7. _logger = logger;
  8. _aliClient = aliClient;
  9. }
  10. [HttpGet]
  11. public async Task<IActionResult> Get(string keywords)
  12. {
  13. var items = await _aliClient.ListPromotionProduct(new ListPromotionProductParameters
  14. {
  15. Keywords = keywords
  16. });
  17. return Json(items);
  18. }
  19. }

Original Aliexpress API documentation is Here

Note: You need to register at https://portals.aliexpress.com

Tests

To setup tests - please edit settings.json file and paste your App key, tracking and signature ids there.

How to create actual Promotion urls using raw product url?

Here is the harsh example of what you need to do.

  1. // Get some products
  2. var items = await _aliClient.ListPromotionProduct(new ListPromotionProductParameters
  3. {
  4. Keywords = keywords
  5. });
  6. // Create comma-separated list of urls
  7. var urlsList = items.Products.Select(p => p.ProductUrl);
  8. var urls = string.Join(",", urlsList);
  9. // Get promotions urls by list of urls
  10. var processed = await _aliClient.GetPromotionLinks(new GetPromotionLinksParameters
  11. {
  12. TrackingId = "YOURTRACKINGID",
  13. Urls = urls
  14. });
  15. // Get promotion url and paste it in your original results
  16. foreach(var i in items.Products)
  17. {
  18. var trueUrl = processed.PromotionUrls.SingleOrDefault(u => u.Url == i.ProductUrl);
  19. if(trueUrl != null)
  20. {
  21. i.ProductUrl = trueUrl.PromotionUrl;
  22. }
  23. }