-
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
8 changed files
with
457 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,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", "src/ArasKargoAPI.csproj", "{CCB965D9-276E-429C-ACDD-17EC69F3FE4B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CCB965D9-276E-429C-ACDD-17EC69F3FE4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CCB965D9-276E-429C-ACDD-17EC69F3FE4B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CCB965D9-276E-429C-ACDD-17EC69F3FE4B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CCB965D9-276E-429C-ACDD-17EC69F3FE4B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {45CB2A26-4E18-4896-B4D3-96FF70B4FFBA} | ||
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,39 @@ | ||
## ArasKargoAPI | ||
Aras Kargo gönderi ve teslimat bilgilerini çekmek için ihtiyacın olan tek library. | ||
|
||
### Özellikler | ||
- Hızlı, class bazlı bir yapı. | ||
- Gönderi ve teslimat bilgilerini çekme. | ||
|
||
### Kullanım | ||
```csharp | ||
|
||
var aras = new ArasKargoClient("TAKIPNO"); | ||
var sonuc = aras.Al(); | ||
|
||
// Kargo İşlemleri (teslim alındı, dağıtıma çıktı vb.) | ||
sonuc.Islemler.ForEach(x => | ||
{ | ||
Console.WriteLine($"{x.Aciklama} - {x.Tarih}"); | ||
}); | ||
|
||
// Çıkış: | ||
ÇIKIŞ ŞUBESİNDE; Kargonuz çıkış şubesinden transfer merkezine gönderilmek üzere aracımıza yüklenmiştir. - 21.07.2023 12:23:21 | ||
YOLDA; Kargonuz çıkış transfer merkezinden varış transfer merkezine gönderiliyor. - 21.07.2023 21:01:58 | ||
YOLDA; Kargonuz çıkış transfer merkezinden varış transfer merkezine gönderiliyor. - 21.07.2023 21:05:00 | ||
YOLDA; Kargonuz çıkış transfer merkezinden varış transfer merkezine gönderiliyor. - 21.07.2023 21:54:00 | ||
TESLİMAT ŞUBESİNDE; Kargonuz transfer merkezimizden teslimat şubemize ulaşmıştır. - 24.07.2023 20:41:53 | ||
|
||
// sonuc.Gonderi ile gönderi bilgilerini (alici şube, alici isim, şube bilgileri, desi vb.) çekebilirsiniz | ||
|
||
``` | ||
|
||
### Notlar | ||
|
||
- Newtonsoft-Json paketini indirmeniz gerekebilir. | ||
- Kodlar içindeki captcha code her 2 haftada bir expire yiyor. Eğer **gönderi alınamadı** hatası alıyorsanız captcha kodunu güncellemeniz gerekebilir. | ||
- Dil seçeneği ingilizce ve türkçe olarak değiştirebilir. | ||
|
||
### Lisans | ||
MIT |
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,60 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{CCB965D9-276E-429C-ACDD-17EC69F3FE4B}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>ArasKargoAPI</RootNamespace> | ||
<AssemblyName>ArasKargoAPI</AssemblyName> | ||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartupObject /> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="ArasKargoClient.cs" /> | ||
<Compile Include="ArasResponse.cs" /> | ||
<Compile Include="DateTimeConverter.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
<None Include="readme.md" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</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,135 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
|
||
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, new JsonSerializerSettings() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore, | ||
DefaultValueHandling = DefaultValueHandling.Ignore, | ||
MissingMemberHandling = MissingMemberHandling.Ignore, | ||
}); | ||
} | ||
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. | ||
// Edit: 2 haftada bir expire yiyor. | ||
const string captcha_code = "n159sc"; | ||
const string uniq_id = "6258ed31-a70e-493a-a41e-54e98d457f14"; | ||
|
||
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); | ||
dynamic kBilgileriNodeFirst = null; | ||
|
||
try | ||
{ | ||
kBilgileriNodeFirst = Convert.ToString(c2Dynamic.Responses.First); | ||
var gonderiBilgileri = JsonConvert.DeserializeObject<GonderiBilgileri>(kBilgileriNodeFirst, new JsonSerializerSettings() | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore, | ||
Error = delegate (object aq, Newtonsoft.Json.Serialization.ErrorEventArgs args) | ||
{ | ||
args.ErrorContext.Handled = true; | ||
} | ||
}); | ||
cikis.Gonderi = gonderiBilgileri; | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new Exception("Gönderi bilgileri alınamadı. +" + e.Message); | ||
} | ||
|
||
|
||
#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,123 @@ | ||
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 | ||
{ | ||
[JsonConverter(typeof(DateTimeConverter))] | ||
[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; } | ||
|
||
[JsonConverter(typeof(DateTimeConverter))] | ||
[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; } | ||
|
||
[JsonConverter(typeof(DateTimeConverter))] | ||
[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; } | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.