using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Web; using System.Net; using System.IO; using System.Threading.Tasks; namespace SignusKHSVR { public class SFLogApi { public void Run() { U3Database db = new U3Database(); string strSQL = ""; strSQL = "select * from T_SYS_LOG_SF where SEND_YN = 'N' and logDt >= '2022-12-01 00:00:00' "; DataTable dt = db.OpenSQL(strSQL); foreach(DataRow dr in dt.Rows) { string crtfcKey = "$5$API$1WbqYTUStuf.RwPb2dgv//OCyn//FDtEWyIAFQQhvE/"; string idx = U3Util.toStr(dr["IDX"]); string logDt = U3Util.toStr(dr["logDt"]); string useSe = U3Util.toStr(dr["useSe"]); string sysUser = U3Util.toStr(dr["sysUser"]); string conectIp = U3Util.toStr(dr["conectIp"]); string dataUsgqty = U3Util.toStr(dr["dataUsgqty"]); if (sysUser.Length == 0) sysUser = "houghton"; string strJson = ""; strJson += "{"; strJson += "\"crtfcKey\":\"" + crtfcKey + "\","; strJson += "\"logDt\":\"" + logDt + "\","; strJson += "\"useSe\":\"" + useSe + "\","; strJson += "\"sysUser\":\"" + sysUser + "\","; strJson += "\"conectIp\":\"" + conectIp + "\","; strJson += "\"dataUsgqty\":\"" + dataUsgqty + "\""; strJson += "}"; string strJsonEnc = HttpUtility.UrlEncode(strJson); string strUrl = "https://log.smart-factory.kr/apisvc/sendLogDataJSON.do?logData="; string strSend = strUrl + strJsonEnc; string strRecv = HttpGet(strSend); //string strUrl = "https://log.smart-factory.kr/apisvc/sendLogData.json"; //string strSend = strJson; //string strRecv = HttpPost(strUrl, strSend); string sql1 = ""; sql1 += " update T_SYS_LOG_SF set SEND_YN = 'Y', "; sql1 += " SEND_DATA = '" + strSend + "', "; sql1 += " RECV_DATA = '" + strRecv + "' "; sql1 += " where IDX = " + idx; db.ExcuteSql(sql1); } } private string HttpGet(string strUrl) { try { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(strUrl); httpWebRequest.Method = "GET"; httpWebRequest.Timeout = 5000; var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { string result = streamReader.ReadToEnd(); return result; } } catch (Exception ex) { U3Util.ErrorLog(ex.Message); return ""; } } private string HttpPost(string strUrl, string strSend) { try { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(strUrl); httpWebRequest.Method = "POST"; //httpWebRequest.ContentType = "application/json; charset=utf-8"; httpWebRequest.ContentType = "application/x-www-form-urlencoded; charset=utf-8"; httpWebRequest.Timeout = 5000; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { byte[] byteArray = Encoding.UTF8.GetBytes(strSend); char[] charArray = Encoding.Default.GetChars(byteArray); streamWriter.Write(charArray, 0, charArray.Length); //streamWriter.Write(strSend); streamWriter.Flush(); streamWriter.Close(); var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { string result = streamReader.ReadToEnd(); return result; } } } catch (Exception ex) { U3Util.ErrorLog(ex.Message); return ""; } } } }