示例#1
0
 public static WapPush GetInstance()
 {
     if (null == push)
     {
         push = new WapPush();
     }
     return(push);
 }
示例#2
0
        public void SetHeader()
        {
            //if (string.IsNullOrEmpty(_MsgContent))
            //    return;

            if (string.IsNullOrEmpty(_WapURL))
            {
                //byte[] buf;
                switch (this._MsgFormat)
                {
                case 8:
                    _MsgContent_Bytes = Encoding.BigEndianUnicode.GetBytes(this._MsgContent);
                    break;

                case 15:     //gb2312
                    _MsgContent_Bytes = Encoding.GetEncoding("gb2312").GetBytes(this._MsgContent);
                    break;

                case 0:     //ascii
                case 3:     //短信写卡操作
                case 4:     //二进制信息
                default:
                    _MsgContent_Bytes = Encoding.ASCII.GetBytes(this._MsgContent);
                    break;
                }

                if (this.Pk_total > 1) //长短信
                {
                    AddTlv(TlvId.TP_udhi, "1");
                    AddTlv(TlvId.PkTotal, this.Pk_total.ToString());
                    AddTlv(TlvId.PkNumber, this.Pk_number.ToString());
                    AddTlv(TlvId.MsgSrc, this._MsgSrc);
                    byte[] tp_udhiHead = new byte[6];
                    tp_udhiHead[0] = 0x05;
                    tp_udhiHead[1] = 0x00;
                    tp_udhiHead[2] = 0x03;
                    tp_udhiHead[3] = 0x0A;
                    tp_udhiHead[4] = (byte)this.Pk_total;
                    tp_udhiHead[5] = (byte)this.Pk_number;
                    byte[] Msg_Content_Bytes_Temp = new byte[_MsgContent_Bytes.Length + 6];
                    int    index = 0;
                    tp_udhiHead.CopyTo(Msg_Content_Bytes_Temp, index);
                    index += tp_udhiHead.Length;
                    _MsgContent_Bytes.CopyTo(Msg_Content_Bytes_Temp, index);
                    _MsgContent_Bytes = Msg_Content_Bytes_Temp;
                }
            }
            else
            {
                AddTlv(TlvId.TP_pid, "1");
                AddTlv(TlvId.TP_udhi, "1");
                AddTlv(TlvId.MsgSrc, this._MsgSrc);
                _MsgContent_Bytes = WapPush.GetInstance().toBytes(this._MsgContent, this._WapURL);
                this._MsgFormat   = 0x04;
            }

            this._MsgLength  = (uint)_MsgContent_Bytes.Length;
            this._BodyLength = (int)(FixedBodyLength + 21 * this._DestTermID.Length + this._MsgLength);
            if (_OtherTlvArray != null)
            {
                for (int i = 0; i < _OtherTlvArray.Length; i++)
                {
                    if (_OtherTlvArray[i].Length > 0)
                    {
                        _BodyLength += _OtherTlvArray[i].Length + 4;
                    }
                }
            }
            this._Header = new MessageHeader((uint)(MessageHeader.Length + this._BodyLength), SMGP3_COMMAND.Submit, this._Sequence_Id);
        }