Ejemplo n.º 1
0
        /// <summary>
        /// 停止服务
        /// </summary>
        /// <returns></returns>
        public bool StopSerice()
        {
            isStart = false;
            int rst = SmsFun.SMSStopSerice();

            return(rst == 0 ? false : true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 异步发送短信(网关使用)
        /// </summary>
        /// <param name="Content"></param>
        /// <param name="MPhone"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool SendMessage(List <string> listReceipts, string Content, out string msg)
        {
            msg = "";
            int nPort = CommFunc.ConvertDBNullToInt32(ComSmsConfig.ComSms);

            if (nPort == 0)
            {
                msg = "发送短息端口不能为空";
                return(false);
            }
            ;
            if (isStart == false)
            {
                ChkPort();
                SmsFun.SMSStopSerice();                          /*关闭服务*/
                int rst = SmsFun.SMSStartService((UInt32)nPort); /*打开服务*/
                msg     = rst == 0 ? "启动失败:未连接好设备或者波特率错误" : "";
                isStart = rst == 0 ? false : true;
                if (rst == 0)
                {
                    return(false);
                }
            }

            bool sue = false;

            foreach (string mpone in listReceipts)
            {
                System.Threading.Thread.Sleep(50);
                UInt32 index = SmsFun.SMSSendMessage(Content, mpone);
                System.Threading.Thread.Sleep(50);
                int ss   = SmsFun.SMSQuery(index);
                int time = 0;
                while (time <= 3000 && ss != 1)
                {
                    System.Threading.Thread.Sleep(1000);
                    ss   = SmsFun.SMSQuery(index);
                    time = time + 1000;
                    if (ss == 1)
                    {
                        break;
                    }
                }
                if (ss == 0)
                {
                    if (!string.IsNullOrEmpty(msg))
                    {
                        msg = msg + ",";
                    }
                    msg = msg + mpone + "发送短信失败";
                }
                if (sue == false)
                {
                    sue = (ss == 0 ? false : true);
                }
            }
            isStart = sue;
            return(sue);
        }