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

📄 smgppacket.cs

📁 smgp协议的小灵通短信数据包 适合SP端程序的开发
💻 CS
📖 第 1 页 / 共 4 页
字号:

	public class SMGP_Deliver			//DELIVER包类
	{
		public SMGP_Header header;
		
		private byte[] MsgID = new byte[10];
		private byte IsReport;
		private byte MsgFormat;
		private byte[] RecvTime = new byte[14];
		private byte[] SrcTermID = new byte[21];
		private byte[] DestTermID = new byte[21];
		private byte MsgLength;
		private byte[] MsgContent;
		private byte[] Reserve = new byte[8];

		public SMGP_Report Reporter;
		

		//	bcd编码转换为字符串输出
		//	描述:bcd编码转换为字符串输出
		//	参数:BCD编码的数组
		//	返回:string 转换好的字符串
		//	创建:李文达 2005-08-24 
		public  string bcdtostring(byte[] b_bcd)
		{
			string[] strbcd=new string[b_bcd.Length];
			string output="";
			for(int i=0;i<b_bcd.Length;i++)
			{
				strbcd[i]=System.Convert.ToString(b_bcd[i],16);
				if(strbcd[i].Length==1)
				{
					strbcd[i]="0" + strbcd[i];
				}
				output=output + strbcd[i];
			}
				
			return output;
		}

		public SMGP_Deliver()
		{
			header=new SMGP_Header();
			Reporter=new SMGP_Report();
		}

		public void SMGP_Deliver_unpack(byte[] bytes)
		{
			int i=0;
			
			this.header.SMGP_Header_unpack(bytes);
			i+=12;

			Buffer.BlockCopy(bytes, i, this.MsgID,0,this.MsgID.Length);
			i+=10;

			this.IsReport=bytes[i];
			i+=1;

			this.MsgFormat=bytes[i];
			i+=1;

			Buffer.BlockCopy(bytes,i,this.RecvTime,0,this.RecvTime.Length);
			i+=14;

			Buffer.BlockCopy(bytes,i,this.SrcTermID,0,this.SrcTermID.Length);
			i+=21;

			Buffer.BlockCopy(bytes,i,this.DestTermID,0,this.DestTermID.Length);
			i+=21;

			this.MsgLength=bytes[i];
			i+=1;

			this.MsgContent=new byte[this.MsgLength];


			Buffer.BlockCopy(bytes,i,this.MsgContent,0,this.MsgContent.Length);
			i+=this.MsgLength;
			
			if(this.getIsReport()==1)		//如果是状态报告就单独处理一下
			{
				//Console.WriteLine("是report");
				Reporter.SMGP_Report_unpack(this.MsgContent);
			}


			Buffer.BlockCopy(bytes,i,this.Reserve,0,this.Reserve.Length);
			i+=this.Reserve.Length;
		}

		public int getStrlen(byte[] buffer)
		{
			int i=0;
			for(i=0;i<buffer.Length;i++)
			{
				if(buffer[i]==0)
				{
					return i;
				}
			}
			return buffer.Length;
		}
		public string getMsgID()
		{
			return bcdtostring(this.MsgID);
		}

		public byte[] getMsgID_b()
		{
			return this.MsgID;
		}

		public int getIsReport()
		{
			return (int)this.IsReport;
		}

		public int getMsgFormat()
		{
			return (int)this.MsgFormat;
		}

		public string getRecvTime()
		{
			return Encoding.ASCII.GetString(this.RecvTime);
		}
			
		public string getSrcTermID()
		{
			return Encoding.ASCII.GetString(this.SrcTermID,0,getStrlen(this.SrcTermID));
		}

		public string getDestTermID()
		{
			return Encoding.ASCII.GetString(this.DestTermID,0,getStrlen(this.DestTermID));	
		}

		public int getMsgLength()
		{
			return (int)this.MsgLength;
		}
		
		public string getMsgContent()
		{
			return Encoding.Default.GetString(this.MsgContent);
		}

	}

	public class SMGP_Deliver_resp		//DELIVER回应包类
	{
		public SMGP_Header header;
		private byte[] MsgID=new byte[10];
		private int Stutas;
		public const int Length =12+10+4;

		public SMGP_Deliver_resp()
		{
			header=new SMGP_Header();
		}

		public byte[] SMGP_Deliver_resp_pack()		//封装
		{
			byte[] bytes = new byte[SMGP_Deliver_resp.Length];
			int i=0;

			Buffer.BlockCopy(header.SMGP_Header_pack(),0,bytes,0,12);
			i+=12;

			Buffer.BlockCopy(this.MsgID,0,bytes,i,this.MsgID.Length);
			i+=10;

			byte[] buffer=BitConverter.GetBytes(this.Stutas);
			Array.Reverse(buffer);
			Buffer.BlockCopy(buffer,0,bytes,i,buffer.Length);

			return bytes; 
		}

		public void setMsgID(byte[] b_msgid)
		{
			Buffer.BlockCopy(this.MsgID,0,b_msgid,0,this.MsgID.Length);
		}

		public void setStatus(int iStatus)
		{
			this.Stutas=iStatus;
		}

		
	}

	public class SMGP_Activetest		//激活测试包类
	{
		public SMGP_Header header;
		public SMGP_Activetest()
		{
			header=new SMGP_Header();
			header.setRequestID(SMGP_COMMAND_ID.SMGP_ACTIVE_TEST);
			
		}
		public byte[] SMGP_Activetest_pack()
		{
				this.header.setPacketLength(12);
			byte[] bytes=new byte[this.header.getPacketLength()];
			Buffer.BlockCopy(header.SMGP_Header_pack(),0,bytes,0,header.getPacketLength());

			return bytes;
		}

		public void SMGP_Activetest_unpack(byte[] bytes)
		{
			this.header.SMGP_Header_unpack(bytes);
		}
	}

	public class SMGP_Activetest_resp		//激活测试回应包类
	{
		public SMGP_Header header;
		public SMGP_Activetest_resp()
		{
			header=new SMGP_Header();
			header.setRequestID(SMGP_COMMAND_ID.SMGP_ACTIVE_TEST_RESP);
			header.setPacketLength(12);
		}
		public byte[] SMGP_Activetest_resp_pack()
		{
			byte[] bytes=new byte[this.header.getPacketLength()];
			Buffer.BlockCopy(header.SMGP_Header_pack(),0,bytes,0,this.header.getPacketLength());

			return bytes;
		}

		public void SMGP_Activetest_resp_unpack(byte[] bytes)
		{
			this.header.SMGP_Header_unpack(bytes);
		}
	}

	public class SMGP_Exit		//退出包类
	{
		public SMGP_Header header;
		public SMGP_Exit()
		{
			header=new SMGP_Header();
			header.setRequestID(SMGP_COMMAND_ID.SMGP_EXIT);
			header.setPacketLength(12);
		}
		public byte[] SMGP_Exit_pack()
		{
			byte[] bytes=new byte[12];
			Buffer.BlockCopy(header.SMGP_Header_pack(),0,bytes,0,12);

			return bytes;
		}

		public void SMGP_Exit_unpack(byte[] bytes)
		{
			this.header.SMGP_Header_unpack(bytes);
		}
	}

	public class SMGP_Exit_resp	//退出回应包类
	{
		public SMGP_Header header;
		public SMGP_Exit_resp()
		{
			header=new SMGP_Header();

			header.setRequestID(SMGP_COMMAND_ID.SMGP_EXIT_RESP);
			header.setPacketLength(12);
		}
		public byte[] SMGP_Exit_resp_pack()
		{
			byte[] bytes=new byte[this.header.getPacketLength()];
			Buffer.BlockCopy(header.SMGP_Header_pack(),0,bytes,0,this.header.getPacketLength());

			return bytes;
		}

		public void SMGP_Exit_resp_unpack(byte[] bytes)
		{
			this.header.SMGP_Header_unpack(bytes);
		}	
	}

	public class SMGP_Report		//状态报告类
	{
		private byte[] Report_Id = new byte[14];
		private byte[] Report_Sub = new byte[8];
		private byte[] Report_Dlvrd = new byte[10];
		private byte[] Report_Submit_date = new byte[23];
		private byte[] Report_Done_date = new byte[21];
		private byte[] Report_Stat = new byte[13];
		private byte[] Report_Err = new byte[8];
		private byte[] Report_Text = new byte[24];
		
		public string getID()
		{
			byte[] b_id=new byte[10];
			Buffer.BlockCopy(this.Report_Id,3,b_id,0,b_id.Length);
			return bcdtostring(b_id);
		}

		public string getSub()
		{
			byte[] b_Sub=new byte[3];
			Buffer.BlockCopy(this.Report_Sub,4,b_Sub,0,b_Sub.Length);
			return Encoding.ASCII.GetString(b_Sub);
		}

		public string getDlvrd()
		{
			byte[] b_Dlvrd=new byte[3];
			Buffer.BlockCopy(this.Report_Dlvrd,6,b_Dlvrd,0,b_Dlvrd.Length);
			return Encoding.ASCII.GetString(b_Dlvrd);
		}

		public string getSubmit_date()
		{
			byte[] b_Submit_date=new byte[10];
			Buffer.BlockCopy(this.Report_Submit_date,12,b_Submit_date,0,b_Submit_date.Length);
			return Encoding.ASCII.GetString(b_Submit_date);
		}

		public string getDone_date()
		{
			byte[] b_Done_date=new byte[10];
			Buffer.BlockCopy(this.Report_Done_date,10,b_Done_date,0,b_Done_date.Length);
			return Encoding.ASCII.GetString(b_Done_date);
		}

		public string getStat()
		{
			byte[] b_Stat=new byte[7];
			Buffer.BlockCopy(this.Report_Stat,5,b_Stat,0,b_Stat.Length);
			return Encoding.ASCII.GetString(b_Stat);
		}

		public string getErr()
		{
			byte[] b_Err=new byte[3];
			Buffer.BlockCopy(this.Report_Err,4,b_Err,0,b_Err.Length);
			return Encoding.ASCII.GetString(b_Err);
		}

		public string getText()
		{
			byte[] b_Text=new byte[19];
			Buffer.BlockCopy(this.Report_Text,5,b_Text,0,b_Text.Length);
			return Encoding.Default.GetString(b_Text);
		}


		public void SMGP_Report_unpack(byte[] bytes)
		{
			int i=0;

			Buffer.BlockCopy(bytes,i,this.Report_Id,0,this.Report_Id.Length);
			//Console.WriteLine("rpt rptid");
			i+=14;

			Buffer.BlockCopy(bytes,i,this.Report_Sub,0,this.Report_Sub.Length);
			//Console.WriteLine("rpt rptsub");
			i+=8;

			Buffer.BlockCopy(bytes,i,this.Report_Dlvrd,0,this.Report_Dlvrd.Length);
			//Console.WriteLine("rpt dlvr");
			i+=10;

			Buffer.BlockCopy(bytes,i,this.Report_Submit_date,0,this.Report_Submit_date.Length);
			//Console.WriteLine("rpt submitdate");
			i+=23;

			Buffer.BlockCopy(bytes,i,this.Report_Done_date,0,this.Report_Done_date.Length);
			//Console.WriteLine("RPT DONEDATE");
			i+=21;

			Buffer.BlockCopy(bytes,i,this.Report_Stat,0,this.Report_Stat.Length);
			//Console.WriteLine("RPT STAT");
				
			i+=13;

			Buffer.BlockCopy(bytes,i,this.Report_Err,0,this.Report_Err.Length);
			//Console.WriteLine("RPT ERR:{0}",Encoding.ASCII.GetString(this.Report_Err));
			i+=8;
			
			Buffer.BlockCopy(bytes,i,this.Report_Text,0,this.Report_Text.Length);
			//Console.WriteLine("RPT TEXT:{0}",Encoding.Default.GetString(this.Report_Text));
				
		}
		
		//	bcd编码转换为字符串输出
		//	描述:bcd编码转换为字符串输出
		//	参数:BCD编码的数组
		//	返回:string 转换好的字符串
		//	创建:李文达 2005-08-24 
		public  string bcdtostring(byte[] b_bcd)
		{
			string[] strbcd=new string[b_bcd.Length];
			string output="";
			for(int i=0;i<b_bcd.Length;i++)
			{
				strbcd[i]=System.Convert.ToString(b_bcd[i],16);
				if(strbcd[i].Length==1)
				{
					strbcd[i]="0" + strbcd[i];
				}
				output=output + strbcd[i];
			}
				
			return output;
		}
	}

}

