示例#1
0
 /// <summary>
 /// 接收短信
 /// </summary>
 /// <returns>接收到的短信数量</returns>
 public int ReceiveSms()
 {
     EucpHelper oEucpHelper = new EucpHelper(ConfigHelper.EucpConfig.SerialNumber, ConfigHelper.EucpConfig.Password);
     List<object> oList = oEucpHelper.ReceiveSms();
     int nCount = 0;
     foreach (Dictionary<string, object> oMessage in oList)
     {
         GeneralMessageReceive oReceive = new GeneralMessageReceive
         {
             SendFrom = oMessage["Mobile"].ToString(),
             Matter = oMessage["Content"].ToString(),
             SentTime = (DateTimeOffset)oMessage["SentTime"],
             GetFrom = oMessage["Channel"].ToString()
         };
         dbEntity.GeneralMessageReceives.Add(oReceive);
         dbEntity.SaveChanges();
         nCount++;
     }
     return nCount;
 }
示例#2
0
        /// <summary>
        /// 发送OpenShop中的手机短信
        /// </summary>
        private static void SendPending()
        {
            string strMyString = ConfigHelper.ConnectionString.MySqlString;
            if (String.IsNullOrEmpty(strMyString))
            {
                EventLog(string.Format("MySQL 连接字符串无效"));
                return;
            }
            try
            {
                MySqlHelper oMySqlHelper = new MySqlHelper(strMyString);
                EucpHelper oEucpHelper = new EucpHelper();
                int nCounter = 0;

                // 发送手机短信
                string sPending = "SELECT * FROM system_message_queue WHERE status = 1";
                Dictionary<int, int> oSendList = new Dictionary<int, int>();
                using (MySqlDataReader oDataReader = oMySqlHelper.ExecuteReader(sPending))
                {
                    if (oDataReader.HasRows)
                    {
                        while (oDataReader.Read())
                        {
                            int nMsgID = (int)oDataReader["id"];
                            string strMsgType = oDataReader["msg_type"].ToString().Trim();
                            string strMobile = oDataReader["target_ids"].ToString();
                            string strContent = oDataReader["msg_content"].ToString();
                            string strMsgName = oDataReader["msg_name"].ToString();
                            string strOrderSn = oDataReader["order_sn"].ToString();
                            int nResult = -1;
                            if (strMsgType == "1")             // 发送邮件
                            {
                                nResult = MailHelper.SendMail(ConfigHelper.SmtpConfig.Sender, ConfigHelper.SmtpConfig.From,
                                    strMobile, "筑巢家居商城订单号:" + strOrderSn, strContent);
                            }
                            else if (strMsgType == "2")        // 发送短信
                            {
                                strContent = strContent.Replace("<p>", "");
                                strContent = strContent.Replace("</p>", "");
                                nResult = oEucpHelper.SendSms(strMobile, strContent);
                            }
                            oSendList.Add(nMsgID, nResult);
                            nCounter++;
                        }
                    }
                    oDataReader.Close();
                }

                // 检测余额
                string strBalance = oEucpHelper.GetBalance().ToString();

                // 更新已发送状态
                foreach (int nKey in oSendList.Keys)
                {
                    string strUpdateStatus = "UPDATE system_message_queue SET status = 3, msg_desc = '" + oSendList[nKey].ToString() + ":" + strBalance + "', send_time = NOW() WHERE id = " + nKey.ToString();
                    oMySqlHelper.ExecuteNonQuery(strUpdateStatus);
                }
                EventLog(string.Format("已发送{0}条手机短信/邮件", nCounter));
                nCounter = 0;

                // 接收手机短信
                List<object> oGetList = oEucpHelper.ReceiveSms();
                foreach (Dictionary<string, object> oMessage in oGetList)
                {
                    string strInsertMessage = "INSERT INTO system_message_receive (mobileNumber, smsContent, sentTime, channelNumber) " +
                        " VALUES ('" + oMessage["Mobile"].ToString() + "', '" + oMessage["Content"].ToString() + "', '" +
                        oMessage["SentTime"].ToString() + "', '" + oMessage["Channel"].ToString() + "')";
                    oMySqlHelper.ExecuteNonQuery(strInsertMessage);
                    nCounter++;
                }
                EventLog(string.Format("已接收{0}条手机短信", nCounter));
            }
            catch (Exception ex)
            {
                EventLog(string.Format("SendPending 出现错误 {0}", ex.Message));
            }
        }
示例#3
0
文件: Form1.cs 项目: NH4CL/UniProject
 private bool Connect()
 {
     bool bResult = false;
     if (objEucpHelper == null)
         bDirty = true;
     if (bDirty)
     {
         if (!String.IsNullOrEmpty(txtSerialNumber.Text) && !String.IsNullOrEmpty(txtPassword.Text))
         {
             try
             {
                 objEucpHelper = new EucpHelper(txtSerialNumber.Text.Trim(), txtPassword.Text.Trim());
                 if (objEucpHelper != null)
                 {
                     bDirty = false;
                     bResult = true;
                 }
             }
             catch
             {
                 bDirty = true;
                 bResult = false;
             }
         }
     }
     else
     {
         bResult = true;
     }
     return bResult;
 }
示例#4
0
 /// <summary>
 /// 发送手机短信
 /// </summary>
 /// <param name="pReceivers">接收人手机号,可用逗号分隔最多20个手机号</param>
 /// <param name="pContent">短信内容,长短信最多970个字节,超出部分可能被舍弃</param>
 /// <returns>返回值,0表示发送成功</returns>
 public int SendSms(string pReceivers, string pContent)
 {
     EucpHelper oEucpHelper = new EucpHelper(ConfigHelper.EucpConfig.SerialNumber, ConfigHelper.EucpConfig.Password);
     int nResult = oEucpHelper.SendSms(pReceivers, pContent);
     return nResult;
 }
示例#5
0
 /// <summary>
 /// 批量发送待发送短信,由定时器在特定时间段内(白天)调用
 /// </summary>
 /// <returns>发送短信数量</returns>
 public int SendPendingSms()
 {
     var oPending = (from p in dbEntity.GeneralMessagePendings
                     where p.Deleted == false
                           && p.Mtype == (byte)ModelEnum.MessageType.SMS
                           && p.Mstatus == (byte)ModelEnum.MessageStatus.PENDING
                     select p).ToList();
     EucpHelper oEucpHelper = new EucpHelper(ConfigHelper.EucpConfig.SerialNumber, ConfigHelper.EucpConfig.Password);
     int nCount = 0;
     foreach (var oMessage in oPending)
     {
         if (!String.IsNullOrEmpty(oMessage.Recipient) && !String.IsNullOrEmpty(oMessage.Matter))
         {
             int nResult = oEucpHelper.SendSms(oMessage.Recipient, oMessage.Matter);
             if (nResult == 0)
             {
                 oMessage.Mstatus = (byte)ModelEnum.MessageStatus.SENDSUCCESS;
                 oMessage.SentTime = DateTimeOffset.Now;
             }
             else
             {
                 oMessage.Mstatus = (byte)ModelEnum.MessageStatus.SENDFAILED;
                 oMessage.SentTime = DateTimeOffset.Now;
                 oMessage.Remark = String.Format("{0} Send Failed: {1}", oMessage.Remark, nResult);
             }
             nCount++;
         }
     }
     dbEntity.SaveChanges();
     return nCount;
 }