using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Services;
using Newtonsoft.Json;
using NLog;
using RestSharp;

namespace HttpsTran
{
    /// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        private readonly Logger _logger = LogManager.GetCurrentClassLogger();
        public static string BaseURL = ConfigurationManager.AppSettings["BaoJing_BaseUrl"];
        [WebMethod]
        public string HelloWorld(string key, string data, string url)
        {
            try
            {
                if (key.Equals("C24cAfK"))
                {
                    //ssl 协议不兼容
                    var A = (SecurityProtocolType)48;
                    var B = (SecurityProtocolType)192;
                    var C = (SecurityProtocolType)768;
                    var D = (SecurityProtocolType)3072;
                    var E = (SecurityProtocolType)12288;
                    ServicePointManager.SecurityProtocol = A | B | C | D | E;
                    //BaseURL = "https://localhost:7009/";
                    var client123 = new RestClient(BaseURL);
                    //var request123 = new RestRequest("/order/checkOut", Method.POST);
                    var request123 = new RestRequest(url, Method.Post);
                    request123.AddHeader("Content-Type", "application/json");
                    //var N = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(data);
                    //var UUU = JsonConvert.SerializeObject(N);
                    _logger.Error("发送的数据为:"+data);
                    //request123.AddJsonBody(data);
                    request123.AddStringBody(data,DataFormat.Json);
                    var Response = client123.Execute(request123).Content;
                    string content12345 = Response;
                    return content12345;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
            }
            return "error";
        }
        [WebMethod()]
        public string HHH()
        {
            var Q = File.ReadAllText(Server.MapPath("1.txt"), Encoding.UTF8);
            var N = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(Q);
            var UUU = JsonConvert.SerializeObject(N);
            return "aaaaaaa";

        }
    }
    public class PMSDataBase
    {
        public string hotel_code { get; set; } = "";
        public string time { get; set; } = "";
        public string sign { get; set; } = "";
        public string hotel_id { get; set; } = "";
        public string order_no { get; set; } = "";
        public string room_no { get; set; } = "";
        public string check_out_original { get; set; }
    }
}
