using Newtonsoft.Json.Linq;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using Newtonsoft.Json;
using System.IO;
using System.Net;
private static readonly string DefaultUserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36";
private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
public static string Base64Encode(Encoding encodeType, string source)
{
string encode = string.Empty;
byte[] bytes = encodeType.GetBytes(source);
try
{
encode = Convert.ToBase64String(bytes);
}
catch
{
encode = source;
}
return encode;
}
public static string PostToYS(string access_token, string account, string year, string ystype)
{
try
{
string returnjsonlist = "";
var dataset = HLYSetCode.FindAll("", "", "", 0, 0);
string url = System.Configuration.ConfigurationManager.AppSettings["HLYGetYSURL"];
JObject patientinfo = new JObject();
JObject patientinfolist = new JObject();
JArray queryLineList1 = new JArray();
JArray queryLineList2 = new JArray();
JArray queryParameterList1 = new JArray();
JArray queryParameterList2 = new JArray();
JObject user = new JObject();
JObject user1 = new JObject();
JObject userB = new JObject();
JObject userB1 = new JObject();
user1["parameterValueCode"] = account + ystype;
queryParameterList1.Add(user1);
user["parameterType"] = "BGT_RULE_PARAMETER_BUDGET";
user["parameterCode"] = "BUDGET_ITEM";
user["isAll"] = dataset[0].IsAll;
user["queryParameterList"] = queryParameterList1;
queryLineList1.Add(user);
userB1["parameterValueCode"] = ystype;
queryParameterList2.Add(userB1);
userB["parameterType"] = "BGT_RULE_PARAMETER_DIM";
userB["parameterCode"] = "2";
userB["isAll"] = "false";
userB["queryParameterList"] = queryParameterList2;
queryLineList1.Add(userB);
patientinfo["companyCode"] = dataset[0].CompanyCode;
patientinfo["organizationCode"] = dataset[0].OrganizationCode;
patientinfo["scenarioCode"] = dataset[0].ScenarioCode;
patientinfo["versionCode"] = dataset[0].VersionCode;
patientinfo["structureCode"] = dataset[0].StructureCode;
patientinfo["conditionCode"] = dataset[0].ConditionCode;
patientinfo["conditionName"] = dataset[0].ConditionName;
patientinfo["periodSummaryFlag"] = dataset[0].PeriodSummaryFlag;
patientinfo["amountQuarterFlag"] = dataset[0].AmountQuarterFlag;
patientinfo["yearLimit"] = year;
patientinfo["periodLowerLimit"] = year + "-01";
patientinfo["periodUpperLimit"] = year + "-12";
patientinfo["versionNumber"] = Convert.ToInt32(dataset[0].VersionNumber);
patientinfo["queryLineList"] = queryLineList1;
string body = JsonConvert.SerializeObject(patientinfo);
HttpWebRequest request = null;
CookieContainer cookie = new CookieContainer();
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
request = WebRequest.Create(url) as HttpWebRequest;
request.CookieContainer = cookie;
request.ProtocolVersion = HttpVersion.Version11;
request.Method = "POST";
request.ContentType = "application/json";
request.UserAgent = DefaultUserAgent;
request.KeepAlive = true;
request.Headers["Authorization"] = "Bearer " + access_token;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
byte[] byteData = Encoding.UTF8.GetBytes(body);
int length = byteData.Length;
request.ContentLength = length;
using (Stream stream = request.GetRequestStream())
{
stream.Write(byteData, 0, byteData.Length);
}
var response = (HttpWebResponse)request.GetResponse();
using (StreamReader st = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")))
{
returnjsonlist = st.ReadToEnd().ToString();
JObject jo = (JObject)JsonConvert.DeserializeObject(returnjsonlist);
access_token = jo["message"].ToString();
}
return returnjsonlist;
}
catch (Exception ex)
{
string err = ex.Message;
return string.Empty;
}
}
|