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

📄 form1.cs

📁 发短信编码解码C#代码,下载测试,不错,推荐下载,值得学习代码思想
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SMSPDULib;

namespace ReadSMS
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			string source = textBox1.Text;

			SMSType smsType = SMSBase.GetSMSType(source);

			switch (smsType) {
				case SMSType.SMS:
					SMS sms = new SMS();
					SMS.Fetch(sms, ref source);

					ShowSMS(sms);
					break;
				case SMSType.StatusReport:
					SMSStatusReport statusReport = new SMSStatusReport();
					SMSStatusReport.Fetch(statusReport, ref source);

					ShowStatusReport(statusReport);
					break;
			}
		}

		private void ShowStatusReport(SMSStatusReport sms)
		{
			string format = "Service center number: {0}\r\nService center time stamp: {1}\r\nMessage reference #: {2}\r\nPhone number: {3}\r\nReport time stamp: {4}\r\nReport status: {5}";

			textBox2.Text = string.Format(format,
				sms.ServiceCenterNumber,
				sms.ServiceCenterTimeStamp,
				sms.MessageReference,
				sms.PhoneNumber,
				sms.ReportTimeStamp,
				sms.ReportStatus);
		}

		private void ShowSMS(SMS sms)
		{
			string format = "Service center number: {0}\r\nService center time stamp: {1}\r\nMessage reference #: {2}\r\nDirection: {3}\r\nPhone number: {4}\r\nStatus report indication: {5}\r\nMessage:\r\n{6}";

			textBox2.Text = string.Format(format,
				sms.ServiceCenterNumber,
				sms.ServiceCenterTimeStamp,
				sms.MessageReference,
				sms.Direction,
				sms.PhoneNumber,
				sms.StatusReportIndication,
				sms.Message);
		}

		private void button2_Click(object sender, EventArgs e)
		{
			SMS sms = new SMS();

			sms.Direction = SMSDirection.Submited;
			sms.PhoneNumber = "+79191234567";
			sms.ValidityPeriod = new TimeSpan(4, 0, 0, 0);
			sms.Message = textBox2.Text;

			textBox1.Text = sms.Compose(SMS.SMSEncoding.UCS2);
		}

		/*private string Decode(string PDU)
		{
			string result = string.Empty;

			try
			{
				string PDUCode = PDU.Replace("\r\n", "");
				
				SMSBase.SMSType T = SMSBase.GetSMSType(PDUCode);
				result = result + T.ToString() + "\r\n";
				if (T == SMSBase.SMSType.EMS_RECEIVED)
				{
					EMS_RECEIVED s = new EMS_RECEIVED(PDUCode);
					result += "From:" + s.SrcAddressValue + " Time:" + s.TP_SCTS + "\r\n" + "\r\n";
					if (s.TP_DCS == 0)
						result += SMSBase.Decode7Bit(s.TP_UD, s.TP_UDL - 8 * (1 + s.TP_UDHL) / 7) + "\r\n";
					else
						result = result + SMSBase.DecodeUnicode(s.TP_UD) + "\r\n";
				}
				else if (T == SMSBase.SMSType.SMS_RECEIVED)
				{
					SMS_RECEIVED s = new SMS_RECEIVED(PDUCode);
					result += "From:" + s.SrcAddressValue + " Time:" + s.TP_SCTS + "\r\n" + "\r\n";
					if (s.TP_DCS == 0)
						result += SMSBase.Decode7Bit(s.TP_UD, s.TP_UDL) + "\r\n";
					else
						result = result + SMSBase.DecodeUnicode(s.TP_UD) + "\r\n";
				}
				else if (T == SMSBase.SMSType.EMS_SUBMIT)
				{
					EMS_SUBMIT s = new EMS_SUBMIT(PDUCode);
					result += "Send to:" + s.DesAddressValue + "\r\n" + "\r\n";
					if (s.TP_DCS == 0)
						result += SMSBase.Decode7Bit(s.TP_UD, s.TP_UDL - 8 * (1 + s.TP_UDHL) / 7) + "\r\n";
					else
						result = result + SMSBase.DecodeUnicode(s.TP_UD) + "\r\n";
				}
				else if (T == SMSBase.SMSType.SMS_SUBMIT)
				{
					SMS_SUBMIT s = new SMS_SUBMIT(PDUCode);
					result += "Send to:" + s.DesAddressValue + "\r\n" + "\r\n";
					if (s.TP_DCS == 0)
						result += SMSBase.Decode7Bit(s.TP_UD, s.TP_UDL) + "\r\n";
					else
						result = result + SMSBase.DecodeUnicode(s.TP_UD) + "\r\n";
				}
				else if (T == SMSBase.SMSType.SMS_STATUS_REPORT)
				{
					SMS_STATUS_REPORT s = new SMS_STATUS_REPORT(PDUCode);
					result += "Send time:" + s.TP_SCTS + " Receive time:" + s.TP_DP + " ״̬:" + (s.Status).ToString() + "\r\n" + "\r\n";
					if (s.TP_DCS == 0)
						result += SMSBase.Decode7Bit(s.TP_UD, s.TP_UDL) + "\r\n";
					else
						result = result + SMSBase.DecodeUnicode(s.TP_UD) + "\r\n";
				}
				else
				{
					result = "Sorry, maybe it is a wrong PDU Code";
				}

			}
			catch (Exception err)
			{
				return err.Message;
			}

			return result;
		}*/
	}
}

⌨️ 快捷键说明

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