Example #1
0
        /// <summary>
        /// 发送命令并返回新增命令的id,外部捕获这个id并轮询这条命令的发送状态
        /// </summary>
        /// <param name="Sim">sim卡号码(11位数字,everdigm的sim卡号码后面带三个0,如89001435000)</param>
        /// <param name="Content">命令内容</param>
        /// <param name="sender">命令发送者的ID</param>
        /// <returns>命令记录的id,后续通过这个id查询命令状态</returns>
        private static int SendSMSCommand(TB_Terminal terminal, string Content, int sender)
        {
            string simno = terminal.Sim;

            // 判断Unitel的卡号,前面两位是89,且长度是8位数字
            simno = simno[0] == '8' && simno[1] == '9' ? simno.Substring(0, 8) : simno;
            string ret = SMSUtility.SendSMS(simno, Content);

            using (var bll = new CommandBLL())
            {
                // 查看发送成功与否的状态
                CommandStatus cs = ret.Equals("SUCCESS") ? CommandStatus.SentBySMS : CommandStatus.SentFail;

                // 新建一个命令发送类实体
                TB_Command ct = bll.GetObject();
                simno             = (simno[0] == '8' && simno[1] == '9' && simno.Length < 11) ? (simno + "000") : simno;
                ct.DestinationNo  = simno;
                ct.Status         = (byte)cs;
                ct.Content        = Content;
                ct.ActualSendTime = DateTime.Now;
                ct.Terminal       = terminal.id;
                ct.SendUser       = (0 == sender ? (int?)null : sender);

                var id = bll.Add(ct).id;
                // 保存终端的命令发送条数

                return(id);
            }
        }
Example #2
0
        /// <summary>
        /// 直接发送SMS命令
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns>返回发送是否成功</returns>
        public static bool SendSMSCommand(TB_Command cmd)
        {
            string simno = cmd.DestinationNo;

            // 判断Unitel的卡号,前面两位是89,且长度是8位数字
            simno = simno[0] == '8' && simno[1] == '9' ? simno.Substring(0, 8) : simno;
            string ret = SMSUtility.SendSMS(simno, cmd.Content);
            // 查看发送成功与否的状态
            CommandStatus cs = ret.Equals("SUCCESS") ? CommandStatus.SentBySMS : CommandStatus.SentFail;

            new CommandBLL().Update(f => f.id == cmd.id, act =>
            {
                act.Status         = (byte)cs;
                act.ActualSendTime = DateTime.Now;
            });
            return(cs == CommandStatus.SentBySMS);
        }