Exemplo n.º 1
0
    protected void btnSend_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            try
            {
                SMSEntity sms = new SMSEntity();
                sms.MobilePhone     = txtMobile.Text.Trim();
                sms.Content         = txtContent.Text.Trim();
                sms.CaseNo          = txtCaseNo.Text.Trim();
                sms.IOC_Class_Alias = "ShangTong";
                TraceEntity result = SMS.Send(sms);

                if (!string.IsNullOrEmpty(result.ErrorMsg))
                {
                    this.lblResult.Text = result.ErrorMsg;
                }
                else
                {
                    this.lblResult.Text = "发送成功!";
                }
            }
            catch (Exception ee)
            {
                Common.LogIt(ee.ToString());
                this.lblResult.Text = ee.ToString();
            }
        }
    }
Exemplo n.º 2
0
        public async Task <SMSDto> UpdateSMS(SMSDto sms)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (sms != null)
                    {
                        SMSEntity entity = sms.ToModel();
                        entity.SMSId = sms.SMSId;
                        db.SMS.Attach(entity);
                        foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                        {
                            if (propName != "SMSId")
                            {
                                db.Entry(entity).Property(propName).IsModified = true;
                            }
                        }
                        await db.SaveChangesAsync();

                        return(entity.ToDto());
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Exemplo n.º 3
0
        public bool SMS_Insert(SMSEntity entity)
        {
            bool           isSuccess = false;
            SqlTransaction trans     = null;
            string         sql       = string.Empty;

            sql += " INSERT INTO M_SignSMS(Customer,Moblie,IsSend,Content,SendTime,SysUserID) ";
            sql += "             VALUES(@Customer,@Moblie,@IsSend,@Content,@SendTime,@SysUserID)";

            SqlParameter[] prms =
            {
                new SqlParameter("@Customer",  SqlDbType.NVarChar,  128),
                new SqlParameter("@Moblie",    SqlDbType.NVarChar,   64),
                new SqlParameter("@IsSend",    SqlDbType.Int),
                new SqlParameter("@Content",   SqlDbType.NVarChar, 1024),
                new SqlParameter("@SendTime",  SqlDbType.NVarChar,   48),
                new SqlParameter("@SysUserID", SqlDbType.Int),
                new SqlParameter("@ModelKey",  SqlDbType.VarChar, 24)
            };
            prms[0].Value = entity.Customer;
            prms[1].Value = entity.Moblie;
            prms[2].Value = entity.IsSend;
            prms[3].Value = entity.Content;
            prms[4].Value = entity.SendTime;
            prms[5].Value = entity.SysUserID;
            prms[6].Value = entity.ModelKey;
            try
            {
                using (SqlConnection conn = new SqlConnection(SQlHelper.MyConnectStr))
                {
                    conn.Open();
                    trans = conn.BeginTransaction();

                    SQlHelper.ExecuteScalar(trans, CommandType.Text, sql, prms);
                    isSuccess = true;
                    trans.Commit();
                }
            }
            catch (Exception ex)
            {
                try
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                }
                catch
                {
                    LogUtil.WriteLog(ex);
                    return(false);
                }

                return(false);
            }
            return(isSuccess);
        }
Exemplo n.º 4
0
 public static SMSDto ToDto(this SMSEntity sms)
 {
     return(new SMSDto()
     {
         DestinationNumber = sms.DestinationNumber,
         ExternalPrice = sms.ExternalPrice,
         LineId = sms.LineId,
         SMSId = sms.SMSId,
         //Line=sms.Line.ToDto()
     });
 }
Exemplo n.º 5
0
        public SMSEntity ConvertSMS(SMSModel originalSMS)
        {
            SMSEntity convertedSMS = new SMSEntity
            {
                SMSId             = originalSMS.Id,
                LineId            = originalSMS.LineId,
                DateCreated       = originalSMS.DateActivityMade,
                DestinationNumber = originalSMS.DestinationNumber
            };

            return(convertedSMS);
        }
Exemplo n.º 6
0
 public static SMSDto ToDto(this SMSEntity sms)
 {
     if (sms == null)
     {
         return(null);
     }
     return(new SMSDto()
     {
         DestinationNumber = sms.DestinationNumber,
         ExternalPrice = sms.ExternalPrice,
         LineId = sms.LineId,
         SMSId = sms.SMSId,
         Line = sms.Line.ToDto(),
         Time = sms.Time
     });
 }
