This commit is contained in:
2020-11-03 19:16:19 +03:00
commit b86507ccd7
6 changed files with 261 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30320.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Covid-Record", "Covid-Record\Covid-Record.csproj", "{C6056CE1-CEE0-4EC4-9717-E61B8A3D9DD6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C6056CE1-CEE0-4EC4-9717-E61B8A3D9DD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6056CE1-CEE0-4EC4-9717-E61B8A3D9DD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6056CE1-CEE0-4EC4-9717-E61B8A3D9DD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6056CE1-CEE0-4EC4-9717-E61B8A3D9DD6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {80533E98-F094-49A1-9816-B33937498F12}
EndGlobalSection
EndGlobal
+13
View File
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Covid_Record</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Telegram.Bot" Version="15.7.1" />
</ItemGroup>
</Project>
+94
View File
@@ -0,0 +1,94 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
namespace Covid_Record
{
public class CovidAvailability
{
private readonly TelegramBot _telegram;
public CovidAvailability(TelegramBot telegram)
{
_telegram = telegram;
}
public string GetSession(string phone, string password)
{
var content = "{\"auth\":{\"login\":\"" + phone + "\",\"password\":\"" + password +"\",\"guid\":\"" + Guid.NewGuid() + "\"}}";
var sessionResponse = Post("https://emp.mos.ru/v1.1/auth/virtualLogin?token=887033d0649e62a84f80433e823526a1", content);
dynamic data = JsonConvert.DeserializeObject(sessionResponse);
var sessionId = (data.session_id.Value as string);
return sessionId;
}
public bool IsAvailable(string session, int? patient)
{
//2010 - covid
//2004 - Пост - для теста
var specialityCode = "2010";
var patientId = patient.Value;
var json =
"{ \"patient_id\":\"" + patientId + "\",\"speciality_code\":\"" + specialityCode + "\",\"auth\":{ \"session_id\":\"" + session + "\"} }";
var response = Post("https://emp.mos.ru/v1.1/doctor/getDoctors?token=887033d0649e62a84f80433e823526a1",
json);
var responseJson = JsonConvert.DeserializeObject<EMaisAnswer>(response);
Console.WriteLine($"[{DateTime.Now}] {responseJson.errorCode}: {responseJson.errorMessage}");
if (responseJson.errorCode == 0)
{
var sb = new StringBuilder();
foreach (var clinic in responseJson.result.clinics)
{
sb.AppendLine($"Клиника: {clinic.address}");
foreach (var doctorsInfo in clinic.doctors_info)
{
sb.AppendLine($"- {doctorsInfo.availability_date}: {doctorsInfo.last_name} {doctorsInfo.first_name} {doctorsInfo.second_name}");
}
}
Console.WriteLine(sb.ToString());
_telegram.SendMessage(sb.ToString());
}
return true;
}
public string Post(string url, string content, string contentType = "application/json")
{
var httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.ContentType = contentType;
httpRequest.Method = "POST";
httpRequest.CookieContainer = new CookieContainer();
httpRequest.Headers.Add("User-Agent", "okhttp/4.2.2");
//httpRequest.CookieContainer.Add(new Cookie { Name = "WILDAUTHNEW_V3", Value = session, Domain = "wildberries.ru" });
using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream()))
{
streamWriter.Write(content);
}
var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
return result;
}
}
public int? GetPatient(string session)
{
var content = "{\"auth\":{\"session_id\":\"" + session + "\"}}";
var patientResponse = Post("https://emp.mos.ru/v1.1/patient/get?token=887033d0649e62a84f80433e823526a1", content);
var data = JsonConvert.DeserializeObject<PatientResponse>(patientResponse);
return data?.result.First().id;
}
}
}
+64
View File
@@ -0,0 +1,64 @@
using System.Collections.Generic;
namespace Covid_Record
{
public class EMaisAnswer
{
public int errorCode { get; set; }
public Result result { get; set; }
public string errorMessage { get; set; }
public double execTime { get; set; }
public string request_id { get; set; }
public string session_id { get; set; }
}
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class DoctorsInfo
{
public string availableResourceId { get; set; }
public string complexResourceId { get; set; }
public string first_name { get; set; }
public string second_name { get; set; }
public string last_name { get; set; }
public string availability_date { get; set; }
public string room { get; set; }
public string clinic { get; set; }
public string code { get; set; }
}
public class Clinic
{
public string clinic { get; set; }
public string address { get; set; }
public List<DoctorsInfo> doctors_info { get; set; }
}
public class Result
{
public List<Clinic> clinics { get; set; }
}
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class Patient
{
public string oms_number { get; set; }
public string birthdate { get; set; }
public int id { get; set; }
public string lastname { get; set; }
public string firstname { get; set; }
public string middlename { get; set; }
}
public class PatientResponse
{
public int errorCode { get; set; }
public List<Patient> result { get; set; }
public string errorMessage { get; set; }
public double execTime { get; set; }
public string request_id { get; set; }
public string session_id { get; set; }
}
}
+33
View File
@@ -0,0 +1,33 @@
using System;
using System.Threading;
namespace Covid_Record
{
class Program
{
static void Main(string[] args)
{
var telegram = new TelegramBot();
var arr = new CovidAvailability(telegram);
var phone = "79160000000";
var password = "testpwd";
var session = arr.GetSession(phone, password);
var patient = arr.GetPatient(session);
if (patient == null)
{
Console.WriteLine("Не могу получить ID пациента.");
Console.ReadLine();
return;
}
while (true)
{
arr.IsAvailable(session, patient);
Thread.Sleep(TimeSpan.FromSeconds(4));
}
}
}
}
+32
View File
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;
using Telegram.Bot;
namespace Covid_Record
{
public class TelegramBot
{
private TelegramBotClient _telegram;
public string Token => "1479535614:AAFqHdsUFikzOti0zknK_pN2sEONNAXecPY";
public long MainChatId;
public TelegramBot(long chatId = -415825856)
{
MainChatId = chatId;
_telegram = new TelegramBotClient(Token);
_telegram.OnMessage += Bot_OnMessage;
_telegram.StartReceiving();
}
public void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
{
Console.WriteLine($"[{e.Message.Chat.Id}, user: {e.Message.From.Id}] @{e.Message.From?.Username}: {e.Message.Text}");
}
public void SendMessage(string message, long? chatId = null)
{
_telegram.SendTextMessageAsync(chatId ?? MainChatId, message).GetAwaiter().GetResult();
}
}
}