using RuralPower;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
internal class Program
{
//public static string GenerateRandomKey(int keyLength)
//{
// byte[] keyBytes = new byte[keyLength / 8];
// using (var rng = new RNGCryptoServiceProvider())
// {
// rng.GetBytes(keyBytes);
// }
// return Convert.ToBase64String(keyBytes);
//}
//// AES 密钥(必须是 16、24 或 32 字节)
//private static readonly byte[] key = Encoding.UTF8.GetBytes("kGBxaThxMCMGaysp");
//// 初始化向量 IV(必须是 16 字节)
//private static readonly byte[] iv = Encoding.UTF8.GetBytes("VXFxgTgcvSDEXHpC");
//public static string Encrypt(string plainText)
//{
// using (Aes aesAlg = Aes.Create())
// {
// aesAlg.Key = key;
// aesAlg.IV = iv;
// aesAlg.Mode = CipherMode.CBC;
// aesAlg.Padding = PaddingMode.PKCS7;
// // 创建加密器对象
// ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
// using (MemoryStream msEncrypt = new MemoryStream())
// {
// using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
// {
// using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
// {
// // 写入加密后的数据到内存流中
// swEncrypt.Write(plainText);
// }
// }
// // 返回加密后的数据的 Base64 字符串
// return Convert.ToBase64String(msEncrypt.ToArray());
// }
// }
//}
//public static string Decrypt(string cipherText)
//{
// byte[] cipherBytes = Convert.FromBase64String(cipherText);
// using (Aes aesAlg = Aes.Create())
// {
// aesAlg.Key = key;
// aesAlg.IV = iv;
// aesAlg.Mode = CipherMode.CBC;
// aesAlg.Padding = PaddingMode.PKCS7;
// // 创建解密器对象
// ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
// using (MemoryStream msDecrypt = new MemoryStream(cipherBytes))
// {
// using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
// {
// using (StreamReader srDecrypt = new StreamReader(csDecrypt))
// {
// // 读取解密后的数据
// return srDecrypt.ReadToEnd();
// }
// }
// }
// }
//}
///
/// 正常调用Get接口方法
///
///
///
public static string get_page(string post_url)
{
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding encoding = Encoding.UTF8;
// 准备请求...
try
{
// 设置参数
request = WebRequest.Create(post_url) as HttpWebRequest;
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.AllowAutoRedirect = true;
//默认值TimeOut:100 秒
//发送请求并获取相应回应数据
response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
//返回结果网页(html)代码
string content = sr.ReadToEnd();
string err = string.Empty;
return content;
}
catch (Exception ex)
{
return ex.Message;
}
}
static void Main(string[] args)
{
//var dic_name = Path.Combine("Upload", "Cable", DateTime.Now.ToString("yyyy-MM-dd"), "" + Path.DirectorySeparatorChar);
//var test = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Json", "FaultTree.json");
//Console.WriteLine(test);
//var url = ConfigurationManager.AppSettings["url"].ToString();
//var result = get_page(url);
//Console.WriteLine(result);
Console.ReadKey();
//decimal total = 2.097m;
//int parts = 2;
//decimal exactPart = Math.Floor(total / parts); // 计算完全整数部分
//decimal remainder = total % parts; // 计算余数
//// 分配第一份,包括整数部分和可能的余数
//decimal firstPart = exactPart + (remainder > 0 ? 1m : 0m);
//remainder -= (remainder > 0 ? 1m : 0m); // 如果有余数,从余数中减去已分配的部分
//// 第二份则直接是另一部分
//decimal secondPart = exactPart + (remainder > 0 ? 0m : 0m);
//decimal select_score_model = 2.097m;
//int numberOfQuestions = 4;
//// 计算基本的每题分数,这里先不考虑余数
//decimal baseScorePerQuestion = select_score_model / numberOfQuestions;
//// 计算剩余的分数,这部分将被加到第一题上
//decimal remainingScore = select_score_model - (baseScorePerQuestion * numberOfQuestions);
//// 确保每份分数只保留3位小数
//decimal scorePerQuestionRounded = Math.Round(baseScorePerQuestion, 3, MidpointRounding.AwayFromZero);
//// 第一题分数加上所有剩余的分数(由于之前已经四舍五入,这里直接加剩余Score即可)
//decimal firstQuestionScore = scorePerQuestionRounded + remainingScore;
//// 其他题目分数保持为四舍五入后的基本分数
//decimal otherQuestionScore = scorePerQuestionRounded;
//// 由于直接加剩余Score可能造成轻微的浮点运算误差,这里再次校正以确保总和正确
//if (Math.Abs(firstQuestionScore + (otherQuestionScore * (numberOfQuestions - 1)) - select_score_model) > 0.0001m)
//{
// // 这里理论上不应该进入,但如果因为浮点运算误差导致不等,可以通过直接赋值确保总和正确
// firstQuestionScore = select_score_model - (otherQuestionScore * (numberOfQuestions - 1));
//}
//// 输出结果
//Console.WriteLine($"第一题分数: {firstQuestionScore}, 其他题分数: {otherQuestionScore}");
//Console.ReadKey();
//string plainText = "x1uz@n+C";
//string encryptedText = Encrypt(plainText);
//Console.WriteLine("加密后的文本: " + encryptedText);
//string decryptedText = Decrypt(encryptedText);
//Console.WriteLine("解密后的文本: " + decryptedText);
//Console.ReadKey();
//string randomKey = GenerateRandomKey(512);
//RuralPowerAPI test = new RuralPowerAPI();
//var result = test.Login("http://172.16.1.253:5003", "ceshi1", "", "gwndjs2022%");
//var resu = test.GetTrainList("http://172.16.1.253:5000", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJVU0VSMjAyMjA0MjExNTE2MDg5NjI1IiwibmJmIjoxNzE2Mjc4MDk2LCJleHAiOjE3MTYyODg4OTYsImlhdCI6MTcxNjI3ODA5NiwiaXNzIjoieW91cl9pc3N1ZXIifQ.ixNccN6jufwnLm2hbhioXmoyQ7E10XN_1vjksFzO__w", "USER202204211516089625", "1", "10");
//var result = test.ChangePassword("http://172.16.1.253:5000", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJVU0VSMjAyMjA0MjExNTE2MDg5NjI1IiwibmJmIjoxNzEzNDkyMjQxLCJleHAiOjE3MTM1MDMwNDEsImlhdCI6MTcxMzQ5MjI0MSwiaXNzIjoieW91cl9pc3N1ZXIifQ.btET0utMtB9kJvjH1ajJrSz0ov_PDHw1KLeQou9qfTo", "wangtianxing", "kfb263", "kfb263");
//var resul1 = test.StartExam("http://172.16.1.253:5003", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJVU0VSMjAyMjA0MjExNTE2MDg5NjI1IiwibmJmIjoxNzEyODA2NTgzLCJleHAiOjE3MTI4MTczODMsImlhdCI6MTcxMjgwNjU4MywiaXNzIjoieW91cl9pc3N1ZXIifQ.wAc_GIx-evY4nEUJQFdFrWqlkmjobQFp0hY61bRVJFA", "c7080a513ec043f2baf695e866efcb67");
//var result = test.GetExam("http://172.16.1.253:5000", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJVU0VSMjAyMjA0MjExNTE2MDg5NjI1IiwibmJmIjoxNzEyNjQxNjkwLCJleHAiOjE3MTI2NDg4OTAsImlhdCI6MTcxMjY0MTY5MCwiaXNzIjoieW91cl9pc3N1ZXIifQ.6ZH006cuW5IEqu41MsQr92TAbSaUYcWp8DfNxHrnZdI", "USER202204211516089625");
//Console.WriteLine(result);
//Console.ReadKey();
//var result = test.UploadFile("http://192.168.1.213:8088", "c7080a513ec043f2baf695e866efcb67", "USER202204211516089625", "测试", "C:\\Users\\Public\\Nwt\\cache\\recv\\吕浩\\04_user-2022-08-18-52150s-800x600.mp4");
//Console.WriteLine(result);
//Font LabelFont = new Font("Adobe 黑体 Std R", 50); //设置字体、字号、是否加粗
//SolidBrush labelColor = new SolidBrush(Color.Black);//设置字体颜色
//MemoryStream ms = new MemoryStream(File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "/Img/BaseMap.jpg"));//底图
//Image imgSource = Image.FromStream(ms);//底图
//Graphics graphics = Graphics.FromImage(imgSource);//设置画图对象
//StringFormat sf = new StringFormat();//位置对象
//sf.Alignment = StringAlignment.Near;//左对齐,使用时看一下注释,尝试一下,和矩形框有关系
// //sf.Alignment = StringAlignment.Center;//居中
// //sf.Alignment = StringAlignment.Near;//右对齐
//Rectangle rt1 = new Rectangle(240, 155, imgSource.Width, imgSource.Height);//绘图区域框,0:x方向开始位置,20:y方向开始位置,宽和高是矩形的宽和高
//graphics.DrawString("台区二1#配变0.4kV411东线出线电缆", LabelFont, labelColor, rt1, sf);
//Rectangle rt2 = new Rectangle(240, 230, imgSource.Width, imgSource.Height);
//graphics.DrawString("台区二1#配变低压综合配电箱411熔断器", LabelFont, labelColor, rt2, sf);
//Rectangle rt3 = new Rectangle(240, 305, imgSource.Width, imgSource.Height);
//graphics.DrawString("台区二1#配变0.4kV411东线001#杆", LabelFont, labelColor, rt3, sf);
//Rectangle rt4 = new Rectangle(360, 380, imgSource.Width, imgSource.Height);
//graphics.DrawString("YJLV22-4*150/12米", LabelFont, labelColor, rt4, sf);
//Rectangle rt5 = new Rectangle(360, 455, imgSource.Width, imgSource.Height);
//graphics.DrawString("配电工程处", LabelFont, labelColor, rt5, sf);
//Rectangle rt6 = new Rectangle(240, 530, imgSource.Width, imgSource.Height);
//graphics.DrawString("2019年8月16日", LabelFont, labelColor, rt6, sf);
////graphics.DrawString("另一种写法,我在x、y位置", LabelFont, labelColor, x, y);//相对于左上角的x、y坐标
//imgSource.Save(AppDomain.CurrentDomain.BaseDirectory +"测试.jpg");
//graphics.Dispose();
}
}
}