Ejemplo n.º 1
0
        /// <summary>
        /// 短信发送
        /// </summary>
        /// <param name="tel"></param>
        /// <param name="content"></param>
        /// <param name="res"></param>
        /// <returns></returns>
        public LocalErrCode SendMsg(string tel, string content, out CMPP_SUBMIT_RESP res, string spNumber = null)
        {
            if (spNumber == null)
            {
                spNumber = spPhoneNumber;
            }

            CMPP_SUBMIT[] subMsg = CreateSubmitMsg(serviceId, spId, spNumber, tel, content);
            //服务器响应
            CMPPMsgBody_Base resp     = null;
            LocalErrCode     localRes = LocalErrCode.组件未启动;

            res = null;
            for (int i = 0; i < subMsg.Length; i++)
            {
                localRes = clien.Submit(subMsg[i], out resp);
                res      = resp as CMPP_SUBMIT_RESP;
                if (localRes != LocalErrCode.成功 || res.Result != DeliverResult.正确)
                {
                    break;
                }
            }
            return(localRes);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 读取失败或无可读数据返回 null
        /// </summary>
        /// <returns></returns>
        private CMPPMsgBody_Base read()
        {
            byte[] buffer;
            try
            {
                //判断是否有可用的数据
                if (channelStateReady && client_sk != null && client_sk.Available > 0)
                {
                    buffer = readBuffer(client_sk.GetStream());
                }
                else
                {
                    return(null);//没有可供读取的数据
                }
                //将读取到的数据构建成对象
                CMPPMsgHeader head;

                //读出头部,判断命令类型
                head = CMPPMsgHeader.Read(buffer);
                //根据指令类型,构建应答对象,对于不处理的指令进行丢弃
                CMPPMsgBody_Base data = null;
                switch (head.Command_Id)
                {
                case Command_Id.CMPP_SUBMIT_RESP:
                    data = new CMPP_SUBMIT_RESP(head.Sequence_Id);
                    break;

                case Command_Id.CMPP_DELIVER:
                    data = new CMPP_DELIVER(head.Sequence_Id);
                    break;

                case Command_Id.CMPP_ACTIVE_TEST:
                    data = new CMPP_ACTIVE_TEST(head.Sequence_Id);
                    break;

                case Command_Id.CMPP_ACTIVE_TEST_RESP:
                    data = new CMPP_ACTIVE_TEST_RESP(head.Sequence_Id);
                    break;

                case Command_Id.CMPP_TERMINATE:
                    data = new CMPP_TERMINATE(head.Sequence_Id);
                    break;

                case Command_Id.CMPP_TERMINATERESP:
                    data = new CMPP_TERMINATE_RESP(head.Sequence_Id);
                    break;

                default:
                    break;
                }
                if (data != null)
                {
                    data.ReadBytes(buffer);
                }
                return(data);
            }
            catch (Exception)//流读取异常
            {
                CloseSoket();
                return(null);
            }
        }