namespace n_inilog
{
	/// <summary>
	/// RecordLog 的摘要说明。
	/// 记录日志
	/// </summary>
	public class RecLog
	{
		//		public StreamWriter sw;
		public RecLog()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
			//			string str_Filename="Smgp_submit"+DateTime.Now.ToString("yyyyMMddHH")+".log";
			//			if (!File.Exists(str_Filename)) 
			//			{
			//				sw = File.CreateText(str_Filename);
			//				
			//			}
			//			else
			//			{
			//				sw = File.AppendText(str_Filename);
			//				
			//			}

		}
		public void WriteFile(string str_logtxt)
		{		
			str_logtxt=DateTime.Now.ToString()+"   "+str_logtxt;

			//string str_Filename="Smgp_submit"+DateTime.Now.ToString("yyyyMMddHH")+".log";
			
			//			if (!File.Exists(str_Filename)) 
			//			{
			//				StreamWriter sw = File.CreateText(str_Filename);
			//				sw.WriteLine(str_logtxt);
			//				sw.Flush();
			//				sw.Close();
			//			}
			//			else
			//			{
			//				StreamWriter sw = File.AppendText(str_Filename);
			//				sw.WriteLine(str_logtxt);
			//				sw.Flush();
			//				sw.Close();
			//			}
			

		}

		public void WriteFilespeed(string str_logtxt)
		{		
			string str;
			

			string str_Filename="Smgp_submit"+DateTime.Now.ToString("yyyyMMddHH")+".log";
	
				
				
			if (!File.Exists(str_Filename)) 
			{
				StreamWriter sw = File.CreateText(str_Filename);
				for(int i=0;i<90000;i++)
				{
					str=DateTime.Now.ToString()+"   "+str_logtxt;
					sw.WriteLine(str);
					sw.Flush();
				}
				sw.Close();
				
			}
			else
			{
				StreamWriter sw = File.AppendText(str_Filename);

				for(int i=0;i<90000;i++)
				{
					str=DateTime.Now.ToString()+"   "+str_logtxt;
					sw.WriteLine(str);
					sw.Flush();
				}
				sw.Close();
				
				
			}
			

		}
		public void WriteFilegSubmit(string [] str_arr)
		{		

⌨️ 快捷键说明

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