From afabafaea89e4fb904f830aeb86ab68e2ce9a829 Mon Sep 17 00:00:00 2001 From: leesh Date: Tue, 2 Aug 2022 05:06:27 +0000 Subject: [PATCH] =?UTF-8?q?PMS(6431)=20:=20SMS=20=EB=B0=9C=EC=86=A1=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95=20(=EC=A0=84=EB=AC=B8?= =?UTF-8?q?=EA=B1=B4=EC=84=A4=EB=8F=84=20=EB=8F=99=EC=8B=9C=EC=97=90=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20=ED=95=B4=EC=95=BC=20=ED=95=A9=EB=8B=88?= =?UTF-8?q?=EB=8B=A4.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Base/Controller/ACommon.cs | 101 ++++++----------------- Base/Controller/BasePartialController.cs | 6 +- 2 files changed, 30 insertions(+), 77 deletions(-) diff --git a/Base/Controller/ACommon.cs b/Base/Controller/ACommon.cs index 6e1a939..3da7538 100644 --- a/Base/Controller/ACommon.cs +++ b/Base/Controller/ACommon.cs @@ -2069,96 +2069,47 @@ namespace NP.Base.Controllers } else if (type == 3) { - //SMS + //알림톡 -> SMS 발송으로 수정 var data = Dao.Get("users.byusernos", usernos); foreach (var u in data) { m.Users.Add(new MemoUser() { userno = u.userno, smstype = "S", isok = string.IsNullOrEmpty(u.mobile) ? -1 : 1, mobile = (u.mobile ?? "").Replace("-", "") }); } + //SMS 발송 - var t = GetConfig("talk"); - var talkurl = t.Split(',')[0]; - var talkid = t.Split(',')[1]; - var talkpw = t.Split(',')[2]; - var talkaccountkey = t.Split(',')[3]; - var talkaccountid = t.Split(',')[4]; - var talkprofilekey = t.Split(',')[5]; - var talksender = t.Split(',')[6]; System.Text.StringBuilder sb = new System.Text.StringBuilder(); + var cbnum = GetConfig("mtssendnum"); + var ismms = System.Text.Encoding.Default.GetBytes(m.mcontents).Length > 90; m.mcontents = (m.mcontents.Length > 1000 ? m.mcontents.Substring(0, 1000) : m.mcontents).Replace("\"", "'"); var us = m.Users.Where(w => w.isok == 1).ToList(); + + m.uno = SUserInfo.UserNo; + m.uip = GetUserIP(); + Dao.Insert("common.sms.in", m); + if (us.Count() > 0) { for (var i = 0; i < us.Count(); i++) { - if ((i + 1) % 100 == 1) - { - sb.Clear(); - sb.Append("["); - } - sb.Append("{\"message_type\": \"AT\", \"" + - "phn\": \"" + us[i].mobile.Replace("-", "") + "\", \"" + - "profile\": \"" + talkprofilekey + "\", \"" + - "reserveDt\": \"00000000000000\", \"" + - "smsLmsTit\": \"[영남건설기술교육원 알림톡]\", \"" + - "msg\": \"" + m.mcontents + "\",\"" + - "smsKind\": \""+(System.Text.Encoding.Default.GetBytes(m.mcontents).Length > 90 ? "L" : "S") +"\", \"" + - "msgSms\": \"" + m.mcontents + "\", \"" + - "smsSender\": \"" + talksender + "\", \"" + - "smsOnly\": \"Y\"" + - "},"); - if ((i + 1) % 100 == 0 || i == us.Count() - 1) - { - String rtntalk = ""; - System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(talkurl); - request.Method = "POST"; - request.ContentType = "application/json"; - request.Accept = "application/json"; - request.Headers.Add("userid", talkaccountid); - rtntalk = ApiCall(request, sb.ToString().Substring(0, sb.Length - 1) + "]"); - if (rtntalk.StartsWith("nptecherr:")) - { - foreach (var d in us) - { - d.isok = -2; - } - } - else - { - System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); - TalkRtn[] rtn = js.Deserialize(rtntalk.StartsWith("[") ? rtntalk : ("[" + rtntalk + "]")); - foreach (var d in rtn) - { - if (d.data == null) - { - foreach (var u2 in us) - { - u2.isok = 0; - } - } - else - { - var u = us.Where(w => w.mobile.Replace("-", "") == d.data.phn).FirstOrDefault(); - if (u != null) - { - u.msgid = d.data.msgid; - u.message = d.message; - if ("fail".Equals(d.code.ToLower())) - { - u.isok = 0; - } - } - } - } - } - } + + var phn = us[i].mobile.Replace("-", ""); + sb.Append(string.Format(",('{0}','{1}','{2}', now(),{5},'{3}','{4}')", phn, cbnum, m.mcontents, m.mno, us[i].userno, ismms ? 4 : 0)); } + + var strConn = GetConfig("mtsdb"); + using (var conn = new MySql.Data.MySqlClient.MySqlConnection(strConn)) + { + conn.Open(); + var cmd = new MySql.Data.MySqlClient.MySqlCommand("insert into mts_" + (ismms ? "m" : "s") + "ms_msg(tran_phone,tran_callback,tran_msg,tran_date,tran_type,tran_etc1,tran_etc2) values" + sb.ToString().Substring(1), conn); + cmd.ExecuteNonQuery(); + } + return JsonOK(Dao.Save("common.smsuser.in", m)); + } - m.uno = SUserInfo.UserNo; - m.uip = GetUserIP(); - Dao.Insert("common.sms.in", m); - Dao.Save("common.smsuser.in", m); - return JsonBack(new JsonRtn() { code = 1000, obj = us.Where(w => w.isok == 1).Count(), msg = string.Format("
전체대상: {0}
발송성공: {1}
휴대폰번호오류: {2}", data.Count(), us.Where(w => w.isok == 1).Count(), us.Where(w => w.isok != 1).Count()) }); + + return JsonOK(0); + + //return JsonBack(new JsonRtn() { code = 1000, obj = us.Where(w => w.isok == 1).Count(), msg = string.Format("
전체대상: {0}
발송성공: {1}
휴대폰번호오류: {2}", data.Count(), us.Where(w => w.isok == 1).Count(), us.Where(w => w.isok != 1).Count()) }); } else if (type == 1) { diff --git a/Base/Controller/BasePartialController.cs b/Base/Controller/BasePartialController.cs index 22e1464..eabf381 100644 --- a/Base/Controller/BasePartialController.cs +++ b/Base/Controller/BasePartialController.cs @@ -1442,13 +1442,15 @@ namespace NP.Base for (var i = 0; i < us.Count(); i++) { us[i].ismms = System.Text.Encoding.Default.GetBytes(us[i].mcontents).Length > 90; + var phn = us[i].mobile.Replace("-", ""); + if (us[i].ismms) { - sbm.Append(string.Format(",('{0}','{1}','{2}', now(),{5},'{3}','{4}')", us[i].mobile, cbnum, us[i].mcontents, m.mno, us[i].userno, us[i].ismms ? 4 : 0)); + sbm.Append(string.Format(",('{0}','{1}','{2}', now(),{5},'{3}','{4}')", phn, cbnum, us[i].mcontents, m.mno, us[i].userno, us[i].ismms ? 4 : 0)); } else { - sbs.Append(string.Format(",('{0}','{1}','{2}', now(),{5},'{3}','{4}')", us[i].mobile, cbnum, us[i].mcontents, m.mno, us[i].userno, us[i].ismms ? 4 : 0)); + sbs.Append(string.Format(",('{0}','{1}','{2}', now(),{5},'{3}','{4}')", phn, cbnum, us[i].mcontents, m.mno, us[i].userno, us[i].ismms ? 4 : 0)); } } var strConn = GetConfig("mtsdb");