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

📄 form1.cs

📁 C# 第3方开发,实现短信下发,接收.这个是一个demo程序
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.IO;

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

        public int socket;

        [DllImport("smsdll.dll",
               EntryPoint = "App_Bind",
               CharSet = CharSet.Ansi,
               CallingConvention = CallingConvention.StdCall)]
        public static extern int App_Bind(string ip, int port, string user, string password);

        [DllImport("smsdll.dll",
               EntryPoint = "App_Unbind",
               CharSet = CharSet.Ansi,
               CallingConvention = CallingConvention.StdCall)]
        public static extern int App_Unbind(int socket);

        [DllImport("smsdll.dll",
              EntryPoint = "App_Submit",
              CharSet = CharSet.Ansi,//Unicode,
           CallingConvention = CallingConvention.Cdecl)]//Cdecl
        public static extern int App_Submit(int socket, string gwid, string innerservid, byte pktotal,
                                            byte pknum, string servid, byte feeusertype, string feetermid,
                                            byte feetermtype, byte msgfmt, string feetype, string feecode,
                                            string srcid, string desttermid, byte desttermtype, string content,
                                            string masid, string appname, int index);//string linkid, 
        [DllImport("smsdll.dll",
             EntryPoint = "App_Deliver_sms",
             CharSet = CharSet.Ansi,//Unicode,
             CallingConvention = CallingConvention.Cdecl)]//Cdecl
        public static extern int App_Deliver_sms(int socket, ref string MsgContent, ref string InDataGwid,
                                                             ref string SrcTrminalId, ref string DestId);


      
                public void Deliver()
                {
                    int ret = 0;
                  
                    string MsgContent = "";
                    string InDataGwid = "";
                    string SrcTrminalId = "";
                    string DestId = "";
                    StreamWriter SW;
                    while (socket > 0)
                    {
                        ret = App_Deliver_sms(socket, ref MsgContent, ref InDataGwid, ref SrcTrminalId, ref DestId);
                        if (ret > 0)
                        {
                           
                            SW=File.AppendText("E:\\new.txt");
                           // SW.WriteLine("This Line Is Appended");
                            SW.WriteLine(MsgContent);
                            SW.Close();
                            continue;
                        }
                        Thread.Sleep(1000);
                    }

                }


        private void button1_Click(object sender, EventArgs e)
        {
            string ip = textBox1.Text;
            int port = 7890;

            string user = textBox2.Text;
            string password = textBox3.Text;
            socket = App_Bind(ip, port, user, password);
            if (socket > 0)
            {
                MessageBox.Show("连接成功");
                  Thread t = new Thread(new ThreadStart(Deliver));
                  t.Start(); 
              
            }
            else
            {
                MessageBox.Show("连接失败");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int ret;
            ret = App_Unbind(socket);
            if (ret > 0)
            {
                MessageBox.Show("断开成功");
            }
            else
            {
                MessageBox.Show("断开失败");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {

            int ret;
            string gwid = this.textBox5.Text.Trim();
            string innerservid = this.textBox8.Text.Trim();
            byte pktotal = 1;
            byte pknum = 1;
            string servid = this.textBox6.Text.Trim();
            byte feeusertype = 0;
            string feetermid = "13500000000";
            byte feetermtype = 0;
            byte msgfmt = 15;
            string feetype = "03";
            string feecode = "100";
            string srcid = this.textBox7.Text.Trim();
            string desttermid = this.textBox4.Text.Trim();
            byte desttermtype = 0;
            string content = this.richTextBox1.Text.Trim();
            //string linkid = null;
            string masid = this.textBox10.Text.Trim();
            string appname = this.textBox11.Text.Trim();
            int index = 0;
            ret = App_Submit(socket, gwid, innerservid, pktotal,
                                pknum, servid, feeusertype, feetermid,
                                feetermtype, msgfmt, feetype, feecode,
                                srcid, desttermid, desttermtype, content,
                                masid, appname, index);//  linkid,   

            if (ret > 0)
            {
                MessageBox.Show("发送成功");
            }
            else
            {
                MessageBox.Show("发送失败");
            }

        }


     /*
        private void timer1_Tick(object sender, EventArgs e)
        {
            int ret = 0;
            string buf = "";
            string MsgContent = "";
            string InDataGwid = "";
            string SrcTrminalId = "";
            string DestId = "";
            // if (socket > 0)

            ret = App_Deliver_sms(socket, ref MsgContent, ref InDataGwid, ref SrcTrminalId, ref DestId);
            if (ret > 0)
            {
               buf = MsgContent;
              //  MessageBox.Show(MsgContent); 
            }

        }*/
    }
    
}

/* 
        public class SUBMIT{
		public Service_Head	head = new Service_Head();  
		public InterProtocol InData = new InterProtocol();
        public byte Pk_total;
        public byte Pk_number;
        public char[] Service_Id = new char[10];//业务标识,是数字、字母和符号的组合


        public byte Fee_UserType;	//计费用户类型字段:
    										//0:对目的终端MSISDN计费;
    										//1:对源终端MSISDN计费;
    										//2:对SP计费;
    										//3:表示本字段无效,
    										//对谁计费参见Fee_terminal_Id字段。
    	public char[] Fee_terminal_Id = new char [32];  //被计费用户的号码,
    										//当Fee_UserType为3时该值有效,
    										//当Fee_UserType为0、1、2时该值无意义。

        public byte Fee_terminal_type;   //被计费用户的号码类型,
    										//0:真实号码;1
    										//:伪码。
        public byte Msg_Fmt;		//短信信息格式
        public char[] FeeType = new char[2];		//资费类别:
												//01:对"计费用户号码"免费;
												//02:对"计费用户号码"按条计信息费;
												//03:对"计费用户号码"按包月收取信息费。

        public char[] FeeCode = new char[6];           //资费代码(以分为单位)

        public char[] Src_id = new char[21];     //源号码

        public char[] Dest_terminal_Id = new char[32];//接收短信的MSISDN号码。

        public byte Dest_terminal_tpye;	//接收短信的用户的号码类型,0:真实号码;1:伪码。// MorelatetoMtflag
        public byte Msg_Length;			//信息长度
        public char[] Msg_Content = new char[160];	//信息

        public char[] LinkID = new char[20];        //CMPP LinkID

        public char[] MasID = new char[20];         //mas服务器编号

        public char[] AppName = new char[5];        //企业接入应用名称编号
               
		public  int         resvlen;            //ems文件长度
        public char[] reserve = new char[256];   //上行:MOURL 下行EMS文件内容
                
        }
        
       public class SUBMITRESP{
	    public Service_Head		head;
        public byte Result;
	    public  char[] Reserve = new char[8];
        }

        public class Service_Head{
         public uint    Message_Length;
         public uint    Command_ID;
         public uint    Sequence1;
         }

        public class InterProtocol{
	     public char[] GWId = new char[8];
	     public char[] ServiceId = new char[8];   //内部业务代码:
	     public uint	Priority;
	     public uint	MsgId;
	     public char[]  UMsgID = new char[8];
         }
        */

/*
 int index = 0;
  SUBMIT m_submit = new SUBMIT();
  SUBMITRESP m_submitresp = new SUBMITRESP();
  m_submit.Dest_terminal_Id = this.textBox4.Text.Trim().ToCharArray();
  m_submit.Fee_terminal_Id = "13501107023".ToCharArray();
  m_submit.FeeType = "03".ToCharArray();
  m_submit.Service_Id = this.textBox8.Text.Trim().ToCharArray();
  m_submit.Src_id = this.textBox7.Text.Trim().ToCharArray();
  m_submit.Msg_Content = this.textBox6.Text.Trim().ToCharArray();
  m_submit.Msg_Fmt = 15;
  m_submit.Fee_UserType = 0;
  m_submit.Pk_total = 1;
  m_submit.Pk_number = 1;
  m_submit.MasID = this.textBox10.Text.Trim().ToCharArray();
  m_submit.InData.GWId = this.textBox5.Text.Trim().ToCharArray();
  m_submit.AppName = this.textBox11.Text.Trim().ToCharArray();
  m_submit.Fee_terminal_type = 0;
  m_submit.Dest_terminal_tpye = 0;
  m_submit.FeeCode = "100".ToCharArray();
  m_submit.InData.ServiceId = "0001".ToCharArray();
 */

⌨️ 快捷键说明

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