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

📄 form1.cs

📁 为了对短消息信息应用开发商提供支持
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			this.close.Location = new System.Drawing.Point(344, 304);
			this.close.Name = "close";
			this.close.Size = new System.Drawing.Size(96, 23);
			this.close.TabIndex = 0;
			this.close.Text = "退  出";
			this.close.Click += new System.EventHandler(this.close_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(504, 373);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox4);
			this.Controls.Add(this.close);
			this.Name = "Form1";
			this.Text = "短信接口测试";
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void conntion_Click(object sender, System.EventArgs e)
		{
			// public static extern long  Sms_Connect(string pServer , long lCorpID,string pLoginName, 
			// string pPasswd , long lTimeOut, HWND hWnd );
			if (!this.connState)
			{
				// 连接短信平台服务器并登录
				string pServer=this.server.Text.Trim();
				int   lCorpID=Convert.ToInt32(this.customID.Text);
				string pLonginName=this.userName.Text.Trim();
				string pPasswd=this.passWord.Text.Trim();
				int   lTimeOut=15;
				IntPtr hWnd=include.FindWindow(null,"短信接口测试");//获得当前的窗口句柄

				int   returnValue=include.Sms_Connect(pServer,lCorpID,pLonginName,pPasswd,lTimeOut,hWnd);

				string strResult="";
				switch (returnValue)
				{
					case 0:
						strResult="初始化成功!!";
						this.connState=!this.connState;
						this.conntion.Text="断 开";

						break;
					case -1:
						strResult="连接服务器失败!!";
						break;
					case -2:
						strResult="连接服务器超时!!";
						break;
					case -3:
						strResult="登录失败,帐号有误!!";
						break;
					case -4:
						strResult="登录失败,相同帐号已在别处登录!!";
						break;
					default:
						strResult="连接失败,无相关失败信息!!";
						break;
						

				}

				MessageBox.Show("当前窗口的句柄为:"+hWnd.ToString()+"    "+strResult);
			}
			else
			{
				include.Sms_DisConnect();
				this.conntion.Text="连 接";
				this.connState=!this.connState;

			}
		}

		private void close_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void send_Click(object sender, System.EventArgs e)
		{
			string pMobile=this.tel.Text;
			string pMsg=this.message.Text;
			int lSmsID;

			int   returnValue=include.Sms_Send(pMobile,pMsg,out lSmsID );

			string strResult="";

			if (returnValue>=0)
			{
				MessageBox.Show("发送成功!!如果没有收到可能是因为帐号到期或帐号余额不足!\n短信ID"+lSmsID.ToString());
			}
			else
			{
				switch (returnValue)
				{
					case -1:
						strResult="接口未初始化!!";
						break;
					case -2:
						strResult="发送超时!!";
						break;
					case -3:
						strResult="发送失败,可能是帐号过期或余额不足!!";
						break;
					case -4:
						strResult="发送失败,发送的信息内容中含有敏感关键字,禁止发送!!";
						break;
					case -5:
						strResult="发送失败,发送的目标号码为黑名单用户,禁止发送。!!";
						break;
					default:
						strResult="发送失败,无相关失败信息!!";
						break;
				}	
				MessageBox.Show("错误信息!"+strResult);

			}
		}

		private void btnState_Click(object sender, System.EventArgs e)
		{
			string lSmsID=this.txtState.Text;

			int   returnValue=include.Sms_Status(Convert.ToInt32(lSmsID) );

			string strResult="";

			if (returnValue>=0)
			{
				MessageBox.Show("发送成功!!返回值:"+returnValue.ToString());
			}
			else
			{
				switch (returnValue)
				{
					case -1:
						strResult="接口未初始化!!";
						break;
					case -2:
						strResult="发送超时!!";
						break;
					case -3:
						strResult="找不到此短信!!检查你的短信ID!!";
						break;
					default:
						strResult="检测失败,无相关失败信息!!";
						break;
				}	
				MessageBox.Show("错误信息!"+strResult);


			}
		}

		private void count_Click(object sender, System.EventArgs e)
		{
			int   returnValue=include.Sms_KYSms();

			string strResult="";

			if (returnValue>=0)
			{
				MessageBox.Show("本帐号可以使用的短信数量:"+returnValue.ToString());
			}
			else
			{
				switch (returnValue)
				{
					case -1:
						strResult="接口未初始化!!";
						break;
					case -2:
						strResult="发送超时!!";
						break;
					default:
						strResult="检测失败,无相关失败信息!!";
						break;
				}	
				MessageBox.Show("错误信息!"+strResult);
			}		
		}

		private void receive_Click(object sender, System.EventArgs e)
		{
			string  pNo;
			string  pMsg;
			string  pTime;
			int     returnValue=-4;
			string  strResult="";
			
			StringBuilder pSendNo2=new StringBuilder(32);
			StringBuilder pRecvNo2=new StringBuilder(32);
			StringBuilder pMsg2=new StringBuilder(256);
			StringBuilder pTime2=new StringBuilder(32);

			try 
			{
				//returnValue=include.Sms_Get(pSendNo2,pMsg2,pTime2);
				returnValue=include.Sms_Get2(pSendNo2,pRecvNo2,pMsg2,pTime2);
			}
			catch(Exception ee)
			{
				MessageBox.Show(ee.ToString());
			}

			if (returnValue>=0)
			{
				pNo = pSendNo2.ToString();
				pMsg = pMsg2.ToString();
				pTime = pTime2.ToString();

				MessageBox.Show("短信内容:"+pMsg+"\r\n发送者手机号码:"+pNo+"\r\n短信发送时间:"+pTime);

			}
			else
			{
				switch (returnValue)
				{
					case -1:
						strResult="取短信失败,短信队列为空!!";
						break;
					default:
						strResult="检测失败,无相关失败信息!!";
						break;
				}	
				MessageBox.Show(strResult);
			}		
		}

		private void sendEx_Click(object sender, System.EventArgs e)
		{
			string pMobile=this.tel.Text;
			string pMsg=this.message.Text;
			int lSmsID;
			int lCount=2;
			int bWaitRet=1;
			include.SmsSend[]  sms=new include.SmsSend[2];
			sms[0].szMobile = pMobile;
			sms[0].szMsg    = pMsg;
			sms[1]=sms[0];   //测试用,将会收到两条相同的信息



			//因为C#数组的定义在内存里不是连续的,先要将其复制到一片连续的内存之中。
			IntPtr p;
			int size = Marshal.SizeOf(sms[0]);
			p = Marshal.AllocCoTaskMem(size * sms.Length);
			for(int i=0;i<sms.Length;i++)
			{
				IntPtr temp;
				temp = (IntPtr)(p.ToInt32()+i*size);
				Marshal.StructureToPtr(sms[i],temp,false);
			}

			int   returnValue=include.Sms_SendEx(p,lCount,bWaitRet );

			//为了得到返回的SmsID,需要将内容再次转换成数组,以便读回里面的信息。
			for(int i=0;i<sms.Length;i++)
			{
				IntPtr temp;
				temp = (IntPtr)(p.ToInt32()+i*size);
				sms[i]=(include.SmsSend)Marshal.PtrToStructure(temp,typeof(include.SmsSend));
			}

			Marshal.FreeCoTaskMem(p); //释放内存

			string strResult="";

			if (returnValue>=0)
			{
				MessageBox.Show("发送成功!!如果没有收到可能是因为帐号到期或帐号余额不足!\n短信ID"+sms[0].lSmsID.ToString()+"/"+sms[1].lSmsID.ToString());
			}
			else
			{
				switch (returnValue)
				{
					case -1:
						strResult="接口未初始化!!";
						break;
					case -2:
						strResult="发送超时!!";
						break;
					case -3:
						strResult="发送失败,可能是帐号过期或余额不足!!";
						break;
					case -4:
						strResult="发送失败,发送的信息内容中含有敏感关键字,禁止发送!!";
						break;
					case -5:
						strResult="发送失败,发送的目标号码为黑名单用户,禁止发送。!!";
						break;
					default:
						strResult="发送失败,无相关失败信息!!";
						break;
				}	
				MessageBox.Show("错误信息!"+strResult);
			}
		}

	}
}

⌨️ 快捷键说明

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