Exemplo n.º 7
0
        public TraceEntity Send(SMSEntity entity)
        {
            TraceEntity result;

            try
            {
                //注入实例
                instance = container.Resolve <ISMS>(entity.IOC_Class_Alias);
            }
            catch (Exception e)
            {
                Common.LogIt(e.ToString());
                throw;
            }

            result = instance.Send(entity);
            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 发送短信信息。
        /// </summary>
        /// <param name="msgInfo"></param>
        /// <returns></returns>
        public bool SendMobileMessage(SMSEntity msgInfo)
        {
            try
            {
                string url = MB.Util.AppConfigSetting.GetKeyValue(REST_MOBILE_MESSAGE_CFG);
                if (string.IsNullOrEmpty(url))
                {
                    throw new APPException("SMSServiceCfg配置节点不能为空", APPMessageType.SysErrInfo);
                }

                RESTServiceHelper restService = new RESTServiceHelper();
                return(restService.PostDataAsJson <SMSEntity, bool>(url, msgInfo));
            }
            catch (Exception ex)
            {
                throw new MB.Util.APPException("手机短信REST发送失败:" + ex.ToString(), APPMessageType.SysErrInfo);
            }
        }
Exemplo n.º 9
0
        public TraceEntity Send(SMSEntity entity)
        {
            TraceEntity result = new TraceEntity();

            //使用BASE64对用户名转码
            String userID = Convert.ToBase64String(System.Text.ASCIIEncoding.Default.GetBytes("bbfd"));
            //使用BASE64对密码转码
            String pwd = Convert.ToBase64String(System.Text.ASCIIEncoding.Default.GetBytes("bbfd123"));
            //使用BASE64对短信内容进行转码
            String smsContent = Convert.ToBase64String(System.Text.ASCIIEncoding.Default.GetBytes(entity.Content));

            //调用接口类中的send方法发送短信

            try
            {
                String ret = ws.send(userID, pwd, entity.MobilePhone, smsContent, "", "");

                switch (ret)
                {
                case "100":
                    break;

                case "102":
                    result.ErrorMsg = "用户或密码错误";
                    break;

                case "103":
                    result.ErrorMsg = "余额不足";
                    break;

                default:
                    result.ErrorMsg = "未知错误(系统异常)";
                    break;
                }
            }
            catch
            {
                Common.LogIt(ws.Url);
                throw;
            }

            return(result);
        }
Exemplo n.º 10
0
    public static TraceEntity Send(SMSEntity entity)
    {
        TraceEntity result = new TraceEntity();

        try
        {
            result = new SMSFacade().Send(entity);
            if (string.IsNullOrEmpty(result.ErrorMsg))
            {
                Case.SetSMS(entity.CaseNo);
            }
        }
        catch (Exception ee)
        {
            Common.LogIt(ee.ToString());
            result.ErrorMsg = ee.Message;
        }

        return(result);
    }
Exemplo n.º 11
0
        public async Task <SMSDto> CreateSMS(SMSDto sms)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (sms != null)
                    {
                        SMSEntity entity = sms.ToModel();
                        db.SMS.Add(entity);
                        await db.SaveChangesAsync();

                        return(sms);
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Exemplo n.º 12
0
        public static void GetdataFromMySQL()
        {
            List <SMSEntity>       lstSMSEntity       = null;
            List <SMSSendResponse> lstSMSSendResponse = null;
            string                  SMSRequest        = string.Empty;
            string                  SMSResponse       = string.Empty;
            string                  UserName          = string.Empty;
            string                  Password          = string.Empty;
            string                  SMSURL            = string.Empty;
            int                     ID                  = 0;
            var                     Programcode         = string.Empty;
            var                     StoreCode           = string.Empty;
            var                     CampaignCode        = string.Empty;
            var                     MobileNumber        = string.Empty;
            var                     EmailID             = string.Empty;
            var                     MessageText         = string.Empty;
            var                     SenderId            = string.Empty;
            int                     ClientID            = 0;
            string                  apiResponse         = string.Empty;
            MySqlConnection         con                 = null;
            List <ListofSMSDetails> objListofSMSDetails = new List <ListofSMSDetails>();

            try
            {
                DataTable dt = new DataTable();

                IConfiguration config       = new ConfigurationBuilder().AddJsonFile("appsettings.json", true, true).Build();
                var            constr       = config.GetSection("ConnectionStrings").GetSection("HomeShop").Value;
                string         ClientAPIURL = config.GetSection("ConnectionStrings").GetSection("ClientAPIURL").Value;
                con = new MySqlConnection(constr);
                MySqlCommand cmd = new MySqlCommand("SP_HSGetDetailforSMSBroadcast", con)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                };
                cmd.Connection.Open();
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                da.Fill(dt);
                cmd.Connection.Close();
                lstSMSEntity = new List <SMSEntity>();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        ID           = Convert.ToInt32(dr["ID"]);
                        Programcode  = Convert.ToString(dr["Programcode"]);
                        StoreCode    = Convert.ToString(dr["StoreCode"]);
                        CampaignCode = Convert.ToString(dr["CampaignCode"]);
                        MobileNumber = Convert.ToString(dr["MobileNumber"]);
                        EmailID      = Convert.ToString(dr["EmailID"]);
                        MessageText  = Convert.ToString(dr["MessageText"]);
                        SenderId     = Convert.ToString(dr["SenderId"]);
                        ClientID     = Convert.ToInt32(dr["ClientID"]);
                        if (!String.IsNullOrEmpty(MessageText))
                        {
                            SMSEntity objSMSEntity = new SMSEntity()
                            {
                                SMSText      = MessageText,
                                SMSID        = ID.ToString(),
                                SMSSenderID  = SenderId,
                                MobileNumber = MobileNumber,
                                SMSSEQ       = ID.ToString()
                            };
                            lstSMSEntity.Add(objSMSEntity);
                        }
                        if (!String.IsNullOrEmpty(MessageText))
                        {
                            ListofSMSDetails listofSMSDetails = new ListofSMSDetails()
                            {
                                ID           = ID.ToString(),
                                Programcode  = Programcode,
                                MobileNumber = MobileNumber
                            };
                            objListofSMSDetails.Add(listofSMSDetails);
                        }
                    }

                    SMSRequest = SMSCore.PrepareBulkSMSXML(lstSMSEntity);
                    SMSSendResponse chatSendSMSResponse = new SMSSendResponse();
                    if (!string.IsNullOrEmpty(SMSRequest))
                    {
                        UserName    = config.GetSection("MySettings").GetSection("SMSAPIUserName").Value;
                        Password    = config.GetSection("MySettings").GetSection("SMSAPIPassword").Value;
                        SMSURL      = config.GetSection("MySettings").GetSection("SMSAPIURL").Value;
                        SMSResponse = SMSCore.ProcessBulkSMSXML(SMSRequest, UserName, Password, SMSURL);
                        if (!string.IsNullOrEmpty(SMSResponse))
                        {
                            lstSMSSendResponse = new List <SMSSendResponse>();
                            lstSMSSendResponse = SMSCore.ParseSendBulkSMSResponse(SMSResponse);

                            for (int j = 0; j < lstSMSSendResponse.Count; j++)
                            {
                                if (lstSMSSendResponse[j].ErrorCODE == null & lstSMSSendResponse[j].ErrorSEQ == null)
                                {
                                    string Responcetext = "Success";
                                    UpdateResponse(Convert.ToInt32(lstSMSSendResponse[j].ID), lstSMSSendResponse[j].SubmitDate, Responcetext, 1);

                                    try
                                    {
                                        ListofSMSDetails objSMSDetails = new ListofSMSDetails();
                                        objSMSDetails = objListofSMSDetails.Where(x => x.ID == lstSMSSendResponse[j].ID).FirstOrDefault();
                                        MakeBellActive(objSMSDetails.MobileNumber, objSMSDetails.Programcode, ClientAPIURL);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                                else
                                {
                                    string Responcetext = "Fail";
                                    UpdateResponse(Convert.ToInt32(lstSMSSendResponse[j].ID), lstSMSSendResponse[j].SubmitDate, Responcetext, 2);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
                GC.Collect();
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// 插入短信
 /// </summary>
 /// <param name="entity">短信信息</param>
 /// <returns></returns>
 public bool InsertSMS(SMSEntity entity)
 {
     return(SMSProcessor.Instance.InsertSMS(entity));
 }
Exemplo n.º 14
0
 public bool SMS_Insert(SMSEntity entity)
 {
     return(dao.SMS_Insert(entity));
 }
Exemplo n.º 15
0
        public string Add(HttpContext context) //发送短消息 send
        {
            try
            {
                string isExcel     = context.Request.Form["isExcel"];
                string txtPhone    = context.Request.Form["txtPhone"];
                string txtCustomer = context.Request.Form["txtCustomer"];
                string txtContent  = context.Request.Form["txtContent"];
                string sysUserID   = context.Request.Form["sUserID"];
                string modelKey    = context.Request.Form["modelKey"];
                string sendContent = string.Empty;
                int    sysID       = 0;
                int.TryParse(sysUserID, out sysID);
                if (string.IsNullOrEmpty(txtContent))
                {
                    return("false");
                }

                //获取和设置消息模板
                OperationResult <IList <SMSModeEntity> > result =
                    BCtrl_SignSMSModel.Instance.SignSMSModel_GetWhere(" AND ModelKey='" + modelKey + "' ");
                if (result.ResultType == OperationResultType.Success)
                {
                    IList <SMSModeEntity> entitys = result.AppendData;
                    if (entitys != null && entitys.Count != 0)
                    {
                        sendContent = entitys[0].ModelContent;
                    }
                    else
                    {
                        return("false");
                    }
                }

                if (isExcel == "0") //如果是单条信息
                {
                    SMSEntity entity = new SMSEntity();
                    entity.Customer  = txtCustomer;
                    entity.Moblie    = txtPhone;
                    entity.IsSend    = 1;
                    entity.SysUserID = sysID;
                    entity.Content   = txtContent.Trim();
                    entity.SendTime  = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    sendContent      = sendContent.Replace("{1}", entity.Customer);
                    sendContent      = sendContent.Replace("{2}", entity.Content);
                    bool isSend = SmsMananger.SendContent(entity.Moblie, modelKey, entity.Customer, entity.Content);
                    entity.Content = sendContent;
                    if (isSend)
                    {
                        BCtrl_SMS.Instance.SMS_Insert(entity);
                    }
                }
                else
                {
                    //查询出所有需要发送的数据
                    string strWhere = string.Empty;
                    strWhere = " AND  IsSend=0 AND SendTime IS NULL AND  Content IS NULL  AND SysUserID= " + sysUserID + " ";
                    IList <SMSEntity> entityList = BCtrl_SMS.Instance.SMS_GetALL(strWhere);
                    for (int i = 0; i < entityList.Count; i++)
                    {
                        //调用短信接口
                        string saveSend = sendContent.Replace("{1}", entityList[i].Customer);
                        saveSend = saveSend.Replace("{2}", txtContent.Trim());
                        bool isSend = SmsMananger.SendContent(entityList[i].Moblie, modelKey, entityList[i].Customer, txtContent.Trim());
                        entityList[i].Content = saveSend;
                        if (isSend)
                        {
                            //改变据库发送状态
                            BCtrl_SMS.Instance.SMS_Update(entityList[i].Content, 1, modelKey, entityList[i].SmsID);
                        }
                        else
                        {
                            BCtrl_SMS.Instance.SMS_Update(entityList[i].Content, 0, modelKey, entityList[i].SmsID);
                        }
                    }
                }
                return("true");
            }
            catch
            {
                return("false");
            }
        }
Exemplo n.º 16
0
        public string Import(HttpContext context)//导入数据
        {
            try
            {
                context.Response.ContentType = "text/plain";
                HttpPostedFile file      = context.Request.Files["Filedata"];
                string         suID      = context.Request.Form["sUserID"];
                string         customer  = string.Empty;//用于输出第一个客户的姓名
                int            sysUserID = 0;
                int.TryParse(suID, out sysUserID);
                string fileName = file.FileName;
                //string tempPath = AppDomain.CurrentDomain.BaseDirectory + "/UploadFile/" + "SMS/";  //设置短消息临时文件夹
                string tempPath = HttpContext.Current.Server.MapPath("~/UploadFile/SMS/");
                //创建目录
                if (!Directory.Exists(tempPath))
                {
                    Directory.CreateDirectory(tempPath);
                }
                fileName = System.IO.Path.GetFileName(fileName);                  //获取文件名(不带路径)
                string currFileExtension = System.IO.Path.GetExtension(fileName); //获取文件的扩展名
                string currFilePath      = tempPath + fileName;                   //获取上传后的文件路径 记录到前面声明的全局变量
                file.SaveAs(currFilePath);                                        //保存临时文件
                DataTable dt = ExcelToDataTable(fileName, currFilePath);
                for (int r = dt.Rows.Count - 1; r >= 0; r--)
                {
                    DataRow row = dt.Rows[r];
                    if (row["手机"].ToString().Trim() == "")
                    {
                        row.Delete();
                    }
                }
                dt.AcceptChanges();

                if (dt.Rows.Count > 0)
                {
                    customer = dt.Rows[0]["姓名"].ToString();
                }

                //清理上次操作未发送的数据
                BCtrl_SMS.Instance.SMS_Delete(sysUserID, 0, true);

                //入库
                string strWhere = "AND  IsSend=0 AND SendTime IS NULL AND  Content IS NULL  AND SysUserID={0} AND Moblie='{1}' ";
                foreach (DataRow item in dt.Rows)
                {
                    SMSEntity entity = new SMSEntity();
                    entity.Customer  = item["姓名"].ToString();
                    entity.Moblie    = item["手机"].ToString();
                    entity.IsSend    = 0;
                    entity.SendTime  = null;
                    entity.SysUserID = sysUserID;

                    //设定此用户还在发送状态,不写入库
                    IList <SMSEntity> entityList = BCtrl_SMS.Instance.SMS_GetALL(string.Format(strWhere, sysUserID, entity.Moblie));
                    if (entityList == null || entityList.Count == 0)
                    {
                        BCtrl_SMS.Instance.SMS_Insert(entity);
                    }
                }
                File.Delete(currFilePath);
                return("true_" + customer);
            }
            catch
            {
                return("false");
            }
        }