⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smppclient.cs

📁 EasySMPP是一个VS.NET平台下的短信开发包
💻 CS
📖 第 1 页 / 共 5 页
字号:
                    pos += 1;
                    _DATA_SM_PDU[pos] = destinationAddressTon;
                    pos += 1;
                    _DATA_SM_PDU[pos] = destinationAddressNpi;
                    pos += 1;
                    _destination_addr = Tools.ConvertStringToByteArray(Tools.GetString(destinationAddress, 20, ""));
                    Array.Copy(_destination_addr, 0, _DATA_SM_PDU, pos, _destination_addr.Length);
                    pos += _destination_addr.Length;
                    _DATA_SM_PDU[pos] = 0x00;
                    pos += 1;
                    _DATA_SM_PDU[pos] = esmClass;
                    pos += 1;
                    _DATA_SM_PDU[pos] = registeredDelivery;
                    pos += 1;
                    _DATA_SM_PDU[pos] = dataCoding;
                    pos += 1;

                    _DATA_SM_PDU[pos] = 0x04;
                    pos += 1;
                    _DATA_SM_PDU[pos] = 0x24;
                    pos += 1;

                    _sm_length = data.Length > 32767 ? (Int16)32767 : (Int16)data.Length;

                    _DATA_SM_PDU[pos] = BitConverter.GetBytes(_sm_length)[1];
                    pos += 1;
                    _DATA_SM_PDU[pos] = BitConverter.GetBytes(_sm_length)[0];
                    pos += 1;
                    Array.Copy(data, 0, _DATA_SM_PDU, pos, _sm_length);
                    pos += _sm_length;

                    Tools.CopyIntToArray(pos, _DATA_SM_PDU, 0);

                    Send(_DATA_SM_PDU, pos);
                    undeliveredMessages++;
                    return _sequence_number;
                }
                catch (Exception ex)
                {
                    logMessage(LogLevels.LogExceptions, "DataSM | " + ex.ToString());
                }
                return -1;

            }//DataSM

            public int SendSms(String from, String to, String text)
            {
                return SendSms(from, to, splitLongText, text, askDeliveryReceipt);
            }//SendSms
            public int SendSms(String from, String to, String text, byte askDeliveryReceipt)
            {
                return SendSms(from, to, splitLongText, text, askDeliveryReceipt);
            }//SendSms
            public int SendSms(String from, String to, bool splitLongText, String text)
            {
                return SendSms(from, to, splitLongText, text, askDeliveryReceipt);
            }//SendSms
            public int SendSms(String from, String to, bool splitLongText, String text, byte askDeliveryReceipt)
            {
                return SendSms(from, to, splitLongText, text, askDeliveryReceipt, 0, Tools.GetDataCoding(text));
            }

            public int SendSms(String from, String to, bool splitLongText, String text, byte askDeliveryReceipt, byte esmClass, byte dataCoding)
            {
                int messageId = -1;
                byte sourceAddressTon;
                byte sourceAddressNpi;
                string sourceAddress;
                byte destinationAddressTon;
                byte destinationAddressNpi;
                string destinationAddress;
                byte registeredDelivery;
                byte maxLength;

                sourceAddress = Tools.GetString(from, 20, "");
                sourceAddressTon = getAddrTon(sourceAddress);
                sourceAddressNpi = getAddrNpi(sourceAddress);

                destinationAddress = Tools.GetString(to, 20, "");
                destinationAddressTon = getAddrTon(destinationAddress);
                destinationAddressNpi = getAddrNpi(destinationAddress);

                registeredDelivery = askDeliveryReceipt;

                if (dataCoding == 8)
                {
                    text = Tools.Endian2UTF(text);
                    maxLength = 70;
                }
                else
                    maxLength = 160;

                if ((text.Length <= maxLength) || (splitLongText))
                {
                    byte protocolId;
                    byte priorityFlag;
                    DateTime sheduleDeliveryTime;
                    DateTime validityPeriod;
                    byte replaceIfPresentFlag;
                    byte smDefaultMsgId;
                    byte[] message;
                    string smsText = text;

                    protocolId = 0;
                    priorityFlag = PriorityFlags.VeryUrgent;
                    sheduleDeliveryTime = DateTime.MinValue;
                    validityPeriod = DateTime.MinValue;
                    replaceIfPresentFlag = ReplaceIfPresentFlags.DoNotReplace;
                    smDefaultMsgId = 0;

                    while (smsText.Length > 0)
                    {
                        if (dataCoding == 8)
                            message = Encoding.UTF8.GetBytes(smsText.Substring(0, smsText.Length > maxLength ? maxLength : smsText.Length));
                        else
                            message = Encoding.ASCII.GetBytes(smsText.Substring(0, smsText.Length > maxLength ? maxLength : smsText.Length));

                        smsText = smsText.Remove(0, smsText.Length > maxLength ? maxLength : smsText.Length);
                        
                        messageId = SubmitSM(sourceAddressTon, sourceAddressNpi, sourceAddress, 
                                            destinationAddressTon, destinationAddressNpi, destinationAddress,
                                            esmClass, protocolId, priorityFlag,
                                            sheduleDeliveryTime, validityPeriod, registeredDelivery, replaceIfPresentFlag,
                                            dataCoding, smDefaultMsgId, message);
                    }
                }
                else
                {
                    byte[] data;

                    if (dataCoding == 8)
                        data = Encoding.UTF8.GetBytes(text);
                    else
                        data = Encoding.ASCII.GetBytes(text);
                    messageId = DataSM(sourceAddressTon, sourceAddressNpi, sourceAddress,
                                        destinationAddressTon, destinationAddressNpi, destinationAddress,
                                        esmClass, registeredDelivery, dataCoding, data);
                }
                return messageId;
            }//SendSms
            public int SendFlashSms(String from, String to, String text)
            {
                return SendFlashSms(from, to, text, askDeliveryReceipt);
            }//SendFlashSms
            public int SendFlashSms(String from, String to, String text, byte askDeliveryReceipt)
            {
                return SendSms(from, to, false, text.Substring(0, text.Length > 160 ? 160 : text.Length), askDeliveryReceipt, 0, 0x10);
            }//SendFlashSms
            public int SendMedia(String from, String to, byte[] media)
            {
                return SendMedia(from, to, media, askDeliveryReceipt);
            }//SendMedia
            public int SendMedia(String from, String to, byte[] media, byte askDeliveryReceipt)
            {
                return SendData(from, to, media, 0x40, 0xF5, askDeliveryReceipt);
            }//SendMedia
            public int SendData(String from, String to, byte[] data)
            {
                return SendData(from, to, data, askDeliveryReceipt);
            }//SendData
            public int SendData(String from, String to, byte[] data, byte askDeliveryReceipt)
            {
                return SendData(from, to, data, 0, 0, 0);
            }//SendData
            public int SendData(String from, String to, byte[] data, byte esmClass, byte dataCoding, byte askDeliveryReceipt)
            {
                int messageId;
                byte sourceAddressTon;
                byte sourceAddressNpi;
                string sourceAddress;
                byte destinationAddressTon;
                byte destinationAddressNpi;
                string destinationAddress;
                byte registeredDelivery;

                sourceAddress = Tools.GetString(from, 20, "");
                sourceAddressTon = getAddrTon(sourceAddress);
                sourceAddressNpi = getAddrNpi(sourceAddress);

                destinationAddress = Tools.GetString(from, 20, "");
                destinationAddressTon = getAddrTon(destinationAddress);
                destinationAddressNpi = getAddrNpi(destinationAddress);

                registeredDelivery = askDeliveryReceipt;

                messageId = DataSM(sourceAddressTon, sourceAddressNpi, sourceAddress,
                                    destinationAddressTon, destinationAddressNpi, destinationAddress,
                                    esmClass, registeredDelivery, dataCoding, data);

                return messageId;
            }//SendData
            #endregion New Send Functions

            #endregion Public Functions

            #region Properties
            public bool CanSend
            {
                get
                {
                    try
                    {
                        if ((connectionState== ConnectionStates.SMPP_BINDED) && (undeliveredMessages <= KernelParameters.MaxUndeliverableMessages))
                            return true;
                    }
                    catch (Exception ex)
                    {
                        logMessage(LogLevels.LogExceptions, "CanSend | " + ex.ToString());
                    }
                    return false;
                }
            }//CanSend

            public int LogLevel
            {
                get
                {
                    return logLevel;
                }
                set
                {
                    logLevel = value;
                }
            }//CanSend


            public byte AskDeliveryReceipt
            {
                get
                {
                    return askDeliveryReceipt;
                }
                set
                {
                    if ((value < 3) && (value >= 0))
                        askDeliveryReceipt = value;
                }
            }//AskDeliveryReceipt

            public bool SplitLongText
            {
                get
                {
                    return splitLongText;
                }
                set
                {
                    splitLongText = value;
                }
            }//SplitLongText
            public int NationalNumberLength
            {
                get
                {
                    return nationalNumberLength;
                }
                set
                {
                    if (value <= 12)
                        nationalNumberLength = value;
                }
            }//NationalNumberLength
            public bool UseEnquireLink
            {
                get
                {
                    return useEnquireLink;
                }
                set
                {
                    useEnquireLink = value;
                }
            }//UseEnquireLink
            public int EnquireLinkTimeout
            {
                get
                {
                    return enquireLinkTimeout;
                }
                set
                {
                    if (value > 1000)
                        enquireLinkTimeout = value;
                }
            }//EnquireLinkTimeout
            public int ReconnectTimeout
            {
                get
                {
                    return reconnectTimeout;
                }
                set
                {
                    if (value > 1000)
                        reconnectTimeout = value;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -