first commit
This commit is contained in:
73
Complex.Infrastructure/SmsService.cs
Normal file
73
Complex.Infrastructure/SmsService.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Complex.Application.Services.Utility;
|
||||
using Flurl.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Complex.Infrastructure
|
||||
{
|
||||
public class SmsService : ISendUserMessage
|
||||
{
|
||||
private string token = "AccessKey jhVG8oE8XSE7YNAWjQcFO-cY7QBykZlSZ_Ymb98A8k8=";
|
||||
private string url = "http://rest.ippanel.com";
|
||||
private string originator = "+98100020400";
|
||||
//private string originator = "+985000262810";
|
||||
|
||||
private FlurlClient _client = null;
|
||||
public FlurlClient Client
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_client == null)
|
||||
{
|
||||
_client = new FlurlClient(url).WithHeader("Authorization", token).AllowHttpStatus("4xx");
|
||||
_client.BaseUrl = url;
|
||||
}
|
||||
return _client;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Response<T>> BaseSend<T>(string urlPath, object postData) where T : Data, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await Client.Request(urlPath)
|
||||
.PostJsonAsync(postData);
|
||||
|
||||
return await response.GetJsonAsync<Response<T>>();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var data = new T { error = ex.Message };
|
||||
return new Response<T> { data = data };
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Response<SendData>> Send(object message, string[] to)
|
||||
{
|
||||
var postData = new
|
||||
{
|
||||
originator = originator,
|
||||
recipients = to,
|
||||
message = message
|
||||
};
|
||||
|
||||
return await BaseSend<SendData>("/v1/messages", postData);
|
||||
}
|
||||
|
||||
public async Task<Response<SendData>> SendPattern(string patternCode, string to, object values)
|
||||
{
|
||||
var postData = new
|
||||
{
|
||||
pattern_code = patternCode,
|
||||
originator = originator,
|
||||
recipient = to,
|
||||
values = values
|
||||
};
|
||||
|
||||
return await BaseSend<SendData>("/v1/messages/patterns/send", postData);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user