Skip to content

Commit c6ac7b6

Browse files
author
Enis Gürkan
committed
Add project files.
1 parent c373c32 commit c6ac7b6

File tree

11 files changed

+373
-0
lines changed

11 files changed

+373
-0
lines changed

ESMS.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>

ESMS.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31019.35
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ESMS", "ESMS.csproj", "{E76635A2-2F51-4E3F-A1AA-742FF3EC410D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E76635A2-2F51-4E3F-A1AA-742FF3EC410D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E76635A2-2F51-4E3F-A1AA-742FF3EC410D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E76635A2-2F51-4E3F-A1AA-742FF3EC410D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E76635A2-2F51-4E3F-A1AA-742FF3EC410D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {C49C2129-9F8F-48DB-95E9-79BD9C9FC916}
24+
EndGlobalSection
25+
EndGlobal

Helper/SmsHelper.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Net;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace EB2B.SMS.Helper
8+
{
9+
public static class SmsHelper
10+
{
11+
public static async Task<string> Post(string PostAddress, string xmlData)
12+
{
13+
try
14+
{
15+
WebClient wUpload = new WebClient();
16+
var uri = new Uri(PostAddress);
17+
HttpWebRequest request = WebRequest.Create(PostAddress) as HttpWebRequest;
18+
request.Method = "POST";
19+
request.ContentType = "application/x-www-form-urlencoded";
20+
Byte[] bPostArray = Encoding.UTF8.GetBytes(xmlData);
21+
Byte[] bResponse = await wUpload.UploadDataTaskAsync(uri, "POST", bPostArray);
22+
Char[] sReturnChars = Encoding.UTF8.GetChars(bResponse);
23+
string sWebPage = new string(sReturnChars);
24+
return sWebPage;
25+
}
26+
catch
27+
{
28+
return "-1";
29+
}
30+
}
31+
32+
public static async Task<string> Get(string Adress)
33+
{
34+
try
35+
{
36+
WebClient wUpload = new WebClient();
37+
var uri = new Uri(Adress);
38+
HttpWebRequest request = WebRequest.Create(Adress) as HttpWebRequest;
39+
request.Method = "POST";
40+
request.ContentType = "application/x-www-form-urlencoded";
41+
Byte[] bPostArray = Encoding.UTF8.GetBytes("");
42+
Byte[] bResponse = await wUpload.UploadDataTaskAsync(uri, "GET", bPostArray);
43+
Char[] sReturnChars = Encoding.UTF8.GetChars(bResponse);
44+
string sWebPage = new string(sReturnChars);
45+
return sWebPage;
46+
}
47+
catch
48+
{
49+
return "-1";
50+
}
51+
}
52+
}
53+
}

ISmsProvider.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
5+
namespace EB2B.SMS
6+
{
7+
public interface ISmsProvider
8+
{
9+
Task SendAsync(string phonenumber, string messagecontent);
10+
Task<double> GetCreditAsync();
11+
}
12+
}

ISmsProviderFactory.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace EB2B.SMS
6+
{
7+
public interface ISmsProviderFactory
8+
{
9+
ISmsProvider Create(SmsTypes type, string Username, string Password,string Title);
10+
}
11+
}

Providers/IletiMerkeziProvider.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using EB2B.SMS.Helper;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace EB2B.SMS.Providers
8+
{
9+
public class IletiMerkeziProvider : ISmsProvider
10+
{
11+
//https://a2psmsapi.com/?ref=iletimerkezicom#apidoc
12+
private string _username { get; set; }
13+
private string _password { get; set; }
14+
private string _title { get; set; }
15+
16+
17+
public IletiMerkeziProvider(string username, string password, string title)
18+
{
19+
this._username = username;
20+
this._password = password;
21+
this._title = title;
22+
23+
}
24+
25+
public async Task SendAsync(string phonenumber, string messagecontent)
26+
{
27+
string getData = await SmsHelper.Get($"https://api.iletimerkezi.com/v1/send-sms/get/?username={_username}&password={_password}&text={messagecontent}&receipents={phonenumber}&sender={_title}");
28+
if (getData == "-1")
29+
throw new ArgumentException("Servis Hatası");
30+
}
31+
32+
public async Task<double> GetCreditAsync()
33+
{
34+
return 0;
35+
}
36+
}
37+
}

Providers/MasGsmProvider.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.Specialized;
4+
using System.Net;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace EB2B.SMS.Providers
9+
{
10+
public class MasGsmProvider : ISmsProvider
11+
{
12+
//http://api.v2.masgsm.com.tr/docs
13+
private string _username { get; set; }
14+
private string _password { get; set; }
15+
private string _title { get; set; }
16+
17+
18+
public MasGsmProvider(string username, string password, string title)
19+
{
20+
this._username = username;
21+
this._password = password;
22+
this._title = title;
23+
}
24+
25+
public async Task<double> GetCreditAsync()
26+
{
27+
using (var wb = new WebClient())
28+
{
29+
var data = new NameValueCollection();
30+
wb.Headers.Add("Authorization", _password);
31+
var response = wb.UploadValues("http://api.v2.masgsm.com.tr/v2/get/balance", "POST", data);
32+
double resp = double.Parse(Encoding.UTF8.GetString(response));
33+
return resp;
34+
}
35+
36+
}
37+
38+
public async Task SendAsync(string phonenumber, string messagecontent)
39+
{
40+
using (var wb = new WebClient())
41+
{
42+
var url = new Uri("http://api.v2.masgsm.com.tr/v2/sms/basic");
43+
var data = new NameValueCollection();
44+
45+
data["originator"] = _title;
46+
data["message"] = messagecontent;
47+
data["encoding"] = "turkish"; // default , turkish , auto
48+
data["to"] = phonenumber;
49+
50+
wb.Headers.Add("Authorization", _password);
51+
var response = wb.UploadValues(url, "POST", data);
52+
string responseInString = Encoding.UTF8.GetString(response);
53+
Console.WriteLine(responseInString);
54+
}
55+
}
56+
}
57+
}

Providers/NetGsmProvider.cs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using EB2B.SMS.Helper;
2+
using System;
3+
using System.Net;
4+
using System.Threading.Tasks;
5+
6+
namespace EB2B.SMS.Providers
7+
{
8+
public class NetGsmProvider : ISmsProvider
9+
{
10+
private string _username { get; set; }
11+
private string _password { get; set; }
12+
private string _title { get; set; }
13+
14+
15+
public NetGsmProvider(string username, string password,string title)
16+
{
17+
if (username == null)
18+
throw new ArgumentException("Username null error");
19+
if (password == null)
20+
throw new ArgumentException("password null error");
21+
if (title == null)
22+
throw new ArgumentException("title null error");
23+
24+
this._username = username;
25+
this._password = password;
26+
this._title = title;
27+
28+
}
29+
30+
31+
public async Task SendAsync(string phonenumber, string messagecontent)
32+
{
33+
34+
if (phonenumber.Length != 11)
35+
throw new ArgumentException("Telefon numarası uyumlu değil : " + phonenumber);
36+
37+
string dt = "";
38+
dt += "<?xml version='1.0' encoding='UTF-8'?>";
39+
dt += "<mainbody>";
40+
dt += "<header>";
41+
dt += "<company dil='TR'>Netgsm</company>";
42+
dt += $"<usercode>{_username}</usercode>";
43+
dt += $"<password>{_password}</password>";
44+
dt += "<type>1:n</type>";
45+
dt += $"<msgheader>{_title}</msgheader>";
46+
dt += "</header>";
47+
dt += "<body>";
48+
dt += "<msg>";
49+
dt += $"<![CDATA[{messagecontent}]]>";
50+
dt += "</msg>";
51+
dt += $"<no>{phonenumber}</no>";
52+
dt += "</body> ";
53+
dt += "</mainbody>";
54+
55+
56+
string getData = await SmsHelper.Post("https://api.netgsm.com.tr/sms/send/xml", dt);
57+
if (getData == "-1")
58+
throw new ArgumentException("Servis Hatası");
59+
60+
string getCode = getData.Split(' ')[0].ToString();
61+
62+
63+
if (getCode == "00" || getCode == "01" || getCode == "02")
64+
{
65+
string Id = getData.Split(' ')[1].ToString();
66+
}
67+
else if (getCode == "20")
68+
throw new ArgumentException("Mesaj metninde ki problemden dolayı gönderilemediğini veya standart maksimum mesaj karakter sayısını geçti.");
69+
else if (getCode == "30")
70+
throw new ArgumentException("Geçersiz kullanıcı adı , şifre veya kullanıcınızın API erişim iznininiz bulunmamakta.");
71+
else if (getCode == "40")
72+
throw new ArgumentException("Mesaj başlığınızın (gönderici adınızın) sistemde tanımlı değil. ");
73+
else if (getCode == "70")
74+
throw new ArgumentException("Hatalı sorgulama. Gönderdiğiniz parametrelerden birisi hatalı veya zorunlu alanlardan birinin eksik. ");
75+
else
76+
throw new ArgumentException("Bilinmeyen bir hata oluştu");
77+
78+
79+
}
80+
81+
public async Task<double> GetCreditAsync()
82+
{
83+
string getData = new WebClient().DownloadString($"https://api.netgsm.com.tr/balance/list/get/?usercode={_username}&password={_password}");
84+
85+
if (getData.Split(' ')[0].ToString() == "00")
86+
return double.Parse(getData.Split(' ')[1].ToString().Replace(',', '.'));
87+
else return 0;
88+
89+
}
90+
91+
}
92+
}

Providers/SmsVitriniProvider.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using EB2B.SMS.Helper;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace EB2B.SMS.Providers
8+
{
9+
public class SmsVitriniProvider : ISmsProvider
10+
{
11+
//http://www.smsvitrini.com.tr/cozumler/api
12+
private string _username { get; set; }
13+
private string _password { get; set; }
14+
private string _title { get; set; }
15+
16+
17+
public SmsVitriniProvider(string username, string password, string title)
18+
{
19+
this._username = username;
20+
this._password = password;
21+
this._title = title;
22+
}
23+
24+
public async Task SendAsync(string phonenumber, string messagecontent)
25+
{
26+
string getData = await SmsHelper.Post("http://api.smsvitrini.com/index.php", $"islem=1&user={_username}&pass={_password}&mesaj={messagecontent}&numaralar={phonenumber}&baslik={_title}");
27+
if (getData == "-1")
28+
throw new ArgumentException("Servis Hatası");
29+
}
30+
31+
public async Task<double> GetCreditAsync()
32+
{
33+
string getData = await SmsHelper.Post("http://api.smsvitrini.com/index.php", $"islem=2&user={_username}&pass={_password}");
34+
35+
string getCode = getData.Split(' ')[0].ToString();
36+
double Amount = 0;
37+
if (getCode == "00")
38+
{
39+
Amount = double.Parse(getData.Split(' ')[1].ToString());
40+
}
41+
42+
return Amount;
43+
}
44+
}
45+
}

SmsProviderFactory.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using EB2B.SMS.Providers;
2+
using System;
3+
4+
namespace EB2B.SMS
5+
{
6+
public class SmsProviderFactory : ISmsProviderFactory
7+
{
8+
public ISmsProvider Create(SmsTypes type, string username, string password, string title)
9+
{
10+
return type switch
11+
{
12+
SmsTypes.NETGSM => new NetGsmProvider(username, password, title),
13+
SmsTypes.MASGSM => new MasGsmProvider(username, password, title),
14+
SmsTypes.ILETIMERKEZI => new IletiMerkeziProvider(username, password, title),
15+
SmsTypes.SMSVITRINI => new SmsVitriniProvider(username, password, title),
16+
_ => throw new NotSupportedException("SMS Provider not found"),
17+
};
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)