-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
329 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.33424.131 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArasKargoAPI", "ArasKargoAPI.csproj", "{626EF5E7-9D28-4DCC-8B50-0F71C976DC1E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{626EF5E7-9D28-4DCC-8B50-0F71C976DC1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{626EF5E7-9D28-4DCC-8B50-0F71C976DC1E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{626EF5E7-9D28-4DCC-8B50-0F71C976DC1E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{626EF5E7-9D28-4DCC-8B50-0F71C976DC1E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {C0D00A0B-0355-4D02-A570-CF6173A07263} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System.ComponentModel; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
using static ArasKargoAPI.ArasKargoClient; | ||
|
||
namespace ArasKargoAPI | ||
{ | ||
public class ArasKargoClient | ||
{ | ||
|
||
public enum Dil | ||
{ | ||
[Description("Türkçe")] | ||
tr, | ||
[Description("English")] | ||
en | ||
} | ||
|
||
private static string _takip_kodu; | ||
private static Dil _dil; | ||
|
||
/// <summary> | ||
/// Client'i hazırlar. | ||
/// </summary> | ||
/// <param name="TakipKodu">Kargo takip kodu.</param> | ||
public ArasKargoClient(string TakipKodu, Dil dil = Dil.tr) | ||
{ | ||
_takip_kodu = TakipKodu; | ||
_dil = dil; | ||
} | ||
|
||
/// <summary> | ||
/// Kargo bilgilerini alır. | ||
/// </summary> | ||
/// <returns>Kargo bilgileri.</returns> | ||
public KargoBilgileri Al() | ||
{ | ||
|
||
if (_takip_kodu == null) | ||
{ | ||
throw new Exception("Önce client'i hazırlamalısın!"); | ||
} | ||
|
||
#region HTTP | ||
|
||
var hClient = new HttpClient(); | ||
var data = "{\r\n \"TrackingNumber\": \"" + _takip_kodu + "\",\r\n \"LanguageCode\": \"" + _dil + "\"\r\n}"; | ||
var contentPost = new StringContent(data, Encoding.UTF8, "application/json"); | ||
var response = hClient.PostAsync("https://kurumsalwebservice.araskargo.com.tr/api/getCargoTransactionByTrackingNumber", contentPost).Result; | ||
var content = response.Content.ReadAsStringAsync().Result; | ||
|
||
#endregion | ||
|
||
#region Json Parsing | ||
|
||
ArasResponse aras; | ||
try | ||
{ | ||
aras = JsonConvert.DeserializeObject<ArasResponse>(content); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw e; | ||
} | ||
|
||
// 200 değil? Hata var demektir. | ||
if (aras.Code != 200) | ||
{ | ||
throw new Exception(aras.Message); | ||
} | ||
|
||
#endregion | ||
|
||
#region Haritalama | ||
|
||
var cikis = new KargoBilgileri | ||
{ | ||
Islemler = aras.Responses | ||
}; | ||
|
||
#endregion | ||
|
||
#region Gönderici / Alıcı / Kaynak bilgilerini alma | ||
|
||
// Bu iki değişken captcha görevi görüyor olmadan alamıyoruz. | ||
// Ne zeman expire yiyor? bende bilmiyorum aslında. | ||
// Expire yiyene kadar bunları kullanmaya devam. | ||
// Unique ID ile matchlenmiş bi kod olabilir. | ||
const string captcha_code = "6o6fva"; | ||
const string uniq_id = "cf5197a9-9445-4e85-923a-9c999be7db73"; | ||
|
||
var postData2 = "{\"TrackingNumber\":\"" + _takip_kodu + "\",\"IsWeb\":true,\"UniqueCode\":\"" + uniq_id + "\",\"SecretKey\":\"" + captcha_code + "\",\"LanguageCode\":\"" + _dil + "\"}"; | ||
var contentPost2 = new StringContent(postData2, Encoding.UTF8, "application/json"); | ||
var response2 = hClient.PostAsync("https://kurumsalwebservice.araskargo.com.tr/api/getShipmentByTrackingNumber", contentPost2).Result; | ||
var content2 = response2.Content.ReadAsStringAsync().Result; | ||
|
||
var c2Dynamic = JsonConvert.DeserializeObject<dynamic>(content2); | ||
var kBilgileriNodeFirst = Convert.ToString(c2Dynamic.Responses.First); | ||
|
||
var gonderiBilgileri = JsonConvert.DeserializeObject<GonderiBilgileri>(kBilgileriNodeFirst); | ||
cikis.Gonderi = gonderiBilgileri; | ||
|
||
#endregion | ||
|
||
return cikis; | ||
|
||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ArasKargoAPI | ||
{ | ||
|
||
internal class ArasResponse | ||
{ | ||
[JsonProperty("Code")] | ||
public int Code { get; set; } | ||
|
||
[JsonProperty("Message")] | ||
public string Message { get; set; } | ||
|
||
[JsonProperty("Responses")] | ||
public List<KargoIslem> Responses { get; set; } | ||
|
||
[JsonProperty("ContactInfo")] | ||
public string ContactInfo { get; set; } | ||
} | ||
|
||
|
||
public class KargoIslem | ||
{ | ||
[JsonProperty("TransactionDate")] | ||
public DateTime Tarih { get; set; } | ||
|
||
[JsonProperty("UnitName")] | ||
public string Bolge { get; set; } | ||
|
||
[JsonProperty("ShipmentLineTransType")] | ||
public string Tur { get; set; } | ||
|
||
[JsonProperty("Description")] | ||
public string Aciklama { get; set; } | ||
} | ||
|
||
public class GonderiBilgileri | ||
{ | ||
[JsonProperty("TrackingNumber")] | ||
public string TakipNo { get; set; } | ||
|
||
[JsonProperty("DocumentSerial")] | ||
public string DokumenSeriNo { get; set; } | ||
|
||
[JsonProperty("DocumentNumber")] | ||
public string DokumanNumarasi { get; set; } | ||
|
||
[JsonProperty("WaybillDate")] | ||
public DateTime GonderiTarihi { get; set; } | ||
|
||
[JsonProperty("SenderAccountAddressName")] | ||
public string GondericiIsim { get; set; } | ||
|
||
[JsonProperty("ReceiverAccountAddressName")] | ||
public string AliciIsim { get; set; } | ||
|
||
[JsonProperty("TotalVolume")] | ||
public string Desi { get; set; } | ||
|
||
[JsonProperty("PieceCount")] | ||
public string Adet { get; set; } | ||
|
||
[JsonProperty("LovShipmentStatusId")] | ||
public string LovShipmentStatusId { get; set; } | ||
|
||
[JsonProperty("LovShipmentStatusName")] | ||
public string SonDurum { get; set; } | ||
|
||
[JsonProperty("SourceUnitName")] | ||
public string CikisSubesi { get; set; } | ||
|
||
[JsonProperty("DeliveryUnitName")] | ||
public string VarisSubesi { get; set; } | ||
|
||
[JsonProperty("PlannedDeliveryDate")] | ||
public DateTime TahminiTeslimTarihi { get; set; } | ||
|
||
[JsonProperty("LovPayorTypeName")] | ||
public string OdemeTuru { get; set; } | ||
|
||
[JsonProperty("LovPackTypeName")] | ||
public string PaketTuru { get; set; } | ||
|
||
[JsonProperty("SourceCity")] | ||
public string CikisIl { get; set; } | ||
|
||
[JsonProperty("DeliveryCity")] | ||
public string VarisIl { get; set; } | ||
|
||
[JsonProperty("SourceTown")] | ||
public string CikisIlce { get; set; } | ||
|
||
[JsonProperty("DeliveryTown")] | ||
public string VarisIlce { get; set; } | ||
|
||
[JsonProperty("LovShipmentTypeName")] | ||
public string GonderimTuru { get; set; } | ||
} | ||
|
||
public class KargoBilgileri | ||
{ | ||
|
||
/// <summary> | ||
/// Kargo işlemleri (işlem tarihleri, gönderi durumları vb.) | ||
/// </summary> | ||
public List<KargoIslem> Islemler { get; set; } | ||
|
||
/// <summary> | ||
/// Kargo bilgileri (gönderici, alıcı, kargo türü vb.) | ||
/// </summary> | ||
public GonderiBilgileri Gonderi { get; set; } | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# ArasKargoAPI | ||
|
||
Aras kargo & gönderim bilgilerini çekmek için en kapsamlı kütüphane. | ||
|
||
## Nasıl kullanılır? | ||
|
||
DLL kütüphanesini projemize ekliyoruz. (.Net standard olduğu için mobil, web gibi projelerinize de ekleyebilirsiniz.) | ||
|
||
```csharp | ||
using ArasKargoAPI; | ||
... | ||
|
||
ArasKargoClient client = new ArasKargoClient(GonderiNumarasi); // gonderi no | ||
KargoBilgileri Bilgiler = client.Al(); | ||
|
||
// Not: Ingilizce desteklenmektedir. | ||
``` | ||
|
||
İle bilgileri aldıktan sonra | ||
* `Bilgiler.Gonderi` ile teslimat şubesi, tahmini variş, gönderici/alıcı bilgilerini, | ||
* `Bilgiler.Islemler` ile transfer bilgilerini (X tarihinde şubeye ulaştı, dağıtıma çıkarıldı vs.) | ||
|
||
ulaşabilirsiniz. | ||
|
||
# Örnekler | ||
|
||
### Gönderi bilgilerini çekme | ||
|
||
```csharp | ||
var gonderici = Bilgiler.Gonderi.GondericiIsim; | ||
var alici = Bilgiler.Gonderi.AliciIsim; | ||
var cikisSubesi = Bilgiler.Gonderi.CikisSubesi; | ||
var varisSubesi = Bilgiler.Gonderi.VarisSubesi; | ||
var tahminiTeslim = Bilgiler.Gonderi.TahminiTeslimTarihi; | ||
var gonderimTarihi = Bilgiler.Gonderi.GonderiTarihi; | ||
|
||
// falan filan... | ||
``` | ||
|
||
### Kargo transfer bilgilerini yazdırma: | ||
|
||
```csharp | ||
Bilgiler.Islemler.ForEach(x => | ||
{ | ||
Console.WriteLine(x.Tarih + " " + x.Bolge + " " + x.Tur + " " + x.Aciklama); | ||
}); | ||
``` | ||
|
||
Verdiği; | ||
```markdown | ||
9/6/2023 5:21:50 PM ORHANLI TRANSFER (YOLDA; Kargonuz çıkış transfer merkezinden varış transfer merkezine gönderiliyor.) | ||
9/6/2023 5:25:00 PM ORHANLI TRANSFER (YOLDA; Kargonuz çıkış transfer merkezinden varış transfer merkezine gönderiliyor.) | ||
10/6/2023 4:56:51 AM HADIMKÖY TRANSFER (YOLDA; Kargonuz varış transfer merkezine indirilmiştir.) | ||
10/6/2023 5:00:00 AM HADIMKÖY TRANSFER (YOLDA; Kargonuz çıkış transfer merkezinden varış transfer merkezine gönderiliyor.) | ||
10/6/2023 5:10:00 AM HADIMKÖY TRANSFER (YOLDA; Kargonuz varış transfer merkezinden varış şubesine gönderiliyor.) | ||
10/6/2023 12:08:41 PM KUZEY MARMARA (TESLİMAT ŞUBESİNDE; Kargonuz transfer merkezimizden teslimat şubemize ulaşmıştır.) | ||
``` |