示例#1
0
 public Cmpp_Submit(CmppSubmitModel submit)
 {
     _submit = submit;
 }
示例#2
0
        private void Submit()
        {
            try
            {
                //if (!_socketClient.IsLogin)
                //{
                //    GlobalModel.WaitSendQueue.Set();
                //    //thisqueueState.Set();
                //    continue;
                //}
                //if (GlobalModel.ServiceIsStop)
                //{
                //    GlobalModel.WaitSendQueue.Set();
                //    continue;
                //}
                QueueItem qi = this.GetMessage();
                //if(i==0)
                //{
                //    qi = new QueueItem();
                //    SmsModel s = new SmsModel();
                //    s.content = "【比亚迪】您好!400客服接到F3用户王文刚(13842636503)其它,需要贵店给予支持,详情请查阅CRM派单信息1,详情请查阅CRM派单信息2,详情请查阅CRM派单信息3!";
                //    s.content = "【比亚迪】Hello World!";
                //    s.mobile = "13682488577";
                //    s.id = 1;
                //    s.subId = "123";
                //    qi.MsgObj = s;
                //    i++;
                //}


                if (qi == null)
                {
                    GlobalModel.WaitSendQueue.Set();
                    //thisqueueState.Set();
                    return;
                }
                SmsModel sms = qi.MsgObj as SmsModel;
                if (sms != null)
                {
                    bool b = false;
                    try
                    {
                        if (!MyTools.IsFirstsign(sms.content) && !MyTools.IsLastsign(sms.content))
                        {
                            SMSLog.Debug("CmppSendThread=>Send无签名[" + sms.id + "]to[" + sms.mobile + "]content=" + sms.content);
                            GlobalModel.TransferDataProcHandler.BeginInvoke((int)sms.id, sms.operatorId, 31013, "", new AsyncCallback((IAsyncResult) => { }), null);
                            return;
                        }
                        if (!MyTools.IsFirstsign(sms.content) && MyTools.IsLastsign(sms.content))
                        {
                            sms.content = MyTools.SignBefore(sms.content);
                        }
                        //SMSLog.Debug("CmppSendThread=>Send[" + sms.id + "][" + sms.srcnum + "]to[" + sms.mobile + "]content=" + sms.content);

                        string srcid  = sms.srcnum;//显示号码
                        string con    = sms.content.Trim();
                        int    msgnum = 1;


                        if (con.Length < 71)
                        {
                            msgnum = 1;
                        }
                        else
                        {
                            msgnum = (int)Math.Ceiling(con.Length / 67.0);
                        }

                        //SMSLog.Debug("CmppSendThread=>msgnum=[" + msgnum + "]");
                        if (msgnum > 1)
                        {
                            CmppSubmitLongModel sub = new CmppSubmitLongModel();

                            sub.Sequence_Id         = sms.id;
                            sub.Msg_Id              = Tools.Timestamp();
                            sub.Pk_total            = (uint)msgnum;
                            sub.Registered_Delivery = 1;
                            sub.Msg_level           = 0;
                            sub.Service_Id          = GlobalModel.Lparams.ServiceId;//_accountInfo.serviceid;
                            sub.Fee_UserType        = 2;
                            sub.Fee_terminal_Id     = 0;
                            sub.TP_pId              = 0;
                            sub.TP_udhi             = 1;
                            sub.Msg_Fmt             = (uint)MsgContentFormat.UCS2;
                            sub.Msg_src             = GlobalModel.Lparams.Spid;// _accountInfo.spid;
                            sub.FeeType             = "02";
                            sub.FeeCode             = "000001";
                            sub.At_Time             = "";
                            sub.ValId_Time          = Tools.GetValIdTime(DateTime.Now);
                            sub.Src_Id              = srcid;
                            sub.DestUsr_tl          = 1;
                            sub.Dest_terminal_Id    = sms.mobile;
                            sub.Reserve             = "";
                            string[] msgarr   = Tools.GetMsgArray(67, con);
                            string[] scontent = msgarr;
                            //SMSLog.Error("SendThread==>Send==>【msgarr】" + msgarr.Length);

                            int    iLength   = msgarr.Length;
                            int    m_LongMsg = 70;
                            string lastMsg   = msgarr[iLength - 1];
                            if (lastMsg.Length > m_LongMsg)
                            {
                                iLength  = iLength + 1;
                                scontent = new string[iLength];
                                for (int i = 0; i < (iLength - 2); i++)
                                {
                                    scontent[i] = msgarr[i];
                                }
                                string[] stmp = Tools.GetMsgArray(m_LongMsg, lastMsg);
                                scontent[iLength - 2] = stmp[0];
                                scontent[iLength - 1] = stmp[1];
                            }
                            else
                            {
                                scontent = msgarr;
                            }

                            for (int i = 0; i < scontent.Length; i++)
                            {
                                try
                                {
                                    string splitcon = scontent[i];
                                    sub.Pk_number   = (uint)(i + 1);
                                    sub.Msg_Length  = (uint)(Encoding.BigEndianUnicode.GetBytes(splitcon).Length + 6);//内容长度+6字节头
                                    sub.Msg_Content = splitcon;
                                    Cmpp_SubmitLong cs  = new Cmpp_SubmitLong(sub);
                                    byte[]          byt = cs.Encode();

                                    b = _socketClient.SendAsync(byt);
                                    SMSLog.Debug("SendThread=>Send[" + b + "] Hex[" + sms.id + "]to[" + sms.mobile + "]index=" + i + ",extnum=" + srcid + ",content=" + splitcon);
                                    //SMSLog.Debug("SendThread=>Send Hex[" + MyTools.ByteToHex(byt) + "]", false);
                                    if (b)
                                    {
                                        longMsgWait.WaitOne(10);
                                        //MyTools.WaitTime(10);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    SMSLog.Error("SendThread==>Send==>【(for)SendAsync 发送异常:】" + ex.ToString());
                                }
                            }
                        }
                        else
                        {
                            CmppSubmitModel sub = new CmppSubmitModel();
                            try
                            {
                                sub.Sequence_Id         = sms.id;
                                sub.Msg_Id              = Tools.Timestamp();
                                sub.Pk_total            = 1;
                                sub.Pk_number           = 1;
                                sub.Registered_Delivery = 1;
                                sub.Msg_level           = 0;
                                sub.Service_Id          = GlobalModel.Lparams.ServiceId;// _accountInfo.serviceid;
                                sub.Fee_UserType        = 2;
                                sub.Fee_terminal_Id     = 0;
                                sub.TP_pId              = 0;
                                sub.TP_udhi             = 0;
                                sub.Msg_Fmt             = (uint)MsgContentFormat.UCS2;
                                sub.Msg_src             = GlobalModel.Lparams.Spid;// _accountInfo.spid;
                                sub.FeeType             = "02";
                                sub.FeeCode             = "000001";
                                sub.At_Time             = "";
                                sub.ValId_Time          = Tools.GetValIdTime(DateTime.Now);
                                sub.Src_Id              = srcid;
                                sub.DestUsr_tl          = 1;
                                sub.Dest_terminal_Id    = sms.mobile;
                                sub.Msg_Length          = (uint)Encoding.BigEndianUnicode.GetBytes(sms.content.Trim()).Length;
                                sub.Msg_Content         = sms.content;
                                sub.Reserve             = "";
                            }
                            catch (Exception ex)
                            {
                                SMSLog.Error("SendThread==>_socketClient==>sub 发送异常:" + ex.StackTrace);
                            }

                            try
                            {
                                Cmpp_Submit cs  = new Cmpp_Submit(sub);
                                byte[]      byt = cs.Encode();
                                b = _socketClient.SendAsync(byt);
                                SMSLog.Debug("SendThread=>Send[" + b + "] Hex[" + sms.id + "]to[" + sms.mobile + "],extnum=" + srcid + ",content=" + sms.content);
                                //SMSLog.Debug("SendThread=>Send Hex[" + MyTools.ByteToHex(byt) + "]", false);
                            }
                            catch (Exception ex)
                            {
                                SMSLog.Error("SendThread==>_socketClient==>SendAsync 【发送异常】:" + ex.ToString());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        b = false;
                        SMSLog.Error("SendThread==>Send 【发送异常】:" + ex.Message);
                    }

                    try
                    {
                        if (b)
                        {
                            qi.MsgState = (int)MSG_STATE.SENDED_WAITTING;

                            GlobalModel.TransferDataProcHandler.BeginInvoke((int)sms.id, sms.operatorId, 0, "", new AsyncCallback((IAsyncResult) => { }), null);

                            if (GlobalModel.Lparams.IsResend.Equals("1"))
                            {
                                AddToWaitingQueue(qi);//添加到等待队列
                            }
                        }
                        else
                        {
                            if (qi.FailedCount < 3)
                            {
                                qi.FailedCount++;
                                this.AddPriorityQueue(qi);
                                SMSLog.Debug("提交失败重新加入队列:CID=" + sms.cid + ",mobile=" + sms.mobile + ",CONTENT=" + sms.content);
                            }
                            else
                            {
                                GlobalModel.TransferDataProcHandler.BeginInvoke((int)sms.id, sms.operatorId, 31999, "", new AsyncCallback((IAsyncResult) => { }), null);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        SMSLog.Error("CmppSendThread==>Send 转移异常:" + ex.Message);
                    }
                }
                else
                {
                    GlobalModel.WaitSendQueue.Set();
                }
            }
            catch (Exception ex)
            {
                SMSLog.Error("CmppSendThread==>Send Exception:" + ex.Message);
            }
        }