java实现来电弹屏_C#检测座机来电号码实现来电弹屏的实现方法

usingServiceDesk;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Runtime.InteropServices;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWinF

{public partial classForm1 : Form

{

//最关键的是下面4行调用DLL的声明

[DllImport("ZSCIDUDP.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "ZSCIDInit")]public static extern int ZSCIDInit(string AUDPS_IP, int AUDPS_Port, bool AIsSendState);

[DllImport("ZSCIDUDP.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "ZSCIDFree")]public static extern void ZSCIDFree(intARef);public int laidianCount { get; set; }public int FRef { get; set; }public voidzsinit()

{

FRef= ZSCIDInit("127.0.0.1", 9013, false);//第一个参数是来电后要发到UDP监听的IP,第二个参数是UDP监听的端口号

}public voidzsfree()

{if (FRef > 0)

{

ZSCIDFree(FRef);

FRef= 0;

}

}publicForm1()

{

InitializeComponent();

UdpLisenter(); //这里实现UDP监听

}private void Form1_Load(objectsender, EventArgs e)

{

zsinit();

}private void Form1_FormClosing(objectsender, FormClosingEventArgs e)

{

free();

}private void btn_init_Click(objectsender, EventArgs e)

{

init();

}private void btn_free_Click(objectsender, EventArgs e)

{

free();

}voidinit()

{try{

zsinit();

btn_free.Enabled= true;

btn_init.Enabled= false;

}catch(Exception ex)

{

MessageBox.Show(ex.Message,"ZSCIDInit异常");

}finally{

txt_FRef.AppendText("初始化【FRef=" + FRef + "】" +Environment.NewLine);

}

}voidfree()

{try{

txt_FRef.AppendText("释放前【FRef=" + FRef + "】" +Environment.NewLine);

zsfree();

btn_free.Enabled= false;

btn_init.Enabled= true;

}catch(Exception ex)

{

MessageBox.Show(ex.Message,"ZSCIDFree异常");

}finally{

txt_FRef.AppendText("释放后【FRef=" + FRef + "】" +Environment.NewLine);

}

}void StateHandler(stringdata)

{

txt_state.AppendText(data.ToString()+Environment.NewLine);

}private voidUdpLisenter()

{

Task.Factory.StartNew(()=>{int updPort = 9013;

UdpClient listener= newUdpClient(updPort);

listener.DontFragment= true;

listener.EnableBroadcast= true;

IPEndPoint RemoteIpEndPoint= newIPEndPoint(IPAddress.Loopback, updPort);while (true)

{try{byte[] bytes = listener.Receive(refRemoteIpEndPoint);string data =System.Text.Encoding.Default.GetString(bytes);string PhoneNumber =getnum(data);

writelog(PhoneNumber);

}catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

}

}, TaskCreationOptions.LongRunning|TaskCreationOptions.PreferFairness);

}string getnum(stringdata)

{string PhoneNumber = "";if (!string.IsNullOrWhiteSpace(data))

{string[] strs = data.Split(new string[] { "\r\n"}, StringSplitOptions.None);foreach (string k instrs)

{string[] tttmp = k.Split('=');if (tttmp.Length > 1 && tttmp[0] == "NUM")

PhoneNumber= tttmp[1];

}

}returnPhoneNumber;

}void writelog(stringnumber)

{if (!string.IsNullOrWhiteSpace(number))

{

txt_udprecieve.AppendText("[" + laidianCount++ + "]:" + number + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +Environment.NewLine);

LaidianWriter wer= newLaidianWriter();

wer.Push(number);

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值